$linuxjunkies
>

ruff(1)

A fast Python linter and code formatter written in Rust that checks code for style, logic errors, and security issues.

UbuntuDebianFedoraArch

Synopsis

ruff check [OPTIONS] [PATH]...

Description

Ruff is an extremely fast Python linter combining the functionality of Pylint, Flake8, isort, and other tools into a single tool. It performs static analysis to detect bugs, style violations, and security issues in Python code. Ruff can also format code automatically, similar to Black.

The tool supports hundreds of linting rules organized by error code prefixes (E/W for style, F for logic errors, C for complexity, etc.). It integrates seamlessly into CI/CD pipelines and modern editors due to its speed and LSP support.

Common options

FlagWhat it does
checkLint files and report violations (default command)
formatFormat Python files in-place
--select=RULESEnable specific rules by code, e.g., --select=E501,W291
--ignore=RULESIgnore specific rules by code, e.g., --ignore=E501
--fixAutomatically fix violations that can be corrected
--unsafe-fixesAllow fixes that may change code behavior
--line-length=NUMSet line length limit (default: 88)
--config=PATHUse a specific configuration file
--output-format=FORMATSet output format: text, json, github, or gitlab
--watchWatch files and re-lint on changes (requires installation extra)
--exit-zeroExit with code 0 even if violations found
--show-fixesDisplay fix details alongside violations

Examples

Lint all Python files in the current directory and subdirectories

ruff check .

Lint the src/ directory and automatically fix all auto-fixable violations

ruff check --fix src/

Format a single Python file in-place to match Black style

ruff format myfile.py

Check only for line-too-long and trailing-whitespace errors in app.py

ruff check --select=E501,W291 app.py

Lint with custom settings: ignore E203/E501, set line length to 100

ruff check --ignore=E203,E501 --line-length=100 .

Output linting results as JSON for programmatic parsing

ruff check --output-format=json . > issues.json

Apply all fixes including ones that may alter code behavior

ruff check --unsafe-fixes --fix src/

Display fixes available but exit successfully regardless of violations

ruff check --show-fixes --exit-zero .

Related commands