본문으로 건너뛰기
cccskills
무료GitHub에 공개

ruff

This skill should be used when users need to lint, format, or validate Python code using the Ruff command-line tool. Use this skill for tasks involving Python code quality checks, automatic code formatting, enforcing style rules (PEP 8), identifying bugs and security issues, or modernizing Python code. This skill should be invoked PROACTIVELY whenever Python code is written or modified to ensure code quality.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구GitHubGitLab
설치 방법 보기

포함된 파일(1)

  • SKILL.md14.6 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Ruff Skill

This skill provides expertise in using Ruff, an extremely fast Python linter and code formatter written in Rust. Ruff combines the functionality of multiple tools (Flake8, isort, Black, and more) into a single, high-performance package.

IMPORTANT: Proactive Usage

You MUST use this skill proactively in the following scenarios:

  1. After writing or modifying Python code - Always run ruff format and ruff check --fix after creating or editing Python files
  2. Before committing code - Ensure all Python code passes linting and formatting checks
  3. When encountering linting errors - Immediately fix them using this skill's guidance
  4. During code reviews - Check code quality before finalizing changes

Default workflow when writing Python code:

# Step 1: Format the code
uv run ruff format .

# Step 2: Fix auto-fixable linting issues
uv run ruff check --fix .

# Step 3: Report any remaining issues
uv run ruff check .

Use the project's just commands when available:

# Format Python code (uses uv run ruff format)
just fmt-python

# Lint Python code (uses uv run ruff check)
just lint-python

About Ruff

Ruff is designed to replace multiple Python development tools with a single, fast, and comprehensive solution. It's 10-100x faster than traditional Python linters while providing comparable or better functionality.

Key Capabilities

  • Linting: Check Python code against 800+ lint rules from popular tools
  • Formatting: Format Python code with Black-compatible output
  • Auto-fixing: Automatically fix many linting issues
  • Import Sorting: Organize imports (isort-compatible)
  • Configuration: Highly customizable via pyproject.toml or ruff.toml
  • Fast: Written in Rust for exceptional performance
  • All-in-one: Replaces Flake8, Black, isort, pydocstyle, pyupgrade, and more

When to Use This Skill

Use this skill when users:

  • Need to lint or format Python code
  • Want to enforce Python code quality standards (PEP 8, etc.)
  • Need to identify bugs, security issues, or code smells
  • Want to automatically fix common Python issues
  • Need to format and organize imports
  • Want to modernize Python code (e.g., upgrade syntax)
  • Need to integrate linting/formatting into CI/CD pipelines
  • Ask about Python code quality best practices
  • Want to configure custom linting or formatting rules
  • Need faster alternatives to Flake8, Black, or isort

How to Use This Skill

Basic Ruff Workflow

Ruff has two main commands:

  1. ruff check: Lint Python code (finds issues)
  2. ruff format: Format Python code (fixes style)

Linting with ruff check

Basic Linting

Check a single file:

ruff check script.py

Check a directory:

ruff check src/
ruff check .

Check multiple paths:

ruff check src/ tests/ script.py

Auto-fixing Issues

Fix issues automatically where possible:

ruff check --fix script.py
ruff check --fix src/

The --fix option will modify files in place to resolve fixable issues.

Unsafe Fixes

Some fixes are considered "unsafe" because they may change code behavior. To apply these:

ruff check --fix --unsafe-fixes script.py

Always review unsafe fixes carefully before committing.

Show Fixes Without Applying

Preview what fixes would be applied:

ruff check --diff script.py

Statistics and Reporting

Show statistics about issues found:

ruff check --statistics src/

Output in different formats:

ruff check --output-format=json src/
ruff check --output-format=github src/  # For GitHub Actions
ruff check --output-format=gitlab src/  # For GitLab CI
ruff check --output-format=junit src/   # For CI/CD tools

Rule Selection

Select specific rules or categories:

# Check only unused imports
ruff check --select F401 src/

# Check multiple rule categories
ruff check --select E,F,W src/

# Ignore specific rules
ruff check --ignore E501 src/

# Extend existing configuration
ruff check --extend-select B src/

Common rule prefixes:

  • F: Pyflakes (errors, undefined names, unused imports)
  • E/W: pycodestyle errors and warnings (PEP 8)
  • C90: mccabe (complexity)
  • I: isort (import sorting)
  • N: pep8-naming
  • UP: pyupgrade (modernize syntax)
  • B: flake8-bugbear (likely bugs)
  • S: flake8-bandit (security)
  • A: flake8-builtins
  • Q: flake8-quotes
  • SIM: flake8-simplify

Watch Mode

Continuously watch for changes and re-lint:

ruff check --watch src/

Formatting with ruff format

Basic Formatting

Format a single file:

ruff format script.py

Format a directory:

ruff format src/
ruff format .

Check Format Without Modifying

Check if files need formatting:

ruff format --check src/

This is useful in CI/CD to verify code is formatted without modifying files.

Show Formatting Differences

Show what changes would be made:

ruff format --diff src/

