Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
719aced
@W-11179348@: improving runtime of windows-unit-tests
gkjung Jun 7, 2022
97acd50
Merge pull request #716 from forcedotcom/d/W-11179348
gkjung Jun 23, 2022
63a0496
@W-10459675@: Added support for NamespaceAccessible annotation.
jfeingold35 Jun 21, 2022
2dddfce
@W-10459675@: Fixed typo in test name.
jfeingold35 Jun 22, 2022
9164a2e
@W-10459675@: Integrating feedback from code review.
jfeingold35 Jun 24, 2022
3ed56f4
Merge pull request #735 from forcedotcom/d/W-10459675
jfeingold35 Jun 24, 2022
c49760e
@W-10459675@: Part 2 of several. Added RemoteAction-annotated methods…
jfeingold35 Jun 24, 2022
9a5cb3b
@W-10459675@: Updated typo in documentation.
jfeingold35 Jun 27, 2022
a978ae7
Merge pull request #736 from forcedotcom/d/W-10459675-2
jfeingold35 Jun 27, 2022
68bb2c7
@W-10459675@: Part 3 of several. Added global methods as sources.
jfeingold35 Jun 27, 2022
e4f834c
@W-10459675@: Fixed issue in which implicitly declared global methods…
jfeingold35 Jun 27, 2022
10fc89e
@W-10459675@: Added additional tests as per code review.
jfeingold35 Jun 28, 2022
a9edb21
Merge pull request #737 from forcedotcom/d/W-10459675-3
jfeingold35 Jun 28, 2022
d64825d
Add more information while handling error
rmohan20 Jun 14, 2022
1dfce6a
work in progress - static block recognition part
rmohan20 Jun 22, 2022
d1eb1c5
Solution to handle static blocks in code - draft
rmohan20 Jun 24, 2022
81ba383
Invoking static block from static class scope
rmohan20 Jun 30, 2022
ecc2bdd
Removing intermediary code now unused
rmohan20 Jun 30, 2022
a9017ba
Adding child index to synthetic methods
rmohan20 Jun 30, 2022
89f7cd6
Attempting to remove compilation error in CircleCI
rmohan20 Jul 5, 2022
d7fd360
Addressing PR feedback
rmohan20 Jul 5, 2022
ddfed9e
Merge pull request #740 from forcedotcom/rm/handleStaticBlock
jfeingold35 Jul 6, 2022
e8832fb
@W-10459675@: Part 4 of several. Added Messaging.InboundEmailHandler …
jfeingold35 Jul 5, 2022
0ae8880
@W-10459675@: Added documentation for methods.
jfeingold35 Jul 5, 2022
92e2a45
@W-10459675@: Integrated changes from rebase into PR.
jfeingold35 Jul 6, 2022
462eca9
@W-10459675@: Fixed failing tests.
jfeingold35 Jul 6, 2022
508aef7
SFGE: adding ability to programatically enable/disable rules
rmohan20 Jun 30, 2022
aa1647c
Applying PR feedback
rmohan20 Jul 6, 2022
7e822f5
Adding missed file
rmohan20 Jul 6, 2022
36f2c23
Merge pull request #742 from forcedotcom/d/W-10459675-4
jfeingold35 Jul 6, 2022
1c2c604
@W-10459675@: Part 5 of 5. Added InvocableMethod-annotated methods as…
jfeingold35 Jul 6, 2022
7b56980
Merge branch 'dev-3' into rm/configToDisableSfgeRules
rmohan20 Jul 6, 2022
971f881
Merge pull request #743 from forcedotcom/d/W-10459675-5
jfeingold35 Jul 6, 2022
941ab87
@W-10459675@: Renamed InheritanceEdgeBuilder to reflect its broadened…
jfeingold35 Jul 6, 2022
f15adeb
Merge pull request #744 from forcedotcom/d/W-10459675-supp-1
jfeingold35 Jul 6, 2022
0061a5b
Merge branch 'dev-3' into rm/configToDisableSfgeRules
rmohan20 Jul 7, 2022
5f13a28
Merge pull request #741 from forcedotcom/rm/configToDisableSfgeRules
rmohan20 Jul 7, 2022
f8aaac7
@W-11404189@: Added VIRTUAL and OVERRIDE keywords to graph.
jfeingold35 Jul 11, 2022
ce05d2e
Merge pull request #746 from forcedotcom/d/W-11404189
jfeingold35 Jul 11, 2022
e0416ac
Adding error message for unreachable code
rmohan20 Jul 11, 2022
73dd811
Merge pull request #747 from forcedotcom/rm/errorOnUnReachable
rmohan20 Jul 13, 2022
96e597d
Upgrading to PMD 6.47.0
rmohan20 Jul 13, 2022
db9bb62
Merge pull request #749 from forcedotcom/rm/3.x-pmd-6.47
rmohan20 Jul 13, 2022
bc27586
@W-11397711@: Added banner requesting that people take our survey.
jfeingold35 Jul 13, 2022
ddeb2e5
@W-11397711@: Integrated feedback from code review.
jfeingold35 Jul 14, 2022
99a6977
Merge pull request #753 from forcedotcom/d/W-11397711-v3
jfeingold35 Jul 15, 2022
c478ef5
@W-11397711@: Updated text to match feedback from PR.
jfeingold35 Jul 18, 2022
1a0b8f0
Merge pull request #757 from forcedotcom/d/W-11397711-v3-b
jfeingold35 Jul 18, 2022
689236a
@W-11445992@: Update version number in preparation for 3.3.0 release.
jfeingold35 Jul 18, 2022
92b0f5b
Merge pull request #754 from forcedotcom/d/W-11445992-v3
jfeingold35 Jul 18, 2022
97782e3
@W-11397711@: Fixing minor typo
rmohan20 Jul 18, 2022
cb9aacb
Merge pull request #760 from forcedotcom/rm/fix-typo-on-survey-link
rmohan20 Jul 18, 2022
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
109 changes: 102 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ commands:
- gradle/collect_test_results:
reports_path: pmd-cataloger/build/reports/
test_results_path: pmd-cataloger/build/test-results/
- gradle/collect_test_results:
reports_path: sfge/build/reports/
test_results_path: sfge/build/test-results/
- store_test_results:
path: test-results
- store_artifacts: # upload nyc test coverage as artifact.
Expand Down Expand Up @@ -218,12 +221,21 @@ jobs:

