Skip to content

clippy

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

clippy documentation

rust-clippy - GitHub

Configuration in MegaLinter

Variable Description Default value
RUST_CLIPPY_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
RUST_CLIPPY_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
RUST_CLIPPY_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".rs"]
RUST_CLIPPY_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
RUST_CLIPPY_PRE_COMMANDS List of bash commands to run before the linter None
RUST_CLIPPY_POST_COMMANDS List of bash commands to run after the linter None
RUST_CLIPPY_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling RUST_CLIPPY and its pre/post commands None
RUST_CLIPPY_CONFIG_FILE clippy configuration file nameUse LINTER_DEFAULT to let the linter find it .clippy.toml
RUST_CLIPPY_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
RUST_CLIPPY_DISABLE_ERRORS Run linter but consider errors as warnings false
RUST_CLIPPY_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
RUST_CLIPPY_CLI_EXECUTABLE Override CLI executable ['cargo-clippy']

IDE Integration

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

IDE Extension Name Install
Atom Atom IDE Rest Visit Web Site

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 125 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 84 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 52 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .rs

How the linting is performed

clippy is called once on the whole project directory (project CLI lint mode)

  • filtering can not be done using MegaLinter configuration variables,it must be done using clippy configuration or ignore file (if existing)
  • VALIDATE_ALL_CODEBASE: false doesn't make clippy analyze only updated files

Example calls

cargo-clippy

Help content

Checks a package to catch common mistakes and improve your Rust code.

Usage:
    cargo clippy [OPTIONS] [--] [<ARGS>...]

Common options:
    --no-deps                Run Clippy only on the given crate, without linting the dependencies
    --fix                    Automatically apply lint suggestions. This flag implies --no-deps and --all-targets
    -h, --help               Print this message
    -V, --version            Print version info and exit
    --explain [LINT]         Print the documentation for a given lint

See all options with cargo check --help.

Allowing / Denying lints

To allow or deny a lint from the command line you can use cargo clippy -- with:

    -W / --warn [LINT]       Set lint warnings
    -A / --allow [LINT]      Set lint allowed
    -D / --deny [LINT]       Set lint denied
    -F / --forbid [LINT]     Set lint forbidden

You can use tool lints to allow or deny lints from your code, e.g.:

    #[allow(clippy::needless_lifetimes)]

Manifest Options:
    --manifest-path <PATH>  Path to Cargo.toml
    --frozen                Require Cargo.lock and cache are up to date
    --locked                Require Cargo.lock is up to date
    --offline               Run without accessing the network

Installation on mega-linter Docker image