Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: adoption of sfdx-scan-pull-request by mitch spano #6

Merged
merged 9 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions .github/workflows/code-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ jobs:
PMD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Setup Salesforce CLI
run: |
yarn global add @salesforce/cli
sf plugins:install @salesforce/sfdx-scanner
- name: SF Code Analyzer - PMD
run: |
sf scanner:run --engine pmd --target force-app --pmdconfig=config/pmd/ruleset.xml --format table --severity-threshold 3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Setup Salesforce CLI
run: |
yarn global add @salesforce/cli
sf plugins:install @salesforce/sfdx-scanner
- name: SF Code Analyzer - PMD - Report findings as comments
uses: mitchspano/[email protected]
with:
report-mode: comments
engine: pmd
pmdconfig: config/pmd/ruleset.xml
severity-threshold: 4
strictly-enforced-rules: '[{ "engine": "pmd", "category": "Performance", "rule": "AvoidDebugStatements" }]'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

RetireJS:
runs-on: ubuntu-latest
Expand All @@ -27,11 +34,16 @@ jobs:
run: |
yarn global add @salesforce/cli
sf plugins:install @salesforce/sfdx-scanner
- name: SF Code Analyzer - RetireJS
run: |
sf scanner:run --engine "retire-js" --target force-app --format table --severity-threshold 3
- name: SF Code Analyzer - RetireJS - Report findings as comments
uses: mitchspano/[email protected]
with:
report-mode: comments
engine: retire-js
severity-threshold: 4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

GraphEngine:
ESLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -40,11 +52,20 @@ jobs:
run: |
yarn global add @salesforce/cli
sf plugins:install @salesforce/sfdx-scanner
- name: SF Code Analyzer - Data Flow Analysis
- name: Install deps
run: |
sf scanner:run:dfa --target force-app --projectdir force-app --format table --severity-threshold 3
yarn install
- name: SF Code Analyzer - ESLint - Report findings as comments
uses: mitchspano/[email protected]
with:
report-mode: comments
engine: eslint
eslintconfig: .eslintrc.json
severity-threshold: 4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ESLint:
GraphEngine:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -53,9 +74,6 @@ jobs:
run: |
yarn global add @salesforce/cli
sf plugins:install @salesforce/sfdx-scanner
- name: Install deps
run: |
yarn install
- name: SF Code Analyzer - ESLint
- name: SF Code Analyzer - Data Flow Analysis
run: |
sf scanner:run --engine eslint --eslintconfig=.eslintrc.json --target "force-app/**/*.js" --format table --severity-threshold 3
sf scanner:run:dfa --target force-app --projectdir force-app --format table --severity-threshold 3
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
paths:
- force-app/**

jobs:
code-analyze:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Pull Request

on:
pull_request:
branches:
- main
paths:
- force-app/**

jobs:
code-analyze:
Expand Down
6 changes: 6 additions & 0 deletions force-app/main/default/classes/Greeter.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Greeter {
// this is another test
public static String greet(String name) {
return 'Hello ' + name + ' from Greeter';
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/Greeter.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
7 changes: 7 additions & 0 deletions force-app/main/default/classes/Test_Greeter.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@isTest
private class Test_Greeter {
@isTest
static void greet() {
System.assertEquals(Greeter.greet('John'), 'Hello John from Greeter');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute Value
Engine pmd-custom
Category Best Practices
Rule ApexAssertionsShouldIncludeMessage
Severity 3
Type Error
Message 'System.assertEquals' should have 3 parameters.
File force-app/main/default/classes/Test_Greeter.cls

}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/Test_Greeter.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
8 changes: 8 additions & 0 deletions force-app/main/default/classes/UglyUpdateCtrl.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Note: This class contains a FLS vulnerability to demo Salesforce Code Analyzer
public without sharing class UglyUpdateCtrl {
@AuraEnabled
public void execute(Account account) {
account.Description = 'My code should not perform DML without enforcing field level security';
update account;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute Value
Engine pmd-custom
Category Security
Rule ApexCRUDViolation
Severity 1
Type Error
Message Validate CRUD permission before SOQL/DML operation or enforce user mode
File force-app/main/default/classes/UglyUpdateCtrl.cls

}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/UglyUpdateCtrl.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ describe('c-hello-world', () => {
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});
});
4 changes: 3 additions & 1 deletion force-app/main/default/lwc/helloWorld/helloWorld.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<template> Hello World </template>
<template>

</template>
9 changes: 8 additions & 1 deletion force-app/main/default/lwc/helloWorld/helloWorld.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { LightningElement } from 'lwc';

export default class HelloWorld extends LightningElement {}
export default class HelloWorld extends LightningElement {

connectedCallback() {
// Vulnerable code snippet
var userInput = "<script>alert('XSS vulnerability!');</script>";
document.getElementById("output").innerHTML = userInput;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute Value
Engine eslint-custom
Category undefined
Rule @lwc/lwc/no-document-query
Severity 2
Type Error
Message Invalid usage of "getElementById". DOM query at the document level is forbidden.
File force-app/main/default/lwc/helloWorld/helloWorld.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute Value
Engine eslint-custom
Category undefined
Rule @lwc/lwc/no-inner-html
Severity 2
Type Error
Message Using 'innerHTML/outputHTML/insertAdjacentHTML' is not allowed
File force-app/main/default/lwc/helloWorld/helloWorld.js

}
6 changes: 3 additions & 3 deletions force-app/main/default/lwc/helloWorld/helloWorld.js-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<apiVersion>57.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
</LightningComponentBundle>
Loading