This rule allows you to specify how different TypeScript directive comments should be handled.
For each directive (@ts-expect-error, @ts-ignore, @ts-nocheck, @ts-check), you can choose one of the following options:
true: Disallow the directive entirely, preventing its use in the entire codebase.
false: Allow the directive without any restrictions.
"allow-with-description": Allow the directive only if it is followed by a description explaining its use. The description must meet the minimum length specified by minimumDescriptionLength.
{ "descriptionFormat": "<regex>" }: Allow the directive only if the description matches the specified regex pattern.
typescript/ban-ts-comment Pedantic
What it does
This rule lets you set which directive comments you want to allow in your codebase.
Why is this bad?
Using TypeScript directives to suppress TypeScript compiler errors reduces the effectiveness of TypeScript overall.
Examples
Examples of incorrect code for this rule:
Configuration
This rule allows you to specify how different TypeScript directive comments should be handled.
For each directive (
@ts-expect-error,@ts-ignore,@ts-nocheck,@ts-check), you can choose one of the following options:true: Disallow the directive entirely, preventing its use in the entire codebase.false: Allow the directive without any restrictions."allow-with-description": Allow the directive only if it is followed by a description explaining its use. The description must meet the minimum length specified byminimumDescriptionLength.{ "descriptionFormat": "<regex>" }: Allow the directive only if the description matches the specified regex pattern.For example:
This rule accepts a configuration object with the following properties:
minimumDescriptionLength
type:
integerdefault:
3Minimum description length required when using directives with
allow-with-description.ts-check
How to handle the
@ts-checkdirective.ts-expect-error
How to handle the
@ts-expect-errordirective.ts-ignore
How to handle the
@ts-ignoredirective.ts-nocheck
How to handle the
@ts-nocheckdirective.How to use
To enable this rule using the config file or in the CLI, you can use:
References