Skip to content
Latchkey

ruff noqa: Suppress Specific Violations

A # noqa comment on a line tells Ruff to ignore violations there, optionally limited to specific rule codes.

noqa is the escape hatch for a single justified violation. Codes make it precise; Ruff itself can flag noqa comments that are no longer needed.

What it does

Appending # noqa to a line suppresses all violations on it; # noqa: E501,F401 suppresses only those codes. The RUF100 rule flags noqa comments that suppress nothing (unused-noqa), and ruff check --add-noqa inserts noqa comments for existing violations.

Common usage

Python / Terminal
import os  # noqa: F401
x = 1  # noqa
very_long_line = "..."  # noqa: E501
# auto-insert noqa for every current violation
ruff check --add-noqa .

Behavior and config

ItemWhat it does
# noqaSuppress every violation on the line
# noqa: <codes>Suppress only the listed rule codes
RUF100Rule that flags unused (stale) noqa comments
--add-noqaInsert noqa comments for current violations
# ruff: noqaFile-level directive to disable noqa enforcement

In CI

Always write code-specific noqa (# noqa: F401), not a bare # noqa, so a real bug on the same line is not hidden. Enable RUF100 so CI fails when a noqa becomes stale, which keeps suppressions honest as rules and code change.

Common errors in CI

"RUF100 Unused noqa directive" means a suppression no longer matches any violation, often after a fix; remove the comment. A bare # noqa silently hiding a new violation is a common review miss. --add-noqa is a migration aid, not a CI step; running it in a pipeline edits files and leaves a dirty tree.

Related guides

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