ruff-format
An extremely fast Python linter, written in Rust. Configured for formatting only.
ruff-format documentation
- Version in MegaLinter: 0.9.4
- Visit Official Web Site
- See How to configure ruff-format rules- If custom .ruff.tomlconfig file isn't found, .ruff.toml will be used
 
- If custom 
- See How to disable ruff-format rules in files
- See Index of problems detected by ruff-format
Configuration in MegaLinter
- Enable ruff-format by adding PYTHON_RUFF_FORMATin ENABLE_LINTERS variable
- Disable ruff-format by adding PYTHON_RUFF_FORMATin DISABLE_LINTERS variable
| Variable | Description | Default value | 
|---|---|---|
| PYTHON_DEFAULT_STYLE | For ruff-format to be active, PYTHON_DEFAULT_STYLE must be ruff | black | 
| PYTHON_RUFF_FORMAT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" | |
| PYTHON_RUFF_FORMAT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" | |
| PYTHON_RUFF_FORMAT_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) | Include every file | 
| PYTHON_RUFF_FORMAT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) | Exclude no file | 
| PYTHON_RUFF_FORMAT_CLI_LINT_MODE | Override default CLI lint mode - file: Calls the linter for each file- list_of_files: Call the linter with the list of files as argument- project: Call the linter from the root of the project | list_of_files | 
| PYTHON_RUFF_FORMAT_FILE_EXTENSIONS | Allowed file extensions. "*"matches any extension,""matches empty extension. Empty list excludes all filesEx: [".py", ""] | [".py"] | 
| PYTHON_RUFF_FORMAT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] | Include every file | 
| PYTHON_RUFF_FORMAT_PRE_COMMANDS | List of bash commands to run before the linter | None | 
| PYTHON_RUFF_FORMAT_POST_COMMANDS | List of bash commands to run after the linter | None | 
| PYTHON_RUFF_FORMAT_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling PYTHON_RUFF_FORMAT and its pre/post commands | None | 
| PYTHON_RUFF_FORMAT_CONFIG_FILE | ruff-format configuration file nameUse LINTER_DEFAULTto let the linter find it | .ruff.toml | 
| PYTHON_RUFF_FORMAT_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules | 
| PYTHON_RUFF_FORMAT_DISABLE_ERRORS | Run linter but consider errors as warnings | true | 
| PYTHON_RUFF_FORMAT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 | 
| PYTHON_RUFF_FORMAT_CLI_EXECUTABLE | Override CLI executable | ['ruff'] | 
IDE Integration
Use ruff-format in your favorite IDE to catch errors before MegaLinter !
| IDE | Extension Name | Install | |
|---|---|---|---|
| IDEA | Ruff | ||
| Visual Studio Code | Ruff |  | 
MegaLinter Flavors
This linter is available in the following flavors
| Flavor | Description | Embedded linters | Info | |
|---|---|---|---|---|
|  | all | Default MegaLinter Flavor | 125 | |
| cupcake | MegaLinter for the most commonly used languages | 85 | ||
| formatters | Contains only formatters | 18 | ||
| python | Optimized for PYTHON based projects | 62 | 
Behind the scenes
How are identified applicable files
- File extensions: .py
How the linting is performed
- ruff-format is called once with the list of files as arguments (list_of_filesCLI lint mode)
Example calls
ruff format --check myfile.py myfile2.py
ruff format --config .ruff.toml myfile.py myfile2.py
Help content
Ruff: An extremely fast Python linter and code formatter.
Usage: ruff [OPTIONS] <COMMAND>
Commands:
  check    Run Ruff on the given files or directories
  rule     Explain a rule (or all rules)
  config   List or describe the available configuration options
  linter   List all supported upstream linters
  clean    Clear any caches in the current directory and any subdirectories
  format   Run the Ruff formatter on the given files or directories
  server   Run the language server
  analyze  Run analysis over Python source code
  version  Display Ruff's version
  help     Print this message or the help of the given subcommand(s)
Options:
  -h, --help     Print help
  -V, --version  Print version
Log levels:
  -v, --verbose  Enable verbose logging
  -q, --quiet    Print diagnostics, but nothing else
  -s, --silent   Disable all logging (but still exit with status code "1" upon detecting
                 diagnostics)
Global options:
      --config <CONFIG_OPTION>  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. Overrides of individual settings using this
                                option always take precedence over all configuration files,
                                including configuration files that were also specified using
                                `--config`
      --isolated                Ignore all configuration files
For help with a specific command, see: `ruff help <command>`.
Installation on mega-linter Docker image
- PIP packages (Python):