Skip to content

Commit 179b81f

Browse files
committed
Document --type flag
1 parent f319370 commit 179b81f

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

book/src/development/adding_lints.md

+34-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ because that's clearly a non-descriptive name.
1010
- [Adding a new lint](#adding-a-new-lint)
1111
- [Setup](#setup)
1212
- [Getting Started](#getting-started)
13+
- [Defining Our Lint](#defining-our-lint)
14+
- [Standalone](#standalone)
15+
- [Specific Type](#specific-type)
16+
- [Tests Location](#tests-location)
1317
- [Testing](#testing)
1418
- [Cargo lints](#cargo-lints)
1519
- [Rustfix tests](#rustfix-tests)
@@ -36,17 +40,37 @@ See the [Basics](basics.md#get-the-code) documentation.
3640
## Getting Started
3741

3842
There is a bit of boilerplate code that needs to be set up when creating a new
39-
lint. Fortunately, you can use the clippy dev tools to handle this for you. We
43+
lint. Fortunately, you can use the Clippy dev tools to handle this for you. We
4044
are naming our new lint `foo_functions` (lints are generally written in snake
41-
case), and we don't need type information so it will have an early pass type
42-
(more on this later on). If you're not sure if the name you chose fits the lint,
43-
take a look at our [lint naming guidelines][lint_naming]. To get started on this
44-
lint you can run `cargo dev new_lint --name=foo_functions --pass=early
45-
--category=pedantic` (category will default to nursery if not provided). This
46-
command will create two files: `tests/ui/foo_functions.rs` and
47-
`clippy_lints/src/foo_functions.rs`, as well as [registering the
48-
lint](#lint-registration). For cargo lints, two project hierarchies (fail/pass)
49-
will be created by default under `tests/ui-cargo`.
45+
case), and we don't need type information, so it will have an early pass type
46+
(more on this later). If you're unsure if the name you chose fits the lint,
47+
take a look at our [lint naming guidelines][lint_naming].
48+
49+
## Defining Our Lint
50+
To get started, there are two ways to define our lint.
51+
52+
### Standalone
53+
Command: `cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
54+
(category will default to nursery if not provided)
55+
56+
This command will create a new file: `clippy_lints/src/foo_functions.rs`, as well
57+
as [register the lint](#lint-registration).
58+
59+
### Specific Type
60+
Command: `cargo dev new_lint --name=foo_functions --type=functions --category=pedantic`
61+
62+
This command will create a new file: `clippy_lints/src/{type}/foo_functions.rs`.
63+
64+
Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone
65+
definition, this lint won't be registered, so a pass doesn't apply.
66+
67+
A "type" is just the name of a directory in `clippy_lints/src`, like `functions` in
68+
the example command. These are groupings of lints with common behaviors, so if your
69+
lint falls into one, it would be best to add it to that type.
70+
71+
### Tests Location
72+
Both commands will create a file: `tests/ui/foo_functions.rs`. For cargo lints,
73+
two project hierarchies (fail/pass) will be created by default under `tests/ui-cargo`.
5074

5175
Next, we'll open up these files and add our lint!
5276

0 commit comments

Comments
 (0)