Chapter 2 · Practice 2 of 5
Lint in CI and fail the build on new warnings
Why it matters
A linter finds bugs that tests miss: unused imports, names that are never defined, mutable default arguments, except blocks that swallow everything. Ruff has over 900 built-in rules and describes itself as a drop-in replacement for Flake8, isort, Black, pyupgrade and others, so one tool replaces a stack of plugins.
A practical setup:
- Start from a small rule set:
E,F(pyflakes),I(import sorting),B(bugbear). - Run
ruff checkandruff format --checkin CI. - Add rule families one at a time and fix or ignore their findings in one pull request.
Use # noqa: B008 with the specific code when you deliberately break a rule. A bare # noqa hides every future warning on that line.
Example
ruff check .
ruff format --check .
ruff check --fix . # apply safe autofixes locally