ruff — скилл для Claude Code: линтер и форматтер Python
Скилл объясняет агенту, как запускать ruff для проверки и форматирования Python-кода, и когда трогать файлы не стоит.
npx skills add astral-sh/claude-code-plugins --skill ruff -a claude-codeЧто делает ruff
Ruff — линтер и форматтер Python. Он заменяет Flake8, isort, Black, pyupgrade, autoflake и десятки других инструментов. Скилл даёт агенту готовые команды и правила поведения, чтобы тот не гадал, чем проверять код.
Внутри — три способа запуска: uv run ruff ... для версии из зависимостей проекта, uvx ruff ... для разовых проверок и ruff ... для глобальной установки. Отдельно расписаны линтинг (ruff check, --fix, --watch, --select, --ignore) и форматирование (ruff format, --check, --diff), плюс таблицы перехода с Black, Flake8 и isort.
Главное ограничение — не форматировать чужой код. Если ruff format --diff показывает изменения по всему файлу, проект, скорее всего, не использует ruff для форматирования, и правки только замаскируют реальные изменения. По той же причине скилл советует ограничивать автофиксы файлами, которые вы и так правите. Флаги --unsafe-fixes меняют поведение кода, а не только стиль, поэтому их применение требует ручной проверки через ruff rule <CODE>.
Какие задачи решает
- прогнать линтер по всему проекту одной командой
- автоматически исправить нарушения стиля перед коммитом
- перейти с Black, Flake8 или isort на один инструмент
- посмотреть, что именно изменит форматтер, не трогая файлы
- разобраться, почему автофикс помечен как небезопасный
Примеры запросов агенту
- проверь линтером файлы, которые я менял, и покажи diff
- отформатируй этот модуль через ruff
- объясни правило E501 через ruff rule
Как установить ruff
1Через Skills CLI (Vercel)
npx skills add astral-sh/claude-code-plugins --skill ruff -a claude-code2Вручную: положить файлы
~/.claude/skills/ruff/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/ruff/
1Через Skills CLI (Vercel)
npx skills add astral-sh/claude-code-plugins --skill ruff -a codex2Вручную: положить файлы
.agents/skills/ruff/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add astral-sh/claude-code-plugins --skill ruff -a cursor2Вручную: положить файлы
.cursor/skills/ruff/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install astral-sh/claude-code-plugins ruff2Вручную: положить файлы
.github/skills/ruff/SKILL.md1Через Skills CLI (Vercel)
npx skills add astral-sh/claude-code-plugins --skill ruff -a gemini-cli2Командой платформы
gemini skills install https://github.com/astral-sh/claude-code-plugins --path plugins/astral/skills/ruffВручную: положить файлы
.devin/skills/ruff/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add astral-sh/claude-code-plugins --skill ruff -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Из того же набора3
Похожие
Рядом в теме «Языки программирования»
Все скиллы по теме «Языки программирования» →Вопросы о ruff
Как установить ruff в Claude?
Выполните npx skills add astral-sh/claude-code-plugins --skill ruff -a claude-code. После этого скилл окажется в ~/.claude/skills/ruff/SKILL.md.
Что делает скилл ruff?
Он описывает агенту, как запускать ruff для линтинга и форматирования Python: команды, конфигурацию в pyproject.toml и ruff.toml, а также случаи, когда правки лучше не применять.
Чем опасны флаги --unsafe-fixes?
Такие автофиксы могут изменить поведение кода, а не только оформление. Скилл советует сначала смотреть ruff check --fix --unsafe-fixes --diff ., а потом уже применять.
Исходный текст
SKILL.md · Apache-2.0
--- name: ruff description: Guide for using ruff, the extremely fast Python linter and formatter. Use this when linting, formatting, or fixing Python code. --- # ruff Ruff is an extremely fast Python linter and code formatter. It replaces Flake8, isort, Black, pyupgrade, autoflake, and dozens of other tools. ## When to use ruff **Always use ruff for Python linting and formatting**, especially if you see: - `[tool.ruff]` section in `pyproject.toml` - A `ruff.toml` or `.ruff.toml` configuration file However, avoid making unnecessary changes: - **Don't format unformatted code** - If `ruff format --diff` shows changes throughout an entire file, the project likely isn't using ruff for formatting. Skip formatting to avoid obscuring actual changes. - **Scope fixes to code being edited** - Use `ruff check --diff` to see fixes relevant to the code you're changing. Only apply fixes to files you're modifying unless the user explicitly asks for broader fixes. ## How to invoke ruff - `uv run ruff ...` - Use when ruff is in the project's dependencies to ensure you use the pinned version - `uvx ruff ...` - Use when ruff is not a project dependency, or for quick one-off checks - `ruff ...` - Use if ruff is installed globally ## Commands ### Linting ```bash ruff check . # Check all files in current directory ruff check path/to/file.py # Check specific file ruff check --fix . # Auto-fix fixable violations ruff check --fix --unsafe-fixes . # Include unsafe fixes (review changes!) ruff check --watch . # Watch for changes and re-lint ruff check --select E,F . # Only check specific rules ruff check --ignore E501 . # Ignore specific rules ruff rule E501 # Explain a specific rule ruff linter # List available linters ``` ### Formatting ```bash ruff format . # Format all files ruff format path/to/file.py # Format specific file ruff format --check . # Check if files are formatted (no changes) ruff format --diff . # Show formatting diff without applying ``` ## Configuration Ruff is configured in `pyproject.toml` or `ruff.toml`: ```toml # pyproject.toml [tool.ruff.lint] select = ["E", "F", "I", "UP"] # Enable specific rule sets ignore = ["E501"] # Ignore specific rules [tool.ruff.lint.isort] known-first-party = ["myproject"] ``` ## Migrating from other tools ### Black → ruff format ```bash black . → ruff format . black --check . → ruff format --check . black --diff . → ruff format --diff . ``` ### Flake8 → ruff check ```bash flake8 . → ruff check . flake8 --select E,F . → ruff check --select E,F . flake8 --ignore E501 . → ruff check --ignore E501 . ``` ### isort → ruff check ```bash isort . → ruff check --select I --fix . isort --check . → ruff check --select I . isort --diff . → ruff check --select I --diff . ``` ## Common patterns ### Apply lint fixes before formatting Run `ruff check --fix` before `ruff format`. Lint fixes can change code structure (e.g., reordering imports), which formatting then cleans up. ```bash ruff check --fix . ruff format . ``` ### Applying and reviewing unsafe fixes Ruff categorizes some auto-fixes as "unsafe" because they may change code behavior, not just style. For example, removing unused imports could break code that relies on side effects. ```bash ruff check --fix --unsafe-fixes --diff . # Preview changes first ruff check --fix --unsafe-fixes . # Apply changes ``` **Always review changes before applying `--unsafe-fixes`:** - Use `ruff rule <CODE>` to understand why the fix is considered unsafe - Verify the fix doesn't violate those assumptions in your code ## Documentation For detailed information, read the official documentation: - https://docs.astral.sh/ruff/
© astral-sh · Apache-2.0 · astral-sh/claude-code-plugins