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
fix(eslint-plugin): [prefer-ts-expect-error] support block comments #2541
Changes from 3 commits
28afda4
b0a88be
7047b57
fec7d36
63159fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Recommends using `// @ts-expect-error` over `// @ts-ignore` (`prefer-ts-expect-error`) | ||
# Recommends using `@ts-expect-error` over `@ts-ignore` (`prefer-ts-expect-error`) | ||
|
||
TypeScript allows you to suppress all errors on a line by placing a single-line comment starting with `@ts-ignore` immediately before the erroring line. | ||
TypeScript allows you to suppress all errors on a line by placing a single-line comment or a comment block line starting with `@ts-ignore` immediately before the erroring line. | ||
While powerful, there is no way to know if a `@ts-ignore` is actually suppressing an error without manually investigating what happens when the `@ts-ignore` is removed. | ||
|
||
This means its easy for `@ts-ignore`s to be forgotten about, and remain in code even after the error they were suppressing is fixed. | ||
|
@@ -20,6 +20,16 @@ Examples of **incorrect** code for this rule: | |
// @ts-ignore | ||
const str: string = 1; | ||
|
||
{ | ||
/* @ts-ignore */ | ||
} | ||
const value: number = 'value'; | ||
|
||
/** | ||
* @ts-ignore | ||
*/ | ||
const block: string = 1; | ||
|
||
const isOptionEnabled = (key: string): boolean => { | ||
// @ts-ignore: if key isn't in globalOptions it'll be undefined which is false | ||
return !!globalOptions[key]; | ||
|
@@ -32,6 +42,16 @@ Examples of **correct** code for this rule: | |
// @ts-expect-error | ||
const str: string = 1; | ||
|
||
{ | ||
/* @ts-expect-error */ | ||
} | ||
const value: number = 'value'; | ||
|
||
/** | ||
* @ts-expect-error | ||
*/ | ||
const block: string = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not valid code - the expect error does not apply to the next line in either of these cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing it out. I think I got mixed up with the following code repl /**
*
* @ts-ignore */
let value: string = 1 Corrected and added additional test cases for the same. |
||
|
||
const isOptionEnabled = (key: string): boolean => { | ||
// @ts-expect-error: if key isn't in globalOptions it'll be undefined which is false | ||
return !!globalOptions[key]; | ||
|
@@ -40,7 +60,7 @@ const isOptionEnabled = (key: string): boolean => { | |
|
||
## When Not To Use It | ||
|
||
If you are not using TypeScript 3.9 (or greater), then you will not be able to use this rule, as the directive is not supported | ||
If you are **NOT** using TypeScript 3.9 (or greater), then you will not be able to use this rule, as the directive is not supported | ||
|
||
## Further Reading | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not valid code - the expect error does not apply to the next line in either of these cases
repl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct now