ruff-recursive-fix

作者: github

執行 Ruff 檢查,可選範圍與規則覆蓋,反覆套用安全與不安全的自動修復,審查每項變更,並解決剩餘的發現…

npx skills add https://github.com/github/awesome-copilot --skill ruff-recursive-fix

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 pyproject.toml.
  • Flexible Ruff invocation (uv, direct ruff, python -m ruff, or equivalent).
  • Optional per-run rule overrides (--select, --ignore, --extend-select, --extend-ignore).
  • 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 # noqa only when suppression is justified.

Inputs

Collect these inputs before running:

  • target_path (optional): folder or file to check. Empty means whole repository.
  • ruff_runner (optional): explicit Ruff command prefix (for example uv run, ruff, python -m ruff, pipx run ruff).
  • rules_select (optional): comma-separated rule codes to enforce.
  • rules_ignore (optional): comma-separated rule codes to ignore.
  • extend_select (optional): extra rules to add without replacing configured defaults.
  • extend_ignore (optional): extra ignored rules without replacing configured defaults.
  • allow_unsafe_fixes (default: true): whether to run Ruff unsafe fixes.
  • ask_on_ambiguity (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 ruff_cmd prefix before building commands.

Resolution order:

  1. If ruff_runner is provided, use it as-is.
  2. Else if uv is available and Ruff is managed through uv, use uv run ruff.
  3. Else if ruff is available on PATH, use ruff.
  4. Else if Python is available and Ruff is installed in that environment, use python -m ruff.
  5. Else use any project-specific equivalent that invokes installed Ruff (for example pipx run ruff), or stop and ask the user.

Use the same resolved ruff_cmd for all check and format commands in the workflow.

Base command:

<ruff_cmd> check

Formatter command:

<ruff_cmd> format

With optional target:

<ruff_cmd> format <target_path>

Add optional target:

<ruff_cmd> check <target_path>

Add optional overrides as needed:

--select <codes>
--ignore <codes>
--extend-select <codes>
--extend-ignore <codes>

Examples:

# 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

  1. Run <ruff_cmd> check with the selected scope and options.
  2. Classify findings by type:
    • Autofixable safe.
    • Autofixable unsafe.
    • Not autofixable.
  3. If no findings remain, stop.

2. Safe Autofix Pass

  1. Run Ruff with --fix using the same scope/options.
  2. Review resulting diff carefully for semantic correctness and style consistency.
  3. Run <ruff_cmd> format on the same scope.
  4. Re-run <ruff_cmd> check to refresh remaining findings.

3. Unsafe Autofix Pass

Run only if findings remain and allow_unsafe_fixes=true.

  1. Run Ruff with --fix --unsafe-fixes using the same scope/options.
  2. Review resulting diff carefully, prioritizing behavior-sensitive edits.
  3. Run <ruff_cmd> format on the same scope.
  4. Re-run <ruff_cmd> check.

4. Manual Remediation Pass

For remaining findings:

  1. Fix directly in code when there is a clear, safe correction.
  2. Keep edits minimal and local.
  3. Run <ruff_cmd> format on the same scope.
  4. Re-run <ruff_cmd> check.

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 (# noqa)

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 # noqa: <RULE> over broad # noqa.
  • 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:

  • <ruff_cmd> check 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 <ruff_cmd> format before the next <ruff_cmd> check.

When no progress is detected:

  1. Summarize blocked rules and affected files.
  2. Present valid options and trade-offs.
  3. 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."

來自 github 的更多技能

console-rendering
github
在 Go 中使用基於結構體標籤的控制台渲染系統的說明
official
acquire-codebase-knowledge
github
當使用者明確要求對現有程式碼庫進行映射、文件化或入門引導時,使用此技能。觸發詞如「映射此程式碼庫」、「文件化…」等提示。
official
acreadiness-assess
github
Run the AgentRC readiness assessment on the current repository and produce a static HTML dashboard at reports/index.html. Wraps `npx github:microsoft/agentrc…
official
acreadiness-generate-instructions
github
透過 AgentRC 指令命令生成量身打造的 AI 代理指令檔案。產生 .github/copilot-instructions.md(預設,建議用於 VS Code 中的 Copilot…
official
acreadiness-policy
github
幫助使用者選取、撰寫或套用 AgentRC 政策。政策可透過停用不相關的檢查、覆寫影響/等級、設定…來自訂整備度評分。
official
add-educational-comments
github
為程式碼檔案添加教育性註解,將其轉化為有效的學習資源。根據三個可設定的知識層級(初學者、中級、進階)調整解釋深度與語氣。若未提供檔案,會自動請求提供,並以編號清單對應以便快速選取。僅透過教育性註解將檔案擴充最多125%(嚴格上限:400行新註解;超過1,000行的檔案上限為300行)。保留檔案編碼、縮排風格、語法正確性及……
official
adobe-illustrator-scripting
github
使用 ExtendScript (JavaScript/JSX) 編寫、除錯及最佳化 Adobe Illustrator 自動化腳本。適用於建立或修改操控…的腳本時。
official
agent-governance
github
宣告式政策、意圖分類與稽核軌跡,用於控制AI代理工具存取與行為。可組合的治理政策定義允許/封鎖的工具、內容過濾器、速率限制與核准要求——以配置而非程式碼形式儲存。語意意圖分類在工具執行前,透過基於模式的訊號偵測危險提示(資料外洩、權限提升、提示注入)。工具層級治理裝飾器在函式層級強制執行政策……
official