From 11066fbbddffb09a25ebaedff429d5ff6192d8be Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 4 Jun 2022 21:52:57 +0530 Subject: raise, don't fix for empty_let_in with comments --- bin/tests/data/empty_let_in.nix | 3 ++- bin/tests/snapshots/main__empty_let_in.snap | 8 ++++++++ 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 @@ ) ( let - # don't match this, we have a comment + # don't fix this, we have a comment + # raise the lint though in null ) 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" · │ · ╰────────────── 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 +────╯ 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 @@ -use std::ops::Not; - use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; use if_chain::if_chain; @@ -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 } -- cgit v1.2.3