Linting & Formatting

🧹 Consistent linting and formatting keep the codebase clean and reduce review time. This project uses ruff for both β€” it is fast, requires almost no configuration, and replaces the older black + pre-commit setup.

ℹ️ Note: This project no longer uses pre-commit. Its checks were removed in favour of a CI-side lint job that runs ruff on every pull request. The filename of this page is kept for backward-compatible links.


πŸ›  The Tools

  • ruff β€” linting, formatting, and type-annotation checks for Python. One tool covers all three jobs.


βš™οΈ Everyday Commands

Run these from the root of the project.

Lint

ruff check .

Lint and autofix

ruff check --fix .

Format

ruff format .

Verify formatting (what CI runs)

ruff format --check .

ruff format --check . does not modify any files β€” it exits non-zero if anything is not already formatted, which is exactly what the CI lint job does.


πŸ€– Enforcement in CI

Every pull request triggers a lint job in GitHub Actions that runs:

ruff check .
ruff format --check .

If either command fails, the job fails. To fix issues before pushing, run ruff check --fix . and ruff format . locally, then commit the result.


πŸ“‹ Cheatsheet

Task

Command

Lint

ruff check .

Lint and autofix

ruff check --fix .

Format

ruff format .

Verify formatting (CI)

ruff format --check .


πŸ”— Learn More

  • Ruff β€” a fast Python linter and formatter written in Rust

  • Pytest β€” a framework for testing Python code