Skip to content

ruff

ruff documentation

toolroom._stubs.ruff.Ruff

Bases: Tool[_R]

Check

Bases: Tool[_R2]

__call__

__call__(
    *args: str | PathLike[str],
    add_ignore: ValuedFlag = ...,
    add_noqa: ValuedFlag = ...,
    cache_dir: Value = ...,
    color: Color | Sequence[Color] | None = ...,
    config: Value = ...,
    diff: Flag = ...,
    exclude: Value = ...,
    exit_non_zero_on_fix: Flag = ...,
    exit_zero: Flag = ...,
    extend_exclude: Value = ...,
    extend_fixable: Value = ...,
    extend_per_file_ignores: Value = ...,
    extend_select: Value = ...,
    extension: Value = ...,
    fix: Flag = ...,
    fix_only: Flag = ...,
    fixable: Value = ...,
    force_exclude: Flag = ...,
    ignore: Value = ...,
    ignore_noqa: Flag = ...,
    isolated: Flag = ...,
    no_cache: Flag = ...,
    output_file: Value = ...,
    output_format: OutputFormat
    | Sequence[OutputFormat]
    | None = ...,
    per_file_ignores: Value = ...,
    preview: Flag = ...,
    quiet: Flag = ...,
    respect_gitignore: Flag = ...,
    select: Value = ...,
    show_files: Flag = ...,
    show_fixes: Flag = ...,
    show_settings: Flag = ...,
    silent: Flag = ...,
    statistics: Flag = ...,
    stdin_filename: Value = ...,
    target_version: TargetVersion
    | Sequence[TargetVersion]
    | None = ...,
    unfixable: Value = ...,
    unsafe_fixes: Flag = ...,
    verbose: Flag = ...,
    watch: Flag = ...,
    **flags: Any,
) -> _R2

Run Ruff on the given files or directories

Parameters:

Name Type Description Default
add_ignore ValuedFlag

Enable automatic additions of ruff: ignore comments to failing lines. Value optional: True for the bare flag, or pass one. Added in 0.15.21.

...
add_noqa ValuedFlag

Enable automatic additions of noqa directives to failing lines. Value optional: True for the bare flag, or pass one.

...
cache_dir Value

Path to the cache directory.

...
color Color | Sequence[Color] | None

Control when colored output is used.

...
config Value

Either a path to a TOML configuration file (pyproject.toml or ruff.toml), or a TOML <KEY> = <VALUE> pair (such as you might find in a ruff.toml configuration file) overriding a specific configuration option (e.g., --config "lint.line-length = 100" or --config "format.quote-style = 'single'").

...
diff Flag

Avoid writing any fixed files back; instead, output a diff for each changed file to stdout, and exit 0 if there are no diffs.

...
exclude Value

List of paths, used to omit files and/or directories from analysis.

...
exit_non_zero_on_fix Flag

Exit with a non-zero status code if any files were modified via fix, even if no lint violations remain.

...
exit_zero Flag

Exit with status code "0", even upon detecting lint violations.

...
extend_exclude Value

Like --exclude, but adds additional files and directories on top of those already excluded.

...
extend_fixable Value

Like --fixable, but adds additional rule codes on top of those already specified.

...
extend_per_file_ignores Value

Like --per-file-ignores, but adds additional ignores on top of those already specified.

...
extend_select Value

Like --select, but adds additional rule codes on top of those already specified.

...
extension Value

List of mappings from file extension to language (one of python, ipynb, pyi).

...
fix Flag

Apply fixes to resolve lint violations. fix=off emits --no-fix.

...
fix_only Flag

Apply fixes to resolve lint violations, but don't report on, or exit non-zero for, leftover violations. fix_only=off emits --no-fix-only.

...
fixable Value

List of rule codes to treat as eligible for fix.

...
force_exclude Flag

Enforce exclusions, even for paths passed to Ruff directly on the command-line. force_exclude=off emits --no-force-exclude.

...
ignore Value

Comma-separated list of rule codes to disable.

...
ignore_noqa Flag

Ignore any # noqa comments.

...
isolated Flag

Ignore all configuration files.

...
no_cache Flag

Disable cache reads.

...
output_file Value

Specify file to write the linter output to. Defaults to stdout.

...
output_format OutputFormat | Sequence[OutputFormat] | None

Output serialization format for violations.

...
per_file_ignores Value

List of mappings from file pattern to code to exclude.

...
preview Flag

Enable preview mode; checks will include unstable rules and fixes. preview=off emits --no-preview.

...
quiet Flag

Print diagnostics, but nothing else.

...
respect_gitignore Flag

Respect file exclusions via .gitignore and other standard ignore files. respect_gitignore=off emits --no-respect-gitignore.

...
select Value

Comma-separated list of rule codes to enable (or ALL, to enable all rules).

...
show_files Flag

See the files Ruff will be run against with the current settings.

...
show_fixes Flag

Show an enumeration of all fixed lint violations. show_fixes=off emits --no-show-fixes.

...
show_settings Flag

See the settings Ruff will use to lint a given Python file.

...
silent Flag

Disable all logging (but still exit with status code "1" upon detecting diagnostics).

...
statistics Flag

Show counts for every rule with at least one violation.

...
stdin_filename Value

The name of the file when passing it through stdin.

...
target_version TargetVersion | Sequence[TargetVersion] | None

The minimum Python version that should be supported.

...
unfixable Value

List of rule codes to treat as ineligible for fix.

...
unsafe_fixes Flag

Include fixes that may not retain the original intent of the code. unsafe_fixes=off emits --no-unsafe-fixes.

...
verbose Flag

Enable verbose logging.

