Loading...
Loading...
This skill should be used when the user asks to "configure ruff", "set up ruff linting", "use ruff formatter", "replace flake8 with ruff", or needs guidance on Python code quality with Ruff linting and formatting best practices.
npx skill4agent add the-perfect-developer/the-perfect-opencode python-ruffpip install ruff
uv add --dev ruffruff check # Lint all files in current directory
ruff check --fix # Lint and auto-fix safe violations
ruff check --unsafe-fixes # Show unsafe fixes (review before applying)
ruff check --fix --unsafe-fixes # Apply all fixes including unsafe ones
ruff check --watch # Re-lint on file changes
ruff format # Format all files in current directory
ruff format --check # Check formatting without writing changes
ruff format --diff # Show formatting diff without writingruff check --select I --fix # Sort imports first
ruff format # Then formatpyproject.tomlruff.toml.ruff.tomlruff.toml.ruff.toml[tool.ruff][tool.ruff]
target-version = "py312"
line-length = 88
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # Pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"I", # isort
]
ignore = ["E501"] # line-too-long (handled by formatter)
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
docstring-code-format = truereferences/configuration-guide.mdPREFIX + digitsF401E711# Step 1: Minimal (safe baseline)
select = ["E4", "E7", "E9", "F"]
# Step 2: Recommended expansion
select = ["E", "F", "UP", "B", "SIM", "I"]
# Step 3: Strict (with targeted ignores)
select = ["ALL"]
ignore = ["D", "ANN", "COM812", "ISC001"]| Prefix | Source | Purpose |
|---|---|---|
| pycodestyle | Style errors and warnings |
| Pyflakes | Logical errors, unused imports |
| flake8-bugbear | Likely bugs and design issues |
| pyupgrade | Upgrade to modern Python syntax |
| flake8-simplify | Code simplification |
| isort | Import sorting |
| pep8-naming | Naming convention checks |
| pydocstyle | Docstring conventions |
| flake8-annotations | Type annotation enforcement |
| flake8-bandit | Security checks |
| Ruff-native | Ruff-specific rules |
lint.selectlint.extend-selectALLignorereferences/rule-categories.md--fix--unsafe-fixes[tool.ruff.lint]
extend-safe-fixes = ["UP"] # Treat pyupgrade fixes as safe
extend-unsafe-fixes = ["B"] # Require explicit opt-in for bugbear fixes[tool.ruff.lint]
fixable = ["ALL"]
unfixable = ["F401"] # Flag unused imports but don't auto-remove themimport os # noqa: F401
x = 1 # noqa: E741, F841 # suppress multiple rules
y = 1 # noqa # suppress all (avoid — too broad)# ruff: disable[E501]
LONG_CONSTANT_1 = "Lorem ipsum dolor sit amet, consectetur adipiscing..."
LONG_CONSTANT_2 = "Lorem ipsum dolor sit amet, consectetur adipiscing..."
# ruff: enable[E501]# ruff: noqa: F841 # suppress specific rule for entire file
# ruff: noqa # suppress all (avoid — use per-file-ignores instead)[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # re-exports are intentional
"tests/**/*.py" = ["S101", "ANN"] # asserts and no annotations in tests
"scripts/**/*.py" = ["T20"] # print() allowed in scriptsruff check --extend-select RUF100 # flag stale noqa comments
ruff check --extend-select RUF100 --fix # auto-remove stale noqa[tool.ruff.format]
quote-style = "double" # "double" | "single" | "preserve"
indent-style = "space" # "space" | "tab"
line-ending = "auto" # "auto" | "lf" | "crlf" | "native"
skip-magic-trailing-comma = false # respect trailing commas (like Black)
docstring-code-format = true # format code examples in docstrings# fmt: off
matrix = [1,0,0,
0,1,0,
0,0,1]
# fmt: on
result = some_call() # fmt: skipruff format[tool.ruff.lint]
ignore = [
"W191", # tab-indentation
"E111", # indentation-with-invalid-multiple
"COM812", # missing-trailing-comma
"ISC002", # multi-line-implicit-string-concatenation
"Q000", # bad-quotes-inline-string
"Q001", # bad-quotes-multiline-string
"Q002", # bad-quotes-docstring
]- name: Lint and format check
run: |
ruff check .
ruff format --check .repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-formatnoqaruff check --add-noqa . # adds noqa to all failing lines
ruff check --extend-select RUF100 --fix . # remove stale noqa over time| Task | Command |
|---|---|
| Lint current directory | |
| Lint and fix safe violations | |
| Format current directory | |
| Check formatting (CI mode) | |
| Sort imports only | |
| Explain a rule | |
| List all rules | |
| Show active config for a file | |
| Flag unused noqa comments | |
references/rule-categories.mdreferences/configuration-guide.mdexamples/pyproject.tomlexamples/ruff.tomlexamples/pre-commit-config.yaml