diff options
author | Akshay <[email protected]> | 2021-10-31 09:05:26 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-31 16:05:15 +0000 |
commit | e8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch) | |
tree | 0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lints/collapsible_let_in.rs | |
parent | 246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff) |
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/collapsible_let_in.rs')
-rw-r--r-- | lib/src/lints/collapsible_let_in.rs | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index 878d218..21199a8 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs | |||
@@ -1,13 +1,41 @@ | |||
1 | use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
5 | use rowan::Direction; | ||
6 | use rnix::{ | 5 | use rnix::{ |
7 | types::{LetIn, TypedNode}, | 6 | types::{LetIn, TypedNode}, |
8 | NodeOrToken, SyntaxElement, SyntaxKind, TextRange | 7 | NodeOrToken, SyntaxElement, SyntaxKind, TextRange, |
9 | }; | 8 | }; |
9 | use rowan::Direction; | ||
10 | 10 | ||
11 | /// ## What it does | ||
12 | /// Checks for `let-in` expressions whose body is another `let-in` | ||
13 | /// expression. | ||
14 | /// | ||
15 | /// ## Why is this bad? | ||
16 | /// Unnecessary code, the `let-in` expressions can be merged. | ||
17 | /// | ||
18 | /// ## Example | ||
19 | /// | ||
20 | /// ``` | ||
21 | /// let | ||
22 | /// a = 2; | ||
23 | /// in | ||
24 | /// let | ||
25 | /// b = 3; | ||
26 | /// in | ||
27 | /// a + b | ||
28 | /// ``` | ||
29 | /// | ||
30 | /// Merge both `let-in` expressions: | ||
31 | /// | ||
32 | /// ``` | ||
33 | /// let | ||
34 | /// a = 2; | ||
35 | /// b = 3; | ||
36 | /// in | ||
37 | /// a + b | ||
38 | /// ``` | ||
11 | #[lint( | 39 | #[lint( |
12 | name = "collapsible let in", | 40 | name = "collapsible let in", |
13 | note = "These let-in expressions are collapsible", | 41 | note = "These let-in expressions are collapsible", |
@@ -47,7 +75,7 @@ impl Rule for CollapsibleLetIn { | |||
47 | let replacement = make::empty().node().clone(); | 75 | let replacement = make::empty().node().clone(); |
48 | 76 | ||
49 | Some( | 77 | Some( |
50 | Self::report() | 78 | self.report() |
51 | .diagnostic(first_annotation, first_message) | 79 | .diagnostic(first_annotation, first_message) |
52 | .suggest(second_annotation, second_message, Suggestion::new(replacement_at, replacement)) | 80 | .suggest(second_annotation, second_message, Suggestion::new(replacement_at, replacement)) |
53 | ) | 81 | ) |
@@ -57,4 +85,3 @@ impl Rule for CollapsibleLetIn { | |||
57 | } | 85 | } |
58 | } | 86 | } |
59 | } | 87 | } |
60 | |||