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: 1-expr tests empty-list-concat

Co-authored-by: Wes Gray <wes.gray@gmail.com>

authored by

Shahar "Dawn" Or
Wes Gray
and committed by
Wes Gray
4e6b73d8 89c67ab9

+120 -131
-16
bin/tests/data/empty_list_concat.nix
··· 1 - [ 2 - # no match 3 - ([1 2] ++ [3 4]) 4 - 5 - # unnecessary left 6 - ([] ++ [1 2 3]) 7 - 8 - # unnecessary right 9 - ([1 2 3] ++ []) 10 - 11 - # collapses to a single array 12 - ([] ++ []) 13 - 14 - # multiple empties 15 - ([] ++ [] ++ []) 16 - ]
+23
bin/tests/empty_list_concat.rs
··· 1 + mod _utils; 2 + 3 + use macros::generate_tests; 4 + 5 + generate_tests! { 6 + rule: empty_list_concat, 7 + expressions: [ 8 + // no match 9 + "[1 2] ++ [3 4]", 10 + 11 + // unnecessary left 12 + "[] ++ [1 2 3]", 13 + 14 + // unnecessary right 15 + "[1 2 3] ++ []", 16 + 17 + // collapses to a single array 18 + "[] ++ []", 19 + 20 + // multiple empties 21 + "[] ++ [] ++ []", 22 + ], 23 + }
-48
bin/tests/main.rs
··· 1 - mod util { 2 - #[macro_export] 3 - macro_rules! test_lint { 4 - ($tname:ident, $($tail:tt)*) => { 5 - test_lint!($tname); 6 - test_lint!($($tail)*); 7 - }; 8 - ($tname:ident, $($tail:tt)*) => { 9 - test_lint!($tname); 10 - test_lint!($($tail)*); 11 - }; 12 - ($tname:ident) => { 13 - paste::paste! { 14 - #[test] 15 - fn [<$tname _lint>](){ 16 - let file_path = concat!("tests/data/", stringify!($tname), ".nix"); 17 - test_cli(concat!(stringify!($tname), "_lint"), file_path, &["check"]); 18 - } 19 - 20 - #[test] 21 - fn [<$tname _fix>](){ 22 - let file_path = concat!("tests/data/", stringify!($tname), ".nix"); 23 - test_cli(concat!(stringify!($tname), "_fix"), file_path, &["fix", "--dry-run"]); 24 - } 25 - } 26 - 27 - }; 28 - } 29 - } 30 - 31 - fn test_cli(test_name: &str, file_path: &str, args: &[&str]) { 32 - let output = std::process::Command::new("cargo") 33 - .arg("run") 34 - .arg("--") 35 - .args(args) 36 - .arg(file_path) 37 - .output() 38 - .expect("command runs successfully"); 39 - 40 - let stdout = strip_ansi_escapes::strip(output.stdout).unwrap(); 41 - let stdout = String::from_utf8(stdout).unwrap(); 42 - 43 - insta::assert_snapshot!(test_name, &stdout); 44 - } 45 - 46 - test_lint! { 47 - empty_list_concat 48 - }
+9
bin/tests/snapshots/empty_list_concat__fix_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[1 2 3] ++ []\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -[1 2 3] ++ [] 9 + +[1 2 3]
+5
bin/tests/snapshots/empty_list_concat__fix_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[1 2] ++ [3 4]\"" 4 + --- 5 +
+9
bin/tests/snapshots/empty_list_concat__fix_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ [] ++ []\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -[] ++ [] ++ [] 9 + +[]
+9
bin/tests/snapshots/empty_list_concat__fix_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ [1 2 3]\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -[] ++ [1 2 3] 9 + +[1 2 3]
+9
bin/tests/snapshots/empty_list_concat__fix_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ []\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -[] ++ [] 9 + +[]
+11
bin/tests/snapshots/empty_list_concat__lint_676800f4240e26802590a123362636e6d87461d7e091b87b44fb8b5959b31b1a.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[1 2 3] ++ []\"" 4 + --- 5 + [W23] Warning: Unnecessary concatenation with empty list 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ [1 2 3] ++ [] 9 + · ──────┬────── 10 + · ╰──────── Concatenation with the empty list, [], is a no-op 11 + ───╯
+5
bin/tests/snapshots/empty_list_concat__lint_6d44e9727e67c4d4d91c4b7abe2a2193f00467aabdd6230c1019702fdabe53bb.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[1 2] ++ [3 4]\"" 4 + --- 5 +
+18
bin/tests/snapshots/empty_list_concat__lint_b13b2273654200cbc2315c6ceec0dbc9e4479628a5b7250418efeb5911e743b2.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ [] ++ []\"" 4 + --- 5 + [W23] Warning: Unnecessary concatenation with empty list 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ [] ++ [] ++ [] 9 + · ───────┬────── 10 + · ╰──────── Concatenation with the empty list, [], is a no-op 11 + ───╯ 12 + [W23] Warning: Unnecessary concatenation with empty list 13 + ╭─[<temp_file_path>:1:7] 14 + 15 + 1 │ [] ++ [] ++ [] 16 + · ────┬─── 17 + · ╰───── Concatenation with the empty list, [], is a no-op 18 + ───╯
+11
bin/tests/snapshots/empty_list_concat__lint_b6d6b2d3b0ff0b3b842e3f816ced62ca22410c59471e767d80ea85a3f7fcc1ef.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ [1 2 3]\"" 4 + --- 5 + [W23] Warning: Unnecessary concatenation with empty list 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ [] ++ [1 2 3] 9 + · ──────┬────── 10 + · ╰──────── Concatenation with the empty list, [], is a no-op 11 + ───╯
+11
bin/tests/snapshots/empty_list_concat__lint_df1c6ef98c749f5c410a485b3d0d5d6851ad340d059d1012ed809a04a21a00a9.snap
··· 1 + --- 2 + source: bin/tests/empty_list_concat.rs 3 + expression: "\"[] ++ []\"" 4 + --- 5 + [W23] Warning: Unnecessary concatenation with empty list 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ [] ++ [] 9 + · ────┬─── 10 + · ╰───── Concatenation with the empty list, [], is a no-op 11 + ───╯
-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
-39
bin/tests/snapshots/main__empty_list_concat_lint.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - [W23] Warning: Unnecessary concatenation with empty list 6 - ╭─[tests/data/empty_list_concat.nix:6:4] 7 - 8 - 6 │ ([] ++ [1 2 3]) 9 - · ──────┬────── 10 - · ╰──────── Concatenation with the empty list, [], is a no-op 11 - ───╯ 12 - [W23] Warning: Unnecessary concatenation with empty list 13 - ╭─[tests/data/empty_list_concat.nix:9:4] 14 - 15 - 9 │ ([1 2 3] ++ []) 16 - · ──────┬────── 17 - · ╰──────── Concatenation with the empty list, [], is a no-op 18 - ───╯ 19 - [W23] Warning: Unnecessary concatenation with empty list 20 - ╭─[tests/data/empty_list_concat.nix:12:4] 21 - 22 - 12 │ ([] ++ []) 23 - · ────┬─── 24 - · ╰───── Concatenation with the empty list, [], is a no-op 25 - ────╯ 26 - [W23] Warning: Unnecessary concatenation with empty list 27 - ╭─[tests/data/empty_list_concat.nix:15:4] 28 - 29 - 15 │ ([] ++ [] ++ []) 30 - · ───────┬────── 31 - · ╰──────── Concatenation with the empty list, [], is a no-op 32 - ────╯ 33 - [W23] Warning: Unnecessary concatenation with empty list 34 - ╭─[tests/data/empty_list_concat.nix:15:10] 35 - 36 - 15 │ ([] ++ [] ++ []) 37 - · ────┬─── 38 - · ╰───── Concatenation with the empty list, [], is a no-op 39 - ────╯
-1
flake-parts/statix.nix
··· 24 24 ] 25 25 ) root) 26 26 (root + "/Cargo.lock") 27 - (root + "/bin/tests/data") 28 27 ]; 29 28 }; 30 29 cargoLock.lockFile = root + "/Cargo.lock";