Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(eslint-plugin): switch auto-generated test cases to hand-written in ban-tslint-comment.test.ts #11328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 115 additions & 54 deletions packages/eslint-plugin/tests/rules/ban-tslint-comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,6 @@ import { RuleTester } from '@typescript-eslint/rule-tester';

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

interface Testable {
code: string;
column?: number;
line?: number;
output?: string;
text?: 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',
column: 13,
output: 'someCode();',
text: '// tslint:disable-line',
}, // 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);
`,
line: 2,
output: `const woah = doSomeStuff();
console.log(woah);
`,
text: '// tslint:disable-line',
},
]

const ruleTester = new RuleTester();

ruleTester.run('ban-tslint-comment', rule, {
Expand All @@ -66,18 +22,123 @@ ruleTester.run('ban-tslint-comment', rule, {
code: '/* another comment that mentions tslint */',
},
],
invalid: [...PALANTIR_EXAMPLES, ...MORE_EXAMPLES].map(
({ code, column, line, output, text }) => ({
code,
invalid: [
{
code: '/* tslint:disable */',
errors: [
{
column: 1,
data: {
text: '/* tslint:disable */',
},
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: '/* tslint:enable */',
errors: [
{
column: 1,
data: {
text: '/* tslint:enable */',
},
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: '/* tslint:disable:rule1 rule2 rule3... */',
errors: [
{
column: 1,
data: {
text: '/* tslint:disable:rule1 rule2 rule3... */',
},
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: '/* tslint:enable:rule1 rule2 rule3... */',
errors: [
{
column: 1,
data: {
text: '/* tslint:enable:rule1 rule2 rule3... */',
},
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: '// tslint:disable-next-line',
errors: [
{
column: 1,
data: {
text: '// tslint:disable-next-line',
},
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: 'someCode(); // tslint:disable-line',
errors: [
{
column: column ?? 1,
data: { text: text ?? code },
line: line ?? 1,
messageId: 'commentDetected' as const,
column: 13,
data: {
text: '// tslint:disable-line',
},
line: 1,
messageId: 'commentDetected',
},
],
output: output ?? '',
}),
),
output: 'someCode();',
},
{
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
errors: [
{
column: 1,
data: { text: '// tslint:disable-next-line:rule1 rule2 rule3...' },
line: 1,
messageId: 'commentDetected',
},
],
output: '',
},
{
code: `
const woah = doSomeStuff();
// tslint:disable-line
console.log(woah);
`,
errors: [
{
column: 1,
data: {
text: '// tslint:disable-line',
},
line: 3,
messageId: 'commentDetected',
},
],
output: `
const woah = doSomeStuff();
console.log(woah);
`,
},
],
});