Skip to content

ruff

GitHub stars autofix 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_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_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 113 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 81 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 58 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
  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
  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 lint violations, but nothing else
  -s, --silent   Disable all logging (but still exit with status code "1" upon detecting lint violations)

For help with a specific command, see: `ruff help <command>`.

Installation on mega-linter Docker image

  • PIP packages (Python):