▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Linting and formatting
ruff and black keep code clean automatically.
🎬 Video version coming soon — read it now
Teams don't argue about spaces and quote styles in code review; tools fix them automatically. Formatters make code look consistent. Linters catch likely bugs and bad patterns.
ruff: one fast tool for both
ruff is written in Rust and checks a large project in well under a second. It combines what used to need several tools (flake8, isort, black and more).
What the linter catches
Look familiar? Unused imports, the mutable default trap and bare excepts are all bugs you met earlier in this series. The linter finds them automatically.
Configure it in pyproject.toml
Start with a modest rule set, then add more as the team agrees.
black
black is the formatter that started the "no arguments about style" movement. ruff format produces almost identical output. Many existing projects use black; new ones increasingly use ruff for both jobs.
Automate it
In your editor: install the Ruff extension for VS Code and turn on "format on save". Your code is clean the moment you save.
Before each commit: use pre-commit:
.pre-commit-config.yaml:
Now every git commit runs ruff first and blocks the commit if problems remain.
In CI: run ruff check, ruff format --check, mypy and pytest on every pull request with GitHub Actions, so nothing unchecked reaches the main branch.
In one line
Use ruff to lint and format automatically, configure it in pyproject.toml, and run it on save, on commit and in CI.
Share with a friend