Ruff Recursive Fix
Overview
Use this skill to enforce code quality with Ruff in a controlled, iterative workflow.
It supports:
- Optional scope limitation to a specific folder.
- Default project settings from .
- Flexible Ruff invocation (, direct , , or equivalent).
- Optional per-run rule overrides (, , , ).
- Automatic safe then unsafe autofixes.
- Diff review after each fix pass.
- Recursive repetition until findings are resolved or require a decision.
- Judicious use of inline only when suppression is justified.
Inputs
Collect these inputs before running:
- (optional): folder or file to check. Empty means whole repository.
- (optional): explicit Ruff command prefix (for example , , , ).
- (optional): comma-separated rule codes to enforce.
- (optional): comma-separated rule codes to ignore.
- (optional): extra rules to add without replacing configured defaults.
- (optional): extra ignored rules without replacing configured defaults.
- (default: true): whether to run Ruff unsafe fixes.
- (default: true): always ask the user when multiple valid choices exist.
Command Construction
Build Ruff commands from inputs.
0. Resolve Ruff Runner
Determine a reusable
prefix before building commands.
Resolution order:
- If is provided, use it as-is.
- Else if is available and Ruff is managed through , use .
- Else if is available on , use .
- Else if Python is available and Ruff is installed in that environment, use .
- Else use any project-specific equivalent that invokes installed Ruff (for example ), or stop and ask the user.
Use the same resolved
for all
and
commands in the workflow.
Base command:
Formatter command:
With optional target:
bash
<ruff_cmd> format <target_path>
Add optional target:
bash
<ruff_cmd> check <target_path>
Add optional overrides as needed:
bash
--select <codes>
--ignore <codes>
--extend-select <codes>
--extend-ignore <codes>
Examples:
bash
# Full project with defaults from pyproject.toml
ruff check
# One folder with defaults
python -m ruff check src/models
# Override to skip docs and TODO-like rules for this run
uv run ruff check src --extend-ignore D,TD
# Check only selected rules in a folder
ruff check src/data --select F,E9,I
Workflow
1. Baseline Analysis
- Run with the selected scope and options.
- Classify findings by type:
- Autofixable safe.
- Autofixable unsafe.
- Not autofixable.
- If no findings remain, stop.
2. Safe Autofix Pass
- Run Ruff with using the same scope/options.
- Review resulting diff carefully for semantic correctness and style consistency.
- Run on the same scope.
- Re-run to refresh remaining findings.
3. Unsafe Autofix Pass
Run only if findings remain and
.
- Run Ruff with using the same scope/options.
- Review resulting diff carefully, prioritizing behavior-sensitive edits.
- Run on the same scope.
- Re-run .
4. Manual Remediation Pass
For remaining findings:
- Fix directly in code when there is a clear, safe correction.
- Keep edits minimal and local.
- Run on the same scope.
- Re-run .
5. Ambiguity Policy
If there are multiple valid solutions at any step, always ask the user before proceeding.
Do not choose silently between equivalent options.
6. Suppression Decision ()
Use suppression only when all conditions are true:
- The rule conflicts with required behavior, public API, framework conventions, or readability goals.
- Refactoring would be disproportionate to the value of the rule.
- The suppression is narrow and specific (single line, explicit code when possible).
Guidelines:
- Prefer over broad .
- Add a brief reason comment for non-obvious suppressions.
- If two or more valid outcomes exist, always ask the user which option to prefer.
7. Recursive Loop and Stop Criteria
Repeat steps 2 to 6 until one of these outcomes:
- returns clean.
- Remaining findings require architectural/product decisions.
- Remaining findings are intentionally suppressed with documented rationale.
- Repeated loop makes no progress.
Each loop iteration must include
before the next
.
When no progress is detected:
- Summarize blocked rules and affected files.
- Present valid options and trade-offs.
- Ask the user to choose.
Quality Gates
Before declaring completion:
- Ruff returns no unexpected findings for the chosen scope/options.
- All autofix diffs are reviewed for correctness.
- No suppression is added without explicit justification.
- Any unsafe fix with possible behavioral impact is highlighted to the user.
- Ruff formatting is executed in every iteration.
Output Contract
At the end of execution, report:
- Scope and Ruff options used.
- Number of iterations performed.
- Summary of fixed findings.
- List of manual fixes.
- List of suppressions with rationale.
- Remaining findings, if any, and required user decisions.
Suggested Prompt Starters
- "Run ruff-recursive-fix on the whole repo with default config."
- "Run ruff-recursive-fix only on src/models, ignore DOC rules."
- "Run ruff-recursive-fix on tests with select F,E9,I and no unsafe fixes."
- "Run ruff-recursive-fix on src/data and ask me before adding any noqa."