@@ -18,6 +18,7 @@ because that's clearly a non-descriptive name.
18
18
- [ Cargo lints] ( #cargo-lints )
19
19
- [ Rustfix tests] ( #rustfix-tests )
20
20
- [ Testing manually] ( #testing-manually )
21
+ - [ Running directly] ( #running-directly )
21
22
- [ Lint declaration] ( #lint-declaration )
22
23
- [ Lint registration] ( #lint-registration )
23
24
- [ Lint passes] ( #lint-passes )
@@ -186,6 +187,15 @@ cargo dev lint input.rs
186
187
from the working copy root. With tests in place, let's have a look at
187
188
implementing our lint now.
188
189
190
+ ## Running directly
191
+
192
+ While it's easier to just use ` cargo dev lint ` , it might be desirable to get
193
+ ` target/release/cargo-clippy ` and ` target/release/clippy-driver ` to work as well in some cases.
194
+ By default, they don't work because clippy dynamically links rustc. To help them find rustc,
195
+ add the path printed by` rustc --print target-libdir ` (ran inside this workspace so that the rustc version matches)
196
+ to your library search path.
197
+ On linux, this can be done by setting the ` LD_LIBRARY_PATH ` environment variable to that path.
198
+
189
199
## Lint declaration
190
200
191
201
Let's start by opening the new file created in the ` clippy_lints ` crate at
@@ -265,7 +275,7 @@ When declaring a new lint by hand and `cargo dev update_lints` is used, the lint
265
275
pass may have to be registered manually in the ` register_plugins ` function in
266
276
` clippy_lints/src/lib.rs ` :
267
277
268
- ``` rust
278
+ ``` rust,ignore
269
279
store.register_early_pass(|| Box::new(foo_functions::FooFunctions));
270
280
```
271
281
@@ -291,7 +301,7 @@ either [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].
291
301
292
302
In short, the ` LateLintPass ` has access to type information while the
293
303
` EarlyLintPass ` doesn't. If you don't need access to type information, use the
294
- ` EarlyLintPass ` . The ` EarlyLintPass ` is also faster. However linting speed
304
+ ` EarlyLintPass ` . The ` EarlyLintPass ` is also faster. However, linting speed
295
305
hasn't really been a concern with Clippy so far.
296
306
297
307
Since we don't need type information for checking the function name, we used
@@ -308,7 +318,7 @@ implementation of the lint logic.
308
318
309
319
Let's start by implementing the ` EarlyLintPass ` for our ` FooFunctions ` :
310
320
311
- ``` rust
321
+ ``` rust,ignore
312
322
impl EarlyLintPass for FooFunctions {
313
323
fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) {
314
324
// TODO: Emit lint here
@@ -327,10 +337,10 @@ variety of lint emission functions. They can all be found in
327
337
[ ` clippy_utils/src/diagnostics.rs ` ] [ diagnostics ] .
328
338
329
339
` span_lint_and_help ` seems most appropriate in this case. It allows us to
330
- provide an extra help message and we can't really suggest a better name
340
+ provide an extra help message, and we can't really suggest a better name
331
341
automatically. This is how it looks:
332
342
333
- ``` rust
343
+ ``` rust,ignore
334
344
impl EarlyLintPass for FooFunctions {
335
345
fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, span: Span, _: NodeId) {
336
346
span_lint_and_help(
@@ -469,7 +479,7 @@ the value from `clippy.toml`. This can be accounted for using the
469
479
` extract_msrv_attr!(LintContext) ` macro and passing
470
480
` LateContext ` /` EarlyContext ` .
471
481
472
- ``` rust
482
+ ``` rust,ignore
473
483
impl<'tcx> LateLintPass<'tcx> for ManualStrip {
474
484
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
475
485
...
@@ -483,7 +493,7 @@ the lint's test file, `tests/ui/manual_strip.rs` in this example. It should
483
493
have a case for the version below the MSRV and one with the same contents but
484
494
for the MSRV version itself.
485
495
486
- ``` rust
496
+ ``` rust,ignore
487
497
...
488
498
489
499
#[clippy::msrv = "1.44"]
@@ -514,7 +524,7 @@ define_Conf! {
514
524
515
525
If you have trouble implementing your lint, there is also the internal ` author `
516
526
lint to generate Clippy code that detects the offending pattern. It does not
517
- work for all of the Rust syntax, but can give a good starting point.
527
+ work for all the Rust syntax, but can give a good starting point.
518
528
519
529
The quickest way to use it, is the [ Rust playground:
520
530
play.rust-lang.org] [ author_example ] . Put the code you want to lint into the
@@ -607,7 +617,7 @@ output in the `stdout` part.
607
617
608
618
## PR Checklist
609
619
610
- Before submitting your PR make sure you followed all of the basic requirements:
620
+ Before submitting your PR make sure you followed all the basic requirements:
611
621
612
622
<!-- Sync this with `.github/PULL_REQUEST_TEMPLATE` -->
613
623
@@ -627,7 +637,7 @@ for some users. Adding a configuration is done in the following steps:
627
637
628
638
1 . Adding a new configuration entry to [ ` clippy_lints::utils::conf ` ] like this:
629
639
630
- ``` rust
640
+ ``` rust,ignore
631
641
/// Lint: LINT_NAME.
632
642
///
633
643
/// <The configuration field doc comment>
@@ -680,7 +690,7 @@ for some users. Adding a configuration is done in the following steps:
680
690
configuration value is now cloned or copied into a local value that is then
681
691
passed to the impl struct like this :
682
692
683
- ```rust
693
+ ```rust , ignore
684
694
// Default generated registration:
685
695
store . register_* _pass (|| box module :: StructName );
686
696
0 commit comments