diff options
-rw-r--r-- | bin/tests/data/empty_let_in.nix | 3 | ||||
-rw-r--r-- | bin/tests/snapshots/main__empty_let_in.snap | 8 | ||||
-rw-r--r-- | lib/src/lints/empty_let_in.rs | 13 |
3 files changed, 17 insertions, 7 deletions
diff --git a/bin/tests/data/empty_let_in.nix b/bin/tests/data/empty_let_in.nix index 54fee2a..6b916d9 100644 --- a/bin/tests/data/empty_let_in.nix +++ b/bin/tests/data/empty_let_in.nix | |||
@@ -6,7 +6,8 @@ | |||
6 | ) | 6 | ) |
7 | ( | 7 | ( |
8 | let | 8 | let |
9 | # don't match this, we have a comment | 9 | # don't fix this, we have a comment |
10 | # raise the lint though | ||
10 | in | 11 | in |
11 | null | 12 | null |
12 | ) | 13 | ) |
diff --git a/bin/tests/snapshots/main__empty_let_in.snap b/bin/tests/snapshots/main__empty_let_in.snap index df0911d..1aa0cb5 100644 --- a/bin/tests/snapshots/main__empty_let_in.snap +++ b/bin/tests/snapshots/main__empty_let_in.snap | |||
@@ -11,4 +11,12 @@ expression: "&out" | |||
11 | · │ | 11 | · │ |
12 | · ╰────────────── This let-in expression has no entries | 12 | · ╰────────────── This let-in expression has no entries |
13 | ───╯ | 13 | ───╯ |
14 | [W02] Warning: Useless let-in expression | ||
15 | ╭─[data/empty_let_in.nix:8:5] | ||
16 | │ | ||
17 | 8 │ ╭─▶ let | ||
18 | 12 │ ├─▶ null | ||
19 | · │ | ||
20 | · ╰────────────── This let-in expression has no entries | ||
21 | ────╯ | ||
14 | 22 | ||
diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index 390a1e1..0714ac0 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | use std::ops::Not; | ||
2 | |||
3 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
4 | 2 | ||
5 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
@@ -49,15 +47,18 @@ impl Rule for EmptyLetIn { | |||
49 | if let Some(body) = let_in_expr.body(); | 47 | if let Some(body) = let_in_expr.body(); |
50 | 48 | ||
51 | // ensure that the let-in-expr does not have comments | 49 | // ensure that the let-in-expr does not have comments |
52 | if node | 50 | let has_comments = node |
53 | .children_with_tokens() | 51 | .children_with_tokens() |
54 | .any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT) | 52 | .any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT); |
55 | .not(); | ||
56 | then { | 53 | then { |
57 | let at = node.text_range(); | 54 | let at = node.text_range(); |
58 | let replacement = body; | 55 | let replacement = body; |
59 | let message = "This let-in expression has no entries"; | 56 | let message = "This let-in expression has no entries"; |
60 | Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) | 57 | Some(if has_comments { |
58 | self.report().diagnostic(at, message) | ||
59 | } else { | ||
60 | self.report().suggest(at, message, Suggestion::new(at, replacement)) | ||
61 | }) | ||
61 | } else { | 62 | } else { |
62 | None | 63 | None |
63 | } | 64 | } |