# Ruff — Python Linter and Formatter in One Fast CLI > Ruff combines linting, import sorting, and formatting in a Rust CLI. Replace several Python style tools with `ruff check` and `ruff format` in seconds. ## Install Copy the content below into your project: ## Quick Use 1. Install the verified package or repo entrypoint: ```bash uv tool install ruff # or: pipx install ruff ``` 2. Run the first local check: ```bash ruff check . ruff format . ``` 3. Add a repeatable verification command: ```bash ruff check . --output-format=github ruff format . --check ``` --- ## Intro Ruff is a verified GitHub-backed tool for modern AI and developer workflows, sourced from `astral-sh/ruff` with 47,458 stars and a MIT license snapshot. Best for: Python repos that want one fast default for linting, formatting, import sorting, and CI-friendly diagnostics. Works with: pyproject.toml, pre-commit, GitHub Actions annotations, editors using the Ruff language server. Setup time: 5 minutes. Use it when you need a concrete, repeatable path rather than another one-off shell snippet. --- ## Operating Pattern ### Fit check | Question | Practical answer | |---|---| | What do you install? | `ruff` from `astral-sh/ruff` | | What is the first command? | `ruff check .` | | What proves it works? | `ruff check . --output-format=github` | | How long should a pilot take? | 5 minutes for a small repo or sandbox | ### Adoption loop 1. Run the tool on a disposable branch or sandbox project. 2. Capture before/after output so reviewers can see the exact effect. 3. Add the smallest CI or local check that prevents regressions. 4. Document owner, upgrade command, and rollback command in the repo. ### Recommended use Adopt Ruff in two passes: first run `ruff check --fix` for mechanical fixes, then gate CI with `ruff format --check` after the team has accepted the style. ### Guardrails Keep the first ruleset conservative. Enabling every rule on day one creates noisy diffs and makes it harder to review the actual code change. ### Rollout checklist - Pin the package or release version before using it in CI. - Keep credentials in environment variables or the platform secret store. - Add one owner who is responsible for upgrades and breaking-change triage. - Re-check the GitHub repo before writing docs that mention APIs or install paths. --- ### FAQ **Q: Is this production-ready?** A: The repo exists at `https://github.com/astral-sh/ruff` and has 47,458 GitHub stars. Treat the first rollout as a controlled pilot until your team has tested install, rollback, and CI behavior. **Q: Why use it instead of a generic script?** A: The value is repeatability: a named package, a documented command, a source repo, and a small verification path that can be reviewed by teammates. **Q: What should I measure first?** A: Measure setup time against the 5 minutes target, count how many files or tasks it changes, and record whether the CI command catches the same issue locally. --- ## Source & Thanks > Built from [astral-sh/ruff](https://github.com/astral-sh/ruff). License: MIT. > > GitHub stars verified from `api.github.com/repos/astral-sh/ruff`: 47,458. --- ## 快速使用 1. 安装已验证的包或仓库入口: ```bash uv tool install ruff # or: pipx install ruff ``` 2. 跑第一次本地检查: ```bash ruff check . ruff format . ``` 3. 加一个可重复验证命令: ```bash ruff check . --output-format=github ruff format . --check ``` --- ## 简介 Ruff 是一个已通过 GitHub 仓库验证的现代 AI / 开发者工具,来源 `astral-sh/ruff`,当前星标快照 47,458,许可证 MIT。适合:想用一个高速默认工具覆盖 lint、格式化、import 排序和 CI 诊断的 Python 仓库。兼容:pyproject.toml、pre-commit、GitHub Actions 注释、使用 Ruff language server 的编辑器。装机时间:5 minutes。当你需要的是可重复落地路径,而不是一次性 shell 片段时,用它。 --- ## 操作模式 ### 适配检查 | 问题 | 实用答案 | |---|---| | 安装什么? | 来自 `astral-sh/ruff` 的 `ruff` | | 第一条命令? | `ruff check .` | | 如何证明可用? | `ruff check . --output-format=github` | | 小范围试点多久? | 小仓库或 sandbox 约 5 minutes | ### 接入循环 1. 先在一次性分支或 sandbox 项目里跑。 2. 记录 before / after 输出,让 reviewer 看见实际影响。 3. 加最小的 CI 或本地检查,防止同类问题回归。 4. 在仓库文档里写清 owner、升级命令和回滚命令。 ### 推荐用法 分两步接入 Ruff:先用 `ruff check --fix` 处理机械问题,团队接受格式后再在 CI 里加 `ruff format --check`。 ### 风险边界 第一版规则集要保守。第一天就全开规则会制造大量噪音 diff,让真实代码变更更难 review。 ### 推广检查表 - 进入 CI 前固定包版本或 release 版本。 - 凭据放进环境变量或平台 secret store。 - 指定一个 owner 负责升级和 breaking change 分流。 - 文档里写 API 或安装路径前,重新核验 GitHub 仓库。 --- ### FAQ **Q: 能直接上生产吗?** A: 仓库已验证存在:`https://github.com/astral-sh/ruff`,GitHub 星标 47,458。第一次上线仍建议控制试点,先验证安装、回滚和 CI 行为。 **Q: 为什么不用普通脚本?** A: 价值在可重复:有命名包、文档化命令、源仓库和可被团队 review 的最小验证路径。 **Q: 第一步应该量什么?** A: 先量装机时间是否接近 5 minutes,它改了多少文件或任务,以及 CI 命令是否能在本地抓到同类问题。 --- ## 来源与感谢 > 来源:[astral-sh/ruff](https://github.com/astral-sh/ruff)。许可证:MIT。 > > GitHub stars 已通过 `api.github.com/repos/astral-sh/ruff` 验证:47,458。 --- Source: https://tokrepo.com/en/workflows/ruff-python-linter-and-formatter-in-one-fast-cli Author: Astral