]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/book/src/README.md
7bdfb97c3acf648c8fa20f30f549960ae7886059
[rustc.git] / src / tools / clippy / book / src / README.md
1 # Clippy
2
3 [![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test+(bors)%22+event%3Apush+branch%3Aauto)
4 [![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](https://github.com/rust-lang/rust-clippy#license)
5
6 A collection of lints to catch common mistakes and improve your
7 [Rust](https://github.com/rust-lang/rust) code.
8
9 [There are over 700 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10
11 Lints are divided into categories, each with a default [lint
12 level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how
13 much Clippy is supposed to ~~annoy~~ help you by changing the lint level by
14 category.
15
16 | Category | Description | Default level |
17 |-----------------------|-------------------------------------------------------------------------------------|---------------|
18 | `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
19 | `clippy::correctness` | code that is outright wrong or useless | **deny** |
20 | `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
21 | `clippy::style` | code that should be written in a more idiomatic way | **warn** |
22 | `clippy::complexity` | code that does something simple but in a complex way | **warn** |
23 | `clippy::perf` | code that can be written to run faster | **warn** |
24 | `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow |
25 | `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow |
26 | `clippy::nursery` | new lints that are still under development | allow |
27 | `clippy::cargo` | lints for the cargo manifest | allow |
28
29 More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
30
31 The `restriction` category should, *emphatically*, not be enabled as a whole. The contained
32 lints may lint against perfectly reasonable code, may not have an alternative suggestion,
33 and may contradict any other lints (including other categories). Lints should be considered
34 on a case-by-case basis before enabling.
35
36 [^restrict]: Some use cases for `restriction` lints include:
37 - Strict coding styles (e.g. [`clippy::else_if_without_else`]).
38 - Additional restrictions on CI (e.g. [`clippy::todo`]).
39 - Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]).
40 - Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module).
41
42 [`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
43 [`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
44 [`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used