# Purpose: Runs the unit tests in a Windows environment.
windows-unit-tests:
# `parallelism` indicates how many simultaneous executors should be run, allowing us to split
# long-running tasks across multiple executors.
parallelism: 4 # larger values didn't seem to affect performance greatly
executor:
name: win/default # executor type
size: "medium"
size: "large"
shell: bash.exe
parameters:
node-version: *node_version_param
# Specify a subset of unit tests to be run, instead of the whole suite.
# This allows us to work around the suboptimal performance of the Windows executor by running
# multiple executors in parallel where different unit tests are ran in each.
test-type:
type: string
default: all
working_directory: C:\repo
steps:
- attach_workspace:
Expand Down Expand Up @@ -259,12 +271,90 @@ jobs:
- run: mkdir test-results

# Unit tests
- run:
name: test
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
shell: bash.exe
command: yarn test --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
when: always
- when:
condition:
equal: [ all, << parameters.test-type >> ]
steps:
- run:
name: test
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
shell: bash.exe
command: yarn test --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
when: always

- when:
condition:
equal: [ sfge, << parameters.test-type >> ]
steps:
- run:
name: test-sfge
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
shell: bash.exe
# Identify all the test files and allocate them between parallelized executors by timing data.
# Then turn the array of tests into something that gradle can accept, and run the tests.
command: |
TESTGLOB=$(circleci tests glob "sfge/src/test/**/*Test.java" | circleci tests split --split-by=timings)
echo $TESTGLOB
TESTARRAY=($TESTGLOB)
TESTARG=""
for element in "${TESTARRAY[@]}"
do
TESTARG="$TESTARG --tests `basename $element .java`"
done
echo $TESTARG
yarn test-sfge $TESTARG
when: always

- when:
condition:
equal: [ cli-messaging, << parameters.test-type >> ]
steps:
- run:
name: test-cli-messaging
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
shell: bash.exe
# This unit test suite is fast, so we have the first parallel executor run the tests, and all others exit early.
command: |
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
then
exit 0
fi
yarn test-cli-messaging
when: always

