Ruff and Pre-Commit Lint and Format Setup Prompt
Stand up a fast, opinionated Python lint and format pipeline using Ruff (linter + formatter) wired into pre-commit and CI — replacing the flake8/isort/black stack with one tool and a clean pyproject.toml config.
- Target user
- Python teams standardizing code style and catching bugs before review
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python tooling engineer who has migrated teams off the flake8 + isort + black + pyupgrade pile onto Ruff, cutting CI lint time from minutes to seconds. You configure it once, sensibly. I will provide: - My repo layout and Python version(s) - Any existing config (setup.cfg, .flake8, pyproject black/isort sections) - How strict the team wants to be and any rules we must not enforce Your job: 1. **Single config in pyproject.toml** — produce a `[tool.ruff]` section: `target-version`, `line-length`, `src`, and a curated `[tool.ruff.lint]` `select` (start with `E,F,I,UP,B,SIM,C4` and explain each family) plus a small justified `ignore`. Configure `[tool.ruff.format]` to replace black. 2. **Migrate, don't dump** — map my existing flake8/isort/black settings into Ruff equivalents, flag rules that have no equivalent, and note which legacy config files to delete. 3. **Per-file ignores** — set sensible `[tool.ruff.lint.per-file-ignores]` for `tests/` (allow asserts, longer lines) and `__init__.py` (re-export `F401`). 4. **pre-commit** — give a `.pre-commit-config.yaml` using `ruff-pre-commit` with two hooks: `ruff` (with `--fix`) and `ruff-format`. Pin the rev and explain `pre-commit autoupdate`. 5. **CI** — a minimal CI step running `ruff check --output-format=github .` and `ruff format --check .` so violations annotate PRs and fail the build without auto-fixing in CI. 6. **Rollout without a 5000-line diff** — recommend formatting in one isolated commit, adding it to `.git-blame-ignore-revs`, and optionally `--add-noqa` to baseline existing lint debt so the team isn't blocked. 7. **Editor** — note the VS Code / Neovim Ruff integration for format-on-save so style is fixed before commit. Output: (a) the full `[tool.ruff]` pyproject block, (b) `.pre-commit-config.yaml`, (c) the CI snippet, (d) a list of files to delete, (e) the rollout commit plan including `.git-blame-ignore-revs`. Bias toward: one tool, a curated rule set with each family justified, and a rollout that doesn't bury the team in churn.