Skip to content
Sarj Code Standards

directive-no-use

Disallow directive comments, eslint-* or oxlint-*, except the allowed kinds, and check block-directive pairing.

Why

Block disables and inline rule configuration hide diagnostics for whole regions of a file. Allowing only line-scoped directives keeps each exception next to the code it excuses. A block disable without an enable directive switches the rule off for the rest of the file, including code written long after the exception was reviewed. When one enable directive closes several disable directives, removing one exception means editing a shared comment, and it is easy to re-enable a rule early or leave one off. An enable directive with nothing to close is left over from an exception that is gone, and it misleads readers into looking for one.

Fix

Replace the directive with one of the allowed kinds, usually an eslint-disable-next-line comment that names the rule and the reason.

Examples

Before — flagged A block disable hides every later line
src/report.ts
/* eslint-disable no-console -- the CLI prints its report */
console.log(report);
After — preferred Disable one line instead
src/report.ts
// eslint-disable-next-line no-console -- the CLI prints its report
console.log(report);

Options

{
"additionalProperties": false,
"properties": {
"allow": {
"description": "Directive kinds to allow, such as `eslint-disable-next-line`; an `oxlint-*` directive follows its `eslint-*` kind.",
"items": { "type": "string" },
"type": "array",
"uniqueItems": true
},
"allowWholeFile": {
"description": "Allow an unpaired disable directive before the file's first token.",
"type": "boolean"
}
},
"type": "object"
}

References

Formerly: directive-disable-enable-pair, directive-no-aggregating-enable, directive-no-unused-enable