noTsIgnore
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/suspicious/noTsIgnore¥Diagnostic Category:
lint/suspicious/noTsIgnore -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
灵感来自
@typescript-eslint/ban-ts-comment¥Inspired from
@typescript-eslint/ban-ts-comment
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noTsIgnore": "error" } } }}¥Description
防止使用 TypeScript 指令 @ts-ignore。
¥Prevents the use of the TypeScript directive @ts-ignore.
指令 @ts-ignore 会抑制所有编译错误,即使是来自上游库或编译器本身的 bug 也不例外。如果你使用 @ts-ignore,则无法得知该错误何时以及是否已修复。
¥The directive @ts-ignore suppresses all compilation errors, even ones that could be considered bugs
coming from an upstream library or the compiler itself. If you use @ts-ignore, it won’t be possible to know
when and if the bug is fixed.
该规则提倡使用 @ts-expect-error 指令,该指令旨在在没有错误的情况下引发错误。这意味着一旦错误修复,你可以安全地删除该指令。
¥The rule promotes the use the directive @ts-expect-error, which is meant to raise an error if there aren’t any errors.
This means that once the bug is fixed, you can delete the directive, safely.
¥Examples
¥Invalid
// @ts-ignorelet foo;code-block.ts:1:4 lint/suspicious/noTsIgnore FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unsafe use of the @ts-ignore directive found in this comment.
> 1 │ // @ts-ignore
│ ^^^^^^^^^^
2 │ let foo;
3 │
ℹ The directive is applied to this line.
1 │ // @ts-ignore
> 2 │ let foo;
│ ^^^
3 │
ℹ The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself.
ℹ Safe fix: Use the @ts-expect-error directive instead.
1 │ - //·@ts-ignore
1 │ + //·@ts-expect-error
2 2 │ let foo;
3 3 │
¥Valid
// @ts-expect-errorlet foo;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号