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 useless-has-attr

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

Wes Gray 1320f58a 7f3fbafa

+117 -72
-10
bin/tests/data/useless_has_attr.nix
··· 1 - [ 2 - # trivial 3 - (if x ? a then x.a else default) 4 - (if x.a ? b then x.a.b else default) 5 - (if x ? a.b then x.a.b else default) 6 - 7 - # complex body 8 - (if x ? a then x.a else if b then c else d) 9 - (if x ? a then x.a else b.c) 10 - ]
-1
bin/tests/main.rs
··· 44 44 } 45 45 46 46 test_lint! { 47 - useless_has_attr, 48 47 repeated_keys, 49 48 empty_list_concat 50 49 }
-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 - ]
-39
bin/tests/snapshots/main__useless_has_attr_lint.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - [W19] Warning: This `if` expression can be simplified with `or` 6 - ╭─[tests/data/useless_has_attr.nix:3:4] 7 - 8 - 3 │ (if x ? a then x.a else default) 9 - · ───────────────┬────────────── 10 - · ╰──────────────── Consider using x.a or default instead of this if expression 11 - ───╯ 12 - [W19] Warning: This `if` expression can be simplified with `or` 13 - ╭─[tests/data/useless_has_attr.nix:4:4] 14 - 15 - 4 │ (if x.a ? b then x.a.b else default) 16 - · ─────────────────┬──────────────── 17 - · ╰────────────────── Consider using x.a.b or default instead of this if expression 18 - ───╯ 19 - [W19] Warning: This `if` expression can be simplified with `or` 20 - ╭─[tests/data/useless_has_attr.nix:5:4] 21 - 22 - 5 │ (if x ? a.b then x.a.b else default) 23 - · ─────────────────┬──────────────── 24 - · ╰────────────────── Consider using x.a.b or default instead of this if expression 25 - ───╯ 26 - [W19] Warning: This `if` expression can be simplified with `or` 27 - ╭─[tests/data/useless_has_attr.nix:8:4] 28 - 29 - 8 │ (if x ? a then x.a else if b then c else d) 30 - · ────────────────────┬──────────────────── 31 - · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression 32 - ───╯ 33 - [W19] Warning: This `if` expression can be simplified with `or` 34 - ╭─[tests/data/useless_has_attr.nix:9:4] 35 - 36 - 9 │ (if x ? a then x.a else b.c) 37 - · ─────────────┬──────────── 38 - · ╰────────────── Consider using x.a or b.c instead of this if expression 39 - ───╯
+9
bin/tests/snapshots/useless_has_attr__fix_3c62cf80cceead28f219a180d924a9293dbb692ce56d6c91e10e49790390913a.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a.b then x.a.b else default\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -if x ? a.b then x.a.b else default 9 + +x.a.b or default
+9
bin/tests/snapshots/useless_has_attr__fix_514032635e11fe0f21c05881885de04587ba8db14854db99efccb6bb57f7bf8c.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else default\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -if x ? a then x.a else default 9 + +x.a or default
+9
bin/tests/snapshots/useless_has_attr__fix_9361572e1b83dd76c88aa8af9b983c7f255936c0326d983f21be6622852e970d.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else if b then c else d\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -if x ? a then x.a else if b then c else d 9 + +x.a or (if b then c else d)
+9
bin/tests/snapshots/useless_has_attr__fix_dcdeee74e5d10b5199175881fce69d02c82ff9084bcc346492482aa279e29160.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x.a ? b then x.a.b else default\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -if x.a ? b then x.a.b else default 9 + +x.a.b or default
+9
bin/tests/snapshots/useless_has_attr__fix_f5edc729a910faa40ea89cb086561a4390af9bdbc4fa3ffdee8e1ce406fba484.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else b.c\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -if x ? a then x.a else b.c 9 + +x.a or b.c
+11
bin/tests/snapshots/useless_has_attr__lint_3c62cf80cceead28f219a180d924a9293dbb692ce56d6c91e10e49790390913a.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a.b then x.a.b else default\"" 4 + --- 5 + [W19] Warning: This `if` expression can be simplified with `or` 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ if x ? a.b then x.a.b else default 9 + · ─────────────────┬──────────────── 10 + · ╰────────────────── Consider using x.a.b or default instead of this if expression 11 + ───╯
+11
bin/tests/snapshots/useless_has_attr__lint_514032635e11fe0f21c05881885de04587ba8db14854db99efccb6bb57f7bf8c.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else default\"" 4 + --- 5 + [W19] Warning: This `if` expression can be simplified with `or` 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ if x ? a then x.a else default 9 + · ───────────────┬────────────── 10 + · ╰──────────────── Consider using x.a or default instead of this if expression 11 + ───╯
+11
bin/tests/snapshots/useless_has_attr__lint_9361572e1b83dd76c88aa8af9b983c7f255936c0326d983f21be6622852e970d.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else if b then c else d\"" 4 + --- 5 + [W19] Warning: This `if` expression can be simplified with `or` 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ if x ? a then x.a else if b then c else d 9 + · ────────────────────┬──────────────────── 10 + · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression 11 + ───╯
+11
bin/tests/snapshots/useless_has_attr__lint_dcdeee74e5d10b5199175881fce69d02c82ff9084bcc346492482aa279e29160.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x.a ? b then x.a.b else default\"" 4 + --- 5 + [W19] Warning: This `if` expression can be simplified with `or` 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ if x.a ? b then x.a.b else default 9 + · ─────────────────┬──────────────── 10 + · ╰────────────────── Consider using x.a.b or default instead of this if expression 11 + ───╯
+11
bin/tests/snapshots/useless_has_attr__lint_f5edc729a910faa40ea89cb086561a4390af9bdbc4fa3ffdee8e1ce406fba484.snap
··· 1 + --- 2 + source: bin/tests/useless_has_attr.rs 3 + expression: "\"if x ? a then x.a else b.c\"" 4 + --- 5 + [W19] Warning: This `if` expression can be simplified with `or` 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ if x ? a then x.a else b.c 9 + · ─────────────┬──────────── 10 + · ╰────────────── Consider using x.a or b.c instead of this if expression 11 + ───╯
+17
bin/tests/useless_has_attr.rs
··· 1 + mod _utils; 2 + 3 + use macros::generate_tests; 4 + 5 + generate_tests! { 6 + rule: useless_has_attr, 7 + expressions: [ 8 + // trivial 9 + "if x ? a then x.a else default", 10 + "if x.a ? b then x.a.b else default", 11 + "if x ? a.b then x.a.b else default", 12 + 13 + // complex body 14 + "if x ? a then x.a else if b then c else d", 15 + "if x ? a then x.a else b.c", 16 + ], 17 + }