ruff
Original:🇺🇸 English
Translated
Build, tune, and operate Ruff for Python linting, formatting, and editor/CI integration. Use when adding or updating Ruff configuration, migrating from Black/Flake8/isort, selecting rule families, enforcing fix safety, or debugging lint/format behavior in local development, pre-commit, and CI.
10installs
Added on
NPX Install
npx skill4agent add kittne/codex-skills-by-codex ruffTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Ruff
Workflow
- Detect current Ruff version, Python targets, and existing lint/format tools.
- Set one canonical Ruff configuration and inheritance strategy.
- Select rule families in adoption layers to control migration noise.
- Configure formatter behavior and notebook handling.
- Integrate editor, pre-commit, and CI with version pinning.
- Apply safe autofixes first, then isolate unsafe changes.
- Tune cache and file discovery for monorepo-scale performance.
Preflight (Ask / Check First)
- Check whether the repo already uses ,
pyproject.toml, orruff.toml..ruff.toml - Check whether Black, Flake8 plugins, or isort are already enforced in CI.
- Check target Python versions across runtime and tooling.
- Check whether Jupyter notebooks are in scope for linting or formatting.
- Check whether the team wants preview features or strict stability.
Version and Stability Policy
- Pin Ruff in CI and pre-commit because minor releases can include breaking changes.
- Set when deterministic behavior matters across contributors.
required-version - Keep by default.
preview = false - Enable preview only in controlled trials and document rollback steps.
- Prefer explicit upgrades with changelog review rather than floating latest.
Canonical Configuration Pattern
- Keep one root config as the policy source of truth.
- Use for subproject inheritance in monorepos.
extend - Avoid duplicated rule lists in child configs unless divergence is intentional.
- Set explicitly for stable parsing and formatting behavior.
target-version - Use and
srcto improve import classification and discovery.respect-gitignore
Example baseline:
toml
[tool.ruff]
target-version = "py311"
line-length = 100
src = ["src"]
respect-gitignore = true
required-version = ">=0.15.1"
[tool.ruff.lint]
extend-select = ["I", "UP", "B", "SIM", "RUF"]
ignore = ["E501"]
[tool.ruff.format]
preview = falseRule Selection Strategy
- Start from Ruff defaults for high-signal correctness checks.
- Add rule families in layers: imports, upgrades, bug-risk, simplifications.
- Add docstring or complexity families only after team policy is clear.
- Use for tests, package
per-file-ignores, and generated code.__init__.py - Track suppressions and remove stale ignores during cleanup cycles.
Formatter Strategy
- Choose one formatter owner for the repo.
- Prefer when replacing Black for speed and single-tool consistency.
ruff format - Avoid style rules that conflict with formatter ownership.
- Exclude generated files and migration outputs from formatting.
- Define notebook behavior explicitly if files are tracked.
.ipynb - Treat notebooks as in-scope by default on modern Ruff; use or section-level excludes when opting out.
extend-exclude
Autofix Safety and Change Control
- Run safe fixes first: .
ruff check . --fix - Run unsafe fixes only in isolated PRs: .
ruff check . --fix --unsafe-fixes - Review runtime and typing-sensitive diffs before merging unsafe fixes.
- Avoid combining policy changes and mass autofix in one commit.
- Keep modernization waves small enough for reviewers to reason about.
Monorepo and Inheritance Guidance
- Use closest-config behavior intentionally.
- Remember Ruff does not implicitly merge parent configs.
- Use child references to preserve organization baseline.
extend - Prefer over
extend-selectin children unless resetting is intentional.select - Keep package-specific deviations narrow and documented inline.
Editor, Pre-commit, and CI Integration
- Use Ruff language server integration where editor support is available.
- Ensure editor and CI run compatible Ruff versions.
- Set if pre-commit passes explicit paths.
force-exclude = true - Run lint and format checks as separate CI steps for clearer failures.
- Emit machine-readable output when CI annotations are required.
Suggested commands:
bash
ruff check .
ruff check . --fix
ruff format .
ruff check . --output-format=githubPerformance Operations
- Keep enabled for incremental speed.
.ruff_cache - Set when workspace cache placement matters.
RUFF_CACHE_DIR - Restrict analyzed paths with ,
src, and focused CI paths.exclude - Avoid running repository-wide checks when change-scoped jobs are enough.
- Profile slow runs before widening ignore patterns.
Migration Playbook
- Baseline with and record current diagnostics volume.
ruff check . - Introduce minimal rule expansion and fix low-risk issues first.
- Enforce no-regression policy in CI before strict expansion.
- Migrate formatter ownership in a dedicated PR.
- Remove legacy linter plugins only after parity is validated.
Failure Modes to Catch Early
- Mixing multiple formatters without clear ownership.
- Resetting rule baselines accidentally in child configs.
- Enabling preview features in CI without local parity.
- Applying unsafe fixes without targeted review.
- Letting ignore lists grow without cleanup ownership.
- Assuming notebooks are excluded by default and silently linting/formatting them in CI.
Definition of Done
- Keep one canonical Ruff config with intentional inheritance.
- Keep lint and format checks deterministic across local, pre-commit, and CI.
- Pin Ruff versions and document upgrade cadence.
- Enforce safe autofix by default and isolated unsafe migrations.
- Keep suppressions small, explicit, and periodically reviewed.
References
references/ruff-2026-02-17.md
Reference Index
rg -n "Version|preview|required-version" references/ruff-2026-02-17.mdrg -n "extend|monorepo|closest config" references/ruff-2026-02-17.mdrg -n "rule|extend-select|per-file-ignores" references/ruff-2026-02-17.mdrg -n "formatter|Black|ruff format" references/ruff-2026-02-17.mdrg -n "cache|RUFF_CACHE_DIR|performance" references/ruff-2026-02-17.mdrg -n "pre-commit|CI|output-format" references/ruff-2026-02-17.md