ban-ts-comment
Disallow
@ts-<directive>comments or require descriptions after directives.
Extending "plugin:@typescript-eslint/recommended" in an ESLint configuration enables this rule.
Some problems reported by this rule are manually fixable by editor suggestions.
TypeScript provides several comment directives that can be used to alter how it processes files. Using these to suppress TypeScript compiler errors reduces the effectiveness of TypeScript overall. Instead, it's generally better to correct the types of code, to make directives unnecessary.
The comment directives supported by TypeScript are:
// @ts-expect-error
// @ts-ignore
// @ts-nocheck
// @ts-check
This rule lets you set which comment directives you want to allow in your codebase.
- Flat Config
- Legacy Config
export default tseslint.config({
rules: {
"@typescript-eslint/ban-ts-comment": "error"
}
});
module.exports = {
"rules": {
"@typescript-eslint/ban-ts-comment": "error"
}
};
Try this rule in the playground ↗
Options
This rule accepts the following options, and has more strict settings in the strict config.
type DirectiveConfigSchema =
| 'allow-with-description'
| {
descriptionFormat?: string;
}
| boolean;
type Options = [
{
/** Whether allow ts-check directives, and with which restrictions. */
'ts-check'?: DirectiveConfigSchema;
/** Whether and when expect-error directives, and with which restrictions. */
'ts-expect-error'?: DirectiveConfigSchema;
/** Whether allow ts-ignore directives, and with which restrictions. */
'ts-ignore'?: DirectiveConfigSchema;
/** Whether allow ts-nocheck directives, and with which restrictions. */
'ts-nocheck'?: DirectiveConfigSchema;
/** A minimum character length for descriptions when `allow-with-description` is enabled. */
minimumDescriptionLength?: number;
},
];
const defaultOptionsRecommended: Options = [
{
minimumDescriptionLength: 3,
'ts-check': false,
'ts-expect-error': 'allow-with-description',
'ts-ignore': true,
'ts-nocheck': true,
},
];
// These options are merged on top of the recommended defaults
const defaultOptionsStrict: Options = [{ minimumDescriptionLength: 10 }];
By default, only @ts-check is allowed, as it enables rather than suppresses errors.