Lints and suggestions for the Nix programming language
1
fork

Configure Feed

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

do not raise empty-let when comments are present

Akshay 33490aa2 d197ae11

+26 -8
+13 -3
bin/tests/data/empty_let_in.nix
··· 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 + ]
+5 -5
bin/tests/snapshots/main__empty_let_in.snap
··· 4 4 5 5 --- 6 6 [W02] Warning: Useless let-in expression 7 - ╭─[data/empty_let_in.nix:1:1] 7 + ╭─[data/empty_let_in.nix:3:5] 8 8 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 13 13 ───╯ 14 14
+8
lib/src/lints/empty_let_in.rs
··· 1 + use std::ops::Not; 2 + 1 3 use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; 2 4 3 5 use if_chain::if_chain; ··· 45 47 if inherits.count() == 0; 46 48 47 49 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(); 48 56 then { 49 57 let at = node.text_range(); 50 58 let replacement = body;