...
watch Flag

Run in watch mode by re-running whenever files change.

...

Clean

Bases: Tool[_R2]

__call__

__call__(
    *,
    color: Color | Sequence[Color] | None = ...,
    config: Value = ...,
    isolated: Flag = ...,
    quiet: Flag = ...,
    silent: Flag = ...,
    verbose: Flag = ...,
    **flags: Any,
) -> _R2

Clear any caches in the current directory and any subdirectories

Parameters:

Name Type Description Default
color Color | Sequence[Color] | None

Control when colored output is used.

...
config Value

Either a path to a TOML configuration file (pyproject.toml or ruff.toml), or a TOML <KEY> = <VALUE> pair (such as you might find in a ruff.toml configuration file) overriding a specific configuration option (e.g., --config "lint.line-length = 100" or --config "format.quote-style = 'single'").

...
isolated Flag

Ignore all configuration files.

...
quiet Flag

Print diagnostics, but nothing else.

...
silent Flag

Disable all logging (but still exit with status code "1" upon detecting diagnostics).

...
verbose Flag

Enable verbose logging.

...

Format

Bases: Tool[_R2]

__call__

__call__(
    *args: str | PathLike[str],
    cache_dir: Value = ...,
    check: Flag = ...,
    color: Color | Sequence[Color] | None = ...,
    config: Value = ...,
    diff: Flag = ...,
    exclude: Value = ...,
    exit_non_zero_on_format: Flag = ...,
    extend_exclude: Value = ...,
    extension: Value = ...,
    force_exclude: Flag = ...,
    isolated: Flag = ...,
    line_length: Value = ...,
    no_cache: Flag = ...,
    output_format: OutputFormat
    | Sequence[OutputFormat]
    | None = ...,
    preview: Flag = ...,
    quiet: Flag = ...,
    range: Value = ...,
    respect_gitignore: Flag = ...,
    silent: Flag = ...,
    stdin_filename: Value = ...,
    target_version: TargetVersion
    | Sequence[TargetVersion]
    | None = ...,
    verbose: Flag = ...,
    **flags: Any,
) -> _R2

Run the Ruff formatter on the given files or directories

Parameters:

Name Type Description Default
cache_dir Value

Path to the cache directory.

...
check Flag

Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise.

...
color Color | Sequence[Color] | None

Control when colored output is used.

...
config Value

Either a path to a TOML configuration file (pyproject.toml or ruff.toml), or a TOML <KEY> = <VALUE> pair (such as you might find in a ruff.toml configuration file) overriding a specific configuration option (e.g., --config "lint.line-length = 100" or --config "format.quote-style = 'single'").

...
diff Flag

Avoid writing any formatted files back; instead, exit with a non-zero status code and the difference between the current file and how the formatted file would look like.

...
exclude Value

List of paths, used to omit files and/or directories from analysis.

...
exit_non_zero_on_format Flag

Exit with a non-zero status code if any files were modified via format, even if all files were formatted successfully.

...
extend_exclude Value

Like --exclude, but adds additional files and directories on top of those already excluded. Added in 0.15.21.

...
extension Value

List of mappings from file extension to language (one of python, ipynb, pyi).

...
force_exclude Flag

Enforce exclusions, even for paths passed to Ruff directly on the command-line. force_exclude=off emits --no-force-exclude.

...
isolated Flag

Ignore all configuration files.

...
line_length Value

Set the line-length.

...
no_cache Flag

Disable cache reads.

...
output_format OutputFormat | Sequence[OutputFormat] | None

Output serialization format for violations, when used with --check.

...
preview Flag

Enable preview mode; enables unstable formatting. preview=off emits --no-preview.

...
quiet Flag

Print diagnostics, but nothing else.

...
range Value

When specified, Ruff will try to only format the code in the given range.

...
respect_gitignore Flag

Respect file exclusions via .gitignore and other standard ignore files. respect_gitignore=off emits --no-respect-gitignore.

...
silent Flag

Disable all logging (but still exit with status code "1" upon detecting diagnostics).

...
stdin_filename Value

The name of the file when passing it through stdin.

...
target_version TargetVersion | Sequence[TargetVersion] | None

The minimum Python version that should be supported.

...
verbose Flag

Enable verbose logging.

...

__call__

__call__(
    *args: str | PathLike[str],
    color: Color | Sequence[Color] | None = ...,
    config: Value = ...,
    isolated: Flag = ...,
    quiet: Flag = ...,
    silent: Flag = ...,
    verbose: Flag = ...,
    **flags: Any,
) -> _R

Ruff: An extremely fast Python linter and code formatter.

Parameters:

Name Type Description Default
color Color | Sequence[Color] | None

Control when colored output is used.

...
config Value

Either a path to a TOML configuration file (pyproject.toml or ruff.toml), or a TOML <KEY> = <VALUE> pair (such as you might find in a ruff.toml configuration file) overriding a specific configuration option (e.g., --config "lint.line-length = 100" or --config "format.quote-style = 'single'").

...
isolated Flag

Ignore all configuration files.

...
quiet Flag

Print diagnostics, but nothing else.

...
silent Flag

Disable all logging (but still exit with status code "1" upon detecting diagnostics).

...
verbose Flag

Enable verbose logging.

...

flags

flags(
    *,
    color: Color | Sequence[Color] | None = ...,
    config: Value = ...,
    isolated: Flag = ...,
    quiet: Flag = ...,
    silent: Flag = ...,
    verbose: Flag = ...,
    **flags: Any,
) -> Self

Bind tool-level global options before the subcommand.

tools.docker.flags(host=...) puts a tool's own options ahead of the verb, where they belong.