clippy
clippy documentation
- Version in MegaLinter: 0.1.82
- Visit Official Web Site
- See How to configure clippy rules
- See How to disable clippy rules in files
- See Index of problems detected by clippy
Configuration in MegaLinter
- Enable clippy by adding
RUST_CLIPPY
in ENABLE_LINTERS variable - Disable clippy by adding
RUST_CLIPPY
in DISABLE_LINTERS variable
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_CLI_LINT_MODE | Override default CLI lint mode ⚠️ As default value is project, overriding might not work - 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 |
project |
RUST_CLIPPY_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".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 Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
all | Default MegaLinter Flavor | 124 | ||
cupcake | MegaLinter for the most commonly used languages | 83 | ||
rust | Optimized for RUST based projects | 50 |
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