Skip to content

ruff

GitHub stars autofix sarif GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

An extremely fast Python linter, written in Rust.

ruff documentation

ruff - GitHub

Configuration in MegaLinter

Variable Description Default value
PYTHON_RUFF_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
PYTHON_RUFF_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
PYTHON_RUFF_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
PYTHON_RUFF_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
PYTHON_RUFF_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_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".py"]
PYTHON_RUFF_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_PRE_COMMANDS List of bash commands to run before the linter None
PYTHON_RUFF_POST_COMMANDS List of bash commands to run after the linter None
PYTHON_RUFF_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling PYTHON_RUFF and its pre/post commands None
PYTHON_RUFF_CONFIG_FILE ruff configuration file nameUse LINTER_DEFAULT to let the linter find it .ruff.toml
PYTHON_RUFF_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
PYTHON_RUFF_DISABLE_ERRORS Run linter but consider errors as warnings false
PYTHON_RUFF_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
PYTHON_RUFF_CLI_EXECUTABLE Override CLI executable ['ruff']

IDE Integration

Use ruff in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
IDEA Ruff
Visual Studio Code Ruff Install in VSCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 122 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 84 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 64 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .py

How the linting is performed

  • ruff is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

ruff check myfile.py
ruff check --config .ruff.toml myfile.py

Help content

Ruff: An extremely fast Python linter.

Usage: ruff [OPTIONS] <COMMAND>

Commands:
  check    Run Ruff on the given files or directories (default)
  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
  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):