← 返回命令列表

Linux command

ruff 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Check current directory

ruff check

Check specific files

ruff check [file.py] [other.py]

Auto-fix issues

ruff check --fix

Format code

ruff format

Show fixable issues

ruff check --show-fixes

Watch mode

ruff check --watch

Select specific rules

ruff check --select [E,F,W]

Ignore rules

ruff check --ignore [E501]

说明

ruff is an extremely fast Python linter written in Rust. It implements rules from Flake8, isort, pyupgrade, and other tools. Speed is the primary advantage. Ruff is 10-100x faster than traditional Python linters. This enables real-time feedback and CI integration without delays. Rule selection controls which checks run. Categories include E (pycodestyle errors), F (Pyflakes), W (warnings), I (isort), UP (pyupgrade), and many more. The formatter is Black-compatible, providing consistent code style. It integrates with the linter for a unified toolchain. Configuration in pyproject.toml or ruff.toml customizes behavior. Per-file ignores and extends support complex project needs. Fix mode modifies files automatically. Unsafe fixes may change behavior and require separate opt-in.

参数

check
Run linting.
format
Format code.
--fix
Auto-fix violations.
--unsafe-fixes
Apply unsafe fixes.
--select _RULES_
Rules to enable.
--ignore _RULES_
Rules to ignore.
--extend-select _RULES_
Additional rules.
--config _FILE_
Configuration file.
--show-fixes
Show available fixes.
--watch
Watch for changes.
--output-format _FMT_
Output format (text, json, etc.).
--statistics
Show statistics.
--diff
Show diff for fixes.

FAQ

What is the ruff command used for?

ruff is an extremely fast Python linter written in Rust. It implements rules from Flake8, isort, pyupgrade, and other tools. Speed is the primary advantage. Ruff is 10-100x faster than traditional Python linters. This enables real-time feedback and CI integration without delays. Rule selection controls which checks run. Categories include E (pycodestyle errors), F (Pyflakes), W (warnings), I (isort), UP (pyupgrade), and many more. The formatter is Black-compatible, providing consistent code style. It integrates with the linter for a unified toolchain. Configuration in pyproject.toml or ruff.toml customizes behavior. Per-file ignores and extends support complex project needs. Fix mode modifies files automatically. Unsafe fixes may change behavior and require separate opt-in.

How do I run a basic ruff example?

Run `ruff check` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does check do in ruff?

Run linting.