Fast Linting and Formatting with Ruff
Use Ruff to lint and format Python code at extreme speed, replacing Flake8, isort, Black, and dozens of other tools in a single binary.
Prerequisites
- -Python 3.8+ installed
Steps
Install Ruff
Install the Ruff linter and formatter. It is a single Rust binary that runs 10-100x faster than Flake8 and Black combined.
You can also install via 'uv tool install ruff' or 'pipx install ruff' for a global installation.
Lint your project
Run the linter across all Python files in the current directory. Ruff supports 800+ lint rules from Flake8, isort, pyupgrade, and more.
Auto-fix lint violations
Automatically fix all safely fixable lint violations. Ruff will only apply fixes that do not change program behavior.
Review the changes after auto-fix. While safe fixes preserve behavior, they may alter code style in ways you want to verify.
Format code (Black-compatible)
Format all Python files using Ruff's built-in formatter, which is compatible with Black's output style. This replaces the need for a separate Black installation.
Check formatting without modifying files
Preview formatting changes without writing them. Useful in CI pipelines to enforce formatting standards without modifying code.
Use this command in your CI pipeline to fail the build if code is not properly formatted.
Full Script
FAQ
Discussion
Loading comments...