Format stdin

Format code from standard input:

echo "x=1" | ruff format -
cat script.py | ruff format -

Configuration

Configuration Files

Ruff looks for configuration in the following order:

  1. ruff.toml
  2. .ruff.toml
  3. pyproject.toml (under [tool.ruff])

Basic Configuration (pyproject.toml)

[tool.ruff]
# Set the maximum line length to 100
line-length = 100

# Assume Python 3.11
target-version = "py311"

# Enable additional rule sets
select = [
    "E",    # pycodestyle errors
    "W",    # pycodestyle warnings
    "F",    # Pyflakes
    "I",    # isort
    "B",    # flake8-bugbear
    "UP",   # pyupgrade
    "S",    # flake8-bandit
    "SIM",  # flake8-simplify
]

# Ignore specific rules
ignore = [
    "E501",  # Line too long (handled by formatter)
]

# Exclude directories
exclude = [
    ".git",
    ".venv",
    "__pycache__",
    "build",
    "dist",
]

# Allow autofix for all enabled rules
fixable = ["ALL"]
unfixable = []

[tool.ruff.per-file-ignores]
# Ignore specific rules in specific files
"tests/**/*.py" = ["S101"]  # Allow assert in tests
"__init__.py" = ["F401"]    # Allow unused imports

[tool.ruff.format]
# Use single quotes for strings
quote-style = "single"

# Indent with spaces (not tabs)
indent-style = "space"

# End files with a newline
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.ruff.isort]
# Configure import sorting
known-first-party = ["myapp"]

Standalone ruff.toml

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

select = ["E", "F", "I", "B", "UP"]
ignore = ["E501"]

[format]
quote-style = "double"
indent-style = "space"

Command-Line Configuration

Override configuration from command line:

# Set line length
ruff check --line-length=120 src/

# Select specific rules
ruff check --select=E,F,I src/

# Set target Python version
ruff check --target-version=py39 src/

Common Workflows

Full Code Quality Check

Run both linting and formatting checks:

# Check formatting
ruff format --check .

# Run linter
ruff check .

Auto-fix Everything

Fix and format all code:

# Fix linting issues
ruff check --fix .

# Format code
ruff format .

Pre-commit Integration

Add to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.7.0
    hooks:
      # Run the linter
      - id: ruff
        args: [--fix]
      # Run the formatter
      - id: ruff-format

CI/CD Integration

GitHub Actions example:

- name: Ruff Linter
  run: ruff check --output-format=github .

- name: Ruff Formatter
  run: ruff format --check .

Migration from Other Tools

Replace existing tools with Ruff:

From Black + isort + Flake8:

# Old workflow
black .
isort .
flake8 .

# New workflow
ruff format .
ruff check --select I --fix .  # isort
ruff check .                    # flake8

Configuration Migration:

# Convert Black settings
[tool.ruff]
line-length = 88  # Black default

[tool.ruff.format]
quote-style = "double"  # Black default

# Convert isort settings
[tool.ruff.isort]
known-first-party = ["myapp"]
force-single-line = false

# Convert Flake8 settings
[tool.ruff]
select = ["E", "F", "W", "C90"]  # Flake8 defaults
ignore = ["E203", "E501", "W503"]  # Common ignores

Gradual Adoption

Introduce Ruff gradually to existing projects:

# Start with just errors and critical issues
ruff check --select=E,F .

# Add more rules progressively
ruff check --select=E,F,B .
ruff check --select=E,F,B,UP .

# Finally add formatting
ruff format .

Use --add-noqa to add # noqa comments for existing violations:

ruff check --add-noqa src/

This allows you to enforce rules for new code while temporarily allowing existing violations.

Fix Specific Issue Types

Fix only certain categories of issues:

# Fix only import sorting
ruff check --select I --fix .

# Fix only unused imports and variables
ruff check --select F401,F841 --fix .

# Apply pyupgrade modernizations
ruff check --select UP --fix .

Rule Categories

Essential Rules (Start Here)

[tool.ruff]
select = [
    "F",   # Pyflakes - errors and undefined names
    "E",   # pycodestyle errors - PEP 8 violations
    "I",   # isort - import sorting
]

Recommended Rules (Add Next)

[tool.ruff]
select = [
    "F", "E", "I",
    "W",   # pycodestyle warnings
    "UP",  # pyupgrade - modernize syntax
    "B",   # bugbear - likely bugs
    "SIM", # simplify - simplification suggestions
]

Advanced Rules (Optional)

[tool.ruff]
select = [
    "F", "E", "I", "W", "UP", "B", "SIM",
    "S",     # bandit - security issues
    "N",     # pep8-naming - naming conventions
    "C90",   # mccabe - complexity checking
    "A",     # flake8-builtins - shadowing builtins
    "Q",     # flake8-quotes - quote consistency
    "RET",   # flake8-return - return statement issues
    "ARG",   # flake8-unused-arguments
    "PTH",   # flake8-use-pathlib - use pathlib instead of os.path
    "PD",    # pandas-vet - pandas best practices
]

