ruff-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRuff Professional Development
Ruff 专业开发指南
Version: 0.14.10 (Documentation generated December 2025)
版本: 0.14.10(文档生成于2025年12月)
Overview
概述
Ruff is an extremely fast Python linter and formatter written in Rust. It combines the functionality of multiple Python tools (Flake8, isort, Black, pyupgrade, and more) into a single high-performance tool.
This skill provides comprehensive guidance for:
- Configuring and integrating Ruff into Python projects
- Understanding and fixing lint rule violations
- Formatting Python code with Ruff's formatter
- Setting up editor integrations
- Migrating from other Python tooling
Ruff是一款用Rust编写的极速Python代码检查器(linter)和格式化工具。它将多款Python工具(Flake8、isort、Black、pyupgrade等)的功能整合到一个高性能工具中。
本指南提供以下方面的全面指导:
- 在Python项目中配置和集成Ruff
- 理解并修复代码检查规则违规问题
- 使用Ruff的格式化工具格式化Python代码
- 配置编辑器集成
- 从其他Python工具迁移至Ruff
Quick Start
快速开始
Installation
安装
See for complete installation instructions across all platforms and package managers.
references/installation.md查看获取全平台及各包管理器的完整安装说明。
references/installation.mdBasic Usage
基础用法
Linting:
bash
ruff check . # Lint all files
ruff check path/to/file.py # Lint specific file
ruff check --fix . # Auto-fix violationsFormatting:
bash
ruff format . # Format all files
ruff format path/to/file.py # Format specific file
ruff format --check . # Check formatting without changesConfiguration:
toml
undefined代码检查:
bash
ruff check . # 检查所有文件
ruff check path/to/file.py # 检查指定文件
ruff check --fix . # 自动修复违规问题代码格式化:
bash
ruff format . # 格式化所有文件
ruff format path/to/file.py # 格式化指定文件
ruff format --check . # 检查格式但不修改文件配置:
toml
undefinedpyproject.toml or ruff.toml
pyproject.toml 或 ruff.toml
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I"]
ignore = ["E501"]
See `references/configuration.md` for comprehensive configuration options.[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I"]
ignore = ["E501"]
查看`references/configuration.md`获取完整的配置选项。Core Workflows
核心工作流
1. Integrating Ruff into a Project
1. 将Ruff集成到项目中
Steps:
- Install Ruff (see )
references/installation.md - Create initial configuration (see )
references/configuration.md - Run initial check:
ruff check . - Review and configure rules (see )
references/settings.md - Set up pre-commit hooks or CI integration (see )
references/integrations.md
步骤:
- 安装Ruff(查看)
references/installation.md - 创建初始配置(查看)
references/configuration.md - 运行初始检查:
ruff check . - 查看并配置规则(查看)
references/settings.md - 设置pre-commit钩子或CI集成(查看)
references/integrations.md
2. Fixing Lint Violations
2. 修复代码检查违规问题
Process:
- Run to identify violations
ruff check . - For specific rule violations, reference
references/rules/<rule-name>.md - Apply automatic fixes:
ruff check --fix . - Manual fixes for remaining violations using rule documentation
Finding Rule Documentation:
- All 937 rules are in
references/rules/ - Rules are named by their description (e.g., ,
unused-import.md)line-too-long.md - See for complete rule index
references/rules/rules.md
流程:
- 运行识别违规问题
ruff check . - 针对特定规则违规,参考
references/rules/<rule-name>.md - 应用自动修复:
ruff check --fix . - 结合规则文档手动修复剩余违规问题
查找规则文档:
- 全部937条规则位于目录下
references/rules/ - 规则按描述命名(例如、
unused-import.md)line-too-long.md - 查看获取完整规则索引
references/rules/rules.md
3. Code Formatting
3. 代码格式化
Workflow:
- Review formatter overview:
references/formatter/overview.md - Configure formatter settings in
pyproject.toml - Run formatter:
ruff format . - For Black compatibility: see
references/formatter/black.md
工作流:
- 查看格式化工具概述:
references/formatter/overview.md - 在中配置格式化工具设置
pyproject.toml - 运行格式化工具:
ruff format . - 关于Black兼容性:查看
references/formatter/black.md
4. Editor Integration
4. 编辑器集成
Setup:
- Review for editor support
references/editors/overview.md - Follow setup instructions:
references/editors/setup.md - Configure editor settings:
references/editors/settings.md - Explore editor features:
references/editors/features.md
设置步骤:
- 查看了解编辑器支持情况
references/editors/overview.md - 按照的说明进行设置
references/editors/setup.md - 配置编辑器设置:
references/editors/settings.md - 探索编辑器功能:
references/editors/features.md
5. Migrating from Other Tools
5. 从其他工具迁移
Migration paths:
- From Black: See
references/formatter/black.md - From Flake8/isort/pyupgrade: See for rule equivalents
references/configuration.md - General migration: See for migration guidance
references/tutorial.md
迁移路径:
- 从Black迁移: 查看
references/formatter/black.md - 从Flake8/isort/pyupgrade迁移: 查看获取等效规则
references/configuration.md - 通用迁移: 查看获取迁移指导
references/tutorial.md
Documentation Organization
文档结构
This skill includes comprehensive reference documentation organized for efficient access:
Navigation Guide: - Complete index of all documentation with use-case based navigation
references/INDEX.mdCore Documentation:
- - Complete configuration reference
configuration.md - - All available settings and options
settings.md - - Linter functionality and configuration
linter.md - - Comprehensive getting started guide
tutorial.md
Formatter:
- - Formatter basics
formatter/overview.md - - Black compatibility
formatter/black.md
Rules (937 total):
- - Rules overview and index
rules/rules.md - - Individual rule documentation
rules/<rule-name>.md
Editor Integration:
- - Editor support overview
editors/overview.md - - Installation instructions
editors/setup.md - - Available features
editors/features.md - - Configuration options
editors/settings.md
Other Resources:
- - Installation guide
installation.md - - CI/CD and tool integrations
integrations.md - - Versioning and compatibility
versioning.md - - Preview features
preview.md - - Frequently asked questions
faq.md - - Contributing to Ruff
contributing.md
本指南包含组织有序的全面参考文档,便于快速访问:
导航指南: - 完整的文档索引,基于使用场景提供导航
references/INDEX.md核心文档:
- - 完整配置参考
configuration.md - - 所有可用设置和选项
settings.md - - 代码检查器功能及配置
linter.md - - 全面的入门指南
tutorial.md
格式化工具:
- - 格式化工具基础
formatter/overview.md - - Black兼容性
formatter/black.md
规则(共937条):
- - 规则概述及索引
rules/rules.md - - 单个规则文档
rules/<rule-name>.md
编辑器集成:
- - 编辑器支持概述
editors/overview.md - - 安装说明
editors/setup.md - - 可用功能
editors/features.md - - 配置选项
editors/settings.md
其他资源:
- - 安装指南
installation.md - - CI/CD及工具集成
integrations.md - - 版本控制及兼容性
versioning.md - - 预览功能
preview.md - - 常见问题
faq.md - - 贡献至Ruff
contributing.md
Finding Specific Information
查找特定信息
For configuration questions:
- Start with for all available options
references/settings.md - Review for configuration patterns
references/configuration.md - Check or
references/linter.mdfor component-specific settingsreferences/formatter/overview.md
For rule violations:
- Note the rule code/name from error message
- Find corresponding file in
references/rules/ - Rules are alphabetically named (e.g., E501 → )
line-too-long.md
For editor setup:
- Check for supported editors
references/editors/overview.md - Follow for your editor
references/editors/setup.md - Configure with
references/editors/settings.md
For tool migration:
- Review for general guidance
references/tutorial.md - See for Black-specific migration
references/formatter/black.md - Check for rule mapping from other linters
references/configuration.md
配置相关问题:
- 首先查看获取所有可用选项
references/settings.md - 查看了解配置模式
references/configuration.md - 查看或
references/linter.md获取组件特定设置references/formatter/overview.md
规则违规相关问题:
- 从错误信息中记录规则代码/名称
- 在目录下找到对应文件
references/rules/ - 规则按字母顺序命名(例如E501 → )
line-too-long.md
编辑器设置相关问题:
- 查看了解支持的编辑器
references/editors/overview.md - 按照针对你的编辑器进行设置
references/editors/setup.md - 参考进行配置
references/editors/settings.md
工具迁移相关问题:
- 查看获取通用指导
references/tutorial.md - 查看获取Black特定迁移指导
references/formatter/black.md - 查看获取与其他代码检查器的规则映射
references/configuration.md
Included Scripts
包含的脚本
This skill includes Python scripts for updating documentation (located in ):
scripts/- scrape_ruff_docs.py - Scrape a single Ruff documentation page
- discover_ruff_docs.py - Discover all Ruff documentation URLs
- bulk_scrape_ruff.py - Bulk scrape all Ruff documentation
These scripts use cloudscraper, BeautifulSoup, and markdownify to fetch and convert Ruff documentation.
本指南包含用于更新文档的Python脚本(位于目录下):
scripts/- scrape_ruff_docs.py - 抓取单个Ruff文档页面
- discover_ruff_docs.py - 发现所有Ruff文档URL
- bulk_scrape_ruff.py - 批量抓取所有Ruff文档
这些脚本使用cloudscraper、BeautifulSoup和markdownify来获取并转换Ruff文档。
Best Practices
最佳实践
When configuring Ruff:
- Start with defaults and incrementally add rules
- Use to enable rule categories,
selectfor exceptionsignore - Test configuration changes incrementally
- Document reasoning for ignored rules in comments
When fixing violations:
- Review auto-fixes before committing
- Understand the rule before ignoring it
- Use inline ignores () sparingly
# noqa - Consider if the rule should be disabled project-wide
When formatting:
- Run formatter before linter to avoid conflicts
- Configure line length consistently across tools
- Use in CI to verify formatting
--check - Format entire codebase at once when first adopting
When integrating:
- Set up editor integration for immediate feedback
- Add pre-commit hooks for team consistency
- Include in CI pipeline with appropriate settings
- Document Ruff configuration in project README
配置Ruff时:
- 从默认设置开始,逐步添加规则
- 使用启用规则类别,
select处理例外情况ignore - 逐步测试配置变更
- 在注释中记录忽略规则的原因
修复违规问题时:
- 提交前查看自动修复内容
- 忽略规则前先理解规则含义
- 谨慎使用行内忽略()
# noqa - 考虑是否应在项目范围内禁用该规则
格式化代码时:
- 先运行格式化工具再运行代码检查器,避免冲突
- 在所有工具中统一配置行长度
- 在CI中使用验证格式
--check - 首次使用时一次性格式化整个代码库
集成Ruff时:
- 设置编辑器集成以获取即时反馈
- 添加pre-commit钩子确保团队一致性
- 在CI流水线中配置合适的设置
- 在项目README中记录Ruff配置
Advanced Usage
高级用法
Performance optimization:
- Use for faster repeated runs
--cache-dir - Configure file exclusions to skip irrelevant paths
- Leverage parallel execution (default behavior)
Preview features:
- See for experimental features
references/preview.md - Enable with in configuration
preview = true - Test preview rules before enabling in production
Custom rule selection:
- Combine rule categories:
select = ["E", "F", "I", "N"] - Use per-file ignores for specific patterns
- Configure different rules for different directories
性能优化:
- 使用加快重复运行速度
--cache-dir - 配置文件排除规则,跳过无关路径
- 利用并行执行(默认行为)
预览功能:
- 查看了解实验性功能
references/preview.md - 在配置中设置启用
preview = true - 在生产环境启用前测试预览规则
自定义规则选择:
- 组合规则类别:
select = ["E", "F", "I", "N"] - 针对特定模式使用按文件忽略规则
- 为不同目录配置不同规则
Documentation Coverage
文档覆盖范围
This skill provides complete coverage of Ruff v0.14.10:
- 937 individual rule documentation files
- Full configuration and settings reference
- Complete editor integration guides
- Formatter documentation including Black compatibility
- Installation, integration, and migration guides
- FAQ and troubleshooting resources
All documentation is current as of December 2025 and reflects the latest stable release (0.14.10).
本指南完整覆盖Ruff v0.14.10:
- 937个单独的规则文档文件
- 完整的配置和设置参考
- 完整的编辑器集成指南
- 包含Black兼容性的格式化工具文档
- 安装、集成和迁移指南
- FAQ及故障排除资源
所有文档截至2025年12月,反映最新稳定版本(0.14.10)。