/
ban-tslint-comment.test.ts
84 lines (79 loc) · 2.05 KB
/
ban-tslint-comment.test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import rule from '../../src/rules/ban-tslint-comment';
import { RuleTester } from '../RuleTester';
interface Testable {
code: string;
text?: string;
column?: number;
line?: number;
output?: string;
}
const PALANTIR_EXAMPLES: Testable[] = [
{ code: '/* tslint:disable */' }, // Disable all rules for the rest of the file
{ code: '/* tslint:enable */' }, // Enable all rules for the rest of the file
{
code: '/* tslint:disable:rule1 rule2 rule3... */',
}, // Disable the listed rules for the rest of the file
{
code: '/* tslint:enable:rule1 rule2 rule3... */',
}, // Enable the listed rules for the rest of the file
{ code: '// tslint:disable-next-line' }, // Disables all rules for the following line
{
code: 'someCode(); // tslint:disable-line',
text: '// tslint:disable-line',
column: 13,
output: 'someCode();',
}, // Disables all rules for the current line
{
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
}, // Disables the listed rules for the next line
];
// prettier-ignore
const MORE_EXAMPLES: Testable[] = [
{
code: `const woah = doSomeStuff();
// tslint:disable-line
console.log(woah);
`,
output: `const woah = doSomeStuff();
console.log(woah);
`,
text: '// tslint:disable-line',
line: 2,
},
]
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});
ruleTester.run('ban-tslint-comment', rule, {
valid: [
{
code: 'let a: readonly any[] = [];',
},
{
code: 'let a = new Array();',
},
{
code: '// some other comment',
},
{
code: '// TODO: this is a comment that mentions tslint',
},
{
code: '/* another comment that mentions tslint */',
},
],
invalid: [...PALANTIR_EXAMPLES, ...MORE_EXAMPLES].map(
({ code, column, line, output, text }) => ({
code,
output: output ?? '',
errors: [
{
column: column ?? 1,
line: line ?? 1,
data: { text: text ?? code },
messageId: 'commentDetected' as const,
},
],
}),
),
});