Skip to content

Commit 33490aa

Browse files
committed
do not raise empty-let when comments are present
1 parent d197ae1 commit 33490aa

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

bin/tests/data/empty_let_in.nix

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
let
2-
in
3-
null
1+
[
2+
(
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+
]

bin/tests/snapshots/main__empty_let_in.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ expression: "&out"
44

55
---
66
[W02] Warning: Useless let-in expression
7-
╭─[data/empty_let_in.nix:1:1]
7+
╭─[data/empty_let_in.nix:3:5]
88
9-
1 │ ╭─▶ let
10-
3 │ ├─▶ null
11-
· │
12-
· ╰──────────── This let-in expression has no entries
9+
3 │ ╭─▶ let
10+
5 │ ├─▶ null
11+
· │
12+
· ╰────────────── This let-in expression has no entries
1313
───╯
1414

lib/src/lints/empty_let_in.rs

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

35
use if_chain::if_chain;
@@ -45,6 +47,12 @@ impl Rule for EmptyLetIn {
4547
if inherits.count() == 0;
4648

4749
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();
4856
then {
4957
let at = node.text_range();
5058
let replacement = body;

0 commit comments

Comments
 (0)