Monday 18 March 2024

Salesforce Code Analyzer Command


Salesforce Code Analyzer Command example/Sample


Installing Salesforce code analyzer:

Link: https://forcedotcom.github.io/sfdx-scanner/en/
v3.x/getting-started/install/

Go to VScode -- > New terminal - -> Enter below command
(It installs analyser)
Project location > sfdx plugins:install @salesforce/sfdx-scanner

To check whether the code analyzer is installed or not:

(It checks whether the code analyzer is installed or not)
Project location > sfdx plugins -->

To generate a report Go: to the command prompt

and enter the below command :

(Can generate different reports like .xml, and .csv as well)
Project location > sfdx scanner:run --target "**/default/**"
--outfile results.html


GENERIC COMMAND for Code Scanner

$sfdx scanner:run --target './force-app/main/default/' --projectdir
'./force-app/main/default' --format csv --outfile=codereviewGeneric.csv

CPD Command
$sfdx scanner:run --engine cpd --target './force-app/main/default/'
--projectdir './force-app/main/default' --format csv --outfile=codereviewCPD.csv

DFA Command - Graph Engine (this one takes time to generate report)
$sfdx scanner:run:dfa --target './force-app/main/default/' --projectdir
'./force-app/main/default' --format csv --outfile=codereviewDFA.csv 




reference from : 

https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/dfa.html

https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/cpd-engine.html


Salesforce Code Analyzer Command example/Sample