Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A bunch of lints to catch common mistakes and improve your Rust code. Book:https://doc.rust-lang.org/clippy/

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

rust-lang/rust-clippy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

License: MIT OR Apache-2.0

A collection of lints to catch common mistakes and improve yourRust code.

There are over 800 lints included in this crate!

Lints are divided into categories, each with a defaultlint level.You can choose how much Clippy is supposed toannoy help you by changing the lint level by category.

CategoryDescriptionDefault level
clippy::allall lints that are on by default (correctness, suspicious, style, complexity, perf)warn/deny
clippy::correctnesscode that is outright wrong or uselessdeny
clippy::suspiciouscode that is most likely wrong or uselesswarn
clippy::stylecode that should be written in a more idiomatic waywarn
clippy::complexitycode that does something simple but in a complex waywarn
clippy::perfcode that can be written to run fasterwarn
clippy::pedanticlints which are rather strict or have occasional false positivesallow
clippy::restrictionlints which prevent the use of language and library features1allow
clippy::nurserynew lints that are still under developmentallow
clippy::cargolints for the cargo manifestallow

More to come, pleasefile an issue if you have ideas!

Therestriction category should,emphatically, not be enabled as a whole. The containedlints may lint against perfectly reasonable code, may not have an alternative suggestion,and may contradict any other lints (including other categories). Lints should be consideredon a case-by-case basis before enabling.


Table of contents:

Usage

Below are instructions on how to use Clippy as a cargo subcommand,in projects that do not use cargo, or in Travis CI.

As a cargo subcommand (cargo clippy)

One way to use Clippy is by installing Clippy through rustup as a cargosubcommand.

Step 1: Install Rustup

You can installRustup on supported platforms. This will helpus install Clippy and its dependencies.

If you already have Rustup installed, update to ensure you have the latestRustup and compiler:

rustup update

Step 2: Install Clippy

Once you have rustup and the latest stable release (at least Rust 1.29) installed, run the following command:

rustup component add clippy

If it says that it can't find theclippy component, please runrustup self update.

Step 3: Run Clippy

Now you can run Clippy by invoking the following command:

cargo clippy

Automatically applying Clippy suggestions

Clippy can automatically apply some lint suggestions, just like the compiler. Note that--fix implies--all-targets, so it can fix as much code as it can.

cargo clippy --fix

Workspaces

All the usual workspace options should work with Clippy. For example the following commandwill run Clippy on theexample crate:

cargo clippy -p example

As withcargo check, this includes dependencies that are members of the workspace, like path dependencies.If you want to run Clippyonly on the given crate, use the--no-deps option like this:

cargo clippy -p example -- --no-deps

Usingclippy-driver

Clippy can also be used in projects that do not use cargo. To do so, runclippy-driverwith the same arguments you use forrustc. For example:

clippy-driver --edition 2018 -Cpanic=abort foo.rs

Note thatclippy-driver is designed for running Clippy only and should not be used as a generalreplacement forrustc.clippy-driver may produce artifacts that are not optimized as expected,for example.

Travis CI

You can add Clippy to Travis CI in the same way you use it locally:

language:rustrust:  -stable  -betabefore_script:  -rustup component add clippyscript:  -cargo clippy# if you want the build job to fail when encountering warnings, use  -cargo clippy -- -D warnings# in order to also check tests and non-default crate features, use  -cargo clippy --all-targets --all-features -- -D warnings  -cargo test# etc.

Note that adding-D warnings will cause your build to fail ifany warnings are found in your code.That includes warnings found by rustc (e.g.dead_code, etc.). If you want to avoid this and only causean error for Clippy warnings, use#![deny(clippy::all)] in your code or-D clippy::all on the commandline. (You can swapclippy::all with the specific lint category you are targeting.)

Configuration

Allowing/denying lints

You can add options to your code toallow/warn/deny Clippy lints:

  • the whole set ofWarn lints using theclippy lint group (#![deny(clippy::all)]).Note thatrustc has additionallint groups.

  • all lints using both theclippy andclippy::pedantic lint groups (#![deny(clippy::all)],#![deny(clippy::pedantic)]). Note thatclippy::pedantic contains some very aggressivelints prone to false positives.

  • only some lints (#![deny(clippy::single_match, clippy::box_vec)], etc.)

  • allow/warn/deny can be limited to a single function or module using#[allow(...)], etc.

Note:allow means to suppress the lint for your code. Withwarn the lintwill only emit a warning, while withdeny the lint will emit an error, whentriggering for your code. An error causes Clippy to exit with an error code, sois useful in scripts like CI/CD.

If you do not want to include your lint levels in your code, you can globallyenable/disable lints by passing extra flags to Clippy during the run:

To allowlint_name, run

cargo clippy -- -A clippy::lint_name

And to warn onlint_name, run

cargo clippy -- -W clippy::lint_name

This also works with lint groups. For example, youcan run Clippy with warnings for all lints enabled:

cargo clippy -- -W clippy::pedantic

If you care only about a single lint, you can allow all others and then explicitly warn onthe lint(s) you are interested in:

cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...

Configure the behavior of some lints

Some lints can be configured in a TOML file namedclippy.toml or.clippy.toml. It contains a basicvariable = value mapping e.g.

avoid-breaking-exported-api =falsedisallowed-names = ["toto","tata","titi"]

Thetable of configurationscontains all config values, their default, and a list of lints they affect.Eachconfigurable lint, also contains information about these values.

For configurations that are a list type with default values such asdisallowed-names,you can use the unique value".." to extend the default values instead of replacing them.

# default of disallowed-names is ["foo", "baz", "quux"]disallowed-names = ["bar",".."]# -> ["bar", "foo", "baz", "quux"]

Note

clippy.toml or.clippy.toml cannot be used to allow/deny lints.

To deactivate the “for further information visitlint-link” message you candefine theCLIPPY_DISABLE_DOCS_LINKS environment variable.

Specifying the minimum supported Rust version

Projects that intend to support old versions of Rust can disable lints pertaining to newer features byspecifying the minimum supported Rust version (MSRV) in the Clippy configuration file.

msrv ="1.30.0"

Alternatively, therust-version fieldin theCargo.toml can be used.

# Cargo.tomlrust-version ="1.30"

The MSRV can also be specified as an attribute, like below.

#![feature(custom_inner_attributes)]#![clippy::msrv ="1.30.0"]fnmain(){  ...}

You can also omit the patch version when specifying the MSRV, somsrv = 1.30is equivalent tomsrv = 1.30.0.

Note:custom_inner_attributes is an unstable feature, so it has to be enabled explicitly.

Lints that recognize this configuration option can be foundhere

Contributing

If you want to contribute to Clippy, you can find more information inCONTRIBUTING.md.

License

Copyright 2014-2025 The Rust Project Developers

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE orhttps://www.apache.org/licenses/LICENSE-2.0> or the MIT license<LICENSE-MIT orhttps://opensource.org/licenses/MIT>, at youroption. Files in the project may not becopied, modified, or distributed except according to those terms.

Footnotes

  1. Some use cases forrestriction lints include:

About

A bunch of lints to catch common mistakes and improve your Rust code. Book:https://doc.rust-lang.org/clippy/

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors1,084


[8]ページ先頭

©2009-2025 Movatter.jp