@@ -16,6 +16,7 @@ because that's clearly a non-descriptive name.
16
16
- [Edition 2018 tests](#edition-2018-tests)
17
17
- [Testing manually](#testing-manually)
18
18
- [Lint declaration](#lint-declaration)
19
+ - [Lint registration](#lint-registration)
19
20
- [Lint passes](#lint-passes)
20
21
- [Emitting a lint](#emitting-a-lint)
21
22
- [Adding the lint logic](#adding-the-lint-logic)
@@ -43,9 +44,9 @@ take a look at our [lint naming guidelines][lint_naming]. To get started on this
43
44
lint you can run `cargo dev new_lint --name=foo_functions --pass=early
44
45
--category=pedantic` (category will default to nursery if not provided). This
45
46
command will create two files: `tests/ui/foo_functions.rs` and
46
- `clippy_lints/src/foo_functions.rs`, as well as run `cargo dev update_lints` to
47
- register the new lint. For cargo lints, two project hierarchies (fail/pass) will
48
- be created by default under `tests/ui-cargo`.
47
+ `clippy_lints/src/foo_functions.rs`, as well as
48
+ [registering the lint](#lint-registration) . For cargo lints, two project
49
+ hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
49
50
50
51
Next, we'll open up these files and add our lint!
51
52
@@ -220,32 +221,34 @@ declare_lint_pass!(FooFunctions => [FOO_FUNCTIONS]);
220
221
impl EarlyLintPass for FooFunctions {}
221
222
```
222
223
223
- Normally after declaring the lint, we have to run `cargo dev update_lints`,
224
- which updates some files, so Clippy knows about the new lint. Since we used
225
- `cargo dev new_lint ...` to generate the lint declaration, this was done
226
- automatically. While `update_lints` automates most of the things, it doesn't
227
- automate everything. We will have to register our lint pass manually in the
228
- `register_plugins` function in `clippy_lints/src/lib.rs`:
224
+ [declare_clippy_lint]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L60
225
+ [example_lint_page]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
226
+ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
227
+ [category_level_mapping]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L110
228
+
229
+ ## Lint registration
230
+
231
+ When using `cargo dev new_lint`, the lint is automatically registered and
232
+ nothing more has to be done.
233
+
234
+ When declaring a new lint by hand and `cargo dev update_lints` is used, the lint
235
+ pass may have to be registered manually in the `register_plugins` function in
236
+ `clippy_lints/src/lib.rs`:
229
237
230
238
```rust
231
- store.register_early_pass(|| box foo_functions::FooFunctions);
239
+ store.register_early_pass(|| Box::new( foo_functions::FooFunctions) );
232
240
```
233
241
234
242
As one may expect, there is a corresponding `register_late_pass` method
235
243
available as well. Without a call to one of `register_early_pass` or
236
244
`register_late_pass`, the lint pass in question will not be run.
237
245
238
- One reason that `cargo dev` does not automate this step is that multiple lints
239
- can use the same lint pass, so registering the lint pass may already be done
240
- when adding a new lint. Another reason that this step is not automated is that
241
- the order that the passes are registered determines the order the passes
242
- actually run, which in turn affects the order that any emitted lints are output
243
- in.
244
-
245
- [declare_clippy_lint]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L60
246
- [example_lint_page]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
247
- [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
248
- [category_level_mapping]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/lib.rs#L110
246
+ One reason that `cargo dev update_lints` does not automate this step is that
247
+ multiple lints can use the same lint pass, so registering the lint pass may
248
+ already be done when adding a new lint. Another reason that this step is not
249
+ automated is that the order that the passes are registered determines the order
250
+ the passes actually run, which in turn affects the order that any emitted lints
251
+ are output in.
249
252
250
253
## Lint passes
251
254
0 commit comments