From 2a855ff6b5f74ff160c3dcf41333e043df3130a4 Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Mon, 25 Jul 2022 15:25:04 -0700 Subject: [PATCH 1/6] Revert "@W-11397711@: Integrated feedback from code review." This reverts commit ddeb2e5ec955b9ba98e52de3f2d35f06ffd48c65. --- test/TestUtils.ts | 9 +-- test/commands/scanner/rule/list.test.ts | 15 ++--- test/commands/scanner/run.severity.test.ts | 74 +++++++++++----------- test/commands/scanner/run.test.ts | 6 +- 4 files changed, 48 insertions(+), 56 deletions(-) diff --git a/test/TestUtils.ts b/test/TestUtils.ts index 06da598c4..b50b3770d 100644 --- a/test/TestUtils.ts +++ b/test/TestUtils.ts @@ -1,7 +1,6 @@ import fs = require('fs'); import path = require('path'); -import { test, expect } from '@salesforce/command/lib/test'; -import * as CommonMessages from '../messages/common.js'; +import { test } from '@salesforce/command/lib/test'; import * as TestOverrides from './test-related-lib/TestOverrides'; import Sinon = require('sinon'); import LocalCatalog from '../src/lib/services/LocalCatalog'; @@ -16,12 +15,6 @@ export function prettyPrint(obj: any): string { return JSON.stringify(obj, null, 2); } -export function stripExtraneousOutput(stdout: string): string { - const splitOutput = stdout.split('\n'); - expect(splitOutput[0]).to.equal('=== ' + CommonMessages.FEEDBACK_SURVEY_BANNER); - return splitOutput.slice(1).join('\n'); -} - export function stubCatalogFixture(): void { // Make sure all catalogs exist where they're supposed to. if (!fs.existsSync(CATALOG_FIXTURE_PATH)) { diff --git a/test/commands/scanner/rule/list.test.ts b/test/commands/scanner/rule/list.test.ts index 973782dfd..7330f892d 100644 --- a/test/commands/scanner/rule/list.test.ts +++ b/test/commands/scanner/rule/list.test.ts @@ -1,5 +1,5 @@ import {expect} from '@salesforce/command/lib/test'; -import {setupCommandTest, stripExtraneousOutput} from '../../../TestUtils'; +import {setupCommandTest} from '../../../TestUtils'; import {Rule} from '../../../../src/types'; import {CATALOG_FILE, ENGINE} from '../../../../src/Constants'; import fs = require('fs'); @@ -54,10 +54,10 @@ describe('scanner:rule:list', () => { .it('All rules for enabled engines are returned', async ctx => { const totalRuleCount = await getRulesFilteredByCategoryCount(false); - // Split the output table by newline and throw out the first two rows, since they just contain header information. That + // Split the output table by newline and throw out the first three rows, since they just contain header information. That // should leave us with the actual data. - const output = stripExtraneousOutput(ctx.stdout); - const rows = output.trim().split('\n'); + const rows = ctx.stdout.trim().split('\n'); + rows.shift(); rows.shift(); rows.shift(); expect(rows).to.have.lengthOf(totalRuleCount, 'All rules should have been returned'); @@ -306,10 +306,9 @@ describe('scanner:rule:list', () => { setupCommandTest .command(['scanner:rule:list', '--category', 'Beebleborp']) .it('Without --json flag, an empty table is printed', ctx => { - // Split the result by newline, and make sure there are two rows. - const output = stripExtraneousOutput(ctx.stdout); - const rows = output.trim().split('\n'); - expect(rows).to.have.lengthOf(2, 'Only the header rows should have been printed'); + // Split the result by newline, and make sure there are three rows. + const rows = ctx.stdout.trim().split('\n'); + expect(rows).to.have.lengthOf(3, 'Only the header rows should have been printed'); }); setupCommandTest diff --git a/test/commands/scanner/run.severity.test.ts b/test/commands/scanner/run.severity.test.ts index 4e411acff..cddfaf993 100644 --- a/test/commands/scanner/run.severity.test.ts +++ b/test/commands/scanner/run.severity.test.ts @@ -1,5 +1,5 @@ import {expect} from '@salesforce/command/lib/test'; -import {setupCommandTest, stripExtraneousOutput} from '../../TestUtils'; +import {setupCommandTest} from '../../TestUtils'; import {Messages} from '@salesforce/core'; import path = require('path'); @@ -31,12 +31,12 @@ describe('scanner:run', function () { '--severity-threshold', '1' ]) .it('When no violations are found equal to or greater than flag value, no error is thrown', ctx => { - const output = stripExtraneousOutput(ctx.stdout); - const outputJson = JSON.parse(output); + // The first line is a header. Strip that away, and parse the rest as JSON. + const output = JSON.parse(ctx.stdout.split('\n')[1]); // check that test file still has severities of 3 - for (let i=0; i { - const output = stripExtraneousOutput(ctx.stdout); - const outputJson = JSON.parse(output); + // The first line is a header. Strip that away, and parse the rest as JSON. + const output = JSON.parse(ctx.stdout.split('\n')[1]); // check that test file still has severities of 3 - for (let i=0; i { - const output = stripExtraneousOutput(ctx.stdout); - const outputJson = JSON.parse(output); - - for (let i=0; i { - const output = stripExtraneousOutput(ctx.stdout); - const outputJson = JSON.parse(output); + // The first line is a header. Strip that away, and parse the rest as JSON. + const output = JSON.parse(ctx.stdout.split('\n')[1]); - for (let i=0; i { - const output = stripExtraneousOutput(ctx.stdout); - validateCsvOutput(output, false); + // Throw away the first line of output, since it's a banner. + validateCsvOutput(ctx.stdout.slice(ctx.stdout.indexOf('\n')), false); }); setupCommandTest From 40bc5938e235deef3e3271a3295a35865c117a1f Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Mon, 25 Jul 2022 15:41:20 -0700 Subject: [PATCH 2/6] Revert "@W-11397711@: Added banner requesting that people take our survey." This reverts commit bc2758628366e28b37219aec5ba108edbe46d9a0. --- messages/common.js | 3 --- src/commands/scanner/rule/add.ts | 3 +-- src/commands/scanner/rule/describe.ts | 2 -- src/commands/scanner/rule/list.ts | 2 -- src/commands/scanner/rule/remove.ts | 2 -- src/lib/ScannerRunCommand.ts | 2 -- test/commands/scanner/rule/list.test.ts | 7 +++---- test/commands/scanner/run.severity.test.ts | 14 ++++++-------- test/commands/scanner/run.test.ts | 4 ++-- 9 files changed, 12 insertions(+), 27 deletions(-) delete mode 100644 messages/common.js diff --git a/messages/common.js b/messages/common.js deleted file mode 100644 index be555a676..000000000 --- a/messages/common.js +++ /dev/null @@ -1,3 +0,0 @@ -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.` -}; diff --git a/src/commands/scanner/rule/add.ts b/src/commands/scanner/rule/add.ts index b4e34515b..54e76c231 100644 --- a/src/commands/scanner/rule/add.ts +++ b/src/commands/scanner/rule/add.ts @@ -13,7 +13,7 @@ Messages.importMessagesDirectory(__dirname); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'add'); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); + export default class Add extends SfdxCommand { @@ -41,7 +41,6 @@ export default class Add extends SfdxCommand { public async run(): Promise { this.validateFlags(); - this.ux.styledHeader(commonMessages.getMessage('FEEDBACK_SURVEY_BANNER')); const language = this.flags.language as string; const paths = this.resolvePaths(); diff --git a/src/commands/scanner/rule/describe.ts b/src/commands/scanner/rule/describe.ts index c5dd74f6a..1e2557305 100644 --- a/src/commands/scanner/rule/describe.ts +++ b/src/commands/scanner/rule/describe.ts @@ -12,7 +12,6 @@ Messages.importMessagesDirectory(__dirname); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'describe'); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); type DescribeStyledRule = Rule & { enabled: boolean; @@ -42,7 +41,6 @@ export default class Describe extends ScannerCommand { }; public async run(): Promise { - this.ux.styledHeader(commonMessages.getMessage('FEEDBACK_SURVEY_BANNER')); const ruleFilters = this.buildRuleFilters(); // It's possible for this line to throw an error, but that's fine because the error will be an SfdxError that we can // allow to boil over. diff --git a/src/commands/scanner/rule/list.ts b/src/commands/scanner/rule/list.ts index ba5406632..ffe4ddc84 100644 --- a/src/commands/scanner/rule/list.ts +++ b/src/commands/scanner/rule/list.ts @@ -13,7 +13,6 @@ Messages.importMessagesDirectory(__dirname); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'list'); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); const columns = [messages.getMessage('columnNames.name'), messages.getMessage('columnNames.languages'), messages.getMessage('columnNames.categories'), @@ -65,7 +64,6 @@ export default class List extends ScannerCommand { }; public async run(): Promise { - this.ux.styledHeader(commonMessages.getMessage('FEEDBACK_SURVEY_BANNER')); const ruleFilters = this.buildRuleFilters(); // It's possible for this line to throw an error, but that's fine because the error will be an SfdxError that we can // allow to boil over. diff --git a/src/commands/scanner/rule/remove.ts b/src/commands/scanner/rule/remove.ts index f121782de..b87f712ec 100644 --- a/src/commands/scanner/rule/remove.ts +++ b/src/commands/scanner/rule/remove.ts @@ -15,7 +15,6 @@ Messages.importMessagesDirectory(__dirname); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'remove'); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); export default class Remove extends ScannerCommand { // These determine what's displayed when the --help/-h flag is supplied. @@ -45,7 +44,6 @@ export default class Remove extends ScannerCommand { }; public async run(): Promise { - this.ux.styledHeader(commonMessages.getMessage('FEEDBACK_SURVEY_BANNER')); // Step 1: Validate our input. this.validateFlags(); diff --git a/src/lib/ScannerRunCommand.ts b/src/lib/ScannerRunCommand.ts index 6cc092fee..4e4fb69e3 100644 --- a/src/lib/ScannerRunCommand.ts +++ b/src/lib/ScannerRunCommand.ts @@ -14,7 +14,6 @@ Messages.importMessagesDirectory(__dirname); // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'run'); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); // This code is used for internal errors. export const INTERNAL_ERROR_CODE = 1; @@ -23,7 +22,6 @@ export abstract class ScannerRunCommand extends ScannerCommand { public async run(): Promise { // First, do any validations that can't be handled with out-of-the-box stuff. await this.validateFlags(); - this.ux.styledHeader(commonMessages.getMessage('FEEDBACK_SURVEY_BANNER')); // If severity-threshold is used, that implicitly normalizes the severity. const normalizeSeverity: boolean = (this.flags['normalize-severity'] || this.flags['severity-threshold']) as boolean; diff --git a/test/commands/scanner/rule/list.test.ts b/test/commands/scanner/rule/list.test.ts index 7330f892d..3bfc3ef50 100644 --- a/test/commands/scanner/rule/list.test.ts +++ b/test/commands/scanner/rule/list.test.ts @@ -54,12 +54,11 @@ describe('scanner:rule:list', () => { .it('All rules for enabled engines are returned', async ctx => { const totalRuleCount = await getRulesFilteredByCategoryCount(false); - // Split the output table by newline and throw out the first three rows, since they just contain header information. That + // Split the output table by newline and throw out the first two rows, since they just contain header information. That // should leave us with the actual data. const rows = ctx.stdout.trim().split('\n'); rows.shift(); rows.shift(); - rows.shift(); expect(rows).to.have.lengthOf(totalRuleCount, 'All rules should have been returned'); }); @@ -306,9 +305,9 @@ describe('scanner:rule:list', () => { setupCommandTest .command(['scanner:rule:list', '--category', 'Beebleborp']) .it('Without --json flag, an empty table is printed', ctx => { - // Split the result by newline, and make sure there are three rows. + // Split the result by newline, and make sure there are two rows. const rows = ctx.stdout.trim().split('\n'); - expect(rows).to.have.lengthOf(3, 'Only the header rows should have been printed'); + expect(rows).to.have.lengthOf(2, 'Only the header rows should have been printed'); }); setupCommandTest diff --git a/test/commands/scanner/run.severity.test.ts b/test/commands/scanner/run.severity.test.ts index cddfaf993..6c9384dc4 100644 --- a/test/commands/scanner/run.severity.test.ts +++ b/test/commands/scanner/run.severity.test.ts @@ -31,8 +31,8 @@ describe('scanner:run', function () { '--severity-threshold', '1' ]) .it('When no violations are found equal to or greater than flag value, no error is thrown', ctx => { - // The first line is a header. Strip that away, and parse the rest as JSON. - const output = JSON.parse(ctx.stdout.split('\n')[1]); + + const output = JSON.parse(ctx.stdout); // check that test file still has severities of 3 for (let i=0; i { - // The first line is a header. Strip that away, and parse the rest as JSON. - const output = JSON.parse(ctx.stdout.split('\n')[1]); + + const output = JSON.parse(ctx.stdout); // check that test file still has severities of 3 for (let i=0; i { - // The first line is a header. Strip that away, and parse the rest as JSON. - const output = JSON.parse(ctx.stdout.split('\n')[1]); + const output = JSON.parse(ctx.stdout); for (let i=0; i { - // The first line is a header. Strip that away, and parse the rest as JSON. - const output = JSON.parse(ctx.stdout.split('\n')[1]); + const output = JSON.parse(ctx.stdout); for (let i=0; i { - // Throw away the first line of output, since it's a banner. - validateCsvOutput(ctx.stdout.slice(ctx.stdout.indexOf('\n')), false); + // Split the output by newline characters and throw away the first entry, so we're left with just the rows. + validateCsvOutput(ctx.stdout, false); }); setupCommandTest From d9f983e8a012c7c59ace6659c7b1fd4e8a061aa2 Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Tue, 26 Jul 2022 10:01:24 -0700 Subject: [PATCH 3/6] Converting stylizedHeader into warning. Pending test failures in add.test.ts --- messages/common.js | 3 +++ src/commands/scanner/rule/add.ts | 6 ++--- src/commands/scanner/rule/describe.ts | 2 +- src/commands/scanner/rule/list.ts | 2 +- src/commands/scanner/rule/remove.ts | 2 +- src/lib/ScannerCommand.ts | 26 +++++++++++++++++++++ src/lib/ScannerRunCommand.ts | 2 +- src/lib/util/CommonCommandUtils.ts | 9 +++++++ test/commands/scanner/rule/describe.test.ts | 4 ++-- test/commands/scanner/run.test.ts | 1 - 10 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 messages/common.js create mode 100644 src/lib/util/CommonCommandUtils.ts diff --git a/messages/common.js b/messages/common.js new file mode 100644 index 000000000..810df19b0 --- /dev/null +++ b/messages/common.js @@ -0,0 +1,3 @@ +module.exports = { + surveyRequestMessage: `We're constantly improving Salesforce Code Analyzer. Tell us what you think! Give feedback at https://research.net/r/SalesforceCA.` +}; \ No newline at end of file diff --git a/src/commands/scanner/rule/add.ts b/src/commands/scanner/rule/add.ts index 54e76c231..909af2151 100644 --- a/src/commands/scanner/rule/add.ts +++ b/src/commands/scanner/rule/add.ts @@ -5,6 +5,7 @@ import {Controller} from '../../../Controller'; import {stringArrayTypeGuard} from '../../../lib/util/Utils'; import path = require('path'); import untildify = require('untildify'); +import { ScannerCommand } from '../../../lib/ScannerCommand'; // Initialize Messages with the current plugin directory @@ -14,8 +15,7 @@ Messages.importMessagesDirectory(__dirname); // or any library that is using the messages framework can also be loaded this way. const messages = Messages.loadMessages('@salesforce/sfdx-scanner', 'add'); - -export default class Add extends SfdxCommand { +export default class Add extends ScannerCommand { public static description = messages.getMessage('commandDescription'); public static longDescription = messages.getMessage('commandDescriptionLong'); @@ -39,7 +39,7 @@ export default class Add extends SfdxCommand { }) }; - public async run(): Promise { + async runInternal(): Promise { this.validateFlags(); const language = this.flags.language as string; diff --git a/src/commands/scanner/rule/describe.ts b/src/commands/scanner/rule/describe.ts index 1e2557305..9dffe7fa0 100644 --- a/src/commands/scanner/rule/describe.ts +++ b/src/commands/scanner/rule/describe.ts @@ -40,7 +40,7 @@ export default class Describe extends ScannerCommand { verbose: flags.builtin() }; - public async run(): Promise { + async runInternal(): Promise { const ruleFilters = this.buildRuleFilters(); // It's possible for this line to throw an error, but that's fine because the error will be an SfdxError that we can // allow to boil over. diff --git a/src/commands/scanner/rule/list.ts b/src/commands/scanner/rule/list.ts index ffe4ddc84..77ae897a9 100644 --- a/src/commands/scanner/rule/list.ts +++ b/src/commands/scanner/rule/list.ts @@ -63,7 +63,7 @@ export default class List extends ScannerCommand { // END: Flags consumed by ScannerCommand#buildRuleFilters }; - public async run(): Promise { + async runInternal(): Promise { const ruleFilters = this.buildRuleFilters(); // It's possible for this line to throw an error, but that's fine because the error will be an SfdxError that we can // allow to boil over. diff --git a/src/commands/scanner/rule/remove.ts b/src/commands/scanner/rule/remove.ts index b87f712ec..26bbe40a9 100644 --- a/src/commands/scanner/rule/remove.ts +++ b/src/commands/scanner/rule/remove.ts @@ -43,7 +43,7 @@ export default class Remove extends ScannerCommand { }) }; - public async run(): Promise { + async runInternal(): Promise { // Step 1: Validate our input. this.validateFlags(); diff --git a/src/lib/ScannerCommand.ts b/src/lib/ScannerCommand.ts index 664373831..1697ca0c0 100644 --- a/src/lib/ScannerCommand.ts +++ b/src/lib/ScannerCommand.ts @@ -2,9 +2,35 @@ import {SfdxCommand} from '@salesforce/command'; import {CategoryFilter, LanguageFilter, RuleFilter, RulesetFilter, RulenameFilter, EngineFilter} from './RuleFilter'; import {uxEvents, EVENTS} from './ScannerEvents'; import {stringArrayTypeGuard} from './util/Utils'; +import {AnyJson} from '@salesforce/ts-types'; + +import {Messages} from '@salesforce/core'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); +const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); + export abstract class ScannerCommand extends SfdxCommand { + public async run(): Promise { + this.runCommonSteps(); + return await this.runInternal(); + } + + /** + * Command's should implement this method to add their + * working steps. + */ + abstract runInternal(): Promise; + + /** + * Common steps that should be run before every command + */ + protected runCommonSteps(): void { + this.ux.warn(commonMessages.getMessage('surveyRequestMessage')); + } + protected buildRuleFilters(): RuleFilter[] { const filters: RuleFilter[] = []; // Create a filter for any provided categories. diff --git a/src/lib/ScannerRunCommand.ts b/src/lib/ScannerRunCommand.ts index 4e4fb69e3..40586d20f 100644 --- a/src/lib/ScannerRunCommand.ts +++ b/src/lib/ScannerRunCommand.ts @@ -19,7 +19,7 @@ export const INTERNAL_ERROR_CODE = 1; export abstract class ScannerRunCommand extends ScannerCommand { - public async run(): Promise { + async runInternal(): Promise { // First, do any validations that can't be handled with out-of-the-box stuff. await this.validateFlags(); diff --git a/src/lib/util/CommonCommandUtils.ts b/src/lib/util/CommonCommandUtils.ts new file mode 100644 index 000000000..d420e3270 --- /dev/null +++ b/src/lib/util/CommonCommandUtils.ts @@ -0,0 +1,9 @@ +import { SfdxCommand } from "@salesforce/command"; +import {Messages} from '@salesforce/core'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); +const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); + + + diff --git a/test/commands/scanner/rule/describe.test.ts b/test/commands/scanner/rule/describe.test.ts index fc70f9d91..16a80e7ae 100644 --- a/test/commands/scanner/rule/describe.test.ts +++ b/test/commands/scanner/rule/describe.test.ts @@ -20,8 +20,8 @@ describe('scanner:rule:describe', () => { .it('--json flag yields correct results', ctx => { const ctxJson = JSON.parse(ctx.stdout); expect(ctxJson.result.length).to.equal(0, 'Should be no results'); - expect(ctxJson.warnings.length).to.equal(1, 'Should be one warning'); - expect(ctxJson.warnings[0]).to.equal(formattedWarning, 'Warning message should match'); + expect(ctxJson.warnings.length).to.equal(2, 'Should be one warning'); + expect(ctxJson.warnings[1]).to.equal(formattedWarning, 'Warning message should match'); }); }); diff --git a/test/commands/scanner/run.test.ts b/test/commands/scanner/run.test.ts index 310651f2d..e7ae3cc91 100644 --- a/test/commands/scanner/run.test.ts +++ b/test/commands/scanner/run.test.ts @@ -640,7 +640,6 @@ describe('scanner:run', function () { .command(['scanner:run', '--target', '**/*.js,**/*.cls', '--format', 'json']) .finally(() => process.chdir("../../../..")) .it('Polyglot project triggers pmd and eslint rules', ctx => { - expect(ctx.stderr, ctx.stdout).to.be.empty; const results = JSON.parse(ctx.stdout.substring(ctx.stdout.indexOf("[{"), ctx.stdout.lastIndexOf("}]") + 2)); // Look through all of the results and gather a set of unique engines const uniqueEngines = new Set(results.map(r => { return r.engine })); From 9b5a49d5478dcb901e4c2e5d50d52cab740c8f1b Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Tue, 26 Jul 2022 11:23:53 -0700 Subject: [PATCH 4/6] Removing unused imports to fix add command --- src/commands/scanner/rule/add.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/scanner/rule/add.ts b/src/commands/scanner/rule/add.ts index 909af2151..65ddee5e6 100644 --- a/src/commands/scanner/rule/add.ts +++ b/src/commands/scanner/rule/add.ts @@ -1,4 +1,4 @@ -import {flags, SfdxCommand} from '@salesforce/command'; +import {flags} from '@salesforce/command'; import {Messages, SfdxError} from '@salesforce/core'; import {AnyJson} from '@salesforce/ts-types'; import {Controller} from '../../../Controller'; From 51284f4b7527aeeb457c1e359dcd3deed415dd48 Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Tue, 26 Jul 2022 11:26:48 -0700 Subject: [PATCH 5/6] Removing unused file --- src/lib/util/CommonCommandUtils.ts | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/lib/util/CommonCommandUtils.ts diff --git a/src/lib/util/CommonCommandUtils.ts b/src/lib/util/CommonCommandUtils.ts deleted file mode 100644 index d420e3270..000000000 --- a/src/lib/util/CommonCommandUtils.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SfdxCommand } from "@salesforce/command"; -import {Messages} from '@salesforce/core'; - -// Initialize Messages with the current plugin directory -Messages.importMessagesDirectory(__dirname); -const commonMessages = Messages.loadMessages('@salesforce/sfdx-scanner', 'common'); - - - From bae4ff4c1e71463a800d04390f152bd54f255591 Mon Sep 17 00:00:00 2001 From: Roopa Mohan Date: Tue, 26 Jul 2022 13:39:00 -0700 Subject: [PATCH 6/6] Test changes --- test/commands/scanner/rule/describe.test.ts | 2 +- test/commands/scanner/run.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/commands/scanner/rule/describe.test.ts b/test/commands/scanner/rule/describe.test.ts index 16a80e7ae..6e992dc3a 100644 --- a/test/commands/scanner/rule/describe.test.ts +++ b/test/commands/scanner/rule/describe.test.ts @@ -20,7 +20,7 @@ describe('scanner:rule:describe', () => { .it('--json flag yields correct results', ctx => { const ctxJson = JSON.parse(ctx.stdout); expect(ctxJson.result.length).to.equal(0, 'Should be no results'); - expect(ctxJson.warnings.length).to.equal(2, 'Should be one warning'); + expect(ctxJson.warnings.length).to.equal(2, 'Incorrect warning count'); expect(ctxJson.warnings[1]).to.equal(formattedWarning, 'Warning message should match'); }); }); diff --git a/test/commands/scanner/run.test.ts b/test/commands/scanner/run.test.ts index e7ae3cc91..d46015977 100644 --- a/test/commands/scanner/run.test.ts +++ b/test/commands/scanner/run.test.ts @@ -693,6 +693,22 @@ describe('scanner:run', function () { }); }); + describe('run with format --json', () => { + setupCommandTest + .command(['scanner:run', + '--target', path.join('test', 'code-fixtures', 'apex', 'AnotherTestClass.cls'), + '--format', 'json' + ]) + .it('provides only json in stdout', ctx => { + try { + JSON.parse(ctx.stdout); + } catch (error) { + expect.fail("Invalid JSON output from --format json: " + ctx.stdout, error); + } + + }); + }); + describe('Validation on custom config flags', () => { setupCommandTest .command(['scanner:run',