Skip to content

Commit 11066fb

Browse files
committed
raise, don't fix for empty_let_in with comments
1 parent 33490aa commit 11066fb

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

bin/tests/data/empty_let_in.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
)
77
(
88
let
9-
# don't match this, we have a comment
9+
# don't fix this, we have a comment
10+
# raise the lint though
1011
in
1112
null
1213
)

bin/tests/snapshots/main__empty_let_in.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ expression: "&out"
1111
· │
1212
· ╰────────────── This let-in expression has no entries
1313
───╯
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+
────╯
1422

lib/src/lints/empty_let_in.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::Not;
2-
31
use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion};
42

53
use if_chain::if_chain;
@@ -49,15 +47,18 @@ impl Rule for EmptyLetIn {
4947
if let Some(body) = let_in_expr.body();
5048

5149
// ensure that the let-in-expr does not have comments
52-
if node
50+
let has_comments = node
5351
.children_with_tokens()
54-
.any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT)
55-
.not();
52+
.any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT);
5653
then {
5754
let at = node.text_range();
5855
let replacement = body;
5956
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+
})
6162
} else {
6263
None
6364
}

0 commit comments

Comments
 (0)