forked from G-Rath/eslint-plugin-eslint-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-unknown-rules.ts
43 lines (38 loc) · 990 Bytes
/
no-unknown-rules.ts
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
40
41
42
43
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils';
import { tryGetConfigInfo } from './utils';
export = ESLintUtils.RuleCreator(name => name)({
name: __filename,
meta: {
type: 'problem',
docs: {
description: 'Ensures that all rules are known',
recommended: 'error'
},
messages: {
unknownRule: "Unknown rule '{{ ruleId }}' - Have you forgotten a plugin?"
},
schema: []
},
defaultOptions: [],
create(context) {
const results = tryGetConfigInfo(context.getSourceCode().getText());
if (!results) {
return {};
}
return {
Literal(node: TSESTree.Literal): void {
if (node.value === null) {
return;
}
const ruleId = node.value.toString();
if (results.unknownRules.includes(ruleId)) {
context.report({
data: { ruleId },
messageId: 'unknownRule',
node
});
}
}
};
}
});