Skip to content

Commit 7465436

Browse files
blyxyasflip1995
authored andcommitted
Improve briefness
1 parent 735380b commit 7465436

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

book/src/development/defining_lints.md

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ name for a function, so we want to trigger this and fix it early in the developm
1010

1111
## Lint name
1212

13-
A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're
14-
unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if
13+
A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if
1514
the lint name doesn't fit, a Clippy team member will alert you in the PR process.
1615

17-
If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR.
18-
1916
---
2017

2118
We'll name our example lint that detects functions named "foo" `foo_functions`. Check the
@@ -32,7 +29,7 @@ If you believe that this new lint is a standalone lint (that doesn't belong to a
3229
command in your Clippy project:
3330

3431
```sh
35-
$ cargo dev new_lint --name=foo_functions --pass=late --category=pedantic
32+
$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic
3633
```
3734

3835
There are two things to note here:
@@ -64,6 +61,7 @@ Untracked files:
6461
tests/ui/foo_functions.rs
6562
```
6663

64+
6765
### Specific Type
6866

6967
> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section
@@ -112,29 +110,7 @@ Untracked files:
112110
tests/ui/foo_functions.rs
113111
```
114112

115-
## Lint registration
116-
117-
If we run the `cargo dev new_lint` command for a new lint,
118-
the lint will be automatically registered and there is nothing more to do.
119-
120-
However, sometimes we might want to declare a new lint by hand.
121-
In this case, we'd use `cargo dev update_lints` command afterwards.
122-
123-
When a lint is manually declared, we might need to register the lint pass
124-
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
125-
126-
```rust
127-
store.register_late_pass(|| Box::new(foo_functions::FooFunctions));
128-
```
129-
130-
As you might have guessed, where there's something late, there is something early:
131-
in Clippy there is a `register_early_pass` method as well.
132-
More on early vs. late passes in a later chapter.
133-
134-
Without a call to one of `register_early_pass` or `register_late_pass`,
135-
the lint pass in question will not be run.
136-
137-
## Lint types
113+
#### Lint types
138114

139115
As of the writing of this documentation update, there are 12 groups (a.k.a. _types_)
140116
of lints besides the numerous standalone lints living under `clippy_lints/src/`:
@@ -160,6 +136,64 @@ For more information, feel free to compare the lint files under any category
160136
with [All Clippy lints][all_lints] or
161137
ask one of the maintainers.
162138

139+
## The `define_clippy_lints` macro
140+
141+
After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint.
142+
143+
The macro looks something like this:
144+
145+
```rust
146+
declare_clippy_lint! {
147+
/// ### What it does
148+
///
149+
/// // Describe here what does the lint do.
150+
///
151+
/// Triggers when detects...
152+
///
153+
/// ### Why is this bad?
154+
///
155+
/// // Describe why this pattern would be bad
156+
///
157+
/// It can lead to...
158+
///
159+
/// ### Example
160+
/// ```rust
161+
/// // example code where clippy issues a warning
162+
/// ```
163+
/// Use instead:
164+
/// ```rust
165+
/// // example code which does not raise clippy warning
166+
/// ```
167+
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
168+
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
169+
pedantic, // <- The lint group
170+
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
171+
}
172+
```
173+
174+
## Lint registration
175+
176+
If we run the `cargo dev new_lint` command for a new lint,
177+
the lint will be automatically registered and there is nothing more to do.
178+
179+
However, sometimes we might want to declare a new lint by hand.
180+
In this case, we'd use `cargo dev update_lints` command afterwards.
181+
182+
When a lint is manually declared, we might need to register the lint pass
183+
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
184+
185+
```rust
186+
store.register_late_pass(|| Box::new(foo_functions::FooFunctions));
187+
```
188+
189+
As you might have guessed, where there's something late, there is something early:
190+
in Clippy there is a `register_early_pass` method as well.
191+
More on early vs. late passes in a later chapter.
192+
193+
Without a call to one of `register_early_pass` or `register_late_pass`,
194+
the lint pass in question will not be run.
195+
196+
163197
[all_lints]: https://rust-lang.github.io/rust-clippy/master/
164198
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
165199
[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy

0 commit comments

Comments
 (0)