Required
Keep every exception in the linter config
Write every exception to a lint rule in the config file, with a reason and a file path. Source files contain 0 comments that turn a linter off.
How to do it
Inline disable comments spread, and nobody can list them. An override in the config is one place to read, review and remove. Make the linter report disable comments that are not needed or have no reason, so the count can only go down. Each exception still follows Check every rule in code.
Examples
Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.
JavaScript example
// stylelint.config.mjs: the one place for exceptions, each with its reason
export default {
reportNeedlessDisables: true,
reportDescriptionlessDisables: true,
overrides: [
{
// Must win over every component, so it is the one allowed !important
files: ['styles/utilities/visually-hidden.css'],
rules: { 'declaration-no-important': null },
},
],
};
Python example
# Build check: no linter is switched off inside a source file
import pathlib, re, sys
DISABLE = re.compile(r"(stylelint|html-validate)-disable")
hits = [str(p) for p in pathlib.Path("src").rglob("*") if p.suffix in {".css", ".html"} and DISABLE.search(p.read_text())]
print("\n".join(f"FAIL {hit} turns a linter off" for hit in hits))
sys.exit(1 if hits else 0)
CSS example
/* Fails the check: an exception hidden in a source file */
/* stylelint-disable-next-line selector-max-id */
#promo { }
How to check
A search of the stylesheets and templates finds 0 stylelint-disable or html-validate-disable comments. Every override in the config names a file path and has a comment with its reason on the line above.
Related rules
- Check every rule in code in Engineering
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers html and css playbook with a link to https://agentwranglers.se/playbook/html-css/checks-in-code/one-exceptions-list. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.