-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrule-mappings.test.ts
More file actions
39 lines (34 loc) · 2.08 KB
/
Copy pathrule-mappings.test.ts
File metadata and controls
39 lines (34 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {Engine, RuleDescription} from "@salesforce/code-analyzer-engine-api";
import {RULE_MAPPINGS} from "../src/rule-mappings";
import {DEFAULT_CONFIG} from "../src/config";
import {ESLintEnginePlugin} from "../src";
import { createDescribeOptions } from "./test-helpers";
describe('Tests for the rule-mappings', () => {
it('Test that the list of all bundled rules matches our RULE_MAPPINGS list', async () => {
const enginePlugin: ESLintEnginePlugin = new ESLintEnginePlugin();
const engine: Engine = await enginePlugin.createEngine('eslint', {
...DEFAULT_CONFIG
});
const ruleDescriptions: RuleDescription[] = await engine.describeRules(createDescribeOptions());
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))
);
}