aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/collapsible_let_in.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-31 09:05:26 +0000
committerAkshay <[email protected]>2021-10-31 16:05:15 +0000
commite8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch)
tree0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lints/collapsible_let_in.rs
parent246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (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.rs37
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 @@
1use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; 1use crate::{make, Metadata, Report, Rule, Suggestion};
2 2
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
5use rowan::Direction;
6use rnix::{ 5use rnix::{
7 types::{LetIn, TypedNode}, 6 types::{LetIn, TypedNode},
8 NodeOrToken, SyntaxElement, SyntaxKind, TextRange 7 NodeOrToken, SyntaxElement, SyntaxKind, TextRange,
9}; 8};
9use 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