Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Last active October 30, 2020 20:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msrivastav13/97a102a58c6fb1aee1fe45ac42990e82 to your computer and use it in GitHub Desktop.
Save msrivastav13/97a102a58c6fb1aee1fe45ac42990e82 to your computer and use it in GitHub Desktop.
Run Salesforce CLI scanner on current file
{
"version": "2.0.0",
"tasks": [
{
"label": "SFDX: Run Security Scan on Current File",
"type": "shell",
"command": "sfdx",
"args": [
"scanner:run",
"-t",
"${relativeFile}",
"-c",
"Security"
],
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
}
]
}
@msrivastav13
Copy link
Author

msrivastav13 commented Oct 9, 2020

  1. Within .vscode directory create a tasks.json file. Create the directory .vscode within project root if you do not have
  2. CMD + SHIFT + B on current file if on MAC or CTRL + SHIFT + B on windows
  3. Select the SFDX: Run Scanner on Current File

@ckarimanoor
Copy link

Hi Mohith,

when i used your tasks.json file and ran the CMD + SHIFT + B on current file, i got the rules error.

ERROR running scanner:run: Oct 28, 2020 8:26:39 PM net.sourceforge.pmd.RuleSetFactory parseRuleReferenceNode
WARNING: Use Rule name category/apex/errorprone.xml/ApexCSRF instead of the deprecated Rule name category/apex/security.xml/ApexCSRF. PMD 7.0.0 will remove support for this deprecated Rule name usage.
Where do i change the Rule in the file.

Upon taking a look at this file, looks like we have to insert some rule ref elements , but i am not sure where to add:
https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#apexcsrf
Please suggest.

@msrivastav13
Copy link
Author

Sounds like issue is very specific to an apex file. Without checking the code it is hard for me to tell.

This is also related to PMD and not related to tasks.json so feel free to raise issue on PMD repo for help!

@rsindall
Copy link

rsindall commented Oct 30, 2020

Hey Mohith,

Thanks for the example task file, how do we set it up to be globally available?

@msrivastav13
Copy link
Author

Hello,

Can you explain me what do you mean by globally here? Do you mean for all project workspace?

Or to scan all the files?

@rsindall
Copy link

Hi Mohith

Apologies, I wasn't very clear.

I meant, how can I set up the task so that it is always available in all projects?

@msrivastav13
Copy link
Author

Hi Robert,

Unfortunately project scaffold command of sfdx at this point does not let you to add your own scaffold templates.

You can build a salesforce cli plugin if you need this in every project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment