This skill should be used when users need to lint, format, or validate Python code using the Ruff command-line tool...
IMPORTANT: Use this skill proactively after writing or modifying Python code.
# Step 1: Format the code
uv run ruff format .
# Step 2: Fix auto-fixable linting issues
uv run ruff check --fix .
# Step 3: Report remaining issues
uv run ruff check .
just fmt-python # Format Python code
just lint-python # Lint Python code
| Command | Purpose |
|---|---|
uv run ruff check . |
Lint code |
uv run ruff check --fix . |
Fix auto-fixable issues |
uv run ruff format . |
Format code |
uv run ruff format --check . |
Check formatting |
uv run ruff check --diff . |
Preview fixes |
| Flag | Effect |
|---|---|
--fix |
Auto-fix issues |
--unsafe-fixes |
Apply risky fixes |
--diff |
Show changes without applying |
--select E,F |
Check specific rules |
--ignore E501 |
Skip specific rules |
--statistics |
Show issue counts |
--watch |
Continuous linting |
uv run ruff check . # All files
uv run ruff check src/ # Directory
uv run ruff check script.py # Single file
uv run ruff check --fix .
uv run ruff check --diff --unsafe-fixes . # Preview
uv run ruff check --fix --unsafe-fixes . # Apply
Fix manually or suppress with # noqa:
import unused_module # noqa: F401
uv run ruff format .
uv run ruff format --check .
uv run ruff format --diff .
[tool.ruff]
select = ["F", "E", "I"]
| Prefix | Source | Purpose |
|---|---|---|
| F | Pyflakes | Errors, undefined names |
| E | pycodestyle | PEP 8 errors |
| I | isort | Import sorting |
[tool.ruff]
select = ["F", "E", "I", "W", "UP", "B", "SIM"]
| Prefix | Source | Purpose |
|---|---|---|
| W | pycodestyle | PEP 8 warnings |
| UP | pyupgrade | Modernize syntax |
| B | bugbear | Likely bugs |
| SIM | simplify | Simplification |
[tool.ruff]
extend-select = ["S"]
[tool.ruff]
line-length = 100
target-version = "py311"
select = ["E", "F", "I", "B", "UP"]
ignore = ["E501"]
[tool.ruff.per-file-ignores]
"tests/**/*.py" = ["S101"]
"__init__.py" = ["F401"]
[tool.ruff.format]
quote-style = "double"
| Pattern | Common Ignores | Reason |
|---|---|---|
tests/**/*.py |
S101 | Allow assert |
__init__.py |
F401 | Allow unused imports |
scripts/*.py |
T201 | Allow print |
# Ignore all rules for line
import os # noqa
# Ignore specific rule
import os # noqa: F401
# Ignore for entire file (at top)
# ruff: noqa: F401
Start with essential rules only:
uv run ruff check --select=F,E .
Add noqa comments to existing violations:
uv run ruff check --add-noqa .
Fix auto-fixable issues first:
uv run ruff check --fix .
Enable rules gradually over time
ruff.toml, .ruff.toml, or pyproject.tomluv run ruff check --config=ruff.toml .Run formatter before linter to avoid conflicts:
uv run ruff format .
uv run ruff check --fix .
uv run ruff check --output-format=github . # GitHub Actions
uv run ruff check --output-format=gitlab . # GitLab CI
uv run ruff check --output-format=json . # JSON
ruff format before ruff check--unsafe-fixes changes