diff --git a/messages/shared.md b/messages/shared.md index 039af4710..f5b76e129 100644 --- a/messages/shared.md +++ b/messages/shared.md @@ -1,6 +1,6 @@ # label.command-state -Developer Preview +Beta # warning.command-state diff --git a/package.json b/package.json index aedef6b0e..0e579f023 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/forcedotcom/sfdx-scanner/issues", "dependencies": { "@oclif/core": "^3.3.2", - "@salesforce/code-analyzer-core": "0.20.1", + "@salesforce/code-analyzer-core": "0.20.2", "@salesforce/code-analyzer-engine-api": "0.16.1", "@salesforce/code-analyzer-eslint-engine": "0.17.0", "@salesforce/code-analyzer-flowtest-engine": "0.16.2", diff --git a/src/commands/code-analyzer/config.ts b/src/commands/code-analyzer/config.ts index e53bf4cd2..ee17dea12 100644 --- a/src/commands/code-analyzer/config.ts +++ b/src/commands/code-analyzer/config.ts @@ -17,7 +17,7 @@ export default class ConfigCommand extends SfCommand implements Displayabl public static readonly description = getMessage(BundleName.ConfigCommand, 'command.description'); public static readonly examples = getMessages(BundleName.ConfigCommand, 'command.examples'); - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA public static readonly state = getMessage(BundleName.Shared, 'label.command-state'); public static readonly flags = { @@ -50,7 +50,7 @@ export default class ConfigCommand extends SfCommand implements Displayabl }; public async run(): Promise { - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA this.warn(getMessage(BundleName.Shared, "warning.command-state", [getMessage(BundleName.Shared, 'label.command-state')])); const parsedFlags = (await this.parse(ConfigCommand)).flags; diff --git a/src/commands/code-analyzer/rules.ts b/src/commands/code-analyzer/rules.ts index 398a24b80..1e47ed925 100644 --- a/src/commands/code-analyzer/rules.ts +++ b/src/commands/code-analyzer/rules.ts @@ -17,7 +17,7 @@ export default class RulesCommand extends SfCommand implements Displayable public static readonly description = getMessage(BundleName.RulesCommand, 'command.description'); public static readonly examples = getMessages(BundleName.RulesCommand, 'command.examples'); - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA public static readonly state = getMessage(BundleName.Shared, 'label.command-state'); public static readonly flags = { @@ -52,7 +52,7 @@ export default class RulesCommand extends SfCommand implements Displayable }; public async run(): Promise { - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA this.warn(getMessage(BundleName.Shared, "warning.command-state", [getMessage(BundleName.Shared, 'label.command-state')])); const parsedFlags = (await this.parse(RulesCommand)).flags; diff --git a/src/commands/code-analyzer/run.ts b/src/commands/code-analyzer/run.ts index 16fa2b2e5..5d72c93e1 100644 --- a/src/commands/code-analyzer/run.ts +++ b/src/commands/code-analyzer/run.ts @@ -19,7 +19,7 @@ export default class RunCommand extends SfCommand implements Displayable { public static readonly description = getMessage(BundleName.RunCommand, 'command.description'); public static readonly examples = getMessages(BundleName.RunCommand, 'command.examples'); - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA public static readonly state = getMessage(BundleName.Shared, 'label.command-state'); public static readonly flags = { @@ -78,7 +78,7 @@ export default class RunCommand extends SfCommand implements Displayable { }; public async run(): Promise { - // TODO: Update when we go to Beta and when we go GA + // TODO: Remove when we go GA this.warn(getMessage(BundleName.Shared, "warning.command-state", [getMessage(BundleName.Shared, 'label.command-state')])); const parsedFlags = (await this.parse(RunCommand)).flags; diff --git a/src/lib/actions/ConfigAction.ts b/src/lib/actions/ConfigAction.ts index f52bf24f2..e7cf94757 100644 --- a/src/lib/actions/ConfigAction.ts +++ b/src/lib/actions/ConfigAction.ts @@ -108,7 +108,7 @@ export class ConfigAction { // We need the Set of all Engines that returned rules for the user's selection on both the Default and User Cores. const relevantEngines: Set = new Set([...userRules.getEngineNames(), ...selectedDefaultRules.getEngineNames()]); - const configModel: ConfigModel = new AnnotatedConfigModel(userConfig, userCore, userRules, allDefaultRules, relevantEngines); + const configModel: ConfigModel = new AnnotatedConfigModel(userCore, userRules, allDefaultRules, relevantEngines); const fileWritten: boolean = this.dependencies.writer ? await this.dependencies.writer.write(configModel) diff --git a/src/lib/models/ConfigModel.ts b/src/lib/models/ConfigModel.ts index 90f3b45c3..de7d9eb66 100644 --- a/src/lib/models/ConfigModel.ts +++ b/src/lib/models/ConfigModel.ts @@ -23,7 +23,6 @@ export interface ConfigModel { } export class AnnotatedConfigModel implements ConfigModel { - private readonly config: CodeAnalyzerConfig; // TODO: It would be nice if we updated the CodeAnalyzer (in our core module) to just return its CodeAnalyzerConfig with a getter so we didn't need to pass it around private readonly codeAnalyzer: CodeAnalyzer; private readonly userRules: RuleSelection; private readonly allDefaultRules: RuleSelection; @@ -34,8 +33,7 @@ export class AnnotatedConfigModel implements ConfigModel { // configs not associated with the user's rule selection, thus we can't use the engines from allDefaultRules. private readonly relevantEngines: Set; - constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { - this.config = config; + constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { this.codeAnalyzer = codeAnalyzer; this.userRules = userRules; this.allDefaultRules = allDefaultRules; @@ -45,9 +43,9 @@ export class AnnotatedConfigModel implements ConfigModel { toFormattedOutput(format: OutputFormat): string { // istanbul ignore else: Should be impossible if (format === OutputFormat.STYLED_YAML) { - return new StyledYamlFormatter(this.config, this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml(); + return new StyledYamlFormatter(this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml(); } else if (format === OutputFormat.RAW_YAML) { - return new PlainYamlFormatter(this.config, this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml(); + return new PlainYamlFormatter(this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml(); } else { throw new Error(`Unsupported`) } @@ -61,8 +59,8 @@ abstract class YamlFormatter { private readonly allDefaultRules: RuleSelection; private readonly relevantEngines: Set; - protected constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { - this.config = config; + protected constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { + this.config = codeAnalyzer.getConfig(); this.codeAnalyzer = codeAnalyzer; this.userRules = userRules; this.allDefaultRules = allDefaultRules; @@ -214,8 +212,8 @@ abstract class YamlFormatter { } class PlainYamlFormatter extends YamlFormatter { - constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { - super(config, codeAnalyzer, userRules, allDefaultRules, relevantEngines); + constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { + super(codeAnalyzer, userRules, allDefaultRules, relevantEngines); } protected toYamlComment(commentText: string): string { @@ -224,8 +222,8 @@ class PlainYamlFormatter extends YamlFormatter { } class StyledYamlFormatter extends YamlFormatter { - constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { - super(config, codeAnalyzer, userRules, allDefaultRules, relevantEngines); + constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set) { + super(codeAnalyzer, userRules, allDefaultRules, relevantEngines); } protected toYamlComment(commentText: string): string { diff --git a/src/lib/viewers/ResultsViewer.ts b/src/lib/viewers/ResultsViewer.ts index 1034533d8..4f77265a2 100644 --- a/src/lib/viewers/ResultsViewer.ts +++ b/src/lib/viewers/ResultsViewer.ts @@ -141,11 +141,11 @@ export class ResultsTableDisplayer extends AbstractResultsDisplayer { protected _view(results: RunResults) { const violations: Violation[] = sortViolations(results.getViolations()); const parentFolder: string = findLongestCommonParentFolderOf(violations.map(v => - getPrimaryLocation(v).getFile()).filter(f => f !== undefined)); + v.getPrimaryLocation().getFile()).filter(f => f !== undefined)); const resultRows: ResultRow[] = violations.map((v, idx) => { const severity = v.getRule().getSeverityLevel(); - const primaryLocation = getPrimaryLocation(v); + const primaryLocation: CodeLocation = v.getPrimaryLocation(); const relativeFile: string | null = primaryLocation.getFile() ? path.relative(parentFolder, primaryLocation.getFile()!) : null; return { @@ -193,11 +193,6 @@ function sortViolations(violations: Violation[]): Violation[] { }); } -// TODO: We should update core module to have this function directly on the Violation object and then remove this helper -function getPrimaryLocation(violation: Violation): CodeLocation { - return violation.getCodeLocations()[violation.getPrimaryLocationIndex()]; -} - /** * Returns the longest comment parent folder of the file paths provided * Note that this function assumes that all the paths are indeed files and not folders diff --git a/yarn.lock b/yarn.lock index 5a806b817..ca3d65b16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1699,10 +1699,10 @@ strip-ansi "6.0.1" ts-retry-promise "^0.8.1" -"@salesforce/code-analyzer-core@0.20.1": - version "0.20.1" - resolved "https://registry.yarnpkg.com/@salesforce/code-analyzer-core/-/code-analyzer-core-0.20.1.tgz#319fa83aa645cec6d14d8b0ad97cbfef505b1cee" - integrity sha512-c/xqGoB2Naea5+xbE/N8dcIC5gt1Fety1QRs2CKrXgv23y2YzYi7W6u7hmGZ9SlqtT0RvT3OngdvY7qgiaLV0Q== +"@salesforce/code-analyzer-core@0.20.2": + version "0.20.2" + resolved "https://registry.yarnpkg.com/@salesforce/code-analyzer-core/-/code-analyzer-core-0.20.2.tgz#bc33c27809929070473e9dd94ef0fcf77f4a23c6" + integrity sha512-b1PqZD2lAW7XUcDjYAS+V40CpHQsLysdfq7Elo9ap6eCasjQ15CTOsctJWjyv2ZpUTyphAYo9iSDjkLZCJD2eg== dependencies: "@salesforce/code-analyzer-engine-api" "0.16.1" "@types/js-yaml" "^4.0.9"