Inline Configuration

Disable Rules for Lines

Use # noqa comments to disable rules:

# Ignore all rules for this line
import os  # noqa

# Ignore specific rule
import os  # noqa: F401

# Ignore multiple rules
x = 1  # noqa: E701, E702

# Ignore for entire file (at top)
# ruff: noqa

# Disable specific rule for entire file
# ruff: noqa: F401

Per-file Ignores in Config

[tool.ruff.per-file-ignores]
"tests/*.py" = ["S101", "PLR2004"]
"__init__.py" = ["F401"]
"scripts/*.py" = ["T201"]  # Allow print statements

Troubleshooting

Too Many Issues

If you're overwhelmed by issues on an existing project:

  1. Start with critical issues only:

    ruff check --select=F,E .
    
  2. Add noqa comments to existing violations:

    ruff check --add-noqa .
    
  3. Fix auto-fixable issues first:

    ruff check --fix .
    
  4. Enable rules gradually over time

Configuration Not Loading

If configuration isn't being applied:

  • Check file name: ruff.toml, .ruff.toml, or pyproject.toml
  • Validate TOML syntax: ruff check --config=ruff.toml .
  • Use absolute paths in exclude patterns if relative paths don't work
  • Check for conflicting configurations in parent directories

Formatter vs Black Differences

Ruff formatter aims for 99% compatibility with Black. Known differences:

  • Magic trailing comma handling in some edge cases
  • Line break decisions in complex nested structures

To report differences: use --diff and compare with Black output

False Positives

If Ruff reports false positives:

  1. Use # noqa comments for specific exceptions
  2. Configure per-file ignores for patterns
  3. Report issues to the Ruff project

Performance Issues

Ruff is typically very fast, but if experiencing slowness:

  • Exclude large directories (venv, node_modules, build)
  • Use .ruffignore file for complex exclusion patterns
  • Check for large files or deeply nested directories

Best Practices

  1. Start Simple: Begin with basic rules (F, E, I) and expand gradually
  2. Format First: Run ruff format before ruff check to avoid style conflicts
  3. Use --fix Liberally: Most auto-fixes are safe and save time
  4. Review Unsafe Fixes: Always review --unsafe-fixes changes before committing
  5. Configure Line Length: Set line-length to match your team's preference
  6. Enable in CI/CD: Enforce checks in CI to maintain code quality
  7. Per-file Ignores: Use per-file configuration for test files, scripts, etc.
  8. Commit Configuration: Keep ruff.toml or pyproject.toml in version control
  9. Document Exceptions: Comment why specific rules are disabled
  10. Keep Updated: Ruff evolves quickly; update regularly for new rules and fixes

Integration with IDEs

VS Code

Install the official Ruff extension:

{
  "ruff.enable": true,
  "ruff.organizeImports": true,
  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": true,
      "source.organizeImports": true
    },
    "editor.defaultFormatter": "charliermarsh.ruff"
  }
}

PyCharm/IntelliJ

Configure Ruff as an external tool or use the Ruff plugin.

Vim/Neovim

Use ALE, null-ls, or native LSP integration with Ruff's language server.

Installation

Ruff can be installed via multiple methods:

Using pip:

pip install ruff

Using pipx (recommended for CLI tool):

pipx install ruff

Using uv:

uv tool install ruff

Using Homebrew:

brew install ruff

Using Conda:

conda install -c conda-forge ruff

Verify installation:

ruff --version
ruff check --help
ruff format --help

Resources

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

duckdb

무료

This skill should be used when users need to work with the DuckDB CLI for querying, analyzing, or transforming data. Use this skill for executing SQL queries, importing/exporting data, configuring DuckDB settings, or performing database operations at the command line.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

Applies Innovations for Poverty Action's official brand colors and typography to any sort of artifact that may benefit from having IPA's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

Draft and quality-check pages for the IPA Knowledge Hub in the site's house style. Use when creating a new .qmd Hub page from source material, adapting outside content into a Hub page, or reviewing an existing page for structure, tone, frontmatter, references, and Diátaxis fit. Replicates the quality-control workflow of IPA's Knowledge Hub Generator assistant.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

Use when the user is explicitly working with Quarto, .qmd files, _quarto.yml, Quarto projects, or Quarto features such as callouts, cross-references, citations, Mermaid diagrams, extensions, websites, books, presentations, and reports. Also use for explicit migration from or comparison with R Markdown, bookdown, blogdown, xaringan, distill, or Jupyter notebooks to Quarto. Do not use for general R Markdown or related-format questions unless Quarto or migration to Quarto is explicitly mentioned.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

uv

무료

This skill should be used when working with Python projects that use uv for package and project management. Use this skill for running Python scripts and CLI tools with `uv run`, managing dependencies, creating projects, handling virtual environments, and executing commands within isolated project environments. Essential for projects with pyproject.toml files.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

PovertyAction/ipa-research-data-science-hub32026년 10월 16일 업데이트

PovertyAction의 스킬 모두 보기

이 스킬의 문제 신고