Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [ban-ts-comments] add "allow-with-description" option#2099
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
bradzacher merged 8 commits intotypescript-eslint:masterfromdimitropoulos:ts-comment-descriptionMay 30, 2020
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
73c5b64 adds "allow-with-description" option to `ban-ts-comments` rule
dimitropoulosa4b99d7 updates message to resemble the eslint-comments/require-description
dimitropoulos12262fe adds threshold for minimum length
dimitropoulosfda8ee1 adds documentation for allow-with-description
dimitropoulos27fd610 removes unknown cspell word to make CI pass
dimitropoulos65c71a0 adds `minimumDescriptionLength` option to `ban-ts-comment`
dimitropoulosa1a8e0e use `noFormat` instead of eslint-disable
dimitropoulosc5b0b9d updates test to satisfy cspell
dimitropoulosFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletionpackages/eslint-plugin/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
58 changes: 53 additions & 5 deletionspackages/eslint-plugin/docs/rules/ban-ts-comment.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Bans `// @ts-<directive>` comments from being usedor 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. | ||
dimitropoulos marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -21,20 +21,24 @@ The configuration looks like this: | ||
| ```ts | ||
| interface Options { | ||
| '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'; | ||
| minimumDescriptionLength?: number; | ||
| } | ||
| const defaultOptions: Options = { | ||
| 'ts-expect-error': true, | ||
| 'ts-ignore': true, | ||
| 'ts-nocheck': true, | ||
| 'ts-check': false, | ||
| minimumDescriptionLength: 3, | ||
| }; | ||
| ``` | ||
| ### `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 +59,50 @@ 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'); | ||
| } | ||
| ``` | ||
| ### `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. | ||
90 changes: 73 additions & 17 deletionspackages/eslint-plugin/src/rules/ban-ts-comment.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.