Skip to content

clippy

clippy documentation

rust-clippy - GitHub

Configuration in Mega-Linter

Variable Description Default value
RUST_CLIPPY_ARGUMENTS User custom arguments to add in linter CLI call
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_CONFIG_FILE clippy configuration file name
Use LINTER_DEFAULT to let the linter find it
.clippy.toml
RUST_CLIPPY_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter 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

IDE Integration

Use clippy in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Atom Atom IDE Rest Visit Web Site

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 94 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 41 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

  • filtering can not be done using Mega-Linter configuration variables,it must be done using clippy configuration or ignore file (if existing)
  • VALIDATE_ALL_CODEBASE: false does not make clippy analyze only updated files

Example calls

cargo clippy

Help content

Rust's package manager

USAGE:
    cargo [+toolchain] [OPTIONS] [SUBCOMMAND]

OPTIONS:
    -V, --version                  Print version info and exit
        --list                     List installed commands
        --explain <CODE>           Run `rustc --explain CODE`
    -v, --verbose                  Use verbose output (-vv very verbose/build.rs output)
    -q, --quiet                    No output printed to stdout
        --color <WHEN>             Coloring: auto, always, never
        --frozen                   Require Cargo.lock and cache are up to date
        --locked                   Require Cargo.lock is up to date
        --offline                  Run without accessing the network
        --config <KEY=VALUE>...    Override a configuration value (unstable)
    -Z <FLAG>...                   Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
    -h, --help                     Prints help information

Some common cargo commands are (see all commands with --list):
    build, b    Compile the current package
    check, c    Analyze the current package and report errors, but don't build object files
    clean       Remove the target directory
    doc, d      Build this package's and its dependencies' documentation
    new         Create a new cargo package
    init        Create a new cargo package in an existing directory
    run, r      Run a binary or example of the local package
    test, t     Run the tests
    bench       Run the benchmarks
    update      Update dependencies listed in Cargo.lock
    search      Search registry for crates
    publish     Package and upload this package to the registry
    install     Install a Rust binary. Default location is $HOME/.cargo/bin
    uninstall   Uninstall a Rust binary

See 'cargo help <command>' for more information on a specific command.

Installation on mega-linter Docker image

  • Dockerfile commands :
# Parent descriptor install
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Linter install
RUN rustup component add clippy

Example success log

Results of clippy linter (version 0.0.212)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/rust_clippy/
-----------------------------------------------

[SUCCESS] .automation/test/rust/good
        Checking megalinter v1.0.0 (.automation/test/rust/good)
    warning: function is never used: `main`
     --> rust_good_1.rs:9:4
      |
    9 | fn main() {
      |    ^^^^
      |
      = note: `#[warn(dead_code)]` on by default

    warning: 1 warning emitted

        Finished dev [unoptimized + debuginfo] target(s) in 0.24s

Example error log

Results of clippy linter (version 0.0.212)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/rust_clippy/
-----------------------------------------------

[ERROR] .automation/test/rust/bad
        Checking megalinter v1.0.0 (.automation/test/rust/bad)
    error: mismatched closing delimiter: `}`
      --> rust_bad_1.rs:14:1
       |
    9  | fn main() {
       |           - closing delimiter possibly meant for this
    ...
    13 |     println!("Hello World!"
       |             - unclosed delimiter
    14 | }
       | ^ mismatched closing delimiter

    error: aborting due to previous error

    error: could not compile `megalinter`

    To learn more, run the command again with --verbose.