Skip to content

Commit 4e6b55e

Browse files
joshrotenbergflip1995
authored andcommitted
Initial commit for the Clippy Book
1 parent 0f6e50f commit 4e6b55e

28 files changed

+1908
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ helper.txt
3939
*.iml
4040
.vscode
4141
.idea
42+
43+
# mdbook generated output
44+
/book/book

book/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Clippy Book
2+
3+
This is the source for the Clippy Book. See the
4+
[book](src/infrastructure/book.md) for more information.

book/book.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[book]
2+
authors = ["The Rust Clippy Developers"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "Clippy Documentation"
7+
8+
[rust]
9+
edition = "2018"
10+
11+
[output.html]
12+
edit-url-template = "https://github.com/rust-lang/rust-clippy/edit/master/book/{path}"
13+
git-repository-url = "https://github.com/rust-lang/rust-clippy/tree/master/book"
14+
mathjax-support = true
15+
site-url = "/rust-clippy/"
16+
17+
[output.html.playground]
18+
editable = true
19+
line-numbers = true
20+
21+
[output.html.search]
22+
boost-hierarchy = 2
23+
boost-paragraph = 1
24+
boost-title = 2
25+
expand = true
26+
heading-split-level = 2
27+
limit-results = 20
28+
use-boolean-and = true

book/src/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Clippy
2+
3+
[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test%22+event%3Apush+branch%3Aauto)
4+
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#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 500 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::complexity` | code that does something simple but in a complex way | **warn** |
22+
| `clippy::perf` | code that can be written to run faster | **warn** |
23+
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
24+
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
25+
| `clippy::nursery` | new lints that are still under development | allow |
26+
| `clippy::cargo` | lints for the cargo manifest | allow | | allow |
27+
28+
More to come, please [file an
29+
issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
30+
31+
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also
32+
contains "restriction lints", which are for things which are usually not
33+
considered "bad", but may be useful to turn on in specific cases. These should
34+
be used very selectively, if at all.

book/src/SUMMARY.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Summary
2+
3+
[Introduction](README.md)
4+
5+
- [Installation and Usage](installation_and_usage.md)
6+
- [Configuration](configuration.md)
7+
- [Clippy's Lints](lints/README.md)
8+
- [Correctness]()
9+
- [Suspicious]()
10+
- [Style]()
11+
- [Complexity]()
12+
- [Perf]()
13+
- [Pendantic]()
14+
- [Nursery]()
15+
- [Cargo]()
16+
- [Development](development/README.md)
17+
- [Basics](development/basics.md)
18+
- [Adding Lints](development/adding_lints.md)
19+
- [Common Tools](development/common_tools_writing_lints.md)
20+
- [Infrastructure](infrastructure/README.md)
21+
- [Backporting Changes](infrastructure/backport.md)
22+
- [Updating the Changelog](infrastructure/changelog_update.md)
23+
- [Release a New Version](infrastructure/release.md)
24+
- [The Clippy Book](infrastructure/book.md)
25+
- [Roadmap](roadmap/README.md)
26+
- [2021](roadmap/2021.md)

book/src/configuration.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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)

book/src/development/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Clippy Development

0 commit comments

Comments
 (0)