Skip to content

Commit 16ca560

Browse files
FIX: @W-16371174@: Fix bug with config commands case insensitivity
1 parent 7e4cd83 commit 16ca560

File tree

5 files changed

+17
-24
lines changed

5 files changed

+17
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/forcedotcom/sfdx-scanner/issues",
77
"dependencies": {
88
"@oclif/core": "^3.3.2",
9-
"@salesforce/code-analyzer-core": "0.20.1",
9+
"@salesforce/code-analyzer-core": "0.20.2",
1010
"@salesforce/code-analyzer-engine-api": "0.16.1",
1111
"@salesforce/code-analyzer-eslint-engine": "0.17.0",
1212
"@salesforce/code-analyzer-flowtest-engine": "0.16.2",

src/lib/actions/ConfigAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ConfigAction {
108108
// We need the Set of all Engines that returned rules for the user's selection on both the Default and User Cores.
109109
const relevantEngines: Set<string> = new Set([...userRules.getEngineNames(), ...selectedDefaultRules.getEngineNames()]);
110110

111-
const configModel: ConfigModel = new AnnotatedConfigModel(userConfig, userCore, userRules, allDefaultRules, relevantEngines);
111+
const configModel: ConfigModel = new AnnotatedConfigModel(userCore, userRules, allDefaultRules, relevantEngines);
112112

113113
const fileWritten: boolean = this.dependencies.writer
114114
? await this.dependencies.writer.write(configModel)

src/lib/models/ConfigModel.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export interface ConfigModel {
2323
}
2424

2525
export class AnnotatedConfigModel implements ConfigModel {
26-
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
2726
private readonly codeAnalyzer: CodeAnalyzer;
2827
private readonly userRules: RuleSelection;
2928
private readonly allDefaultRules: RuleSelection;
@@ -34,8 +33,7 @@ export class AnnotatedConfigModel implements ConfigModel {
3433
// configs not associated with the user's rule selection, thus we can't use the engines from allDefaultRules.
3534
private readonly relevantEngines: Set<string>;
3635

37-
constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
38-
this.config = config;
36+
constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
3937
this.codeAnalyzer = codeAnalyzer;
4038
this.userRules = userRules;
4139
this.allDefaultRules = allDefaultRules;
@@ -45,9 +43,9 @@ export class AnnotatedConfigModel implements ConfigModel {
4543
toFormattedOutput(format: OutputFormat): string {
4644
// istanbul ignore else: Should be impossible
4745
if (format === OutputFormat.STYLED_YAML) {
48-
return new StyledYamlFormatter(this.config, this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml();
46+
return new StyledYamlFormatter(this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml();
4947
} else if (format === OutputFormat.RAW_YAML) {
50-
return new PlainYamlFormatter(this.config, this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml();
48+
return new PlainYamlFormatter(this.codeAnalyzer, this.userRules, this.allDefaultRules, this.relevantEngines).toYaml();
5149
} else {
5250
throw new Error(`Unsupported`)
5351
}
@@ -61,8 +59,8 @@ abstract class YamlFormatter {
6159
private readonly allDefaultRules: RuleSelection;
6260
private readonly relevantEngines: Set<string>;
6361

64-
protected constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
65-
this.config = config;
62+
protected constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
63+
this.config = codeAnalyzer.getConfig();
6664
this.codeAnalyzer = codeAnalyzer;
6765
this.userRules = userRules;
6866
this.allDefaultRules = allDefaultRules;
@@ -214,8 +212,8 @@ abstract class YamlFormatter {
214212
}
215213

216214
class PlainYamlFormatter extends YamlFormatter {
217-
constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
218-
super(config, codeAnalyzer, userRules, allDefaultRules, relevantEngines);
215+
constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
216+
super(codeAnalyzer, userRules, allDefaultRules, relevantEngines);
219217
}
220218

221219
protected toYamlComment(commentText: string): string {
@@ -224,8 +222,8 @@ class PlainYamlFormatter extends YamlFormatter {
224222
}
225223

226224
class StyledYamlFormatter extends YamlFormatter {
227-
constructor(config: CodeAnalyzerConfig, codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
228-
super(config, codeAnalyzer, userRules, allDefaultRules, relevantEngines);
225+
constructor(codeAnalyzer: CodeAnalyzer, userRules: RuleSelection, allDefaultRules: RuleSelection, relevantEngines: Set<string>) {
226+
super(codeAnalyzer, userRules, allDefaultRules, relevantEngines);
229227
}
230228

231229
protected toYamlComment(commentText: string): string {

src/lib/viewers/ResultsViewer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ export class ResultsTableDisplayer extends AbstractResultsDisplayer {
141141
protected _view(results: RunResults) {
142142
const violations: Violation[] = sortViolations(results.getViolations());
143143
const parentFolder: string = findLongestCommonParentFolderOf(violations.map(v =>
144-
getPrimaryLocation(v).getFile()).filter(f => f !== undefined));
144+
v.getPrimaryLocation().getFile()).filter(f => f !== undefined));
145145

146146
const resultRows: ResultRow[] = violations.map((v, idx) => {
147147
const severity = v.getRule().getSeverityLevel();
148-
const primaryLocation = getPrimaryLocation(v);
148+
const primaryLocation: CodeLocation = v.getPrimaryLocation();
149149
const relativeFile: string | null = primaryLocation.getFile() ?
150150
path.relative(parentFolder, primaryLocation.getFile()!) : null;
151151
return {
@@ -193,11 +193,6 @@ function sortViolations(violations: Violation[]): Violation[] {
193193
});
194194
}
195195

196-
// TODO: We should update core module to have this function directly on the Violation object and then remove this helper
197-
function getPrimaryLocation(violation: Violation): CodeLocation {
198-
return violation.getCodeLocations()[violation.getPrimaryLocationIndex()];
199-
}
200-
201196
/**
202197
* Returns the longest comment parent folder of the file paths provided
203198
* Note that this function assumes that all the paths are indeed files and not folders

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,10 +1699,10 @@
16991699
strip-ansi "6.0.1"
17001700
ts-retry-promise "^0.8.1"
17011701

1702-
"@salesforce/[email protected].1":
1703-
version "0.20.1"
1704-
resolved "https://registry.yarnpkg.com/@salesforce/code-analyzer-core/-/code-analyzer-core-0.20.1.tgz#319fa83aa645cec6d14d8b0ad97cbfef505b1cee"
1705-
integrity sha512-c/xqGoB2Naea5+xbE/N8dcIC5gt1Fety1QRs2CKrXgv23y2YzYi7W6u7hmGZ9SlqtT0RvT3OngdvY7qgiaLV0Q==
1702+
"@salesforce/[email protected].2":
1703+
version "0.20.2"
1704+
resolved "https://registry.yarnpkg.com/@salesforce/code-analyzer-core/-/code-analyzer-core-0.20.2.tgz#bc33c27809929070473e9dd94ef0fcf77f4a23c6"
1705+
integrity sha512-b1PqZD2lAW7XUcDjYAS+V40CpHQsLysdfq7Elo9ap6eCasjQ15CTOsctJWjyv2ZpUTyphAYo9iSDjkLZCJD2eg==
17061706
dependencies:
17071707
"@salesforce/code-analyzer-engine-api" "0.16.1"
17081708
"@types/js-yaml" "^4.0.9"

0 commit comments

Comments
 (0)