Skip to content

Commit 783c119

Browse files
committed
Address review comments and formatting
1 parent 6076cda commit 783c119

File tree

1 file changed

+50
-44
lines changed

1 file changed

+50
-44
lines changed

book/src/development/defining_lints.md

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
The first step in the journey of a new lint is the definition
44
and registration of the lint in Clippy's codebase.
5-
We can use the Clippy dev tools to handle this step since setting up the
5+
We can use the Clippy dev tools to handle this step since setting up the
66
lint involves some boilerplate code.
77

88
#### Lint types
99

1010
A lint type is the category of items and expressions in which your lint focuses on.
1111

12-
As of the writing of this documentation update, there are 12 groups (a.k.a. _types_)
13-
of lints besides the numerous standalone lints living under `clippy_lints/src/`:
12+
As of the writing of this documentation update, there are 12 _types_ of lints
13+
besides the numerous standalone lints living under `clippy_lints/src/`:
1414

1515
- `cargo`
1616
- `casts`
@@ -25,47 +25,52 @@ of lints besides the numerous standalone lints living under `clippy_lints/src/`:
2525
- `unit_types`
2626
- `utils / internal` (Clippy internal lints)
2727

28-
These types group together lints that share some common behaviors.
29-
For instance, `functions` groups together lints
30-
that deal with some aspects of function calls in Rust.
28+
These types group together lints that share some common behaviors. For instance,
29+
`functions` groups together lints that deal with some aspects of functions in
30+
Rust, like definitions, signatures and attributes.
3131

3232
For more information, feel free to compare the lint files under any category
33-
with [All Clippy lints][all_lints] or
34-
ask one of the maintainers.
33+
with [All Clippy lints][all_lints] or ask one of the maintainers.
3534

3635
## Lint name
3736

38-
A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if
39-
the lint name doesn't fit, a Clippy team member will alert you in the PR process.
37+
A good lint name is important, make sure to check the [lint naming
38+
guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy
39+
team member will alert you in the PR process.
4040

4141
---
4242

43-
We'll name our example lint that detects functions named "foo" `foo_functions`. Check the
44-
[lint naming guidelines][lint_naming] to see why this name makes sense.
43+
We'll name our example lint that detects functions named "foo" `foo_functions`.
44+
Check the [lint naming guidelines][lint_naming] to see why this name makes
45+
sense.
4546

4647
## Add and Register the Lint
4748

48-
Now that a name is chosen, we shall register `foo_functions` as a lint to the codebase.
49-
There are two ways to register a lint.
49+
Now that a name is chosen, we shall register `foo_functions` as a lint to the
50+
codebase. There are two ways to register a lint.
5051

5152
### Standalone
5253

53-
If you believe that this new lint is a standalone lint (that doesn't belong to any specific [type](#lint-types) like `functions` or `loops`), you can run the following
54-
command in your Clippy project:
54+
If you believe that this new lint is a standalone lint (that doesn't belong to
55+
any specific [type](#lint-types) like `functions` or `loops`), you can run the
56+
following command in your Clippy project:
5557

5658
```sh
5759
$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic
5860
```
5961

6062
There are two things to note here:
6163

62-
1. We set `--pass=late` in this command to do a late lint pass. The alternative
63-
is an `early` lint pass. We will discuss this difference in a later chapter.
64-
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
65-
2. If not provided, the `category` of this new lint will default to `nursery`.
64+
1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The
65+
alternative is an `early` lint pass. We will discuss this difference in a
66+
later chapter.
67+
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
68+
2. `--category`: If not provided, the `category` of this new lint will default
69+
to `nursery`.
6670

67-
The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs`
68-
as well as [register the lint](#lint-registration).
71+
The `cargo dev new_lint` command will create a new file:
72+
`clippy_lints/src/foo_functions.rs` as well as [register the
73+
lint](#lint-registration).
6974

7075
Overall, you should notice that the following files are modified or created:
7176

@@ -115,7 +120,6 @@ call your lint from within the type's lint pass, found in `clippy_lints/src/{typ
115120
A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in
116121
the example command. Clippy groups together some lints that share common behaviors,
117122
so if your lint falls into one, it would be best to add it to that type.
118-
Read more about [lint types](#lint-types) below.
119123

120124
Overall, you should notice that the following files are modified or created:
121125

@@ -138,24 +142,25 @@ Untracked files:
138142

139143
## The `define_clippy_lints` macro
140144

141-
After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file
142-
if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint.
145+
After `cargo dev new_lint`, you should see a macro with the name
146+
`define_clippy_lints`. It will be in the same file if you defined a standalone
147+
lint, and it will be in `mod.rs` if you defined a type-specific lint.
143148

144149
The macro looks something like this:
145150

146151
```rust
147152
declare_clippy_lint! {
148-
/// ### What it does
153+
/// ### What it does
154+
///
155+
/// // Describe here what does the lint do.
156+
///
157+
/// Triggers when detects...
149158
///
150-
/// // Describe here what does the lint do.
151-
///
152-
/// Triggers when detects...
153-
///
154159
/// ### Why is this bad?
155-
///
156-
/// // Describe why this pattern would be bad
157-
///
158-
/// It can lead to...
160+
///
161+
/// // Describe why this pattern would be bad
162+
///
163+
/// It can lead to...
159164
///
160165
/// ### Example
161166
/// ```rust
@@ -174,25 +179,26 @@ declare_clippy_lint! {
174179

175180
## Lint registration
176181

177-
If we run the `cargo dev new_lint` command for a new lint,
178-
the lint will be automatically registered and there is nothing more to do.
182+
If we run the `cargo dev new_lint` command for a new lint, the lint will be
183+
automatically registered and there is nothing more to do.
179184

180-
However, sometimes we might want to declare a new lint by hand.
181-
In this case, we'd use `cargo dev update_lints` command afterwards.
185+
However, sometimes we might want to declare a new lint by hand. In this case,
186+
we'd use `cargo dev update_lints` command afterwards.
182187

183188
When a lint is manually declared, we might need to register the lint pass
184189
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
185190

186191
```rust
187-
store.register_late_pass(|| Box::new(foo_functions::FooFunctions));
192+
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));
188193
```
189194

190-
As you might have guessed, where there's something late, there is something early:
191-
in Clippy there is a `register_early_pass` method as well.
192-
More on early vs. late passes in a later chapter.
195+
As you might have guessed, where there's something late, there is something
196+
early: in Clippy there is a `register_early_pass` method as well. More on early
197+
vs. late passes in a later chapter.
198+
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
193199

194-
Without a call to one of `register_early_pass` or `register_late_pass`,
195-
the lint pass in question will not be run.
200+
Without a call to one of `register_early_pass` or `register_late_pass`, the lint
201+
pass in question will not be run.
196202

197203

198204
[all_lints]: https://rust-lang.github.io/rust-clippy/master/

0 commit comments

Comments
 (0)