Skip to content

ruff_format

ruff documentation

toolroom._stubs.ruff_format.RuffFormat

Bases: Tool[_R]

__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,
) -> _R

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.

...