@@ -33,26 +33,29 @@ disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"]
33
33
To deactivate the "for further information visit * lint-link* " message you can define the ` CLIPPY_DISABLE_DOCS_LINKS `
34
34
environment variable.
35
35
36
- ### Allowing/denying lints
36
+ ### Allowing/Denying Lints
37
37
38
- You can add options to your code to ` allow ` / ` warn ` / ` deny ` Clippy lints:
38
+ #### Attributes in Code
39
39
40
- * the whole set of ` Warn ` lints using the ` clippy ` lint group ( ` #![ deny(clippy::all)] ` )
40
+ You can add attributes to your code to ` allow ` / ` warn ` / ` deny ` Clippy lints:
41
41
42
- * all lints using both the ` clippy ` and ` clippy::pedantic ` lint groups (` #![deny(clippy::all)] ` ,
43
- ` #![deny(clippy::pedantic)] ` ). Note that ` clippy::pedantic ` contains some very aggressive lints prone to false
44
- positives.
42
+ * the whole set of ` warn ` -by-default lints using the ` clippy ` lint group (` #![allow(clippy::all)] ` )
43
+
44
+ * all lints using both the ` clippy ` and ` clippy::pedantic ` lint groups (` #![warn(clippy::all, clippy::pedantic)] ` . Note
45
+ that ` clippy::pedantic ` contains some very aggressive lints prone to false positives.
45
46
46
47
* only some lints (` #![deny(clippy::single_match, clippy::box_vec)] ` , etc.)
47
48
48
49
* ` allow ` /` warn ` /` deny ` can be limited to a single function or module using ` #[allow(...)] ` , etc.
49
50
50
51
Note: ` allow ` means to suppress the lint for your code. With ` warn ` the lint will only emit a warning, while with ` deny `
51
- the lint will emit an error, when triggering for your code. An error causes clippy to exit with an error code, so is
52
- useful in scripts like CI/CD.
52
+ the lint will emit an error, when triggering for your code. An error causes Clippy to exit with an error code, so is
53
+ most useful in scripts used in CI/CD.
54
+
55
+ #### Command Line Flags
53
56
54
- If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra
55
- flags to Clippy during the run:
57
+ If you do not want to include your lint levels in the code, you can globally enable/disable lints by passing extra flags
58
+ to Clippy during the run:
56
59
57
60
To allow ` lint_name ` , run
58
61
@@ -66,19 +69,33 @@ And to warn on `lint_name`, run
66
69
cargo clippy -- -W clippy::lint_name
67
70
```
68
71
69
- This also works with lint groups. For example, you can run Clippy with warnings for all lints enabled:
72
+ This also works with lint groups. For example, you can run Clippy with warnings for all pedantic lints enabled:
70
73
71
74
``` terminal
72
75
cargo clippy -- -W clippy::pedantic
73
76
```
74
77
75
- If you care only about a single lint , you can allow all others and then explicitly warn on the lint(s) you are
78
+ If you care only about a certain lints , you can allow all others and then explicitly warn on the lints you are
76
79
interested in:
77
80
78
81
``` terminal
79
82
cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
80
83
```
81
84
85
+ #### Lints Section in ` Cargo.toml `
86
+
87
+ Finally, lints can be allowed/denied using [ the lints
88
+ section] ( https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section ) ) in the ` Cargo.toml ` file:
89
+
90
+ To deny ` clippy::enum_glob_use ` , put the following in the ` Cargo.toml ` :
91
+
92
+ ``` toml
93
+ [lints .clippy ]
94
+ enum_glob_use = " deny"
95
+ ```
96
+
97
+ For more details and options, refer to the Cargo documentation.
98
+
82
99
### Specifying the minimum supported Rust version
83
100
84
101
Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the
@@ -113,17 +130,14 @@ found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)
113
130
114
131
Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with
115
132
[ conditional compilation] ( https://doc.rust-lang.org/reference/conditional-compilation.html ) by checking that the
116
- ` cargo- clippy` feature is not set. You may need to provide a stub so that the code compiles:
133
+ ` clippy ` cfg is not set. You may need to provide a stub so that the code compiles:
117
134
118
135
``` rust
119
- #[cfg(not(feature = " cargo- clippy" ) )]
136
+ #[cfg(not(clippy)]
120
137
include! (concat! (env! (" OUT_DIR" ), " /my_big_function-generated.rs" ));
121
138
122
- #[cfg(feature = " cargo- clippy" )]
139
+ #[cfg(clippy)]
123
140
fn my_big_function (_input : & str ) -> Option <MyStruct > {
124
141
None
125
142
}
126
143
```
127
-
128
- This feature is not actually part of your crate, so specifying ` --all-features ` to other tools, e.g. `cargo test
129
- --all-features`, will not disable it.
0 commit comments