]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/book/src/configuration.md
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / book / src / configuration.md
1 # Configuring Clippy
2
3 > **Note:** The configuration file is unstable and may be deprecated in the future.
4
5 Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a
6 basic `variable = value` mapping eg.
7
8 ```toml
9 avoid-breaking-exported-api = false
10 blacklisted-names = ["toto", "tata", "titi"]
11 cognitive-complexity-threshold = 30
12 ```
13
14 See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which
15 lints can be configured and the meaning of the variables.
16
17 To deactivate the "for further information visit *lint-link*" message you can define the `CLIPPY_DISABLE_DOCS_LINKS`
18 environment variable.
19
20 ### Allowing/denying lints
21
22 You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
23
24 * the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`)
25
26 * all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
27 `#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive lints prone to false
28 positives.
29
30 * only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
31
32 * `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc.
33
34 Note: `allow` means to suppress the lint for your code. With `warn` the lint will only emit a warning, while with `deny`
35 the lint will emit an error, when triggering for your code. An error causes clippy to exit with an error code, so is
36 useful in scripts like CI/CD.
37
38 If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra
39 flags to Clippy during the run:
40
41 To allow `lint_name`, run
42
43 ```terminal
44 cargo clippy -- -A clippy::lint_name
45 ```
46
47 And to warn on `lint_name`, run
48
49 ```terminal
50 cargo clippy -- -W clippy::lint_name
51 ```
52
53 This also works with lint groups. For example you can run Clippy with warnings for all lints enabled:
54
55 ```terminal
56 cargo clippy -- -W clippy::pedantic
57 ```
58
59 If you care only about a single lint, you can allow all others and then explicitly warn on the lint(s) you are
60 interested in:
61
62 ```terminal
63 cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
64 ```
65
66 ### Specifying the minimum supported Rust version
67
68 Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the
69 minimum supported Rust version (MSRV) in the clippy configuration file.
70
71 ```toml
72 msrv = "1.30.0"
73 ```
74
75 The MSRV can also be specified as an inner attribute, like below.
76
77 ```rust
78 #![feature(custom_inner_attributes)]
79 #![clippy::msrv = "1.30.0"]
80
81 fn main() {
82 ...
83 }
84 ```
85
86 You can also omit the patch version when specifying the MSRV, so `msrv = 1.30`
87 is equivalent to `msrv = 1.30.0`.
88
89 Note: `custom_inner_attributes` is an unstable feature so it has to be enabled explicitly.
90
91 Lints that recognize this configuration option can be
92 found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)