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
@@ -107,7 +108,8 @@ state the thing that is being checked for and read well when used with
107
108
* The last part should be a text that explains what exactly is wrong with the
108
109
code
109
110
110
-
With our lint declaration done, we will now make sure that our lint declaration is assigned to a lint pass:
111
+
With our lint declaration done, we will now make sure that our lint declaration
112
+
is assigned to a lint pass:
111
113
112
114
```rust
113
115
// clippy_lints/src/foo_functions.rs
@@ -130,31 +132,43 @@ impl LintPass for FooFunctionsPass {
130
132
}
131
133
```
132
134
133
-
Don't worry about the `name` method here. As long as it includes the name of the lint pass it should be fine.
135
+
Don't worry about the `name` method here. As long as it includes the name of the
136
+
lint pass it should be fine.
134
137
135
138
Next you should run `util/dev update_lints` to register the lint in various
136
139
places, mainly in `clippy_lints/src/lib.rs`.
137
140
138
-
While `update_lints` automates some things, it doesn't automate everything. We will have to register our lint pass manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
141
+
While `update_lints` automates some things, it doesn't automate everything. We
142
+
will have to register our lint pass manually in the `register_plugins` function
Without that, running the UI tests would produce an error like `unknown clippy lint: clippy::foo_functions`.
145
-
The next decision we have to make is which lint pass our lint is going to need.
149
+
Without that, running the UI tests would produce an error like `unknown clippy
150
+
lint: clippy::foo_functions`. The next decision we have to make is which lint
151
+
pass our lint is going to need.
146
152
147
153
### Lint passes
148
154
149
155
Writing a lint that just checks for the name of a function means that we just
150
156
have to deal with the AST and don't have to deal with the type system at all.
151
157
This is good, because it makes writing this particular lint less complicated.
152
158
153
-
We have to make this decision with every new Clippy lint. It boils down to using either `EarlyLintPass` or `LateLintPass`. This is a result of Rust's compilation process. You can read more about it [in the rustc guide][compilation_stages].
159
+
We have to make this decision with every new Clippy lint. It boils down to using
160
+
either [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].
161
+
This is a result of Rust's compilation process. You can read more about it [in
162
+
the rustc guide][compilation_stages].
154
163
155
-
In short, the `LateLintPass` has access to type information while the `EarlyLintPass` doesn't. If you don't need access to type information, use the `EarlyLintPass`. The `EarlyLintPass` is also faster. However linting speed hasn't really been a concern with Clippy so far.
164
+
In short, the `LateLintPass` has access to type information while the
165
+
`EarlyLintPass` doesn't. If you don't need access to type information, use the
166
+
`EarlyLintPass`. The `EarlyLintPass` is also faster. However linting speed
167
+
hasn't really been a concern with Clippy so far.
156
168
157
-
Since we don't need type information for checking the function name, we are going to use the `EarlyLintPass`. It has to be imported as well, changing our imports to:
169
+
Since we don't need type information for checking the function name, we are
170
+
going to use the `EarlyLintPass`. It has to be imported as well, changing our
We implement the [`check_fn`][check_fn] method from the [`EarlyLintPass`][early_lint_pass] trait. This gives us access to various information about the function that is currently being checked. More on that in the next section. Let's worry about the details later and emit our lint for *every* function definition first.
192
+
We implement the [`check_fn`][check_fn] method from the
193
+
[`EarlyLintPass`][early_lint_pass] trait. This gives us access to various
194
+
information about the function that is currently being checked. More on that in
195
+
the next section. Let's worry about the details later and emit our lint for
196
+
*every* function definition first.
179
197
180
-
Depending on how complex we want our lint message to be, we can choose from a variety of lint emission functions.
181
-
They can all be found in [`clippy_lints/src/utils/diagnostics.rs`][diagnostics].
198
+
Depending on how complex we want our lint message to be, we can choose from a
199
+
variety of lint emission functions. They can all be found in
0 commit comments