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.
中文简介正在准备中。当前显示原文说明。
Fix all Python lint violations and enforce consistent formatting in one command.
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
I run ruff to auto-fix all fixable lint violations and enforce consistent code formatting in one step:
[tool.ruff] section to pyproject.toml if ruff isn't yet configured/ruff
/ruff check
/ruff format
/ruff init
"fix linting"
"fix all lint issues"
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:
F401)I001) — replaces isortUnion[X, Y] → X | Y for Python 3.10+)Interpreting output:
Fixed 1 error. or Found 3 errors (3 fixed, 0 remaining).Example output:
Found 5 errors (5 fixed, 0 remaining).
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:
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.
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:
| Rule | Name | Fix |
|---|---|---|
E501 | Line too long | Manually break the line or raise line-length in config |
F841 | Unused variable | Remove or use the variable |
F811 | Redefinition of unused name | Remove duplicate definition |
S101 | Assert detected | Replace with proper exception in production code |
B006 | Mutable default argument | Use None default + if arg is None: arg = [] pattern |
PLR0913 | Too many arguments | Refactor 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.
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:
| Code | Ruleset | Replaces |
|---|---|---|
E, W | pycodestyle | flake8 E/W |
F | pyflakes | flake8 F |
I | isort | isort |
B | flake8-bugbear | flake8-bugbear |
S | flake8-bandit | bandit |
UP | pyupgrade | pyupgrade |
RUF | ruff-specific | — |
Start with ["E", "F", "I"] as a minimal set and add more as your project adopts stricter standards.
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.
Dry run before fixing: ruff check . (no --fix) shows all violations without modifying files — useful to understand the scope before applying changes.
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.
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.
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.
Check ruff is installed: ruff --version. Install with pip install ruff, uv add --dev ruff, or brew install ruff.
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.
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
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.
中文简介正在准备中。当前显示原文说明。
Tabular and numerical data analysis with descriptive statistics and insights. Use when the user provides data, tables, CSVs, or numbers and wants analysis.
中文简介正在准备中。当前显示原文说明。
Financial factsheet analysis with key metrics extraction and investment rationale
中文简介正在准备中。当前显示原文说明。
Diagnose and fix CI failures without leaving your editor.
中文简介正在准备中。当前显示原文说明。
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.
中文简介正在准备中。当前显示原文说明。
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.
中文简介正在准备中。当前显示原文说明。