| name | ruff |
| description | Ruff — fast Python linter and formatter replacing flake8, black, isort. Configuration, rule selection, and common fixes. |
Ruff
Running
uv run ruff check .
uv run ruff check --fix .
uv run ruff check --fix --unsafe-fixes .
uv run ruff format .
uv run ruff format --check .
uv run ruff check --select ALL .
pyproject.toml config
[tool.ruff]
target-version = "py310"
line-length = 100
src = ["src", "tests"]
[tool.ruff.lint]
select = [
"E",
"W",
"F",
"I",
"UP",
"B",
"SIM",
"N",
"RUF",
]
ignore = [
"E501",
"N802",
"N803",
"N806",
"B905",
"SIM108",
]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]
"scripts/*" = ["T201"]
[tool.ruff.lint.isort]
known-first-party = ["stgraph_fs"]
Common rule codes
| Code | Rule | Description |
|---|
F401 | unused-import | Imported but unused |
F841 | unused-variable | Assigned but never used |
E711 | comparison-to-none | Use is None not == None |
UP006 | deprecated-collection-type | List[x] → list[x] |
UP007 | deprecated-union | Optional[x] → x | None |
B006 | mutable-default-arg | Mutable default in function def |
B007 | unused-loop-var | Loop variable unused (use _) |
I001 | unsorted-imports | Imports not sorted per isort |
RUF010 | explicit-f-string | str(x) inside f-string → {x!s} |
Inline suppression
import os
x = 1
Auto-fixable patterns
Ruff auto-fixes many UP rules:
from typing import List, Optional, Dict
def f(x: Optional[int]) -> List[Dict[str, int]]:
...
def f(x: int | None) -> list[dict[str, int]]:
...
Pitfalls
ruff format and ruff check --fix are separate commands — run both.
select = ["ALL"] enables experimental rules; always pin ignore list before using in CI.
line-length in [tool.ruff] applies to the formatter; set it in [tool.ruff.lint] too if using E501.
- Ruff's isort is not 100% compatible with standalone isort — if migrating, run
ruff check --select I --fix to reconcile.
- Per-file ignores use glob patterns relative to the project root, not the file location.