Skip to content

Commit

Permalink
Merge pull request #1037 from forcedotcom/dev
Browse files Browse the repository at this point in the history
RELEASE: @W-12699834@: Promote dev to release for 3.11.0
  • Loading branch information
rmohan20 authored Mar 29, 2023
2 parents 33e0fff + a61a91e commit 4fceb75
Show file tree
Hide file tree
Showing 89 changed files with 3,500 additions and 2,139 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Instructions [here](CONTRIBUTING.md).

# Usage

Here is the information on [How to Install the plugin](https://forcedotcom.github.io/sfdx-scanner/en/getting-started/install/)
Here is the information on [How to Install the plugin](https://forcedotcom.github.io/sfdx-scanner/en/v3.x/getting-started/install/)

Please check out the [Salesforce CLI Scanner Plug-In Command Reference](https://forcedotcom.github.io/sfdx-scanner/en/scanner-commands/run/) for usage and demo of the plugin.
Please check out the [Salesforce CLI Scanner Plug-In Command Reference](https://forcedotcom.github.io/sfdx-scanner/en/v3.x/scanner-commands/run/) for usage and demo of the plugin.
2 changes: 2 additions & 0 deletions messages/run-common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
"flags": {
"categoryDescription": "one or more categories of rules to run",
"categoryDescriptionLong": "One or more categories of rules to run. Specify multiple values as a comma-separated list.",
"formatDescription": "specify results output format",
"formatDescriptionLong": "Specifies results output format written directly to the console.",
"normalizesevDescription": "return normalized severity 1 (high), 2 (moderate), and 3 (low), and the engine-specific severity",
Expand Down
4 changes: 2 additions & 2 deletions messages/run-dfa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions messages/run-pathless.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = {
"commandDescription": "scan a codebase with a selection of rules",
"commandDescriptionLong": `Scans a codebase with a selection of rules. You can scan the codebase with all the rules in the registry, or use parameters to filter the rules based on rulename, category, or ruleset. You can specify the format of the output, such as XML or JUnit. You can print the output to the console (default) or to a file using the --outfile parameter.`,
"flags": {
"categoryDescription": "one or more categories of rules to run",
"categoryDescriptionLong": "One or more categories of rules to run. Specify multiple values as a comma-separated list.",
"rulesetDescription": "[deprecated] rulesets to run",
"rulesetDescriptionLong": "[deprecated] One or more rulesets to run. Specify multiple values as a comma-separated list.",
"targetDescription": "source code location",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/sfdx-scanner",
"description": "Static code scanner that applies quality and security rules to Apex code, and provides feedback.",
"version": "3.10.0",
"version": "3.11.0",
"author": "ISV SWAT",
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pmd-cataloger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group = "sfdx"
version = "1.0"

val distDir = "$buildDir/../../dist"
val pmdVersion = "6.54.0"
val pmdVersion = "6.55.0"
val pmdFile = "pmd-bin-$pmdVersion.zip"
val pmdUrl = "https://github.com/pmd/pmd/releases/download/pmd_releases%2F${pmdVersion}/${pmdFile}"
val skippableJarRegexes = setOf("""^common_[\d\.-]*\.jar""".toRegex(),
Expand Down
5 changes: 3 additions & 2 deletions sfge/src/main/java/com/salesforce/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ int process(String... args) {
}
if (args.length == 0) {
// No args means we can't do anything productive.
dependencies.printError(UserFacingMessages.REQUIRES_AT_LEAST_ONE_ARGUMENT);
dependencies.printError(
UserFacingMessages.InvocationErrors.REQUIRES_AT_LEAST_ONE_ARGUMENT);
return EXIT_WITH_INTERNAL_ERROR_NO_VIOLATIONS;
}

Expand Down Expand Up @@ -222,7 +223,7 @@ private String formatError(Throwable error) {
return ERROR_PREFIX
+ (error.getCause() != null
? String.format(
UserFacingMessages.EXCEPTION_FORMAT_TEMPLATE,
UserFacingMessages.CompilationErrors.EXCEPTION_FORMAT_TEMPLATE,
error.getMessage(),
error.getCause().getMessage())
: error.getMessage());
Expand Down
3 changes: 2 additions & 1 deletion sfge/src/main/java/com/salesforce/apex/jorje/JorjeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public static AstNodeWrapper<?> compileApexFromString(String sourceCode) {
.map(
e ->
String.format(
UserFacingMessages.INVALID_SYNTAX_TEMPLATE,
UserFacingMessages.CompilationErrors
.INVALID_SYNTAX_TEMPLATE,
e.getLoc().getLine(),
e.getLoc().getColumn(),
e.getError()))
Expand Down
5 changes: 3 additions & 2 deletions sfge/src/main/java/com/salesforce/cli/CliArgParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public CLI_ACTION getCliAction(String... args) {
return CLI_ACTION.CATALOG;
} else {
throw new InvocationException(
String.format(UserFacingMessages.UNRECOGNIZED_ACTION, actionArg));
String.format(
UserFacingMessages.InvocationErrors.UNRECOGNIZED_ACTION, actionArg));
}
}

Expand Down Expand Up @@ -120,7 +121,7 @@ public void parseArgs(String... args) {
if (args.length != ARG_COUNT) {
throw new InvocationException(
String.format(
UserFacingMessages.INCORRECT_ARGUMENT_COUNT,
UserFacingMessages.InvocationErrors.INCORRECT_ARGUMENT_COUNT,
ARG_COUNT,
args.length));
}
Expand Down
72 changes: 40 additions & 32 deletions sfge/src/main/java/com/salesforce/config/UserFacingMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
public final class UserFacingMessages {

public static final class RuleDescriptions {
public static final String APEX_NULL_POINTER_EXCEPTION_RULE =
"Identfies Apex operations that dereference null objects and throw NullPointerExceptions.";
public static final String UNIMPLEMENTED_TYPE_RULE =
"Identifies abstract classes and interfaces that are non-global and don't have implementations or extensions.";
}

public static final class RuleViolationTemplates {
public static final String APEX_NULL_POINTER_EXCEPTION_RULE =
"%s dereferences a null object. Review your code and add a null check.";
/** CRUD/FLS Violation messages */
// format: "CRUD" or "FLS", DML operation, Object type, Field information
public static final String MISSING_CRUD_FLS_CHECK =
Expand All @@ -21,46 +25,50 @@ public static final class RuleViolationTemplates {
// Second %s is the name of a class or interface.
public static final String UNIMPLEMENTED_TYPE_RULE = "Extend, implement, or delete %s %s";
public static final String LIMIT_REACHED_VIOLATION_MESSAGE =
"%s. The analysis preemptively stopped running on this path to prevent an OutOfMemory error. Rerun Graph Engine targeting this entry method with a larger heap space.";
"%s. The analysis preemptively stopped running on this path to prevent an OutOfMemory error. Rerun Graph Engine and target this entry method with a larger heap space.";
}

/** Main args and process checks * */
public static final String REQUIRES_AT_LEAST_ONE_ARGUMENT =
"SFGE invocation requires at least one argument.";

public static final String UNRECOGNIZED_ACTION = "Unrecognized action to invoke SFGE: %s.";
public static final String INCORRECT_ARGUMENT_COUNT =
"Wrong number of arguments. Expected %d; received %d";
public static final class InvocationErrors {
public static final String REQUIRES_AT_LEAST_ONE_ARGUMENT =
"SFGE invocation requires at least one argument.";
public static final String UNRECOGNIZED_ACTION = "Unrecognized action to invoke SFGE: %s.";
public static final String INCORRECT_ARGUMENT_COUNT =
"Wrong number of arguments. Expected %d; received %d";
}

/** UserActionException * */
public static final class UserActionMessage {
// format: filename,defined type, line number
public static final String UNREACHABLE_CODE =
"Remove unreachable code to proceed with the analysis: %s,%s:%d";
public static final String VARIABLE_DECLARED_MULTIPLE_TIMES =
"Rename or delete this reused variable to proceed with the analysis: %s,%s:%d";
}

// format: filename,defined type, line number
public static final String UNREACHABLE_CODE =
"Remove unreachable code to proceed with the analysis: %s,%s:%d";

public static final String VARIABLE_DECLARED_MULTIPLE_TIMES =
"This variable is reused. Rename or delete it to proceed with the analysis: %s,%s:%d";

public static final String INSUFFICIENT_HEAP_SPACE =
"There's insufficient heap space (%d bytes) to execute Graph Engine. Increase heap space using --sfgejvmargs option and retry.";

public static final String STRIP_INACCESSIBLE_READ_WARNING_TEMPLATE =
"For stripInaccessible checks on READ operation, Salesforce Graph Engine can't verify that only sanitized data is used after the check. Discard unsanitized data for [%2$s].";

public static final String UNRESOLVED_CRUD_FLS_TEMPLATE =
"Salesforce Graph Engine couldn't resolve the parameter passed to [%2$s] operation%4$s. Confirm that this operation has the necessary %1$s checks.";

public static final String FIELDS_MESSAGE_TEMPLATE = " with field(s) [%s]";
public static final String FIELD_HANDLING_NOTICE =
". Confirm that the objects and fields involved in these segments have FLS checks: [%s]";
public static final class PathExpansionTemplates {
public static final String INSUFFICIENT_HEAP_SPACE =
"There's insufficient heap space (%d bytes) to execute Graph Engine. Increase heap space using the --sfgejvmargs option and retry.";
public static final String PATH_EXPANSION_LIMIT_REACHED =
"Graph Engine reached the path expansion upper limit (%d)";
}

public static final String INVALID_SYNTAX_TEMPLATE = "Invalid syntax at %d:%d. (%s)";
public static final class CrudFlsTemplates {

public static final String FIX_COMPILATION_ERRORS =
"Graph engine encountered compilation errors. Fix the errors in %s and retry.";
public static final String STRIP_INACCESSIBLE_READ_WARNING_TEMPLATE =
"For stripInaccessible checks on READ operation, Salesforce Graph Engine can't verify that only sanitized data is used after the check. Discard unsanitized data for [%2$s].";
public static final String UNRESOLVED_CRUD_FLS_TEMPLATE =
"Salesforce Graph Engine couldn't resolve the parameter passed to [%2$s] operation%4$s. Confirm that this operation has the necessary %1$s checks.";
public static final String FIELDS_MESSAGE_TEMPLATE = " with field(s) [%s]";
public static final String FIELD_HANDLING_NOTICE =
". Confirm that the objects and fields involved in these segments have FLS checks: [%s]";
}

public static final String EXCEPTION_FORMAT_TEMPLATE = "%s, Caused by:\n%s";
public static final class CompilationErrors {

public static final String PATH_EXPANSION_LIMIT_REACHED =
"Graph Engine reached the path expansion upper limit (%d).";
public static final String INVALID_SYNTAX_TEMPLATE = "Invalid syntax at %d:%d. (%s)";
public static final String FIX_COMPILATION_ERRORS =
"Graph engine encountered compilation errors. Fix the errors in %s and retry.";
public static final String EXCEPTION_FORMAT_TEMPLATE = "%s, Caused by:\n%s";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ public static GraphTraversal<Object, Object> hasWithin(
}
}

public static GraphTraversal<Object, Object> hasStartingWith(
String nodeType, String property, String value) {
String caseSafeVariant = toCaseSafeProperty(property).orElse(null);
if (caseSafeVariant != null) {
return __.has(
nodeType, caseSafeVariant, TextP.startingWith(toCaseSafeValue(value)));
} else {
return __.has(nodeType, property, TextP.startingWith(value));
}
}

public static GraphTraversal<Object, Object> hasEndingWith(
String nodeType, String property, String value) {
if (property.equalsIgnoreCase(Schema.DEFINING_TYPE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private void addEdge(String name, Vertex from, Vertex to) {
// Ask user to fix unreachable code
throw new UserActionException(
String.format(
UserFacingMessages.UNREACHABLE_CODE,
UserFacingMessages.UserActionMessage.UNREACHABLE_CODE,
GremlinUtil.getFileName(g, to),
to.value(Schema.DEFINING_TYPE),
to.value(Schema.BEGIN_LINE)));
Expand Down
Loading

0 comments on commit 4fceb75

Please sign in to comment.