Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

raise, don't fix for empty_let_in with comments

Akshay 11066fbb 33490aa2

+17 -7
+2 -1
bin/tests/data/empty_let_in.nix
··· 6 6 ) 7 7 ( 8 8 let 9 - # don't match this, we have a comment 9 + # don't fix this, we have a comment 10 + # raise the lint though 10 11 in 11 12 null 12 13 )
+8
bin/tests/snapshots/main__empty_let_in.snap
··· 11 11 · │ 12 12 · ╰────────────── This let-in expression has no entries 13 13 ───╯ 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 + ────╯ 14 22
+7 -6
lib/src/lints/empty_let_in.rs
··· 1 - use std::ops::Not; 2 - 3 1 use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; 4 2 5 3 use if_chain::if_chain; ··· 49 47 if let Some(body) = let_in_expr.body(); 50 48 51 49 // ensure that the let-in-expr does not have comments 52 - if node 50 + let has_comments = node 53 51 .children_with_tokens() 54 - .any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT) 55 - .not(); 52 + .any(|el| el.kind() == SyntaxKind::TOKEN_COMMENT); 56 53 then { 57 54 let at = node.text_range(); 58 55 let replacement = body; 59 56 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 + }) 61 62 } else { 62 63 None 63 64 }