搜索

PythonReactSEOPDF
GitHub Skill

ruff-formatter

Fix Python code formatting issues using the Ruff formatter. Use when: (1) Formatting errors are detected by ruff format --check, (2) Python files need to be formatted to match project style, (3) Pre-commit hooks or CI fail due to formatting issues.

frizzle-chan☆ 3 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Ruff Formatter

Fast Python code formatter, drop-in replacement for Black with >99.9% compatibility.

Quick Reference

# Format all files in current directory
ruff format .

# Format specific file(s)
ruff format path/to/file.py

# Check without modifying (CI/pre-commit)
ruff format --check .

# Show diff of what would change
ruff format --diff .

Fixing Formatting Issues

When ruff format --check fails:

  1. Run ruff format . to auto-fix all formatting
  2. Review changes with git diff
  3. Commit the formatted code

For import sorting issues, run linter first:

ruff check --select I --fix .  # Sort imports
ruff format .                   # Then format

Format Suppression

Disable formatting for specific code:

# fmt: off
matrix = [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1],
]
# fmt: on

x = 1  # fmt: skip

Configuration

In pyproject.toml or ruff.toml:

[tool.ruff.format]
quote-style = "double"      # or "single"
indent-style = "space"      # or "tab"
line-length = 88            # default
docstring-code-format = true

Exit Codes

  • 0: Success (files formatted or already formatted)
  • 1: With --check: files need formatting
  • 2: Error (invalid config, CLI error)

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-28
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!