@@ -10,6 +10,10 @@ because that's clearly a non-descriptive name.
10
10
- [ Adding a new lint] ( #adding-a-new-lint )
11
11
- [ Setup] ( #setup )
12
12
- [ Getting Started] ( #getting-started )
13
+ - [ Defining Our Lint] ( #defining-our-lint )
14
+ - [ Standalone] ( #standalone )
15
+ - [ Specific Type] ( #specific-type )
16
+ - [ Tests Location] ( #tests-location )
13
17
- [ Testing] ( #testing )
14
18
- [ Cargo lints] ( #cargo-lints )
15
19
- [ Rustfix tests] ( #rustfix-tests )
@@ -36,17 +40,38 @@ See the [Basics](basics.md#get-the-code) documentation.
36
40
## Getting Started
37
41
38
42
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
40
44
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 in the traditional sense. Instead, you will
66
+ call your lint from within the type's lint pass, found in ` clippy_lints/src/{type}/mod.rs ` .
67
+
68
+ A "type" is just the name of a directory in ` clippy_lints/src ` , like ` functions ` in
69
+ the example command. These are groupings of lints with common behaviors, so if your
70
+ lint falls into one, it would be best to add it to that type.
71
+
72
+ ### Tests Location
73
+ Both commands will create a file: ` tests/ui/foo_functions.rs ` . For cargo lints,
74
+ two project hierarchies (fail/pass) will be created by default under ` tests/ui-cargo ` .
50
75
51
76
Next, we'll open up these files and add our lint!
52
77
0 commit comments