Skip to content

Commit 766217f

Browse files
authored
Merge pull request #1227 from Manishearth/readme_improvements
List lints at the end of the readme
2 parents dc84759 + b778269 commit 766217f

File tree

1 file changed

+157
-157
lines changed

1 file changed

+157
-157
lines changed

README.md

+157-157
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,163 @@ Table of contents:
1515
* [*clippy-service*](#link-with-clippy-service)
1616
* [License](#license)
1717

18+
## Usage
19+
20+
As a general rule clippy will only work with the *latest* Rust nightly for now.
21+
22+
### As a Compiler Plugin
23+
24+
Since stable Rust is backwards compatible, you should be able to
25+
compile your stable programs with nightly Rust with clippy plugged in to
26+
circumvent this.
27+
28+
Add in your `Cargo.toml`:
29+
30+
```toml
31+
[dependencies]
32+
clippy = "*"
33+
```
34+
35+
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
36+
of your crate entry point (`main.rs` or `lib.rs`).
37+
38+
Sample `main.rs`:
39+
40+
```rust
41+
#![feature(plugin)]
42+
43+
#![plugin(clippy)]
44+
45+
46+
fn main(){
47+
let x = Some(1u8);
48+
match x {
49+
Some(y) => println!("{:?}", y),
50+
_ => ()
51+
}
52+
}
53+
```
54+
55+
Produces this warning:
56+
57+
```terminal
58+
src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
59+
src/main.rs:8 match x {
60+
src/main.rs:9 Some(y) => println!("{:?}", y),
61+
src/main.rs:10 _ => ()
62+
src/main.rs:11 }
63+
src/main.rs:8:5: 11:6 help: Try
64+
if let Some(y) = x { println!("{:?}", y) }
65+
```
66+
67+
### As a cargo subcommand (`cargo clippy`)
68+
69+
An alternate way to use clippy is by installing clippy through cargo as a cargo
70+
subcommand.
71+
72+
```terminal
73+
cargo install clippy
74+
```
75+
76+
Now you can run clippy by invoking `cargo clippy`, or
77+
`rustup run nightly cargo clippy` directly from a directory that is usually
78+
compiled with stable.
79+
80+
In case you are not using rustup, you need to set the environment flag
81+
`SYSROOT` during installation so clippy knows where to find `librustc` and
82+
similar crates.
83+
84+
```terminal
85+
SYSROOT=/path/to/rustc/sysroot cargo install clippy
86+
```
87+
88+
### Running clippy from the command line without installing
89+
90+
To have cargo compile your crate with clippy without needing `#![plugin(clippy)]`
91+
in your code, you can use:
92+
93+
```terminal
94+
cargo rustc -- -L /path/to/clippy_so -Z extra-plugins=clippy
95+
```
96+
97+
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):*
98+
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
99+
100+
### Optional dependency
101+
102+
If you want to make clippy an optional dependency, you can do the following:
103+
104+
In your `Cargo.toml`:
105+
106+
```toml
107+
[dependencies]
108+
clippy = {version = "*", optional = true}
109+
110+
[features]
111+
default = []
112+
```
113+
114+
And, in your `main.rs` or `lib.rs`:
115+
116+
```rust
117+
#![cfg_attr(feature="clippy", feature(plugin))]
118+
119+
#![cfg_attr(feature="clippy", plugin(clippy))]
120+
```
121+
122+
Then build by enabling the feature: `cargo build --features "clippy"`
123+
124+
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
125+
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
126+
(the `-Z no trans`, while not neccessary, will stop the compilation process after
127+
typechecking (and lints) have completed, which can significantly reduce the runtime).
128+
129+
## Configuration
130+
131+
Some lints can be configured in a `clippy.toml` file. It contains basic `variable = value` mapping eg.
132+
133+
```toml
134+
blacklisted-names = ["toto", "tata", "titi"]
135+
cyclomatic-complexity-threshold = 30
136+
```
137+
138+
See the wiki for more information about which lints can be configured and the
139+
meaning of the variables.
140+
141+
You can also specify the path to the configuration file with:
142+
143+
```rust
144+
#![plugin(clippy(conf_file="path/to/clippy's/configuration"))]
145+
```
146+
147+
To deactivate the “for further information visit *wiki-link*” message you can
148+
define the `CLIPPY_DISABLE_WIKI_LINKS` environment variable.
149+
150+
### Allowing/denying lints
151+
152+
You can add options to `allow`/`warn`/`deny`:
153+
154+
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
155+
156+
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
157+
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
158+
lints prone to false positives.
159+
160+
* only some lints (`#![deny(single_match, box_vec)]`, etc)
161+
162+
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
163+
164+
Note: `deny` produces errors instead of warnings.
165+
166+
## Link with clippy service
167+
168+
`clippy-service` is a rust web initiative providing `rust-clippy` as a web service.
169+
170+
Both projects are independent and maintained by different people
171+
(even if some `clippy-service`'s contributions are authored by some `rust-clippy` members).
172+
173+
You can check out this great service at [clippy.bashy.io](https://clippy.bashy.io/).
174+
18175
## Lints
19176

20177
There are 171 lints included in this crate:
@@ -195,163 +352,6 @@ name
195352

196353
More to come, please [file an issue](https://github.com/Manishearth/rust-clippy/issues) if you have ideas!
197354

198-
## Usage
199-
200-
As a general rule clippy will only work with the *latest* Rust nightly for now.
201-
202-
### As a Compiler Plugin
203-
204-
Since stable Rust is backwards compatible, you should be able to
205-
compile your stable programs with nightly Rust with clippy plugged in to
206-
circumvent this.
207-
208-
Add in your `Cargo.toml`:
209-
210-
```toml
211-
[dependencies]
212-
clippy = "*"
213-
```
214-
215-
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
216-
of your crate entry point (`main.rs` or `lib.rs`).
217-
218-
Sample `main.rs`:
219-
220-
```rust
221-
#![feature(plugin)]
222-
223-
#![plugin(clippy)]
224-
225-
226-
fn main(){
227-
let x = Some(1u8);
228-
match x {
229-
Some(y) => println!("{:?}", y),
230-
_ => ()
231-
}
232-
}
233-
```
234-
235-
Produces this warning:
236-
237-
```terminal
238-
src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
239-
src/main.rs:8 match x {
240-
src/main.rs:9 Some(y) => println!("{:?}", y),
241-
src/main.rs:10 _ => ()
242-
src/main.rs:11 }
243-
src/main.rs:8:5: 11:6 help: Try
244-
if let Some(y) = x { println!("{:?}", y) }
245-
```
246-
247-
### As a cargo subcommand (`cargo clippy`)
248-
249-
An alternate way to use clippy is by installing clippy through cargo as a cargo
250-
subcommand.
251-
252-
```terminal
253-
cargo install clippy
254-
```
255-
256-
Now you can run clippy by invoking `cargo clippy`, or
257-
`rustup run nightly cargo clippy` directly from a directory that is usually
258-
compiled with stable.
259-
260-
In case you are not using rustup, you need to set the environment flag
261-
`SYSROOT` during installation so clippy knows where to find `librustc` and
262-
similar crates.
263-
264-
```terminal
265-
SYSROOT=/path/to/rustc/sysroot cargo install clippy
266-
```
267-
268-
### Running clippy from the command line without installing
269-
270-
To have cargo compile your crate with clippy without needing `#![plugin(clippy)]`
271-
in your code, you can use:
272-
273-
```terminal
274-
cargo rustc -- -L /path/to/clippy_so -Z extra-plugins=clippy
275-
```
276-
277-
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):*
278-
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
279-
280-
### Optional dependency
281-
282-
If you want to make clippy an optional dependency, you can do the following:
283-
284-
In your `Cargo.toml`:
285-
286-
```toml
287-
[dependencies]
288-
clippy = {version = "*", optional = true}
289-
290-
[features]
291-
default = []
292-
```
293-
294-
And, in your `main.rs` or `lib.rs`:
295-
296-
```rust
297-
#![cfg_attr(feature="clippy", feature(plugin))]
298-
299-
#![cfg_attr(feature="clippy", plugin(clippy))]
300-
```
301-
302-
Then build by enabling the feature: `cargo build --features "clippy"`
303-
304-
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
305-
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
306-
(the `-Z no trans`, while not neccessary, will stop the compilation process after
307-
typechecking (and lints) have completed, which can significantly reduce the runtime).
308-
309-
## Configuration
310-
311-
Some lints can be configured in a `clippy.toml` file. It contains basic `variable = value` mapping eg.
312-
313-
```toml
314-
blacklisted-names = ["toto", "tata", "titi"]
315-
cyclomatic-complexity-threshold = 30
316-
```
317-
318-
See the wiki for more information about which lints can be configured and the
319-
meaning of the variables.
320-
321-
You can also specify the path to the configuration file with:
322-
323-
```rust
324-
#![plugin(clippy(conf_file="path/to/clippy's/configuration"))]
325-
```
326-
327-
To deactivate the “for further information visit *wiki-link*” message you can
328-
define the `CLIPPY_DISABLE_WIKI_LINKS` environment variable.
329-
330-
### Allowing/denying lints
331-
332-
You can add options to `allow`/`warn`/`deny`:
333-
334-
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
335-
336-
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
337-
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
338-
lints prone to false positives.
339-
340-
* only some lints (`#![deny(single_match, box_vec)]`, etc)
341-
342-
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
343-
344-
Note: `deny` produces errors instead of warnings.
345-
346-
## Link with clippy service
347-
348-
`clippy-service` is a rust web initiative providing `rust-clippy` as a web service.
349-
350-
Both projects are independent and maintained by different people
351-
(even if some `clippy-service`'s contributions are authored by some `rust-clippy` members).
352-
353-
You can check out this great service at [clippy.bashy.io](https://clippy.bashy.io/).
354-
355355
## License
356356

357357
Licensed under [MPL](https://www.mozilla.org/MPL/2.0/).

0 commit comments

Comments
 (0)