← 返回命令列表

Linux command

ruff-format 命令

文本

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

常用示例

Format current directory

ruff format

Format specific files

ruff format [file.py]

Check formatting without changes

ruff format --check

Show diff

ruff format --diff

说明

ruff format is the code formatting subcommand of Ruff, providing a Black-compatible Python formatter written in Rust. It enforces consistent code style by reformatting Python source files according to opinionated rules covering indentation, line length, string quoting, and whitespace. The --check flag validates formatting without modifying files, returning a non-zero exit code if changes would be made, which is useful for CI pipelines. The --diff flag displays the exact changes that would be applied. Configuration options like --line-length can be set per-project in pyproject.toml or ruff.toml.

参数

--check
Check without modifying.
--diff
Show formatting diff.
--config _file_
Configuration file.
--line-length _n_
Maximum line length.

FAQ

What is the ruff-format command used for?

ruff format is the code formatting subcommand of Ruff, providing a Black-compatible Python formatter written in Rust. It enforces consistent code style by reformatting Python source files according to opinionated rules covering indentation, line length, string quoting, and whitespace. The --check flag validates formatting without modifying files, returning a non-zero exit code if changes would be made, which is useful for CI pipelines. The --diff flag displays the exact changes that would be applied. Configuration options like --line-length can be set per-project in pyproject.toml or ruff.toml.

How do I run a basic ruff-format example?

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

What does --check do in ruff-format?

Check without modifying.