diff options
-rw-r--r-- | bin/tests/data/empty_let_in.nix | 16 | ||||
-rw-r--r-- | bin/tests/snapshots/main__empty_let_in.snap | 10 | ||||
-rw-r--r-- | lib/src/lints/empty_let_in.rs | 8 |
3 files changed, 26 insertions, 8 deletions
diff --git a/bin/tests/data/empty_let_in.nix b/bin/tests/data/empty_let_in.nix index 3ecb6e4..54fee2a 100644 --- a/bin/tests/data/empty_let_in.nix +++ b/bin/tests/data/empty_let_in.nix | |||
@@ -1,3 +1,13 @@ | |||
1 | let | 1 | [ |
2 | in | 2 | ( |
3 | null | 3 | let |
4 | in | ||
5 | null | ||
6 | ) | ||
7 | ( | ||
8 | let | ||
9 | # don't match this, we have a comment | ||
10 | in | ||
11 | null | ||
12 | ) | ||
13 | ] | ||
diff --git a/bin/tests/snapshots/main__empty_let_in.snap b/bin/tests/snapshots/main__empty_let_in.snap index 426692f..df0911d 100644 --- a/bin/tests/snapshots/main__empty_let_in.snap +++ b/bin/tests/snapshots/main__empty_let_in.snap | |||
@@ -4,11 +4,11 @@ expression: "&out" | |||
4 | 4 | ||
5 | --- | 5 | --- |
6 | [W02] Warning: Useless let-in expression | 6 | [W02] Warning: Useless let-in expression |
7 | ╭─[data/empty_let_in.nix:1:1] | 7 | ╭─[data/empty_let_in.nix:3:5] |
8 | │ | 8 | │ |
9 | 1 │ ╭─▶ let | 9 | 3 │ ╭─▶ let |
10 | 3 │ ├─▶ null | 10 | 5 │ ├─▶ null |
11 | · │ | 11 | · │ |
12 | · ╰──────────── This let-in expression has no entries | 12 | · ╰────────────── This let-in expression has no entries |
13 | ───╯ | 13 | ───╯ |
14 | 14 | ||
diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index e42f658..390a1e1 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::ops::Not; | ||
2 | |||
1 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; | 3 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 4 | ||
3 | use if_chain::if_chain; | 5 | use if_chain::if_chain; |
@@ -45,6 +47,12 @@ impl Rule for EmptyLetIn { | |||
45 | if inherits.count() == 0; | 47 | if inherits.count() == 0; |
46 | 48 | ||
47 | if let Some(body) = let_in_expr.body(); | 49 | if let Some(body) = let_in_expr.body(); |
50 | |||
51 | // ensure that the let-in-expr does not have comments | ||
52 | if node | ||
53 | .children_with_tokens() | ||
54 | .any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT) | ||
55 | .not(); | ||
48 | then { | 56 | then { |
49 | let at = node.text_range(); | 57 | let at = node.text_range(); |
50 | let replacement = body; | 58 | let replacement = body; |