Skip to content

Commit

Permalink
Merge pull request #32 from forcedotcom/d/W-14329763-msg
Browse files Browse the repository at this point in the history
@W-14329763@: Removed references to SFDX.
  • Loading branch information
jfeingold35 authored Dec 13, 2023
2 parents 34c7ab7 + a855fdd commit 3305266
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 371 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ jobs:
DOWNLOAD_PATH=`[[ $DOWNLOAD_PATH = C* ]] && echo $DOWNLOAD_PATH | cut -d':' -f 2 || echo $DOWNLOAD_PATH`
echo $DOWNLOAD_PATH
# Pipe in a `y` to simulate agreeing to install an unsigned package. Use a URI of the file's full path.
echo y | sfdx plugins:install "file://${DOWNLOAD_PATH}/sfdx-scanner/${TARBALL_NAME}"
echo y | sf plugins install "file://${DOWNLOAD_PATH}/sfdx-scanner/${TARBALL_NAME}"
- name: Install Production scanner
if: ${{ inputs.use-scanner-tarball == false }}
run: sfdx plugins:install @salesforce/sfdx-scanner
run: sf plugins install @salesforce/sfdx-scanner
# Run the tests. (Linux and non-Linux need slightly different commands.)
- name: 'Run Tests (Linux)'
run: xvfb-run -a yarn test
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
"commands": [
{
"command": "sfca.runOnActiveFile",
"title": "SFDX: Scan current file with Code Analyzer"
"title": "SF: Scan current file with Code Analyzer"
},
{
"command": "sfca.runOnSelected",
"title": "SFDX: Scan selected files or folders with Code Analyzer"
"title": "SF: Scan selected files or folders with Code Analyzer"
},
{
"command": "sfca.runDfaOnSelectedMethod",
"title": "SFDX: Scan selected method with Graph Engine path-based analysis"
"title": "SF: Scan selected method with Graph Engine path-based analysis"
}
],
"configuration": {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export class ScanRunner {
}

/**
* Creates the arguments for an execution of {@code sfdx scanner:run:dfa}, for use in a child process.
* Creates the arguments for an execution of {@code sf scanner run dfa}, for use in a child process.
* @param targets The files/methods to be targeted.
* @param projectDir The root of the project to be scanned.
*/
private createDfaArgArray(targets: string[], projectDir: string): string[] {
const args: string[] = [
'scanner:run:dfa',
'scanner', 'run', 'dfa',
'--target', `${targets.join(',')}`,
`--projectdir`, projectDir,
// NOTE: For now, we're using HTML output since it's the easiest to display to the user.
Expand Down Expand Up @@ -95,12 +95,12 @@ export class ScanRunner {
}

/**
* Creates the arguments for an execution of {@code sfdx scanner:run}.
* Creates the arguments for an execution of {@code sf scanner run}.
* @param targets The files to be scanned.
*/
private async createPathlessArgArray(targets: string[]): Promise<string[]> {
const args: string[] = [
'scanner:run',
'scanner', 'run',
'--target', `${targets.join(',')}`,
'--engine', 'pmd,retire-js',
'--json'
Expand All @@ -122,7 +122,7 @@ export class ScanRunner {
*/
private async invokeAnalyzer(args: string[]): Promise<ExecutionResult> {
return new Promise((res) => {
const cp = cspawn.spawn('sfdx', args);
const cp = cspawn.spawn('sf', args);

let stdout = '';

Expand All @@ -138,7 +138,7 @@ export class ScanRunner {
}

/**
*
*
* @param executionResult The results from a scan
* @returns The HTML-formatted scan results, or an empty string.
* @throws If {@code executionResult.result} is not a string.
Expand Down Expand Up @@ -189,7 +189,7 @@ export class ScanRunner {
}

/**
*
*
* @param executionResult The results from a scan.
* @returns The Rule Results pulled out of the execution results, or an empty array.
* @throws if {@coder executionResult.status} is non-zero
Expand All @@ -210,4 +210,4 @@ export class ScanRunner {
throw new Error(executionResult.message);
}
}
}
}
10 changes: 5 additions & 5 deletions src/lib/sf-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import cspawn = require('cross-spawn');
export class SfCli {

/**
*
*
* @returns True if {@code sf} or {@code sfdx} is installed.
*/
public static async isSfCliInstalled(): Promise<boolean> {
return new Promise((res) => {
const cp = cspawn.spawn('sfdx', ['-v']);
const cp = cspawn.spawn('sf', ['-v']);

cp.on('exit', code => {
// If the exit code is 0, then SF or SFDX is present.
Expand All @@ -28,12 +28,12 @@ export class SfCli {
}

/**
*
*
* @returns True if {@code @salesforce/sfdx-scanner} is installed.
*/
public static async isCodeAnalyzerInstalled(): Promise<boolean> {
return new Promise((res) => {
const cp = cspawn.spawn('sfdx', ['plugins']);
const cp = cspawn.spawn('sf', ['plugins']);

let stdout = '';

Expand All @@ -47,4 +47,4 @@ export class SfCli {
});
});
}
}
}
4 changes: 2 additions & 2 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ suite('Extension Test Suite', () => {

test('Throws error if `sf`/`sfdx` is missing', async () => {
// ===== SETUP =====
// Simulate SFDX being unavailable.
// Simulate SF being unavailable.
const errorSpy = Sinon.spy(vscode.window, 'showErrorMessage');
Sinon.stub(SfCli, 'isSfCliInstalled').resolves(false);
const fakeTelemetryName = 'FakeName';
Expand All @@ -253,7 +253,7 @@ suite('Extension Test Suite', () => {

test('Throws error if `sfdx-scanner` is missing', async () => {
// ===== SETUP =====
// Simulate SFDX being available but SFDX Scanner being absent.
// Simulate SF being available but SFDX Scanner being absent.
const errorSpy = Sinon.spy(vscode.window, 'showErrorMessage');
Sinon.stub(SfCli, 'isSfCliInstalled').resolves(true);
Sinon.stub(SfCli, 'isCodeAnalyzerInstalled').resolves(false);
Expand Down
97 changes: 51 additions & 46 deletions src/test/suite/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(6, 'Wrong number of args');
expect(args[0]).to.equal('scanner:run', 'Wrong arg');
expect(args[1]).to.equal('--target', 'Wrong arg');
expect(args[2]).to.equal(targets.join(','), 'Wrong arg');
expect(args[3]).to.equal('--engine', 'Wrong arg');
expect(args[4]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[5]).to.equal('--json', 'Wrong arg');
expect(args).to.have.lengthOf(7, 'Wrong number of args');
expect(args[0]).to.equal('scanner', 'Wrong arg');
expect(args[1]).to.equal('run', 'Wrong arg');
expect(args[2]).to.equal('--target', 'Wrong arg');
expect(args[3]).to.equal(targets.join(','), 'Wrong arg');
expect(args[4]).to.equal('--engine', 'Wrong arg');
expect(args[5]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[6]).to.equal('--json', 'Wrong arg');
});
});

Expand All @@ -72,15 +73,16 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(8, 'Wrong number of args');
expect(args[0]).to.equal('scanner:run', 'Wrong arg');
expect(args[1]).to.equal('--target', 'Wrong arg');
expect(args[2]).to.equal(targets.join(','), 'Wrong arg');
expect(args[3]).to.equal('--engine', 'Wrong arg');
expect(args[4]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[5]).to.equal('--json', 'Wrong arg');
expect(args[6]).to.equal('--pmdconfig', 'Wrong arg');
expect(args[7]).to.equal(dummyConfigPath, 'Wrong arg');
expect(args).to.have.lengthOf(9, 'Wrong number of args');
expect(args[0]).to.equal('scanner', 'Wrong arg');
expect(args[1]).to.equal('run', 'Wrong arg');
expect(args[2]).to.equal('--target', 'Wrong arg');
expect(args[3]).to.equal(targets.join(','), 'Wrong arg');
expect(args[4]).to.equal('--engine', 'Wrong arg');
expect(args[5]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[6]).to.equal('--json', 'Wrong arg');
expect(args[7]).to.equal('--pmdconfig', 'Wrong arg');
expect(args[8]).to.equal(dummyConfigPath, 'Wrong arg');
});

test('When custom PMD config is non-existent, an error is thrown', async () => {
Expand Down Expand Up @@ -117,13 +119,14 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(6, 'Wrong number of args');
expect(args[0]).to.equal('scanner:run', 'Wrong arg');
expect(args[1]).to.equal('--target', 'Wrong arg');
expect(args[2]).to.equal(targets.join(','), 'Wrong arg');
expect(args[3]).to.equal('--engine', 'Wrong arg');
expect(args[4]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[5]).to.equal('--json', 'Wrong arg');
expect(args).to.have.lengthOf(7, 'Wrong number of args');
expect(args[0]).to.equal('scanner', 'Wrong arg');
expect(args[1]).to.equal('run', 'Wrong arg');
expect(args[2]).to.equal('--target', 'Wrong arg');
expect(args[3]).to.equal(targets.join(','), 'Wrong arg');
expect(args[4]).to.equal('--engine', 'Wrong arg');
expect(args[5]).to.equal('pmd,retire-js', 'Wrong arg');
expect(args[6]).to.equal('--json', 'Wrong arg');
});
});
});
Expand All @@ -150,15 +153,17 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Perform the validations common to all cases.
expect(args).to.have.length.of.at.least(8, 'Wrong number of args');
expect(args[0]).to.equal('scanner:run:dfa', 'Wrong arg');
expect(args[1]).to.equal('--target', 'Wrong arg');
expect(args[2]).to.equal(targets.join(','), 'Wrong arg');
expect(args[3]).to.equal('--projectdir', 'Wrong arg');
expect(args[4]).to.equal(projectDir, 'Wrong arg');
expect(args[5]).to.equal('--format', 'Wrong arg');
expect(args[6]).to.equal('html', 'Wrong arg');
expect(args[7]).to.equal('--json', 'Wrong arg');
expect(args).to.have.length.of.at.least(10, 'Wrong number of args');
expect(args[0]).to.equal('scanner', 'Wrong arg');
expect(args[1]).to.equal('run', 'Wrong arg');
expect(args[2]).to.equal('dfa', 'Wrong arg');
expect(args[3]).to.equal('--target', 'Wrong arg');
expect(args[4]).to.equal(targets.join(','), 'Wrong arg');
expect(args[5]).to.equal('--projectdir', 'Wrong arg');
expect(args[6]).to.equal(projectDir, 'Wrong arg');
expect(args[7]).to.equal('--format', 'Wrong arg');
expect(args[8]).to.equal('html', 'Wrong arg');
expect(args[9]).to.equal('--json', 'Wrong arg');

return args;
}
Expand All @@ -183,7 +188,7 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Assert we got the right number of args. Everything else has been checked already.
expect(args).to.have.lengthOf(8, 'Wrong number of args');
expect(args).to.have.lengthOf(10, 'Wrong number of args');
});
});

Expand All @@ -208,8 +213,8 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(9, 'Wrong number of args');
expect(args[8]).to.equal('--rule-disable-warning-violation', 'Wrong arg');
expect(args).to.have.lengthOf(11, 'Wrong number of args');
expect(args[10]).to.equal('--rule-disable-warning-violation', 'Wrong arg');
});

test('Thread Timeout', () => {
Expand All @@ -228,9 +233,9 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(10, 'Wrong number of args');
expect(args[8]).to.equal('--rule-thread-timeout', 'Wrong arg');
expect(args[9]).to.equal(`${timeout}`, 'Wrong arg');
expect(args).to.have.lengthOf(12, 'Wrong number of args');
expect(args[10]).to.equal('--rule-thread-timeout', 'Wrong arg');
expect(args[11]).to.equal(`${timeout}`, 'Wrong arg');
});

test('Path Expansion Limit', () => {
Expand All @@ -249,9 +254,9 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(10, 'Wrong number of args');
expect(args[8]).to.equal('--pathexplimit', 'Wrong arg');
expect(args[9]).to.equal(`${limit}`, 'Wrong arg');
expect(args).to.have.lengthOf(12, 'Wrong number of args');
expect(args[10]).to.equal('--pathexplimit', 'Wrong arg');
expect(args[11]).to.equal(`${limit}`, 'Wrong arg');
});

test('JVM Args', () => {
Expand All @@ -270,9 +275,9 @@ suite('ScanRunner', () => {

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(10, 'Wrong number of args');
expect(args[8]).to.equal('--sfgejvmargs', 'Wrong arg');
expect(args[9]).to.equal(jvmArgs, 'Wrong arg');
expect(args).to.have.lengthOf(12, 'Wrong number of args');
expect(args[10]).to.equal('--sfgejvmargs', 'Wrong arg');
expect(args[11]).to.equal(jvmArgs, 'Wrong arg');
});
});
});
Expand Down Expand Up @@ -402,7 +407,7 @@ suite('ScanRunner', () => {
// Feed the results into the processor.
const scanner = new ScanRunner();
const processedResults: string = (scanner as any).processDfaResults(spoofedOutput);

// ===== ASSERTIONS =====
// Verify that an empty string was returned.
expect(processedResults).to.equal("", "Expected empty string");
Expand Down Expand Up @@ -461,4 +466,4 @@ suite('ScanRunner', () => {
});
});

});
});
Loading

0 comments on commit 3305266

Please sign in to comment.