| created | "2025-12-16T00:00:00.000Z" |
| modified | "2026-05-29T00:00:00.000Z" |
| reviewed | "2026-05-29T00:00:00.000Z" |
| name | ruff-linting |
| description | Python linting with ruff. Fast linting, rule selection, auto-fixing, and config. Use when checking Python code quality, enforcing standards, or finding bugs. |
| user-invocable | false |
| allowed-tools | Bash(ruff *), Bash(python *), Bash(uv *), Read, Edit, Write, Grep, Glob |
ruff Linting
Expert knowledge for using ruff check as an extremely fast Python linter with comprehensive rule support and automatic fixing.
When to Use This Skill
| Use this skill when... | Use a focused sibling instead when... |
|---|
Running ruff check, selecting rule sets, or auto-fixing lint violations | Running ruff format to enforce code style — use ruff-formatting |
Configuring [tool.ruff.lint] rules and per-file ignores in pyproject.toml | Comparing ruff against type-checkers and formatters at a stack level — use python-code-quality |
| Wiring ruff into editors, pre-commit, CI/CD, Docker, or build systems | See the quick forms in CI/CD Integration below; full editor/CI/Docker/migration recipes in REFERENCE.md |
| Migrating from Flake8/pylint/isort/pyupgrade to ruff's combined rule set | Running ruff format to enforce code style — use ruff-formatting |
Core Expertise
ruff Advantages
- Extremely fast (10-100x faster than Flake8)
- Written in Rust for performance
- Replaces multiple tools (Flake8, pylint, isort, pyupgrade, etc.)
- Auto-fix capabilities for many rules
- Compatible with existing configurations
- Over 800 built-in rules
Basic Usage
Simple Linting
ruff check
ruff check path/to/file.py
ruff check src/ tests/
ruff check services/orchestrator
cd services/orchestrator && ruff check
Auto-Fixing
ruff check --diff
ruff check --fix
ruff check --fix src/main.py
ruff check --diff services/orchestrator
ruff check --fix services/orchestrator
Output Formats
ruff check
ruff check --statistics
ruff check --output-format json
ruff check --output-format github
ruff check --output-format gitlab
ruff check --output-format concise
Rule Selection
Common Rule Codes
| Code | Description | Example Rules |
|---|
E | pycodestyle errors | E501 (line too long) |
F | Pyflakes | F401 (unused import) |
W | pycodestyle warnings | W605 (invalid escape) |
B | flake8-bugbear | B006 (mutable default) |
I | isort | I001 (unsorted imports) |
UP | pyupgrade | UP006 (deprecated types) |
SIM | flake8-simplify | SIM102 (nested if) |
D | pydocstyle | D100 (missing docstring) |
N | pep8-naming | N806 (variable naming) |
S | flake8-bandit (security) | S101 (assert usage) |
C4 | flake8-comprehensions | C400 (unnecessary generator) |
Selecting Rules
ruff check --select E,F,B,I
ruff check --extend-select UP,SIM
ruff check --ignore E501,E402
ruff rule --all
ruff rule F401
Rule Queries
ruff rule --all
ruff rule --all | grep "import"
ruff rule F401
ruff linter
ruff rule F401 --output-format json
Configuration
pyproject.toml
[tool.ruff]
line-length = 88
target-version = "py311"
exclude = [
".git",
".venv",
"__pycache__",
"build",
"dist",
]
[tool.ruff.lint]
select = [
"E",
"F",
"B",
"I",
"UP",
"SIM",
]
ignore = [
"E501",
"B008",
]
fixable = ["ALL"]
unfixable = ["B"]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "E402"]
"tests/**/*.py" = ["S101"]
ruff.toml (standalone)
line-length = 100
target-version = "py39"
[lint]
select = ["E", "F", "B"]
ignore = ["E501"]
[lint.isort]
known-first-party = ["myapp"]
force-single-line = true
Advanced Usage
Per-File Configuration
ruff check --config path/to/ruff.toml
ruff check --select E,F,B --ignore E501
Targeting Specific Issues
ruff check --select F401,F841
ruff check --select S
ruff check --select I --fix
ruff check --select D
Integration Patterns
git diff --name-only --diff-filter=d | grep '\.py$' | xargs ruff check
git diff --name-only main...HEAD | grep '\.py$' | xargs ruff check
ruff check src/ &
ruff check tests/ &
wait
ruff check && pytest && ty check
CI/CD Integration
Quick form — lint with PR annotations on GitHub Actions:
name: Lint
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
args: 'check --output-format github'
Quick form — pre-commit hook:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.0
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
For the full integration recipes — editor setup (VS Code, Neovim, Zed, Helix), the advanced pre-commit config, GitLab/CircleCI/Jenkins, Make/Just/Task/tox, Docker, LSP server settings, and Flake8/Black/pylint migration guides — see REFERENCE.md.
Common Patterns
Finding Specific Issues
ruff check --select F401
ruff check --select B006
ruff check --select UP006
ruff check --select S
ruff check --select C901
ruff check --select FIX
Gradual Adoption
ruff check --select E,F
ruff check --select E,F,B
ruff check --select E,F,B,I --fix
ruff check --select E,F,B,I,UP --fix
ruff check --select ALL --ignore <violations> > ruff-baseline.toml
Refactoring Support
ruff check --fix
ruff check --diff | less
ruff check --select I --fix
ruff check --select UP --fix
ruff check --select C4,SIM --fix
Plugin Configuration
isort (Import Sorting)
[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["myapp"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
flake8-quotes
[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "single"
multiline-quotes = "double"
pydocstyle
[tool.ruff.lint.pydocstyle]
convention = "google"
pylint
[tool.ruff.lint.pylint]
max-args = 10
max-branches = 15
max-returns = 8
max-statements = 60
Best Practices
When to Use ruff check
- Code quality enforcement
- Pre-commit validation
- CI/CD pipelines
- Refactoring assistance
- Security scanning
- Import organization
Critical: Directory Parameters
- ✅ Always pass directory as parameter:
ruff check services/orchestrator
- ❌ Never use cd:
cd services/orchestrator && ruff check
- Reason: Parallel execution, clearer output, tool compatibility
Rule Selection Strategy
- Start minimal:
select = ["E", "F"] (errors + pyflakes)
- Add bugbear:
select = ["E", "F", "B"]
- Add imports:
select = ["E", "F", "B", "I"]
- Add pyupgrade:
select = ["E", "F", "B", "I", "UP"]
- Consider security:
select = ["E", "F", "B", "I", "UP", "S"]
Fixable vs Unfixable
- Mark uncertain rules as
unfixable to review manually
- Common unfixables:
B (bugbear), F (pyflakes F401)
- Let ruff fix safe rules:
I (isort), UP (pyupgrade)
Common Mistakes to Avoid
- Using
cd instead of passing directory parameter
- Enabling ALL rules immediately (use gradual adoption)
- Not using
--diff before --fix
- Ignoring rule explanations (
ruff rule <code>)
- Not configuring per-file ignores for special cases
Quick Reference
Essential Commands
ruff check
ruff check path/to/dir
ruff check --diff
ruff check --fix
ruff rule --all
ruff rule F401
ruff linter
ruff check --statistics
ruff check --output-format json
ruff check --output-format github
ruff check --select E,F,B
ruff check --ignore E501
ruff check --extend-select UP
Configuration Hierarchy
- Command-line arguments (highest priority)
ruff.toml in current directory
pyproject.toml in current directory
- Parent directory configs (recursive)
- User config:
~/.config/ruff/ruff.toml
Common Rule Combinations
ruff check --select E,F
ruff check --select E,F,B,I
ruff check --select E,F,B,I,UP,SIM
ruff check --select E,F,B,S
ruff check --select D --config '[lint.pydocstyle]\nconvention = "google"'
This makes ruff check the preferred tool for fast, comprehensive Python code linting.