Lints and suggestions for the Nix programming language
1
fork

Configure Feed

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

Merge pull request #95 from RobWalt/fix-snapshots

authored by

Shahar "Dawn" Or and committed by
GitHub
879b6a6c 758970f2

+329 -15
+7
Cargo.lock
··· 388 388 ] 389 389 390 390 [[package]] 391 + name = "paste" 392 + version = "1.0.15" 393 + source = "registry+https://github.com/rust-lang/crates.io-index" 394 + checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" 395 + 396 + [[package]] 391 397 name = "proc-macro-error" 392 398 version = "1.0.4" 393 399 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 595 601 "ignore", 596 602 "insta", 597 603 "lib", 604 + "paste", 598 605 "rayon", 599 606 "rnix", 600 607 "serde",
+1
bin/Cargo.toml
··· 37 37 [dev-dependencies] 38 38 insta = "1.8.0" 39 39 strip-ansi-escapes = "0.1.1" 40 + paste = "1.0.15" 40 41 41 42 [features] 42 43 json = [ "lib/json-out", "serde_json" ]
+35 -15
bin/tests/main.rs
··· 22 22 test_lint!($tname => session_info!("2.6")); 23 23 }; 24 24 ($tname:ident => $sess:expr) => { 25 - #[test] 26 - fn $tname() { 27 - use statix::{config::OutFormat, traits::WriteDiagnostic, lint}; 28 - use vfs::ReadOnlyVfs; 25 + paste::paste! { 26 + #[test] 27 + fn [<$tname _lint>](){ 28 + use statix::{config::OutFormat, traits::WriteDiagnostic, lint}; 29 + use vfs::ReadOnlyVfs; 29 30 30 - let file_path = concat!("data/", stringify!($tname), ".nix"); 31 - let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); 31 + let file_path = concat!("data/", stringify!($tname), ".nix"); 32 + let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); 32 33 33 - let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); 34 + let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); 34 35 35 - let session = $sess; 36 + let session = $sess; 36 37 37 - let mut buffer = Vec::new(); 38 - vfs.iter().map(|entry| lint::lint(entry, &session)).for_each(|r| { 39 - buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); 40 - }); 38 + let mut buffer = Vec::new(); 39 + vfs.iter().map(|entry| lint::lint(entry, &session)).for_each(|r| { 40 + buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); 41 + }); 41 42 42 - let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); 43 - let out = std::str::from_utf8(&stripped).unwrap(); 44 - insta::assert_snapshot!(&out); 43 + let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); 44 + let out = std::str::from_utf8(&stripped).unwrap(); 45 + insta::assert_snapshot!(&out); 46 + } 47 + 48 + #[test] 49 + fn [<$tname _fix>](){ 50 + let file_path = concat!("tests/data/", stringify!($tname), ".nix"); 51 + 52 + let output = std::process::Command::new("cargo") 53 + .arg("run") 54 + .arg("fix") 55 + .arg("-d") 56 + .arg(file_path) 57 + .output() 58 + .expect("command runs successfully"); 59 + 60 + let stdout = String::from_utf8(output.stdout).expect("output is valid utf8"); 61 + 62 + insta::assert_snapshot!(&stdout); 63 + } 45 64 } 65 + 46 66 }; 47 67 } 48 68 }
bin/tests/snapshots/main__bool_comparison.snap bin/tests/snapshots/main__bool_comparison_lint.snap
+28
bin/tests/snapshots/main__bool_comparison_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/bool_comparison.nix 6 + +++ tests/data/bool_comparison.nix [fixed] 7 + @@ -1,13 +1,13 @@ 8 + [ 9 + # trivial 10 + - (a == true) 11 + - (b == true) 12 + - (true == c) 13 + - (true == d) 14 + + a 15 + + b 16 + + c 17 + + d 18 + 19 + # not equals 20 + - (e != true) 21 + - (f != false) 22 + - (true != g) 23 + - (false != h) 24 + + (!e) 25 + + f 26 + + (!g) 27 + + h 28 + ]
bin/tests/snapshots/main__bool_simplification.snap bin/tests/snapshots/main__bool_simplification_lint.snap
+14
bin/tests/snapshots/main__bool_simplification_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/bool_simplification.nix 6 + +++ tests/data/bool_simplification.nix [fixed] 7 + @@ -1,6 +1,6 @@ 8 + let 9 + - _ = !(a == b); 10 + + _ = a != b; 11 + # do not match here 12 + _ = !(a != b); 13 + _ = a != b; 14 + in
bin/tests/snapshots/main__collapsible_let_in.snap bin/tests/snapshots/main__collapsible_let_in_lint.snap
+17
bin/tests/snapshots/main__collapsible_let_in_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/collapsible_let_in.nix 6 + +++ tests/data/collapsible_let_in.nix [fixed] 7 + @@ -1,9 +1,8 @@ 8 + let 9 + a = 2; 10 + b = 3; 11 + -in 12 + - let 13 + + 14 + c = 5; 15 + d = 6; 16 + in 17 + a + b + c + d
bin/tests/snapshots/main__deprecated_to_path.snap bin/tests/snapshots/main__deprecated_to_path_lint.snap
+5
bin/tests/snapshots/main__deprecated_to_path_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 +
bin/tests/snapshots/main__empty_inherit.snap bin/tests/snapshots/main__empty_inherit_lint.snap
+10
bin/tests/snapshots/main__empty_inherit_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/empty_inherit.nix 6 + +++ tests/data/empty_inherit.nix [fixed] 7 + @@ -1,3 +1,2 @@ 8 + { 9 + - inherit; 10 + }
bin/tests/snapshots/main__empty_let_in.snap bin/tests/snapshots/main__empty_let_in_lint.snap
+18
bin/tests/snapshots/main__empty_let_in_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/empty_let_in.nix 6 + +++ tests/data/empty_let_in.nix [fixed] 7 + @@ -1,10 +1,6 @@ 8 + [ 9 + - ( 10 + - let 11 + - in 12 + - null 13 + - ) 14 + + null 15 + ( 16 + let 17 + # don't fix this, we have a comment 18 + # raise the lint though
bin/tests/snapshots/main__empty_list_concat.snap bin/tests/snapshots/main__empty_list_concat_lint.snap
+27
bin/tests/snapshots/main__empty_list_concat_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/empty_list_concat.nix 6 + +++ tests/data/empty_list_concat.nix [fixed] 7 + @@ -2,15 +2,15 @@ 8 + # no match 9 + ([1 2] ++ [3 4]) 10 + 11 + # unnecessary left 12 + - ([] ++ [1 2 3]) 13 + + [1 2 3] 14 + 15 + # unnecessary right 16 + - ([1 2 3] ++ []) 17 + + [1 2 3] 18 + 19 + # collapses to a single array 20 + - ([] ++ []) 21 + + [] 22 + 23 + # multiple empties 24 + - ([] ++ [] ++ []) 25 + + [] 26 + ] 27 + \ No newline at end of file
bin/tests/snapshots/main__empty_pattern.snap bin/tests/snapshots/main__empty_pattern_lint.snap
+20
bin/tests/snapshots/main__empty_pattern_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/empty_pattern.nix 6 + +++ tests/data/empty_pattern.nix [fixed] 7 + @@ -1,11 +1,11 @@ 8 + [ 9 + # match 10 + - ({ ... }: 42) 11 + + (_: 42) 12 + 13 + # don't match 14 + ({ a, ... }: a) 15 + - ({ ... } @ inputs: inputs) 16 + + (inputs: inputs) 17 + 18 + # nixos module, don't match 19 + ({ ... }: { 20 + imports = [
bin/tests/snapshots/main__eta_reduction.snap bin/tests/snapshots/main__eta_reduction_lint.snap
+16
bin/tests/snapshots/main__eta_reduction_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/eta_reduction.nix 6 + +++ tests/data/eta_reduction.nix [fixed] 7 + @@ -7,9 +7,9 @@ 8 + val = 2; 9 + }; 10 + in 11 + [ 12 + - (map (x: double x) xs) 13 + + (map double xs) 14 + 15 + # don't lint on non-free exprs 16 + (map (f: f.double f.val) [ f ])
bin/tests/snapshots/main__faster_groupby.snap bin/tests/snapshots/main__faster_groupby_lint.snap
+5
bin/tests/snapshots/main__faster_groupby_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 +
bin/tests/snapshots/main__faster_zipattrswith.snap bin/tests/snapshots/main__faster_zipattrswith_lint.snap
+5
bin/tests/snapshots/main__faster_zipattrswith_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 +
bin/tests/snapshots/main__legacy_let_syntax.snap bin/tests/snapshots/main__legacy_let_syntax_lint.snap
+14
bin/tests/snapshots/main__legacy_let_syntax_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/legacy_let_syntax.nix 6 + +++ tests/data/legacy_let_syntax.nix [fixed] 7 + @@ -1,5 +1,5 @@ 8 + -let { 9 + +rec { 10 + body = x + y; 11 + x = "hello,"; 12 + y = " world!"; 13 + -} 14 + +}.body
bin/tests/snapshots/main__manual_inherit.snap bin/tests/snapshots/main__manual_inherit_lint.snap
+17
bin/tests/snapshots/main__manual_inherit_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/manual_inherit.nix 6 + +++ tests/data/manual_inherit.nix [fixed] 7 + @@ -3,9 +3,9 @@ 8 + y = "y"; 9 + in 10 + { 11 + # trivial 12 + - a = a; 13 + + inherit a; 14 + 15 + # don't lint 16 + x.y = y; 17 + }
bin/tests/snapshots/main__manual_inherit_from.snap bin/tests/snapshots/main__manual_inherit_from_lint.snap
+16
bin/tests/snapshots/main__manual_inherit_from_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/manual_inherit_from.nix 6 + +++ tests/data/manual_inherit_from.nix [fixed] 7 + @@ -1,8 +1,8 @@ 8 + let 9 + a = {b = 2; c = 3;}; 10 + in 11 + { 12 + - b = a.b; 13 + - c = a.c; 14 + + inherit (a) b; 15 + + inherit (a) c; 16 + }
bin/tests/snapshots/main__redundant_pattern_bind.snap bin/tests/snapshots/main__redundant_pattern_bind_lint.snap
+9
bin/tests/snapshots/main__redundant_pattern_bind_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/redundant_pattern_bind.nix 6 + +++ tests/data/redundant_pattern_bind.nix [fixed] 7 + @@ -1 +1 @@ 8 + -{ ... } @ inputs: null 9 + +inputs: null
bin/tests/snapshots/main__repeated_keys.snap bin/tests/snapshots/main__repeated_keys_lint.snap
+5
bin/tests/snapshots/main__repeated_keys_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 +
bin/tests/snapshots/main__unquoted_uri.snap bin/tests/snapshots/main__unquoted_uri_lint.snap
+9
bin/tests/snapshots/main__unquoted_uri_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/unquoted_uri.nix 6 + +++ tests/data/unquoted_uri.nix [fixed] 7 + @@ -1 +1 @@ 8 + -github:nerdypepper/statix 9 + +"github:nerdypepper/statix"
bin/tests/snapshots/main__useless_has_attr.snap bin/tests/snapshots/main__useless_has_attr_lint.snap
+22
bin/tests/snapshots/main__useless_has_attr_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/useless_has_attr.nix 6 + +++ tests/data/useless_has_attr.nix [fixed] 7 + @@ -1,10 +1,10 @@ 8 + [ 9 + # trivial 10 + - (if x ? a then x.a else default) 11 + - (if x.a ? b then x.a.b else default) 12 + - (if x ? a.b then x.a.b else default) 13 + + (x.a or default) 14 + + (x.a.b or default) 15 + + (x.a.b or default) 16 + 17 + # complex body 18 + - (if x ? a then x.a else if b then c else d) 19 + - (if x ? a then x.a else b.c) 20 + + (x.a or (if b then c else d)) 21 + + (x.a or b.c) 22 + ]
bin/tests/snapshots/main__useless_parens.snap bin/tests/snapshots/main__useless_parens_lint.snap
+29
bin/tests/snapshots/main__useless_parens_fix.snap
··· 1 + --- 2 + source: bin/tests/main.rs 3 + expression: "& stdout" 4 + --- 5 + --- tests/data/useless_parens.nix 6 + +++ tests/data/useless_parens.nix [fixed] 7 + @@ -1,16 +1,16 @@ 8 + let 9 + # parens around primitives 10 + a = { 11 + - b = ("hello"); 12 + - c = (d); 13 + - e = ({ f = 2; }); 14 + + b = "hello"; 15 + + c = d; 16 + + e = { f = 2; }; 17 + }; 18 + 19 + # parens around let-value 20 + - g = (1 + 2); 21 + - h = ({ inherit i; }); 22 + + g = 1 + 2; 23 + + h = { inherit i; }; 24 + 25 + # TODO: binary exprs, function args etc. 26 + in 27 + # parens around let body 28 + - (null) 29 + + null