-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW(eslint): @W-17378695@: Add in rule mappings to lock in severities…
… and tags for eslint (#179)
- Loading branch information
1 parent
14a7933
commit 9b81fbc
Showing
18 changed files
with
8,749 additions
and
2,879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,344 changes: 1,344 additions & 0 deletions
1,344
packages/code-analyzer-eslint-engine/src/rule-mappings.ts
Large diffs are not rendered by default.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
packages/code-analyzer-eslint-engine/test/rule-mappings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {RuleDescription} from "@salesforce/code-analyzer-engine-api"; | ||
import {RULE_MAPPINGS} from "../src/rule-mappings"; | ||
import {ESLintEngine} from "../src/engine"; | ||
import {DEFAULT_CONFIG} from "../src/config"; | ||
|
||
describe('Tests for the rule-mappings', () => { | ||
it('Test that the list of all bundled rules matches our RULE_MAPPINGS list', async () => { | ||
const engine: ESLintEngine = new ESLintEngine(DEFAULT_CONFIG); | ||
const ruleDescriptions: RuleDescription[] = await engine.describeRules({}); | ||
const actualRuleNames: Set<string> = new Set(ruleDescriptions.map(rd => rd.name)); | ||
const ruleNamesInRuleMappings: Set<string> = new Set(Object.keys(RULE_MAPPINGS)); | ||
|
||
const unusedRuleNamesFromRuleMappings: Set<string> = setDiff(ruleNamesInRuleMappings, actualRuleNames); | ||
if (unusedRuleNamesFromRuleMappings.size > 0) { | ||
throw new Error("The following rule names are found in RULE_MAPPINGS but do not associated to any bundled eslint rules that come with our base configs:\n " + | ||
[...unusedRuleNamesFromRuleMappings].join(', ')); | ||
|
||
} | ||
|
||
const missingRuleNamesFromRuleMappings: Set<string> = setDiff(actualRuleNames, ruleNamesInRuleMappings); | ||
if (missingRuleNamesFromRuleMappings.size > 0) { | ||
throw new Error("The following bundled rules are missing from the RULE_MAPPINGS list (Note: when adding them, make sure to add in the appropriate language tags):\n " + | ||
[...missingRuleNamesFromRuleMappings].join(', ') + "\n\n" + | ||
"Calculated Rule Descriptions for the missing rules: \n" + | ||
JSON.stringify(ruleDescriptions.filter(rd => missingRuleNamesFromRuleMappings.has(rd.name)), null, 2) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
function setDiff(setA: Set<string>, setB: Set<string>): Set<string> { | ||
return new Set( | ||
[...setA].filter(value => !setB.has(value)) | ||
); | ||
} |
Oops, something went wrong.