diff options
Diffstat (limited to 'lib/src/lints/empty_let_in.rs')
-rw-r--r-- | lib/src/lints/empty_let_in.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index aae1377..b255c23 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs | |||
@@ -1,12 +1,30 @@ | |||
1 | use crate::{Lint, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{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 rnix::{ | 5 | use rnix::{ |
6 | types::{LetIn, TypedNode, EntryHolder}, | 6 | types::{EntryHolder, LetIn, TypedNode}, |
7 | NodeOrToken, SyntaxElement, SyntaxKind, | 7 | NodeOrToken, SyntaxElement, SyntaxKind, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | /// ## What it does | ||
11 | /// Checks for `let-in` expressions which create no new bindings. | ||
12 | /// | ||
13 | /// ## Why is this bad? | ||
14 | /// `let-in` expressions that create no new bindings are useless. | ||
15 | /// These are probably remnants from debugging or editing expressions. | ||
16 | /// | ||
17 | /// ## Example | ||
18 | /// | ||
19 | /// ``` | ||
20 | /// let in pkgs.statix | ||
21 | /// ``` | ||
22 | /// | ||
23 | /// Preserve only the body of the `let-in` expression: | ||
24 | /// | ||
25 | /// ``` | ||
26 | /// pkgs.statix | ||
27 | /// ``` | ||
10 | #[lint( | 28 | #[lint( |
11 | name = "empty let-in", | 29 | name = "empty let-in", |
12 | note = "Useless let-in expression", | 30 | note = "Useless let-in expression", |
@@ -31,11 +49,10 @@ impl Rule for EmptyLetIn { | |||
31 | let at = node.text_range(); | 49 | let at = node.text_range(); |
32 | let replacement = body; | 50 | let replacement = body; |
33 | let message = "This let-in expression has no entries"; | 51 | let message = "This let-in expression has no entries"; |
34 | Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) | 52 | Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) |
35 | } else { | 53 | } else { |
36 | None | 54 | None |
37 | } | 55 | } |
38 | } | 56 | } |
39 | } | 57 | } |
40 | } | 58 | } |
41 | |||