diff options
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 | |||