跳到正文
cccskills
免费在 GitHub 公开

ruff

Fix all Python lint violations and enforce consistent formatting in one command.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md6.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

What I do

I run ruff to auto-fix all fixable lint violations and enforce consistent code formatting in one step:

  • Auto-fix lint violations — unused imports, line length, style issues, import sorting, and more
  • Enforce formatting — consistent code style via ruff's Black-compatible formatter
  • Surface unfixable issues — show exactly which violations need manual attention, with rule codes and locations
  • Configure ruff — add a minimal [tool.ruff] section to pyproject.toml if ruff isn't yet configured

When to use me

  • You want to clean up a Python file or entire project before committing
  • CI is failing on lint or format checks and you want to auto-fix everything fixable
  • You want to see what violations remain after auto-fix so you know what to fix manually
  • You're setting up ruff in a project that doesn't have it configured yet

Example usage

/ruff
/ruff check
/ruff format
/ruff init
"fix linting"
"fix all lint issues"

Workflow

Fixing lint violations automatically

Run ruff check --fix to auto-fix all fixable lint violations in the current directory:

ruff check --fix .

ruff fixes violations it can safely transform automatically — including:

  • Unused imports (F401)
  • Import sorting (I001) — replaces isort
  • Unnecessary f-strings, redundant open modes, and other style issues
  • pyupgrade-style modernisations (e.g. Union[X, Y] → X | Y for Python 3.10+)

Interpreting output:

  • ruff prints each fixed violation: Fixed 1 error. or Found 3 errors (3 fixed, 0 remaining).
  • Exit code 0: all violations fixed or none found
  • Exit code 1: violations remain that could not be auto-fixed (see Understanding unfixable violations)

Example output:

Found 5 errors (5 fixed, 0 remaining).

Enforcing consistent formatting

Run ruff format to apply consistent code style across all Python files:

ruff format .

ruff's formatter is Black-compatible — it produces the same output as Black for the vast majority of code. It handles:

  • Line length normalisation (default 88 characters)
  • Quote normalisation (double quotes by default)
  • Trailing comma handling
  • Blank line normalisation

Formatting is separate from linting: ruff check --fix fixes lint rules; ruff format fixes style. Run both for a complete cleanup:

ruff check --fix . && ruff format .

This is the recommended default invocation — lint first, then format. The order matters because formatting after linting ensures the final output is consistently styled even when lint fixes change code structure.


Understanding unfixable violations

After running ruff check --fix ., any remaining output represents violations that require manual attention:

ruff check .    # dry run: show all current violations without fixing

Example output:

src/main.py:42:5: E501 Line too long (96 > 88 characters)
src/utils.py:18:1: F841 Local variable `result` is assigned to but never used
tests/test_api.py:7:1: S101 Use of `assert` detected

Reading the output: file:line:col: RULE-CODE message

Common unfixable rules:

RuleNameFix
E501Line too longManually break the line or raise line-length in config
F841Unused variableRemove or use the variable
F811Redefinition of unused nameRemove duplicate definition
S101Assert detectedReplace with proper exception in production code
B006Mutable default argumentUse None default + if arg is None: arg = [] pattern
PLR0913Too many argumentsRefactor to use a dataclass or config object

When unfixable violations are found, the skill shows the count, lists each with its rule code and location, and explains how to resolve the most common ones.


Configuring ruff in pyproject.toml

If ruff is not yet configured in the project, add a [tool.ruff] section to pyproject.toml:

[tool.ruff]
line-length = 88
target-version = "py311"    # match your Python version

[tool.ruff.lint]
select = ["E", "F", "I", "B", "S"]   # pycodestyle + pyflakes + isort + bugbear + bandit
ignore = ["S101"]                      # ignore assert in tests

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101", "PLR2004"]  # allow assert and magic values in tests

Alternatively, use a standalone ruff.toml at the project root (same format, without [tool.ruff] prefix):

line-length = 88
target-version = "py311"

[lint]
select = ["E", "F", "I"]

Rule set guidance:

CodeRulesetReplaces
E, Wpycodestyleflake8 E/W
Fpyflakesflake8 F
Iisortisort
Bflake8-bugbearflake8-bugbear
Sflake8-banditbandit
UPpyupgradepyupgrade
RUFruff-specific—

Start with ["E", "F", "I"] as a minimal set and add more as your project adopts stricter standards.


Tips for Success

  1. Run ruff check --fix . && ruff format . as your standard cleanup — this covers both lint and format in one pass. Alias it or add it to a Makefile target.

  2. Dry run before fixing: ruff check . (no --fix) shows all violations without modifying files — useful to understand the scope before applying changes.

  3. ruff replaces multiple tools — ruff covers flake8, isort, pyupgrade, and parts of pylint. If you're migrating, you can remove those tools from pyproject.toml dev dependencies once ruff is configured.

  4. Add ruff to pre-commit: ruff runs in milliseconds on large codebases, making it ideal for pre-commit hooks. The official hooks are available at github.com/astral-sh/ruff-pre-commit.

  5. CI auto-patch: In CI, run ruff check --fix . && ruff format . && git diff --exit-code to fail the build if unfixed violations or unformatted files are committed.

  6. Check ruff is installed: ruff --version. Install with pip install ruff, uv add --dev ruff, or brew install ruff.

  7. E501 (line too long) is often not worth fixing manually — consider raising line-length in [tool.ruff] to 100 or 120 if your codebase has many long lines and reformatting isn't feasible.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Implement comprehensive error handling for Python code paths to keep services resilient and user-friendly. Use when failures are currently silent or exceptions leak through.

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

Tabular and numerical data analysis with descriptive statistics and insights. Use when the user provides data, tables, CSVs, or numbers and wants analysis.

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

Financial factsheet analysis with key metrics extraction and investment rationale

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

ci-fix

免费

Diagnose and fix CI failures without leaving your editor.

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

Reproduce ai-repo PR checks locally with Poe and CI scripts, including per-package typecheck and coverage behavior. Use when validating changes before push or when user asks which local commands match CI.

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

Ask clarifying questions before implementing to ensure Python requirements are understood. Use when a task lacks detail, dependencies are unclear, or multiple interpretations are possible.

中文简介正在准备中。当前显示原文说明。

Unique-AG/ai52026年10月19日 更新

查看 Unique-AG 的全部技能

报告此技能的问题