Skip to content

Commit 4b09d60

Browse files
authored
Merge pull request #934 from forcedotcom/dev
RELEASE: @W-12278374@: Merging dev to release for 3.8.0
2 parents 6b140a3 + b8bfc92 commit 4b09d60

File tree

99 files changed

+5945
-1520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5945
-1520
lines changed

messages/DefaultRuleManager.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ module.exports = {
33
"targetSkipped": "The specified target wasn't processed by any engines. Use the --engine parameter to select a different engine or specify a different target. Specified target: %s.",
44
"targetsSkipped": "The specified targets weren't processed by any engines: %s. Review your target and engine combinations and try again.",
55
"pathsDoubleProcessed": "One or more files were processed by eslint and eslint-lwc simultaneously. To remove possible duplicate violations, customize the targetPatterns property for eslint and eslint-lwc engines in %s on these files: %s.",
6+
},
7+
"error": {
8+
"cannotRunDfaAndNonDfaConcurrently": "DFA engines %s cannot be run concurrently with non-DFA engines %s"
69
}
710
}

messages/RunOutputProcessor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
"output": {
3+
"engineSummaryTemplate": "Executed %s, found %s violation(s) across %s file(s).",
4+
"noViolationsDetected": "Executed engines: %s. No rule violations found.",
5+
"sevThresholdSummary": "Rule violations of severity %s or more severe were detected.",
6+
"writtenToConsole": "Rule violations were logged to the console.",
7+
"writtenToOutFile": "Rule violations were written to %s."
8+
}
9+
}

messages/SfgeEngine.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
module.exports = {
2-
"spinnerStart": "Analyzing with Salesforce Graph Engine. See %s for details.",
3-
"pleaseWait": "Please wait"
2+
"messages": {
3+
"pleaseWait": "Please wait",
4+
"spinnerStart": "Analyzing with Salesforce Graph Engine. See %s for details."
5+
},
6+
"errors": {
7+
"failedWithoutProjectDir": `The --projectdir|-p flag is missing. Rerun your command with --projectdir|-p to allow Graph Engine to run, or with --engine|-e to exclude Graph Engine from execution.`
8+
}
49
};

messages/run-common.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
"flags": {
3+
"formatDescription": "specify results output format",
4+
"formatDescriptionLong": "Specifies results output format written directly to the console.",
5+
"normalizesevDescription": "return normalized severity 1 (high), 2 (moderate), and 3 (low), and the engine-specific severity",
6+
"normalizesevDescriptionLong": "Returns normalized severity 1 (high), 2 (moderate), and 3 (low), and the engine-specific severity. For the html option, the normalized severity is displayed instead of the engine severity.",
7+
"outfileDescription": "write output to a file",
8+
"outfileDescriptionLong": "Writes output to a file.",
9+
"projectdirDescription": "provide root directory of project",
10+
"projectdirDescriptionLong": "Provides the relative or absolute root project directory used to set the context for Graph Engine's analysis. Project directory must be a path, not a glob. Specify multiple values as a comma-separated list.",
11+
"sevthresholdDescription": "throw an error when a violation threshold is reached, the --normalize-severity is invoked, and severity levels are reset to the baseline",
12+
"sevthresholdDescriptionLong": "Throws an error when violations are found with equal or greater severity than the provided value. Values are 1 (high), 2 (moderate), and 3 (low). Exit code is the most severe violation. Using this flag also invokes the --normalize-severity flag."
13+
},
14+
"validations": {
15+
"cannotWriteTableToFile": "Format 'table' can't be written to a file. Specify a different format.",
16+
"outfileFormatMismatch": "The selected output format doesn't match the output file type. Output format: %s. Output file type: %s.",
17+
"outfileMustBeValid": "--outfile must be a well-formed filepath.",
18+
"outfileMustBeSupportedType": "--outfile must be of a supported type: .csv; .xml; .json; .html; .sarif.",
19+
"projectdirCannotBeGlob": "--projectdir cannot specify globs",
20+
"projectdirMustBeDir": "--projectdir must specify directories",
21+
"projectdirMustExist": "--projectdir must specify existing paths"
22+
}
23+
}