- when:
condition:
equal: [ pmd-cataloger, << parameters.test-type >> ]
steps:
- run:
name: test-pmd-cataloger
# Necessary to explicitly use bash, otherwise gradlew's status code won't be received and the job will hang.
shell: bash.exe
# This unit test suite is fast, so we have the first parallel executor run the tests, and all others exit early.
command: |
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
then
exit 0
fi
yarn test-pmd-cataloger
when: always

- when:
condition:
equal: [ ts, << parameters.test-type >> ]
steps:
- run:
name: test-ts
# Explicitly using bash, for simplicity of required shell script.
shell: bash.exe
# This unit test suite is relatively fast, so we have the first parallel executor run the tests, and all others exit early.
command: |
if [[ $CIRCLE_NODE_INDEX -gt 0 ]]
then
exit 0
fi
yarn test-ts --reporter mocha-junit-reporter --reporter-option mochaFile=test-results/mocha/test-results.xml
when: always

# Linting
- run:
Expand Down Expand Up @@ -510,6 +600,11 @@ workflows:
<<: *testing_filters
requires:
- setup
matrix:
parameters:
# The values of the parameters will be appended to the jobs they create.
# So we'll get "windows-unit-tests-pmd-cataloger", "windows-unit-tests-ts", etc.
test-type: [pmd-cataloger, cli-messaging, ts, sfge]
- linux-tarball-test:
filters:
<<: *testing_filters
Expand Down
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

