Skip to content

Commit 9fb60d2

Browse files
authored
chore(eslint-plugin): switch auto-generated test cases to hand-written in ban-tslint-comment.test.ts (typescript-eslint#11328)
Switch to handwritten test cases
1 parent c273e03 commit 9fb60d2

File tree

1 file changed

+115
-54
lines changed

1 file changed

+115
-54
lines changed

packages/eslint-plugin/tests/rules/ban-tslint-comment.test.ts

Lines changed: 115 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,6 @@ import { RuleTester } from '@typescript-eslint/rule-tester';
22

33
import rule from '../../src/rules/ban-tslint-comment';
44

5-
interface Testable {
6-
code: string;
7-
column?: number;
8-
line?: number;
9-
output?: string;
10-
text?: string;
11-
}
12-
13-
const PALANTIR_EXAMPLES: Testable[] = [
14-
{ code: '/* tslint:disable */' }, // Disable all rules for the rest of the file
15-
{ code: '/* tslint:enable */' }, // Enable all rules for the rest of the file
16-
{
17-
code: '/* tslint:disable:rule1 rule2 rule3... */',
18-
}, // Disable the listed rules for the rest of the file
19-
{
20-
code: '/* tslint:enable:rule1 rule2 rule3... */',
21-
}, // Enable the listed rules for the rest of the file
22-
{ code: '// tslint:disable-next-line' }, // Disables all rules for the following line
23-
{
24-
code: 'someCode(); // tslint:disable-line',
25-
column: 13,
26-
output: 'someCode();',
27-
text: '// tslint:disable-line',
28-
}, // Disables all rules for the current line
29-
{
30-
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
31-
}, // Disables the listed rules for the next line
32-
];
33-
34-
// prettier-ignore
35-
const MORE_EXAMPLES: Testable[] = [
36-
{
37-
code: `const woah = doSomeStuff();
38-
// tslint:disable-line
39-
console.log(woah);
40-
`,
41-
line: 2,
42-
output: `const woah = doSomeStuff();
43-
console.log(woah);
44-
`,
45-
text: '// tslint:disable-line',
46-
},
47-
]
48-
495
const ruleTester = new RuleTester();
506

517
ruleTester.run('ban-tslint-comment', rule, {
@@ -66,18 +22,123 @@ ruleTester.run('ban-tslint-comment', rule, {
6622
code: '/* another comment that mentions tslint */',
6723
},
6824
],
69-
invalid: [...PALANTIR_EXAMPLES, ...MORE_EXAMPLES].map(
70-
({ code, column, line, output, text }) => ({
71-
code,
25+
invalid: [
26+
{
27+
code: '/* tslint:disable */',
28+
errors: [
29+
{
30+
column: 1,
31+
data: {
32+
text: '/* tslint:disable */',
33+
},
34+
line: 1,
35+
messageId: 'commentDetected',
36+
},
37+
],
38+
output: '',
39+
},
40+
{
41+
code: '/* tslint:enable */',
42+
errors: [
43+
{
44+
column: 1,
45+
data: {
46+
text: '/* tslint:enable */',
47+
},
48+
line: 1,
49+
messageId: 'commentDetected',
50+
},
51+
],
52+
output: '',
53+
},
54+
{
55+
code: '/* tslint:disable:rule1 rule2 rule3... */',
56+
errors: [
57+
{
58+
column: 1,
59+
data: {
60+
text: '/* tslint:disable:rule1 rule2 rule3... */',
61+
},
62+
line: 1,
63+
messageId: 'commentDetected',
64+
},
65+
],
66+
output: '',
67+
},
68+
{
69+
code: '/* tslint:enable:rule1 rule2 rule3... */',
70+
errors: [
71+
{
72+
column: 1,
73+
data: {
74+
text: '/* tslint:enable:rule1 rule2 rule3... */',
75+
},
76+
line: 1,
77+
messageId: 'commentDetected',
78+
},
79+
],
80+
output: '',
81+
},
82+
{
83+
code: '// tslint:disable-next-line',
84+
errors: [
85+
{
86+
column: 1,
87+
data: {
88+
text: '// tslint:disable-next-line',
89+
},
90+
line: 1,
91+
messageId: 'commentDetected',
92+
},
93+
],
94+
output: '',
95+
},
96+
{
97+
code: 'someCode(); // tslint:disable-line',
7298
errors: [
7399
{
74-
column: column ?? 1,
75-
data: { text: text ?? code },
76-
line: line ?? 1,
77-
messageId: 'commentDetected' as const,
100+
column: 13,
101+
data: {
102+
text: '// tslint:disable-line',
103+
},
104+
line: 1,
105+
messageId: 'commentDetected',
78106
},
79107
],
80-
output: output ?? '',
81-
}),
82-
),
108+
output: 'someCode();',
109+
},
110+
{
111+
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
112+
errors: [
113+
{
114+
column: 1,
115+
data: { text: '// tslint:disable-next-line:rule1 rule2 rule3...' },
116+
line: 1,
117+
messageId: 'commentDetected',
118+
},
119+
],
120+
output: '',
121+
},
122+
{
123+
code: `
124+
const woah = doSomeStuff();
125+
// tslint:disable-line
126+
console.log(woah);
127+
`,
128+
errors: [
129+
{
130+
column: 1,
131+
data: {
132+
text: '// tslint:disable-line',
133+
},
134+
line: 3,
135+
messageId: 'commentDetected',
136+
},
137+
],
138+
output: `
139+
const woah = doSomeStuff();
140+
console.log(woah);
141+
`,
142+
},
143+
],
83144
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy