From 73c5b64a24baac80b8b1c52080508e3958b05a31 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Mon, 25 May 2020 14:02:41 -0400 Subject: [PATCH 1/8] adds "allow-with-description" option to `ban-ts-comments` rule --- packages/eslint-plugin/README.md | 2 +- .../docs/rules/ban-ts-comment.md | 2 +- .../eslint-plugin/src/rules/ban-ts-comment.ts | 79 +++++++++++++++---- .../tests/rules/ban-ts-comment.test.ts | 67 ++++++++++++++++ 4 files changed, 131 insertions(+), 19 deletions(-) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index b32cb4a1782b..975bb88f08b2 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -92,7 +92,7 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive | :heavy_check_mark: | | | | [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays | | :wrench: | | | [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :heavy_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `// @ts-` comments from being used | :heavy_check_mark: | | | +| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `// @ts-` comments from being used or requires descriptions after directive | :heavy_check_mark: | | | | [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | | :wrench: | | | [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | | | | diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index cb540bc8d092..247ea80c2fdd 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -1,4 +1,4 @@ -# Bans `// @ts-` comments from being used (`ban-ts-comment`) +# Bans `// @ts-` comments from being used or requires descriptions after directive (`ban-ts-comment`) TypeScript provides several directive comments that can be used to alter how it processes files. Using these to suppress TypeScript Compiler Errors reduces the effectiveness of TypeScript overall. diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index bcbc02e9a0a1..3fb0b1548e76 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -2,10 +2,10 @@ import { AST_TOKEN_TYPES } from '@typescript-eslint/experimental-utils'; import * as util from '../util'; interface Options { - 'ts-expect-error'?: boolean; - 'ts-ignore'?: boolean; - 'ts-nocheck'?: boolean; - 'ts-check'?: boolean; + 'ts-expect-error'?: boolean | 'allow-with-description'; + 'ts-ignore'?: boolean | 'allow-with-description'; + 'ts-nocheck'?: boolean | 'allow-with-description'; + 'ts-check'?: boolean | 'allow-with-description'; } const defaultOptions: [Options] = [ @@ -17,40 +17,73 @@ const defaultOptions: [Options] = [ }, ]; -type MessageIds = 'tsDirectiveComment'; +type MessageIds = + | 'tsDirectiveComment' + | 'tsDirectiveCommentRequiresDescription'; export default util.createRule<[Options], MessageIds>({ name: 'ban-ts-comment', meta: { type: 'problem', docs: { - description: 'Bans `// @ts-` comments from being used', + description: + 'Bans `// @ts-` comments from being used or requires descriptions after directive', category: 'Best Practices', recommended: 'error', }, messages: { tsDirectiveComment: 'Do not use "// @ts-{{directive}}" because it alters compilation errors.', + tsDirectiveCommentRequiresDescription: + 'When using "// @ts-{{directive}}" you must also provide a description after the the directive.', }, schema: [ { type: 'object', properties: { 'ts-expect-error': { - type: 'boolean', - default: true, + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + ], }, 'ts-ignore': { - type: 'boolean', - default: true, + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + ], }, 'ts-nocheck': { - type: 'boolean', - default: true, + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + ], }, 'ts-check': { - type: 'boolean', - default: false, + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + ], }, }, additionalProperties: false, @@ -59,7 +92,7 @@ export default util.createRule<[Options], MessageIds>({ }, defaultOptions, create(context, [options]) { - const tsCommentRegExp = /^\/*\s*@ts-(expect-error|ignore|check|nocheck)/; + const tsCommentRegExp = /^\/*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/; const sourceCode = context.getSourceCode(); return { @@ -71,17 +104,29 @@ export default util.createRule<[Options], MessageIds>({ return; } - const [, directive] = tsCommentRegExp.exec(comment.value) ?? []; + const [, directive, description] = + tsCommentRegExp.exec(comment.value) ?? []; const fullDirective = `ts-${directive}` as keyof Options; - if (options[fullDirective]) { + const option = options[fullDirective]; + if (option === true) { context.report({ data: { directive }, node: comment, messageId: 'tsDirectiveComment', }); } + + if (option === 'allow-with-description') { + if (description.length === 0) { + context.report({ + data: { directive }, + node: comment, + messageId: 'tsDirectiveCommentRequiresDescription', + }); + } + } }); }, }; diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index 89ff1db4a615..82e2f231fd49 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -19,6 +19,10 @@ ruleTester.run('ts-expect-error', rule, { code: '// @ts-expect-error', options: [{ 'ts-expect-error': false }], }, + { + code: '// @ts-expect-error here is why the error is expected', + options: [{ 'ts-expect-error': 'allow-with-description' }], + }, ], invalid: [ { @@ -74,6 +78,18 @@ if (false) { }, ], }, + { + code: '// @ts-expect-error', + options: [{ 'ts-expect-error': 'allow-with-description' }], + errors: [ + { + data: { directive: 'expect-error' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -91,6 +107,11 @@ ruleTester.run('ts-ignore', rule, { code: '// @ts-ignore', options: [{ 'ts-ignore': false }], }, + { + code: + '// @ts-ignore I am Ziltoid the Omniscient and I am exempted from any need to follow the rules!', + options: [{ 'ts-ignore': 'allow-with-description' }], + }, ], invalid: [ { @@ -154,6 +175,18 @@ if (false) { }, ], }, + { + code: '// @ts-ignore', + options: [{ 'ts-ignore': 'allow-with-description' }], + errors: [ + { + data: { directive: 'ignore' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -171,6 +204,11 @@ ruleTester.run('ts-nocheck', rule, { code: '// @ts-nocheck', options: [{ 'ts-nocheck': false }], }, + { + code: + '// @ts-nocheck no doubt, people will put nonsense here from time to time just to get the rule to stop reporting, perhaps even long messages with other nonsense in them like other // @ts-nocheck or // @ts-ignore things', + options: [{ 'ts-nocheck': 'allow-with-description' }], + }, ], invalid: [ { @@ -234,6 +272,18 @@ if (false) { }, ], }, + { + code: '// @ts-nocheck', + options: [{ 'ts-nocheck': 'allow-with-description' }], + errors: [ + { + data: { directive: 'nocheck' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -251,6 +301,11 @@ ruleTester.run('ts-check', rule, { code: '// @ts-check', options: [{ 'ts-check': false }], }, + { + code: + '// @ts-check with a description and also with a no-op // @ts-ignore', + options: [{ 'ts-check': 'allow-with-description' }], + }, ], invalid: [ { @@ -307,5 +362,17 @@ if (false) { }, ], }, + { + code: '// @ts-ignore', + options: [{ 'ts-ignore': 'allow-with-description' }], + errors: [ + { + data: { directive: 'ignore' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, ], }); From a4b99d7b602843a04b34e573da31dd4b6d83cfbd Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Mon, 25 May 2020 14:38:39 -0400 Subject: [PATCH 2/8] updates message to resemble the eslint-comments/require-description --- packages/eslint-plugin/src/rules/ban-ts-comment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 3fb0b1548e76..ac9ffa9a275c 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -35,7 +35,7 @@ export default util.createRule<[Options], MessageIds>({ tsDirectiveComment: 'Do not use "// @ts-{{directive}}" because it alters compilation errors.', tsDirectiveCommentRequiresDescription: - 'When using "// @ts-{{directive}}" you must also provide a description after the the directive.', + 'Include a description after the "// @ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary.', }, schema: [ { From 12262fe6c61079569dbf7bf68ea1213cd5d2fdc8 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 14:43:00 -0400 Subject: [PATCH 3/8] adds threshold for minimum length --- .../eslint-plugin/src/rules/ban-ts-comment.ts | 3 ++- .../tests/rules/ban-ts-comment.test.ts | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index ac9ffa9a275c..25d189c89132 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -119,7 +119,8 @@ export default util.createRule<[Options], MessageIds>({ } if (option === 'allow-with-description') { - if (description.length === 0) { + const threshold = 3; + if (description.trim().length < threshold) { context.report({ data: { directive }, node: comment, diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index 82e2f231fd49..93397e140f12 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -187,6 +187,31 @@ if (false) { }, ], }, + { + // eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting + code: '// @ts-ignore ', + options: [{ 'ts-ignore': 'allow-with-description' }], + errors: [ + { + data: { directive: 'ignore' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-ignore .', + options: [{ 'ts-ignore': 'allow-with-description' }], + errors: [ + { + data: { directive: 'ignore' }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, ], }); From fda8ee1ceaf272889322d416785632840d90b6ee Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 14:52:09 -0400 Subject: [PATCH 4/8] adds documentation for allow-with-description --- .../docs/rules/ban-ts-comment.md | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index 247ea80c2fdd..c36f5cc6702b 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -21,10 +21,10 @@ The configuration looks like this: ```ts interface Options { - 'ts-expect-error'?: boolean; - 'ts-ignore'?: boolean; - 'ts-nocheck'?: boolean; - 'ts-check'?: boolean; + 'ts-expect-error'?: boolean | 'allow-with-description'; + 'ts-ignore'?: boolean | 'allow-with-description'; + 'ts-nocheck'?: boolean | 'allow-with-description'; + 'ts-check'?: boolean | 'allow-with-description'; } const defaultOptions: Options = { @@ -35,6 +35,8 @@ const defaultOptions: Options = { }; ``` +### `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check` directives + A value of `true` for a particular directive means that this rule will report if it finds any usage of said directive. For example, with the defaults above the following patterns are considered warnings: @@ -55,6 +57,28 @@ if (false) { } ``` +### `allow-with-description` + +A value of `'allow-with-description'` for a particular directive means that this rule will report if it finds a directive that does not have a description following the directive (on the same line). + +For example, with `{ 'ts-expect-error': 'allow-with-description' }` the following pattern is considered a warning: + +```ts +if (false) { + // @ts-expect-error + console.log('hello'); +} +``` + +The following pattern is not a warning: + +```ts +if (false) { + // @ts-expect-error: Unreachable code error + console.log('hello'); +} +``` + ## When Not To Use It If you want to use all of the TypeScript directives. From 27fd6102ad0acceafe94cdec8099b3cbd18a6ac5 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 15:06:49 -0400 Subject: [PATCH 5/8] removes unknown cspell word to make CI pass --- packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index 93397e140f12..bd7368f66b94 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -109,7 +109,7 @@ ruleTester.run('ts-ignore', rule, { }, { code: - '// @ts-ignore I am Ziltoid the Omniscient and I am exempted from any need to follow the rules!', + '// @ts-ignore I think that I am exempted from any need to follow the rules!', options: [{ 'ts-ignore': 'allow-with-description' }], }, ], From 65c71a018013841916efad9e8aba4ddcb1352d38 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 15:58:57 -0400 Subject: [PATCH 6/8] adds `minimumDescriptionLength` option to `ban-ts-comment` --- .../docs/rules/ban-ts-comment.md | 24 +++++++++ .../eslint-plugin/src/rules/ban-ts-comment.ts | 18 +++++-- .../tests/rules/ban-ts-comment.test.ts | 54 +++++++++++++++---- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index c36f5cc6702b..60e6508d3bd3 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -25,6 +25,7 @@ interface Options { 'ts-ignore'?: boolean | 'allow-with-description'; 'ts-nocheck'?: boolean | 'allow-with-description'; 'ts-check'?: boolean | 'allow-with-description'; + minimumDescriptionLength?: number; } const defaultOptions: Options = { @@ -32,6 +33,7 @@ const defaultOptions: Options = { 'ts-ignore': true, 'ts-nocheck': true, 'ts-check': false, + minimumDescriptionLength: 3, }; ``` @@ -79,6 +81,28 @@ if (false) { } ``` +### `minimumDescriptionLength` + +Use `minimumDescriptionLength` to set a minimum length for descriptions when using the `allow-with-description` option for a directive. + +For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 10 }` the following pattern is considered a warning: + +```ts +if (false) { + // @ts-expect-error: TODO + console.log('hello'); +} +``` + +The following pattern is not a warning: + +```ts +if (false) { + // @ts-expect-error The rationale for this override is described in issue #1337 on GitLab + console.log('hello'); +} +``` + ## When Not To Use It If you want to use all of the TypeScript directives. diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 25d189c89132..3eccf04ced20 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -6,14 +6,18 @@ interface Options { 'ts-ignore'?: boolean | 'allow-with-description'; 'ts-nocheck'?: boolean | 'allow-with-description'; 'ts-check'?: boolean | 'allow-with-description'; + minimumDescriptionLength?: number; } +export const defaultMinimumDescriptionLength = 3; + const defaultOptions: [Options] = [ { 'ts-expect-error': true, 'ts-ignore': true, 'ts-nocheck': true, 'ts-check': false, + minimumDescriptionLength: defaultMinimumDescriptionLength, }, ]; @@ -35,7 +39,7 @@ export default util.createRule<[Options], MessageIds>({ tsDirectiveComment: 'Do not use "// @ts-{{directive}}" because it alters compilation errors.', tsDirectiveCommentRequiresDescription: - 'Include a description after the "// @ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary.', + 'Include a description after the "// @ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary. The description must be {{minimumDescriptionLength}} characters or longer.', }, schema: [ { @@ -85,6 +89,10 @@ export default util.createRule<[Options], MessageIds>({ }, ], }, + minimumDescriptionLength: { + type: 'number', + default: defaultMinimumDescriptionLength, + }, }, additionalProperties: false, }, @@ -119,10 +127,12 @@ export default util.createRule<[Options], MessageIds>({ } if (option === 'allow-with-description') { - const threshold = 3; - if (description.trim().length < threshold) { + const { + minimumDescriptionLength = defaultMinimumDescriptionLength, + } = options; + if (description.trim().length < minimumDescriptionLength) { context.report({ - data: { directive }, + data: { directive, minimumDescriptionLength }, node: comment, messageId: 'tsDirectiveCommentRequiresDescription', }); diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index bd7368f66b94..18de8fad0d77 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -21,7 +21,20 @@ ruleTester.run('ts-expect-error', rule, { }, { code: '// @ts-expect-error here is why the error is expected', - options: [{ 'ts-expect-error': 'allow-with-description' }], + options: [ + { + 'ts-expect-error': 'allow-with-description', + }, + ], + }, + { + code: '// @ts-expect-error abcdefghij', + options: [ + { + 'ts-expect-error': 'allow-with-description', + minimumDescriptionLength: 10, + }, + ], }, ], invalid: [ @@ -80,10 +93,31 @@ if (false) { }, { code: '// @ts-expect-error', - options: [{ 'ts-expect-error': 'allow-with-description' }], + options: [ + { + 'ts-expect-error': 'allow-with-description', + }, + ], errors: [ { - data: { directive: 'expect-error' }, + data: { directive: 'expect-error', minimumDescriptionLength: 3 }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-expect-error: TODO', + options: [ + { + 'ts-expect-error': 'allow-with-description', + minimumDescriptionLength: 10, + }, + ], + errors: [ + { + data: { directive: 'expect-error', minimumDescriptionLength: 10 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, @@ -180,7 +214,7 @@ if (false) { options: [{ 'ts-ignore': 'allow-with-description' }], errors: [ { - data: { directive: 'ignore' }, + data: { directive: 'ignore', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, @@ -193,7 +227,7 @@ if (false) { options: [{ 'ts-ignore': 'allow-with-description' }], errors: [ { - data: { directive: 'ignore' }, + data: { directive: 'ignore', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, @@ -205,7 +239,7 @@ if (false) { options: [{ 'ts-ignore': 'allow-with-description' }], errors: [ { - data: { directive: 'ignore' }, + data: { directive: 'ignore', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, @@ -302,7 +336,7 @@ if (false) { options: [{ 'ts-nocheck': 'allow-with-description' }], errors: [ { - data: { directive: 'nocheck' }, + data: { directive: 'nocheck', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, @@ -329,7 +363,9 @@ ruleTester.run('ts-check', rule, { { code: '// @ts-check with a description and also with a no-op // @ts-ignore', - options: [{ 'ts-check': 'allow-with-description' }], + options: [ + { 'ts-check': 'allow-with-description', minimumDescriptionLength: 3 }, + ], }, ], invalid: [ @@ -392,7 +428,7 @@ if (false) { options: [{ 'ts-ignore': 'allow-with-description' }], errors: [ { - data: { directive: 'ignore' }, + data: { directive: 'ignore', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, From a1a8e0ea95a6afcfae2c98a34e713f23c998cc4d Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 17:00:00 -0400 Subject: [PATCH 7/8] use `noFormat` instead of eslint-disable --- packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index 18de8fad0d77..9eb25738f860 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -1,5 +1,5 @@ import rule from '../../src/rules/ban-ts-comment'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, noFormat } from '../RuleTester'; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', @@ -222,8 +222,7 @@ if (false) { ], }, { - // eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting - code: '// @ts-ignore ', + code: noFormat`// @ts-ignore `, options: [{ 'ts-ignore': 'allow-with-description' }], errors: [ { From c5b0b9d259da63296265ef918da18f2091e7ba23 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 26 May 2020 17:01:26 -0400 Subject: [PATCH 8/8] updates test to satisfy cspell --- packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index 9eb25738f860..2d59e1b315a9 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -28,11 +28,11 @@ ruleTester.run('ts-expect-error', rule, { ], }, { - code: '// @ts-expect-error abcdefghij', + code: '// @ts-expect-error exactly 21 characters', options: [ { 'ts-expect-error': 'allow-with-description', - minimumDescriptionLength: 10, + minimumDescriptionLength: 21, }, ], },