Expand Down
3 changes: 3 additions & 0 deletions messages/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
FEEDBACK_SURVEY_BANNER: `We're constantly improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA.`
};
6 changes: 5 additions & 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.2.0",
"version": "3.3.0",
"author": "ISV SWAT",
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
"dependencies": {
Expand Down Expand Up @@ -133,6 +133,10 @@
"postpack": "rm -f oclif.manifest.json",
"lint": "eslint ./src --ext .ts",
"test": "./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
"test-cli-messaging": "./gradlew cli-messaging:test",
"test-pmd-cataloger": "./gradlew pmd-cataloger:test",
"test-sfge": "./gradlew sfge:test",
"test-ts": "nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
"coverage": "nyc report --reporter text",
"version": "oclif-dev readme && git add README.md"
}
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.45.0"
val pmdVersion = "6.47.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
2 changes: 1 addition & 1 deletion sfge/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
indent_style = tab
indent_style = space
indent_size = 4
8 changes: 7 additions & 1 deletion sfge/src/main/java/com/salesforce/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.salesforce.cli.OutputFormatter;
import com.salesforce.exception.SfgeException;
import com.salesforce.exception.SfgeRuntimeException;
import com.salesforce.exception.UnexpectedException;
import com.salesforce.graph.ops.GraphUtil;
import com.salesforce.messaging.CliMessager;
import com.salesforce.metainfo.MetaInfoCollector;
Expand Down Expand Up @@ -88,7 +89,7 @@ private int catalog() {
LOGGER.info("Invoked CATALOG flow");
List<AbstractRule> rules;
try {
rules = RuleUtil.getAllRules();
rules = RuleUtil.getEnabledRules();
} catch (SfgeException | SfgeRuntimeException ex) {
System.err.println(ex.getMessage());
return INTERNAL_ERROR;
Expand Down Expand Up @@ -129,6 +130,11 @@ private int execute(String... args) {
LOGGER.error("Error while loading graph", ex);
System.err.println(formatError(ex));
return INTERNAL_ERROR;
} catch (UnexpectedException ex) {
LOGGER.error("Unexpected exception while loading graph", ex);
System.err.println(
"Unexpected exception while loading graph. See logs for more information.");
return INTERNAL_ERROR;
}

// Run all of the rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ protected void fillProperties(Map<String, Object> properties) {
properties.put(Schema.ABSTRACT, Modifier.isAbstract(javaModifiers));
properties.put(Schema.STATIC, Modifier.isStatic(javaModifiers));
properties.put(Schema.GLOBAL, getNode().getModifiers().has(ModifierTypeInfos.GLOBAL));
properties.put(Schema.VIRTUAL, getNode().getModifiers().has(ModifierTypeInfos.VIRTUAL));
properties.put(Schema.OVERRIDE, getNode().getModifiers().has(ModifierTypeInfos.OVERRIDE));
}
}
10 changes: 7 additions & 3 deletions sfge/src/main/java/com/salesforce/cli/CliArgParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ private List<String> readFile(String fileName) throws IOException {

private void identifyRules(List<String> rulesToRun) {
try {
for (String ruleName : rulesToRun) {
AbstractRule rule = RuleUtil.getRule(ruleName);
selectedRules.add(rule);
if (rulesToRun.isEmpty()) {
selectedRules.addAll(RuleUtil.getEnabledRules());
} else {
for (String ruleName : rulesToRun) {
AbstractRule rule = RuleUtil.getRule(ruleName);
selectedRules.add(rule);
}
}
} catch (RuleUtil.RuleNotFoundException ex) {
throw new InvocationException(ex.getMessage(), ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.salesforce.config;

/**
* Contains error message constants that will be displayed to users. TODO: move all other
* user-facing messages here.
*/
public final class UserFacingErrorMessages {

/** UserActionException * */

// format: filename,defined type, line number
public static final String UNREACHABLE_CODE =
"Please remove unreachable code to proceed with analysis: %s,%s:%d";
}
5 changes: 4 additions & 1 deletion sfge/src/main/java/com/salesforce/graph/ApexPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ public void addVertices(List<BaseSFVertex> vertices) {
!(vertices.get(0) instanceof BlockStatementVertex)
&&
// Class Instantiation Path
!(vertices.get(0) instanceof FieldVertex)) {
!(vertices.get(0) instanceof FieldVertex)
&&
// Static blocks
!(vertices.get(0) instanceof MethodCallExpressionVertex)) {
throw new UnexpectedException(vertices);
}
this.vertices.addAll(vertices);
Expand Down
18 changes: 18 additions & 0 deletions sfge/src/main/java/com/salesforce/graph/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class Schema {
public static final String IDENTIFIER = "Identifier";
public static final String IMPLEMENTATION_OF = "ImplementationOf";
public static final String IMPLEMENTED_BY = "ImplementedBy";
public static final String INTERFACE_DEFINING_TYPES = "InterfaceDefiningTypes";
public static final String INTERFACE_NAMES = "InterfaceNames";
public static final String INVOCABLE_METHOD = "InvocableMethod";
/** True if this vertex is part of the Apex Standard Library */
public static final String IS_STANDARD = "IsStandard";
/**
Expand All @@ -44,8 +46,11 @@ public class Schema {
public static final String MODIFIERS = "Modifiers";
public static final String NAME = "Name";
public static final String NAMES = "Names";
public static final String NAMESPACE_ACCESSIBLE = "NamespaceAccessible";
public static final String OPERATOR = "Operator";
public static final String OVERRIDE = "Override";
public static final String REFERENCE_TYPE = "ReferenceType";
public static final String REMOTE_ACTION = "RemoteAction";
public static final String RETURN_TYPE = "ReturnType";
public static final String RULE_NAMES = "RulesNames";
public static final String STATIC = "Static";
Expand All @@ -56,6 +61,7 @@ public class Schema {
public static final String TYPE_REF = "TypeRef";

public static final String VALUE = "Value";
public static final String VIRTUAL = "Virtual";
public static final String QUERY = "Query";

public static final class JorjeNodeType {
Expand All @@ -67,4 +73,16 @@ public static final class JorjeNodeType {
public static final String CHILD = "Child";
public static final String PARENT = "Parent";
public static final String NEXT_SIBLING = "NextSibling";

/** Mark a vertex as synthetic */
public static final String IS_SYNTHETIC = "IsSynthetic";
/** Indicates if a method is a synthetic static block method */
public static final String IS_STATIC_BLOCK_METHOD = "IsStaticBlockMethod";
/** Indicates if a method is a synthetic static block invoker method */
public static final String IS_STATIC_BLOCK_INVOKER_METHOD = "IsStaticBlockInvokerMethod";
/**
* Indicates if a MethodCallExpression is a synthetic invocation of static block from invoker
* method
*/
public static final String IS_STATIC_BLOCK_INVOCATION = "IsStaticBlockInvocation";
}
Loading