messages/run-dfa.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@ module.exports = {
33
"commandDescriptionLong": `Scans codebase with all DFA rules by default.
44
Specify the format of output and print results directly or as contents of a file that you provide with --outfile flag.`,
55
"flags": {
6-
"formatDescription": "specify results output format",
7-
"formatDescriptionLong": "Specifies results output format written directly to the console.",
8-
"normalizesevDescription": "return normalized severity in addition to the engine-specific severity",
9-
"normalizesevDescriptionLong": "Returns normalized severity 1 (high), 2 (moderate), and 3 (low) and the engine-specific severity. For the html option, normalized severity is displayed instead of the engine severity.",
10-
"outfileDescription": "write output to a file",
11-
"outfileDescriptionLong": "Writes output to a file.",
12-
"projectdirDescription": "provide root directory of project",
13-
"projectdirDescriptionLong": "Provides the relative or absolute root project directory used to set the context for Graph Engine's analysis. Project directory must be a path, not a glob. Specify multiple values as a comma-separated list.",
146
"ruledisablewarningviolationDescription": "disable warning violations from Salesforce Graph Engine. Alternatively, set value using environment variable `SFGE_RULE_DISABLE_WARNING_VIOLATION`",
157
"ruledisablewarningviolationDescriptionLong": "Disables warning violations, such as those on StripInaccessible READ access, to get only high-severity violations (default: false). Inherits value from SFGE_RULE_DISABLE_WARNING_VIOLATION env-var if set.",
168
"rulethreadcountDescription": "specify number of threads that evaluate DFA rules. Alternatively, set value using environment variable `SFGE_RULE_THREAD_COUNT`. Default is 4",
179
"rulethreadcountDescriptionLong": "Specifies number of rule evaluation threads, or how many entrypoints can be evaluated concurrently. Inherits value from SFGE_RULE_THREAD_COUNT env-var, if set. Default is 4.",
1810
"rulethreadtimeoutDescription": "specify timeout for individual rule threads in milliseconds. Alternatively, set the timeout value using environment variable `SFGE_RULE_THREAD_TIMEOUT`. Default: 90000 ms",
1911
"rulethreadtimeoutDescriptionLong": "Specifies time limit for evaluating a single entrypoint in milliseconds. Inherits value from SFGE_RULE_THREAD_TIMEOUT env-var if set. Default is 900,000 ms, or 15 minutes.",
20-
"sevthresholdDescription": "throw an error when violations of specific or higher severity are detected, and invoke --normalize-severity",
21-
"sevthresholdDescriptionLong": "Throws an error when violations are found with equal or greater severity than provided value. Values are 1 (high), 2 (moderate), and 3 (low). Exit code is the most severe violation. Using this flag also invokes the --normalize-severity flag.",
2212
"sfgejvmargsDescription": "specify Java Virtual Machine (JVM) arguments to optimize Salesforce Graph Engine execution to your system (optional)",
2313
"sfgejvmargsDescriptionLong": "Specifies Java Virtual Machine arguments to override system defaults while executing Salesforce Graph Engine. For multiple arguments, add them to the same string separated by space.",
2414
"targetDescription": "return location of source code",
@@ -27,12 +17,10 @@ module.exports = {
2717
"validations": {
2818
"methodLevelTargetCannotBeGlob": "Method-level targets supplied to --target cannot be globs",
2919
"methodLevelTargetMustBeRealFile": "Method-level target %s must be a real file",
30-
"projectdirCannotBeGlob": "--projectdir cannot specify globs",
31-
"projectdirMustBeDir": "--projectdir must specify directories",
32-
"projectdirMustExist": "--projectdir must specify existing paths"
20+
"projectdirIsRequired": "--projectdir is required for this command.",
3321
},
3422
"examples": `The paths specified for --projectdir must contain all files specified through --target cumulatively.
35-
$ sfdx sacnner:run:dfa --target "./myproject/main/default/classes/*.cls" --projectdir "./myproject/"
23+
$ sfdx scanner:run:dfa --target "./myproject/main/default/classes/*.cls" --projectdir "./myproject/"
3624
$ sfdx scanner:run:dfa --target "./**/*.cls" --projectdir "./"
3725
$ sfdx scanner:run:dfa --target "./dir1/file1.cls,./dir2/file2.cls" --projectdir "./dir1/,./dir2/"
3826
This example fails because the set of files included in --target is larger than that contained in --projectdir:

messages/run.js renamed to messages/run-pathless.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,26 @@ module.exports = {
88
"rulesetDescriptionLong": "[deprecated] One or more rulesets to run. Specify multiple values as a comma-separated list.",
99
"targetDescription": "source code location",
1010
"targetDescriptionLong": "Source code location. May use glob patterns. Specify multiple values as a comma-separated list.",
11-
"formatDescription": "specify results output format",
12-
"formatDescriptionLong": "Specifies output format with results written directly to the console.",
13-
"outfileDescription": "write output to a file",
14-
"outfileDescriptionLong": "Writes output to a file.",
1511
"envDescription": "[deprecated] override ESLint's default environment variables, in JSON-formatted string",
1612
"envDescriptionLong": "[deprecated] Overrides ESLint's default environmental variables, in JSON-formatted string.",
1713
"envParamDeprecationWarning": "--env parameter is being deprecated, and will be removed in a future release.",
1814
"tsconfigDescription": "location of tsconfig.json file",
1915
"tsconfigDescriptionLong": "Location of tsconfig.json file used by eslint-typescript engine.",
20-
"stDescription": "throw an error when a violation threshold is reached, the --normalize-severity is invoked, and severity levels are reset to the baseline",
21-
"stDescriptionLong": "Throws an error when violations are found with equal or greater severity than the provided value. --normalize-severity is invoked and severity levels are reset to the baseline. Normalized severity values are: 1 (high), 2 (moderate), and 3 (low). Exit code is the most severe violation.",
22-
"nsDescription": "return normalized severity 1 (high), 2 (moderate), and 3 (low), and the engine-specific severity",
23-
"nsDescriptionLong": "Returns normalized severity 1 (high), 2 (moderate), and 3 (low), and the engine-specific severity. For the html option, the normalized severity is displayed instead of the engine severity.",
2416
'engineDescription': "specify which engines to run",
2517
'engineDescriptionLong': "Specifies one or more engines to run. Submit multiple values as a comma-separated list.",
2618
'eslintConfigDescription': 'specify the location of eslintrc config to customize eslint engine',
2719
'eslintConfigDescriptionLong': 'Specifies the location of eslintrc config to customize eslint engine.',
2820
'pmdConfigDescription': 'specify location of PMD rule reference XML file to customize rule selection',
2921
'pmdConfigDescriptionLong': 'Specifies the location of PMD rule reference XML file to customize rule selection.',
3022
"verboseViolationsDescription": "return retire-js violation message details",
31-
"verboseViolationsDescriptionLong": "Returns retire-js violation messages details about each vulnerability, including summary, Common Vulnerabilities and Exposures (CVE), and URLs."
23+
"verboseViolationsDescriptionLong": "Returns retire-js violation messages details about each vulnerability, including summary, Common Vulnerabilities and Exposures (CVE), and URLs."
3224
},
3325
"validations": {
3426
"methodLevelTargetingDisallowed": "The target '%s' is invalid because method-level targeting isn't supported with this command.",
35-
"outfileFormatMismatch": "The selected output format doesn't match the output file type. Output format: %s. Output file type: %s.",
36-
"outfileMustBeValid": "--outfile must be a well-formed filepath.",
37-
"outfileMustBeSupportedType": "--outfile must be of a supported type: .csv; .xml; .json; .html; .sarif.",
38-
"cannotWriteTableToFile": "Format 'table' can't be written to a file. Specify a different format.",
3927
"tsConfigEslintConfigExclusive": "A --tsconfig flag can't be specified with an --eslintconfig flag. Review your tsconfig path in the eslint config file under 'parseOptions.project'.",
4028
},
4129
"output": {
42-
"noViolationsDetected": "Executed engines: %s. No rule violations found.",
4330
"invalidEnvJson": "--env parameter must be a well-formed JSON.",
44-
"engineSummaryTemplate": "Executed %s, found %s violation(s) across %s file(s).",
45-
"writtenToOutFile": "Rule violations were written to %s.",
46-
"writtenToConsole": "Rule violations were logged to the console.",
47-
"sevThresholdSummary": "Rule violations of severity %s or more severe were detected.",
48-
"pleaseSeeAbove": "Review the logs.",
4931
"filtersIgnoredCustom": "Rule filters will be ignored by engines that are run with custom config using --pmdconfig or --eslintconfig flags. Modify your config file to include your filters."
5032
},
5133
"rulesetDeprecation": "The 'ruleset' command parameter is deprecated. Use 'category' instead.",
@@ -96,5 +78,13 @@ This example uses --normalize-severity to output normalized severity and engine-
9678
9779
This example uses --severity-threshold to throw a non-zero exit code when rule violations of normalized severity 2 or greater are found. If any violations with the specified severity (or greater) are found, the exit code equals the severity of the most severe violation.
9880
$ sfdx scanner:run --target "/some-project/" --severity-threshold 2
81+
82+
The paths specified for --projectdir must contain all files specified through --target cumulatively.
83+
$ sfdx scanner:run --target "./myproject/main/default/classes/*.cls" --projectdir "./myproject/"
84+
$ sfdx scanner:run --target "./**/*.cls" --projectdir "./"
85+
$ sfdx scanner:run --target "./dir1/file1.cls,./dir2/file2.cls" --projectdir "./dir1/,./dir2/"
86+
87+
This example fails because the set of files included in --target is larger than that contained in --projectdir:
88+
$ sfdx scanner:run --target "./**/*.cls" --projectdir "./myproject/"
9989
`
10090
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/sfdx-scanner",
33
"description": "Static code scanner that applies quality and security rules to Apex code, and provides feedback.",
4-
"version": "3.7.1",
4+
"version": "3.8.0",
55
"author": "ISV SWAT",
66
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
77
"dependencies": {
@@ -22,7 +22,7 @@
2222
"eslint": "^8.10.0",
2323
"eslint-plugin-import": "^2.25.4",
2424
"eslint-plugin-jest": "^26.1.1",
25-
"find-java-home": "1.1.0",
25+
"find-java-home": "1.2.2",
2626
"globby": "^11.0.0",
2727
"html-escaper": "^3.0.0",
2828
"is-zip": "^1.0.0",

sfge/src/main/java/com/salesforce/Main.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.salesforce.rules.AbstractRule;
1818
import com.salesforce.rules.AbstractRuleRunner;
1919
import com.salesforce.rules.RuleRunner;
20-
import com.salesforce.rules.RuleUtil;
2120
import com.salesforce.rules.Violation;
2221
import com.salesforce.rules.ops.ProgressListenerProvider;
2322
import java.util.Arrays;
@@ -28,30 +27,28 @@
2827
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
2928

3029
/**
31-
* The main class, invoked by sfdx-scanner. `catalog` flow lists all of the available rules in a
32-
* standardized format.
33-
*
34-
* <p>The `execute` flow accepts as a parameter the name of a file whose contents are a JSON with
35-
* the following structure:
30+
* The main class, invoked by sfdx-scanner. The first arg should be either `catalog` or `execute`,
31+
* and determines which flow runs. <br>
32+
* For `catalog`, the second arg should be either `pathless` or `dfa`. Enabled rules matching that
33+
* type will be logged as a JSON. No meaningful environment variables exist for this flow. Exit code
34+
* 0 means success. Any other exit code means failure. <br>
35+
* For `execute`, the second arg should be the path to a JSON file whose contents are structured as:
3636
*
3737
* <ol>
38-
* <li>rulesToRun: An array of rule names.
39-
* <li>projectDirs: An array of directories from which the graph should be built.
40-
* <li>targets: An array of objects with a `targetFile` property indicating the file to be
41-
* analyzed and a `targetMethods` property indicating individual methods.
38+
* <li>rulesToRun: an array of rule names.
39+
* <li>projectDirs: an array of directories from which the graph should be built.
40+
* <li>targets: an array of objects with a `targetFile` property indicating the file to be
41+
* analyzed and a `targetMethods` property that may optionally indicate individual methods
42+
* within that file.
4243
* </ol>
4344
*
44-
* <p>Exit codes:
45-
*
46-
* <ul>
47-
* <li>Negative numbers indicate an internal error.
48-
* <li>0 indicates a successful run with * no violations.
49-
* <li>Positive numbers indicate a successful run with exit-code-many violations.
50-
* </ul>
45+
* The following exit codes are possible:
5146
*
52-
* <p>Usage: mvn exec:java -Dexec.mainClass=com.salesforce.Main -Dexec.args="catalog" OR mvn
53-
* exec:java -Dexec.mainClass=com.salesforce.Main -Dexec.args="execute [path to file listing
54-
* targets] [path to file listing sources] [comma-separated rules]"
47+
* <ol>
48+
* <li>0: Successful run without violations.
49+
* <li>1: Internal error with no violations.
50+
* <li>4: Successful run with violations.5: Internal error with some violations.>
51+
* </ol>
5552
*/
5653
@SuppressWarnings(
5754
"PMD.SystemPrintln") // Since println is currently used to communicate to outer layer
@@ -97,19 +94,22 @@ int process(String... args) {
9794

9895
switch (action) {
9996
case CATALOG:
100-
return catalog();
97+
return catalog(args);
10198
case EXECUTE:
10299
return execute(args);
103100
default:
104101
throw new ProgrammingException("Unhandled action: " + action);
105102
}
106103
}
107104

108-
private int catalog() {
105+
/** Expectations for args documented in class header above. */
106+
private int catalog(String... args) {
109107
LOGGER.info("Invoked CATALOG flow");
108+
CliArgParser.CatalogArgParser cap = new CliArgParser.CatalogArgParser();
110109
List<AbstractRule> rules;
111110
try {
112-
rules = RuleUtil.getEnabledRules();
111+
cap.parseArgs(args);
112+
rules = cap.getSelectedRules();
113113
} catch (SfgeException | SfgeRuntimeException ex) {
114114
dependencies.printError(ex.getMessage());
115115
return EXIT_WITH_INTERNAL_ERROR_NO_VIOLATIONS;
@@ -119,6 +119,7 @@ private int catalog() {
119119
return EXIT_GOOD_RUN_NO_VIOLATIONS;
120120
}
121121

122+
/** Expectations for args documented in class header above. */
122123
private int execute(String... args) {
123124
LOGGER.info("Invoked EXECUTE flow");
124125
// Parse the arguments with our delegate class.

sfge/src/main/java/com/salesforce/apex/jorje/ASTConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import apex.jorje.semantic.ast.expression.ReferenceExpression;
2828
import apex.jorje.semantic.ast.expression.SoqlExpression;
2929
import apex.jorje.semantic.ast.expression.SoslExpression;
30+
import apex.jorje.semantic.ast.expression.SuperMethodCallExpression;
3031
import apex.jorje.semantic.ast.expression.ThisMethodCallExpression;
3132
import apex.jorje.semantic.ast.expression.ThisVariableExpression;
3233
import apex.jorje.semantic.ast.expression.TriggerVariableExpression;
@@ -145,6 +146,8 @@ public static String getVertexLabel(Class<? extends AstNode> clazz) {
145146
public static final String REFERENCE_EXPRESSION = getVertexLabel(ReferenceExpression.class);
146147
public static final String RETURN_STATEMENT = getVertexLabel(ReturnStatement.class);
147148
public static final String STANDARD_CONDITION = getVertexLabel(StandardCondition.class);
149+
public static final String SUPER_METHOD_CALL_EXPRESSION =
150+
getVertexLabel(SuperMethodCallExpression.class);
148151
public static final String THIS_METHOD_CALL_EXPRESSION =
149152
getVertexLabel(ThisMethodCallExpression.class);
150153
public static final String THIS_VARIABLE_EXPRESSION =

0 commit comments

Comments
 (0)