Ruff
Extremely fast Python linter and formatter written in Rust by Astral. Current version is 0.15.7. Two separate subcommands: ruff check (linting, replaces Flake8/isort/pyupgrade) and ruff format (formatting, replaces Black). Not a Python library to import — CLI tool only. The format setting and RUFF_FORMAT env var were repurposed/removed; use output-format and RUFF_OUTPUT_FORMAT instead. 2026 style guide introduced in 0.15.0 changes lambda formatting.
Warnings
- breaking The format setting in [tool.ruff] was repurposed: it no longer controls CLI output format. Use output-format instead. The RUFF_FORMAT env var was removed — use RUFF_OUTPUT_FORMAT. Old configs using format = 'json' to get JSON output are silently broken.
- breaking 2026 style guide (introduced in 0.15.0) changes lambda formatting — lambda bodies are now parenthesized instead of breaking parameters across lines. Reformatting existing code will produce diffs.
- breaking build/ directory no longer excluded by default. Previously ruff excluded build/, which caused confusion when projects had a legitimate build/ directory. Now build/ is only excluded if in .gitignore or extend-exclude.
- gotcha ruff check and ruff format are separate subcommands — running ruff check does NOT format code. Need both: ruff check --fix && ruff format. In pre-commit, two separate hooks are needed: ruff-check and ruff-format.
- gotcha Ruff only enables F (Pyflakes) and a subset of E (pycodestyle) rules by default. Common rules like isort (I), bugbear (B), pyupgrade (UP) must be explicitly selected. Not specifying select means most linting power is unused.
- gotcha --format flag on ruff check and ruff linter was renamed to --output-format. Using --format raises an error.
Install
-
uv tool install ruff@latest -
uv add --dev ruff -
pip install ruff -
pipx install ruff
Imports
- ruff (CLI)
# ruff is a CLI tool — not a Python library to import # Two separate subcommands: # Linting (replaces flake8, isort, pyupgrade, etc.) ruff check . # lint all files ruff check . --fix # lint and auto-fix safe issues ruff check . --unsafe-fixes # also apply unsafe fixes # Formatting (replaces Black) ruff format . # format all files ruff format . --check # check only, no changes # Configuration in pyproject.toml: # [tool.ruff] # line-length = 88 # [tool.ruff.lint] # select = ["E", "F", "B", "I"] # [tool.ruff.format] # quote-style = "double"
Quickstart
# Install pip install ruff # Lint all Python files in current directory ruff check . # Lint with auto-fix ruff check . --fix # Format all Python files ruff format . # Check formatting without modifying (for CI) ruff format . --check # Minimal pyproject.toml config # [tool.ruff] # line-length = 88 # target-version = "py311" # # [tool.ruff.lint] # select = ["E", "F", "B", "I", "UP"] # ignore = ["E501"] # # [tool.ruff.format] # quote-style = "double" # indent-style = "space" # Pre-commit hook (pin the version!) # - repo: https://github.com/astral-sh/ruff-pre-commit # rev: v0.15.7 # hooks: # - id: ruff-check # args: [--fix] # - id: ruff-format