Skip to content
Latchkey

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

Terminal
ruff rule F401
ruff rule E501
ruff linter                # list all rule families
ruff rule --all --output-format json

Commands

CommandWhat it does
ruff rule <code>Explain a single rule
ruff rule --allPrint documentation for every rule
ruff linterList rule families and prefixes
--output-format jsonEmit 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →