ruff rule: Explain a Lint Rule
ruff rule <code> prints the documentation for a single rule: what it flags, why, and how it fixes it.
When CI fails on a code you do not recognize, ruff rule turns it into a sentence. It is the offline rule reference built into the binary.
What it does
ruff rule takes a rule code (for example F401 or E501) and prints its name, what it detects, the rationale, and whether it has a fix. ruff linter lists the rule families and their prefixes, and ruff rule --all dumps every rule.
Common usage
ruff rule F401
ruff rule E501
ruff linter # list all rule families
ruff rule --all --output-format jsonCommands
| Command | What it does |
|---|---|
| ruff rule <code> | Explain a single rule |
| ruff rule --all | Print documentation for every rule |
| ruff linter | List rule families and prefixes |
| --output-format json | Emit machine-readable rule metadata |
In CI
When a pipeline fails on an unfamiliar code, the fastest path is ruff rule <code> in the same Ruff version the runner uses, since rules and their fixes change across releases. Pin the version so the explanation matches the failure.
Common errors in CI
"error: Invalid value for '<RULE>'" or an unknown-rule message means the code does not exist in this Ruff version, often a code that was renamed or added later. A rule that exists but is not firing may be in preview; check whether it needs --preview. ruff rule is informational and never affects exit codes of a check.