Lints and suggestions for the Nix programming language

chore: 1-expr tests repeated-keys

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

Wes Gray 89c67ab9 1320f58a

+106 -65
-29
bin/tests/data/repeated_keys.nix
··· 1 - [ 2 - # fine 3 - { 4 - foo.bar = 1; 5 - } 6 - 7 - # do not raise on rec 8 - rec { 9 - foo.x = foo.y; 10 - foo.y = 2; 11 - foo.z = 3; 12 - } 13 - 14 - # exactly 3 occurrences 15 - { 16 - foo.bar = 1; 17 - foo.bar."hello" = 1; 18 - foo.again = 1; 19 - } 20 - 21 - # more than 3, omit the extra 22 - { 23 - foo.baz.bar1 = 1; 24 - foo.baz.bar2 = 2; 25 - foo.baz.bar3 = 3; 26 - foo.baz.bar4 = 4; 27 - foo.baz.bar5 = 5; 28 - } 29 - ]
-1
bin/tests/main.rs
··· 44 44 } 45 45 46 46 test_lint! { 47 - repeated_keys, 48 47 empty_list_concat 49 48 }
+42
bin/tests/repeated_keys.rs
··· 1 + mod _utils; 2 + 3 + use indoc::indoc; 4 + 5 + use macros::generate_tests; 6 + 7 + generate_tests! { 8 + rule: useless_has_attr, 9 + expressions: [ 10 + // fine 11 + "{ foo.bar = 1; }", 12 + 13 + // do not raise on rec 14 + indoc! {" 15 + rec { 16 + foo.x = foo.y; 17 + foo.y = 2; 18 + foo.z = 3; 19 + } 20 + "}, 21 + 22 + // exactly 3 occurrences 23 + indoc! {r#" 24 + { 25 + foo.bar = 1; 26 + foo.bar."hello" = 1; 27 + foo.again = 1; 28 + } 29 + "#}, 30 + 31 + // more than 3, omit the extra 32 + indoc! {" 33 + { 34 + foo.baz.bar1 = 1; 35 + foo.baz.bar2 = 2; 36 + foo.baz.bar3 = 3; 37 + foo.baz.bar4 = 4; 38 + foo.baz.bar5 = 5; 39 + } 40 + "}, 41 + ], 42 + }
-5
bin/tests/snapshots/main__repeated_keys_fix.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 -
-30
bin/tests/snapshots/main__repeated_keys_lint.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - [W20] Warning: Avoid repeated keys in attribute sets 6 - ╭─[tests/data/repeated_keys.nix:16:5] 7 - 8 - 16 │ foo.bar = 1; 9 - · ───┬─── 10 - · ╰───── The key foo is first assigned here ... 11 - 17 │ foo.bar."hello" = 1; 12 - · ───────┬─────── 13 - · ╰───────── ... repeated here ... 14 - 18 │ foo.again = 1; 15 - · ────┬──── 16 - · ╰────── ... and here. Try foo = { bar=...; bar."hello"=...; again=...; } instead. 17 - ────╯ 18 - [W20] Warning: Avoid repeated keys in attribute sets 19 - ╭─[tests/data/repeated_keys.nix:23:5] 20 - 21 - 23 │ foo.baz.bar1 = 1; 22 - · ──────┬───── 23 - · ╰─────── The key foo is first assigned here ... 24 - 24 │ foo.baz.bar2 = 2; 25 - · ──────┬───── 26 - · ╰─────── ... repeated here ... 27 - 25 │ foo.baz.bar3 = 3; 28 - · ──────┬───── 29 - · ╰─────── ... and here (2 occurrences omitted). Try foo = { baz.bar1=...; baz.bar2=...; baz.bar3=...; } instead. 30 - ────╯
+5
bin/tests/snapshots/repeated_keys__fix_107c49dd2c0b84878c81852acfd4aee37038d8367b6bc7f5b43ce051c24908e5.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{\\n foo.bar = 1;\\n foo.bar.\\\"hello\\\" = 1;\\n foo.again = 1;\\n}\\n\"" 4 + --- 5 +
+5
bin/tests/snapshots/repeated_keys__fix_2987d09ebf239c581be44d6a044ceb0290e769e15f802483ec2f796af57c4e0a.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{ foo.bar = 1; }\"" 4 + --- 5 +
+5
bin/tests/snapshots/repeated_keys__fix_653aae0c9fb8b448e30e62c7daa38519eded4ba2078838f788b3e769db564123.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{\\n foo.baz.bar1 = 1;\\n foo.baz.bar2 = 2;\\n foo.baz.bar3 = 3;\\n foo.baz.bar4 = 4;\\n foo.baz.bar5 = 5;\\n}\\n\"" 4 + --- 5 +
+5
bin/tests/snapshots/repeated_keys__fix_7928b443d258628d0f648fe2e30278f84cbe97274683df67fd436584732d7b2c.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"rec {\\n foo.x = foo.y;\\n foo.y = 2;\\n foo.z = 3;\\n}\\n\"" 4 + --- 5 +
+17
bin/tests/snapshots/repeated_keys__lint_107c49dd2c0b84878c81852acfd4aee37038d8367b6bc7f5b43ce051c24908e5.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{\\n foo.bar = 1;\\n foo.bar.\\\"hello\\\" = 1;\\n foo.again = 1;\\n}\\n\"" 4 + --- 5 + [W20] Warning: Avoid repeated keys in attribute sets 6 + ╭─[<temp_file_path>:2:3] 7 + 8 + 2 │ foo.bar = 1; 9 + · ───┬─── 10 + · ╰───── The key foo is first assigned here ... 11 + 3 │ foo.bar."hello" = 1; 12 + · ───────┬─────── 13 + · ╰───────── ... repeated here ... 14 + 4 │ foo.again = 1; 15 + · ────┬──── 16 + · ╰────── ... and here. Try foo = { bar=...; bar."hello"=...; again=...; } instead. 17 + ───╯
+5
bin/tests/snapshots/repeated_keys__lint_2987d09ebf239c581be44d6a044ceb0290e769e15f802483ec2f796af57c4e0a.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{ foo.bar = 1; }\"" 4 + --- 5 +
+17
bin/tests/snapshots/repeated_keys__lint_653aae0c9fb8b448e30e62c7daa38519eded4ba2078838f788b3e769db564123.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"{\\n foo.baz.bar1 = 1;\\n foo.baz.bar2 = 2;\\n foo.baz.bar3 = 3;\\n foo.baz.bar4 = 4;\\n foo.baz.bar5 = 5;\\n}\\n\"" 4 + --- 5 + [W20] Warning: Avoid repeated keys in attribute sets 6 + ╭─[<temp_file_path>:2:3] 7 + 8 + 2 │ foo.baz.bar1 = 1; 9 + · ──────┬───── 10 + · ╰─────── The key foo is first assigned here ... 11 + 3 │ foo.baz.bar2 = 2; 12 + · ──────┬───── 13 + · ╰─────── ... repeated here ... 14 + 4 │ foo.baz.bar3 = 3; 15 + · ──────┬───── 16 + · ╰─────── ... and here (2 occurrences omitted). Try foo = { baz.bar1=...; baz.bar2=...; baz.bar3=...; } instead. 17 + ───╯
+5
bin/tests/snapshots/repeated_keys__lint_7928b443d258628d0f648fe2e30278f84cbe97274683df67fd436584732d7b2c.snap
··· 1 + --- 2 + source: bin/tests/repeated_keys.rs 3 + expression: "\"rec {\\n foo.x = foo.y;\\n foo.y = 2;\\n foo.z = 3;\\n}\\n\"" 4 + --- 5 +