You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
138
114
139
115
As of the writing of this documentation update, there are 12 groups (a.k.a. _types_)
140
116
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
160
136
with [All Clippy lints][all_lints] or
161
137
ask one of the maintainers.
162
138
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
+
pubLINT_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`:
0 commit comments