Skip to content

Commit

Permalink
raise, don't fix for empty_let_in with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oppiliappan committed Jun 4, 2022
1 parent 33490aa commit 11066fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bin/tests/data/empty_let_in.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
)
(
let
# don't match this, we have a comment
# don't fix this, we have a comment
# raise the lint though
in
null
)
Expand Down
8 changes: 8 additions & 0 deletions bin/tests/snapshots/main__empty_let_in.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ expression: "&out"
· │
· ╰────────────── This let-in expression has no entries
───╯
[W02] Warning: Useless let-in expression
╭─[data/empty_let_in.nix:8:5]
8 │ ╭─▶ let
12 │ ├─▶ null
· │
· ╰────────────── This let-in expression has no entries
────╯

13 changes: 7 additions & 6 deletions lib/src/lints/empty_let_in.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ops::Not;

use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion};

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

// ensure that the let-in-expr does not have comments
if node
let has_comments = node
.children_with_tokens()
.any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT)
.not();
.any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT);
then {
let at = node.text_range();
let replacement = body;
let message = "This let-in expression has no entries";
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
Some(if has_comments {
self.report().diagnostic(at, message)
} else {
self.report().suggest(at, message, Suggestion::new(at, replacement))
})
} else {
None
}
Expand Down

0 comments on commit 11066fb

Please sign in to comment.