Lints and suggestions for the Nix programming language
1
fork

Configure Feed

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

chore: test check subcommand using cli

Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>

Wes Gray 09a1f5c2 e6bd7931

+76 -93
+8 -25
bin/tests/main.rs
··· 1 - use std::path::Path; 2 - 3 1 mod util { 4 2 #[macro_export] 5 3 macro_rules! test_lint { ··· 15 13 paste::paste! { 16 14 #[test] 17 15 fn [<$tname _lint>](){ 18 - let file_path = concat!("data/", stringify!($tname), ".nix"); 19 - let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); 20 - test_lint(file_path, contents); 16 + let file_path = concat!("tests/data/", stringify!($tname), ".nix"); 17 + test_cli(file_path, &["check"]); 21 18 } 22 19 23 20 #[test] 24 21 fn [<$tname _fix>](){ 25 22 let file_path = concat!("tests/data/", stringify!($tname), ".nix"); 26 - test_fix(file_path); 23 + test_cli(file_path, &["fix", "--dry-run"]); 27 24 } 28 25 } 29 26 ··· 31 28 } 32 29 } 33 30 34 - fn test_lint(file_path: impl AsRef<Path>, contents: &str) { 35 - use statix::{config::OutFormat, lint, traits::WriteDiagnostic}; 36 - use vfs::ReadOnlyVfs; 37 - 38 - let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); 39 - 40 - let mut buffer = Vec::new(); 41 - vfs.iter().map(|entry| lint::lint(&entry)).for_each(|r| { 42 - buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); 43 - }); 44 - 45 - let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); 46 - let out = std::str::from_utf8(&stripped).unwrap(); 47 - insta::assert_snapshot!(&out); 48 - } 49 - fn test_fix(file_path: &str) { 31 + fn test_cli(file_path: &str, args: &[&str]) { 50 32 let output = std::process::Command::new("cargo") 51 33 .arg("run") 52 - .arg("fix") 53 - .arg("-d") 34 + .arg("--") 35 + .args(args) 54 36 .arg(file_path) 55 37 .output() 56 38 .expect("command runs successfully"); 57 39 58 - let stdout = String::from_utf8(output.stdout).expect("output is valid utf8"); 40 + let stdout = strip_ansi_escapes::strip(output.stdout).unwrap(); 41 + let stdout = String::from_utf8(stdout).unwrap(); 59 42 60 43 insta::assert_snapshot!(&stdout); 61 44 }
+15 -15
bin/tests/snapshots/main__bool_comparison_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W01] Warning: Unnecessary comparison with boolean 6 - ╭─[data/bool_comparison.nix:3:4] 6 + ╭─[tests/data/bool_comparison.nix:3:4] 7 7 8 8 3 │ (a == true) 9 9 · ────┬──── 10 10 · ╰────── Comparing a with boolean literal true 11 11 ───╯ 12 12 [W01] Warning: Unnecessary comparison with boolean 13 - ╭─[data/bool_comparison.nix:4:4] 13 + ╭─[tests/data/bool_comparison.nix:4:4] 14 14 15 15 4 │ (b == true) 16 16 · ────┬──── 17 17 · ╰────── Comparing b with boolean literal true 18 18 ───╯ 19 19 [W01] Warning: Unnecessary comparison with boolean 20 - ╭─[data/bool_comparison.nix:5:4] 20 + ╭─[tests/data/bool_comparison.nix:5:4] 21 21 22 22 5 │ (true == c) 23 23 · ────┬──── 24 24 · ╰────── Comparing c with boolean literal true 25 25 ───╯ 26 26 [W01] Warning: Unnecessary comparison with boolean 27 - ╭─[data/bool_comparison.nix:6:4] 27 + ╭─[tests/data/bool_comparison.nix:6:4] 28 28 29 29 6 │ (true == d) 30 30 · ────┬──── 31 31 · ╰────── Comparing d with boolean literal true 32 32 ───╯ 33 33 [W01] Warning: Unnecessary comparison with boolean 34 - ╭─[data/bool_comparison.nix:9:4] 34 + ╭─[tests/data/bool_comparison.nix:9:4] 35 35 36 36 9 │ (e != true) 37 37 · ────┬──── 38 38 · ╰────── Comparing e with boolean literal true 39 39 ───╯ 40 40 [W01] Warning: Unnecessary comparison with boolean 41 - ╭─[data/bool_comparison.nix:10:4] 41 + ╭─[tests/data/bool_comparison.nix:10:4] 42 42 43 43 10 │ (f != false) 44 44 · ─────┬──── 45 45 · ╰────── Comparing f with boolean literal false 46 46 ────╯ 47 47 [W01] Warning: Unnecessary comparison with boolean 48 - ╭─[data/bool_comparison.nix:11:4] 48 + ╭─[tests/data/bool_comparison.nix:11:4] 49 49 50 50 11 │ (true != g) 51 51 · ────┬──── 52 52 · ╰────── Comparing g with boolean literal true 53 53 ────╯ 54 54 [W01] Warning: Unnecessary comparison with boolean 55 - ╭─[data/bool_comparison.nix:12:4] 55 + ╭─[tests/data/bool_comparison.nix:12:4] 56 56 57 57 12 │ (false != h) 58 58 · ─────┬──── 59 59 · ╰────── Comparing h with boolean literal false 60 60 ────╯ 61 61 [W01] Warning: Unnecessary comparison with boolean 62 - ╭─[data/bool_comparison.nix:19:4] 62 + ╭─[tests/data/bool_comparison.nix:19:4] 63 63 64 64 19 │ (false == false) 65 65 · ───────┬────── 66 66 · ╰──────── Comparing false with boolean literal false 67 67 ────╯ 68 68 [W01] Warning: Unnecessary comparison with boolean 69 - ╭─[data/bool_comparison.nix:20:4] 69 + ╭─[tests/data/bool_comparison.nix:20:4] 70 70 71 71 20 │ (false == true) 72 72 · ──────┬────── 73 73 · ╰──────── Comparing true with boolean literal false 74 74 ────╯ 75 75 [W01] Warning: Unnecessary comparison with boolean 76 - ╭─[data/bool_comparison.nix:21:4] 76 + ╭─[tests/data/bool_comparison.nix:21:4] 77 77 78 78 21 │ (true == false) 79 79 · ──────┬────── 80 80 · ╰──────── Comparing false with boolean literal true 81 81 ────╯ 82 82 [W01] Warning: Unnecessary comparison with boolean 83 - ╭─[data/bool_comparison.nix:22:4] 83 + ╭─[tests/data/bool_comparison.nix:22:4] 84 84 85 85 22 │ (true == true) 86 86 · ──────┬───── 87 87 · ╰─────── Comparing true with boolean literal true 88 88 ────╯ 89 89 [W01] Warning: Unnecessary comparison with boolean 90 - ╭─[data/bool_comparison.nix:25:4] 90 + ╭─[tests/data/bool_comparison.nix:25:4] 91 91 92 92 25 │ (false == m ? n) 93 93 · ───────┬────── 94 94 · ╰──────── Comparing m ? n with boolean literal false 95 95 ────╯ 96 96 [W01] Warning: Unnecessary comparison with boolean 97 - ╭─[data/bool_comparison.nix:26:4] 97 + ╭─[tests/data/bool_comparison.nix:26:4] 98 98 99 99 26 │ (true == o ? p) 100 100 · ──────┬──────
+2 -2
bin/tests/snapshots/main__bool_simplification_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W18] Warning: This boolean expression can be simplified 6 - ╭─[data/bool_simplification.nix:2:7] 6 + ╭─[tests/data/bool_simplification.nix:2:7] 7 7 8 8 2 │ _ = !(a == b); 9 9 · ────┬────
+2 -2
bin/tests/snapshots/main__collapsible_let_in_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W06] Warning: These let-in expressions are collapsible 6 - ╭─[data/collapsible_let_in.nix:1:1] 6 + ╭─[tests/data/collapsible_let_in.nix:1:1] 7 7 8 8 1 │ ╭───▶ let 9 9 5 │ │ ╭─▶ let
+5 -5
bin/tests/snapshots/main__deprecated_to_path_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W17] Warning: Found usage of deprecated builtin toPath 6 - ╭─[data/deprecated_to_path.nix:2:4] 6 + ╭─[tests/data/deprecated_to_path.nix:2:4] 7 7 8 8 2 │ (builtins.toPath x) 9 9 · ────────┬──────── 10 10 · ╰────────── builtins.toPath is deprecated, see :doc builtins.toPath within the REPL for more 11 11 ───╯ 12 12 [W17] Warning: Found usage of deprecated builtin toPath 13 - ╭─[data/deprecated_to_path.nix:3:4] 13 + ╭─[tests/data/deprecated_to_path.nix:3:4] 14 14 15 15 3 │ (toPath x) 16 16 · ────┬─── 17 17 · ╰───── toPath is deprecated, see :doc builtins.toPath within the REPL for more 18 18 ───╯ 19 19 [W17] Warning: Found usage of deprecated builtin toPath 20 - ╭─[data/deprecated_to_path.nix:4:4] 20 + ╭─[tests/data/deprecated_to_path.nix:4:4] 21 21 22 22 4 │ (toPath "/abc/def") 23 23 · ────────┬──────── 24 24 · ╰────────── toPath is deprecated, see :doc builtins.toPath within the REPL for more 25 25 ───╯ 26 26 [W17] Warning: Found usage of deprecated builtin toPath 27 - ╭─[data/deprecated_to_path.nix:5:4] 27 + ╭─[tests/data/deprecated_to_path.nix:5:4] 28 28 29 29 5 │ (builtins.toPath "/some/path") 30 30 · ──────────────┬─────────────
+2 -2
bin/tests/snapshots/main__empty_inherit_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W14] Warning: Found empty inherit statement 6 - ╭─[data/empty_inherit.nix:2:3] 6 + ╭─[tests/data/empty_inherit.nix:2:3] 7 7 8 8 2 │ inherit; 9 9 · ────┬───
+3 -3
bin/tests/snapshots/main__empty_let_in_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W02] Warning: Useless let-in expression 6 - ╭─[data/empty_let_in.nix:3:5] 6 + ╭─[tests/data/empty_let_in.nix:3:5] 7 7 8 8 3 │ ╭─▶ let 9 9 5 │ ├─▶ null ··· 11 11 · ╰────────────── This let-in expression has no entries 12 12 ───╯ 13 13 [W02] Warning: Useless let-in expression 14 - ╭─[data/empty_let_in.nix:8:5] 14 + ╭─[tests/data/empty_let_in.nix:8:5] 15 15 16 16 8 │ ╭─▶ let 17 17 12 │ ├─▶ null
+6 -6
bin/tests/snapshots/main__empty_list_concat_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W23] Warning: Unnecessary concatenation with empty list 6 - ╭─[data/empty_list_concat.nix:6:4] 6 + ╭─[tests/data/empty_list_concat.nix:6:4] 7 7 8 8 6 │ ([] ++ [1 2 3]) 9 9 · ──────┬────── 10 10 · ╰──────── Concatenation with the empty list, [], is a no-op 11 11 ───╯ 12 12 [W23] Warning: Unnecessary concatenation with empty list 13 - ╭─[data/empty_list_concat.nix:9:4] 13 + ╭─[tests/data/empty_list_concat.nix:9:4] 14 14 15 15 9 │ ([1 2 3] ++ []) 16 16 · ──────┬────── 17 17 · ╰──────── Concatenation with the empty list, [], is a no-op 18 18 ───╯ 19 19 [W23] Warning: Unnecessary concatenation with empty list 20 - ╭─[data/empty_list_concat.nix:12:4] 20 + ╭─[tests/data/empty_list_concat.nix:12:4] 21 21 22 22 12 │ ([] ++ []) 23 23 · ────┬─── 24 24 · ╰───── Concatenation with the empty list, [], is a no-op 25 25 ────╯ 26 26 [W23] Warning: Unnecessary concatenation with empty list 27 - ╭─[data/empty_list_concat.nix:15:4] 27 + ╭─[tests/data/empty_list_concat.nix:15:4] 28 28 29 29 15 │ ([] ++ [] ++ []) 30 30 · ───────┬────── 31 31 · ╰──────── Concatenation with the empty list, [], is a no-op 32 32 ────╯ 33 33 [W23] Warning: Unnecessary concatenation with empty list 34 - ╭─[data/empty_list_concat.nix:15:10] 34 + ╭─[tests/data/empty_list_concat.nix:15:10] 35 35 36 36 15 │ ([] ++ [] ++ []) 37 37 · ────┬───
+3 -3
bin/tests/snapshots/main__empty_pattern_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W10] Warning: Found empty pattern in function argument 6 - ╭─[data/empty_pattern.nix:3:4] 6 + ╭─[tests/data/empty_pattern.nix:3:4] 7 7 8 8 3 │ ({ ... }: 42) 9 9 · ───┬─── 10 10 · ╰───── This pattern is empty, use _ instead 11 11 ───╯ 12 12 [W11] Warning: Found redundant pattern bind in function argument 13 - ╭─[data/empty_pattern.nix:7:4] 13 + ╭─[tests/data/empty_pattern.nix:7:4] 14 14 15 15 7 │ ({ ... } @ inputs: inputs) 16 16 · ────────┬───────
+2 -2
bin/tests/snapshots/main__eta_reduction_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W07] Warning: This function expression is eta reducible 6 - ╭─[data/eta_reduction.nix:11:9] 6 + ╭─[tests/data/eta_reduction.nix:11:9] 7 7 8 8 11 │ (map (x: double x) xs) 9 9 · ─────┬─────
+2 -2
bin/tests/snapshots/main__legacy_let_syntax_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W05] Warning: Using undocumented `let` syntax 6 - ╭─[data/legacy_let_syntax.nix:1:1] 6 + ╭─[tests/data/legacy_let_syntax.nix:1:1] 7 7 8 8 1 │ ╭─▶ let { 9 9 5 │ ├─▶ }
+3 -3
bin/tests/snapshots/main__manual_inherit_from_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W04] Warning: Assignment instead of inherit from 6 - ╭─[data/manual_inherit_from.nix:5:3] 6 + ╭─[tests/data/manual_inherit_from.nix:5:3] 7 7 8 8 5 │ b = a.b; 9 9 · ────┬─── 10 10 · ╰───── This assignment is better written with inherit 11 11 ───╯ 12 12 [W04] Warning: Assignment instead of inherit from 13 - ╭─[data/manual_inherit_from.nix:6:3] 13 + ╭─[tests/data/manual_inherit_from.nix:6:3] 14 14 15 15 6 │ c = a.c; 16 16 · ────┬───
+2 -2
bin/tests/snapshots/main__manual_inherit_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W03] Warning: Assignment instead of inherit 6 - ╭─[data/manual_inherit.nix:7:3] 6 + ╭─[tests/data/manual_inherit.nix:7:3] 7 7 8 8 7 │ a = a; 9 9 · ───┬──
+2 -2
bin/tests/snapshots/main__redundant_pattern_bind_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W11] Warning: Found redundant pattern bind in function argument 6 - ╭─[data/redundant_pattern_bind.nix:1:1] 6 + ╭─[tests/data/redundant_pattern_bind.nix:1:1] 7 7 8 8 1 │ { ... } @ inputs: null 9 9 · ────────┬────────
+3 -3
bin/tests/snapshots/main__repeated_keys_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W20] Warning: Avoid repeated keys in attribute sets 6 - ╭─[data/repeated_keys.nix:16:5] 6 + ╭─[tests/data/repeated_keys.nix:16:5] 7 7 8 8 16 │ foo.bar = 1; 9 9 · ───┬─── ··· 16 16 · ╰────── ... and here. Try foo = { bar=...; bar."hello"=...; again=...; } instead. 17 17 ────╯ 18 18 [W20] Warning: Avoid repeated keys in attribute sets 19 - ╭─[data/repeated_keys.nix:23:5] 19 + ╭─[tests/data/repeated_keys.nix:23:5] 20 20 21 21 23 │ foo.baz.bar1 = 1; 22 22 · ──────┬─────
+2 -2
bin/tests/snapshots/main__unquoted_uri_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W12] Warning: Found unquoted URI expression 6 - ╭─[data/unquoted_uri.nix:1:1] 6 + ╭─[tests/data/unquoted_uri.nix:1:1] 7 7 8 8 1 │ github:nerdypepper/statix 9 9 · ────────────┬────────────
+6 -6
bin/tests/snapshots/main__useless_has_attr_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W19] Warning: This `if` expression can be simplified with `or` 6 - ╭─[data/useless_has_attr.nix:3:4] 6 + ╭─[tests/data/useless_has_attr.nix:3:4] 7 7 8 8 3 │ (if x ? a then x.a else default) 9 9 · ───────────────┬────────────── 10 10 · ╰──────────────── Consider using x.a or default instead of this if expression 11 11 ───╯ 12 12 [W19] Warning: This `if` expression can be simplified with `or` 13 - ╭─[data/useless_has_attr.nix:4:4] 13 + ╭─[tests/data/useless_has_attr.nix:4:4] 14 14 15 15 4 │ (if x.a ? b then x.a.b else default) 16 16 · ─────────────────┬──────────────── 17 17 · ╰────────────────── Consider using x.a.b or default instead of this if expression 18 18 ───╯ 19 19 [W19] Warning: This `if` expression can be simplified with `or` 20 - ╭─[data/useless_has_attr.nix:5:4] 20 + ╭─[tests/data/useless_has_attr.nix:5:4] 21 21 22 22 5 │ (if x ? a.b then x.a.b else default) 23 23 · ─────────────────┬──────────────── 24 24 · ╰────────────────── Consider using x.a.b or default instead of this if expression 25 25 ───╯ 26 26 [W19] Warning: This `if` expression can be simplified with `or` 27 - ╭─[data/useless_has_attr.nix:8:4] 27 + ╭─[tests/data/useless_has_attr.nix:8:4] 28 28 29 29 8 │ (if x ? a then x.a else if b then c else d) 30 30 · ────────────────────┬──────────────────── 31 31 · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression 32 32 ───╯ 33 33 [W19] Warning: This `if` expression can be simplified with `or` 34 - ╭─[data/useless_has_attr.nix:9:4] 34 + ╭─[tests/data/useless_has_attr.nix:9:4] 35 35 36 36 9 │ (if x ? a then x.a else b.c) 37 37 · ─────────────┬────────────
+8 -8
bin/tests/snapshots/main__useless_parens_lint.snap
··· 1 1 --- 2 2 source: bin/tests/main.rs 3 - expression: "&out" 3 + expression: "&stdout" 4 4 --- 5 5 [W08] Warning: These parentheses can be omitted 6 - ╭─[data/useless_parens.nix:4:9] 6 + ╭─[tests/data/useless_parens.nix:4:9] 7 7 8 8 4 │ b = ("hello"); 9 9 · ────┬──── 10 10 · ╰────── Useless parentheses around value in binding 11 11 ───╯ 12 12 [W08] Warning: These parentheses can be omitted 13 - ╭─[data/useless_parens.nix:5:9] 13 + ╭─[tests/data/useless_parens.nix:5:9] 14 14 15 15 5 │ c = (d); 16 16 · ─┬─ 17 17 · ╰─── Useless parentheses around value in binding 18 18 ───╯ 19 19 [W08] Warning: These parentheses can be omitted 20 - ╭─[data/useless_parens.nix:6:9] 20 + ╭─[tests/data/useless_parens.nix:6:9] 21 21 22 22 6 │ e = ({ f = 2; }); 23 23 · ──────┬───── 24 24 · ╰─────── Useless parentheses around value in binding 25 25 ───╯ 26 26 [W08] Warning: These parentheses can be omitted 27 - ╭─[data/useless_parens.nix:10:7] 27 + ╭─[tests/data/useless_parens.nix:10:7] 28 28 29 29 10 │ g = (1 + 2); 30 30 · ───┬─── 31 31 · ╰───── Useless parentheses around value in binding 32 32 ────╯ 33 33 [W08] Warning: These parentheses can be omitted 34 - ╭─[data/useless_parens.nix:11:7] 34 + ╭─[tests/data/useless_parens.nix:11:7] 35 35 36 36 11 │ h = ({ inherit i; }); 37 37 · ────────┬─────── 38 38 · ╰───────── Useless parentheses around value in binding 39 39 ────╯ 40 40 [W08] Warning: These parentheses can be omitted 41 - ╭─[data/useless_parens.nix:16:3] 41 + ╭─[tests/data/useless_parens.nix:16:3] 42 42 43 43 16 │ (null) 44 44 · ───┬── 45 45 · ╰──── Useless parentheses around primitive expression 46 46 ────╯ 47 47 [W08] Warning: These parentheses can be omitted 48 - ╭─[data/useless_parens.nix:20:5] 48 + ╭─[tests/data/useless_parens.nix:20:5] 49 49 50 50 20 │ (a.b) 51 51 · ──┬──