/
ban-ts-ignore.ts
41 lines (38 loc) · 993 Bytes
/
ban-ts-ignore.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
import * as util from '../util';
export default util.createRule({
name: 'ban-ts-ignore',
meta: {
type: 'problem',
docs: {
description: 'Bans “// @ts-ignore” comments from being used',
category: 'Best Practices',
recommended: 'error',
},
schema: [],
messages: {
tsIgnoreComment:
'Do not use "// @ts-ignore" comments because they suppress compilation errors.',
},
},
defaultOptions: [],
create(context) {
const tsIgnoreRegExp = /^\/*\s*@ts-ignore/;
const sourceCode = context.getSourceCode();
return {
Program(): void {
const comments = sourceCode.getAllComments();
comments.forEach(comment => {
if (comment.type !== 'Line') {
return;
}
if (tsIgnoreRegExp.test(comment.value)) {
context.report({
node: comment,
messageId: 'tsIgnoreComment',
});
}
});
},
};
},
});