···11-[
22- # trivial
33- (if x ? a then x.a else default)
44- (if x.a ? b then x.a.b else default)
55- (if x ? a.b then x.a.b else default)
66-77- # complex body
88- (if x ? a then x.a else if b then c else d)
99- (if x ? a then x.a else b.c)
1010-]
···11----
22-source: bin/tests/main.rs
33-expression: "&stdout"
44----
55---- tests/data/useless_has_attr.nix
66-+++ tests/data/useless_has_attr.nix [fixed]
77-@@ -1,10 +1,10 @@
88- [
99- # trivial
1010-- (if x ? a then x.a else default)
1111-- (if x.a ? b then x.a.b else default)
1212-- (if x ? a.b then x.a.b else default)
1313-+ (x.a or default)
1414-+ (x.a.b or default)
1515-+ (x.a.b or default)
1616-1717- # complex body
1818-- (if x ? a then x.a else if b then c else d)
1919-- (if x ? a then x.a else b.c)
2020-+ (x.a or (if b then c else d))
2121-+ (x.a or b.c)
2222- ]
···11----
22-source: bin/tests/main.rs
33-expression: "&stdout"
44----
55-[W19] Warning: This `if` expression can be simplified with `or`
66- ╭─[tests/data/useless_has_attr.nix:3:4]
77- │
88- 3 │ (if x ? a then x.a else default)
99- · ───────────────┬──────────────
1010- · ╰──────────────── Consider using x.a or default instead of this if expression
1111-───╯
1212-[W19] Warning: This `if` expression can be simplified with `or`
1313- ╭─[tests/data/useless_has_attr.nix:4:4]
1414- │
1515- 4 │ (if x.a ? b then x.a.b else default)
1616- · ─────────────────┬────────────────
1717- · ╰────────────────── Consider using x.a.b or default instead of this if expression
1818-───╯
1919-[W19] Warning: This `if` expression can be simplified with `or`
2020- ╭─[tests/data/useless_has_attr.nix:5:4]
2121- │
2222- 5 │ (if x ? a.b then x.a.b else default)
2323- · ─────────────────┬────────────────
2424- · ╰────────────────── Consider using x.a.b or default instead of this if expression
2525-───╯
2626-[W19] Warning: This `if` expression can be simplified with `or`
2727- ╭─[tests/data/useless_has_attr.nix:8:4]
2828- │
2929- 8 │ (if x ? a then x.a else if b then c else d)
3030- · ────────────────────┬────────────────────
3131- · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression
3232-───╯
3333-[W19] Warning: This `if` expression can be simplified with `or`
3434- ╭─[tests/data/useless_has_attr.nix:9:4]
3535- │
3636- 9 │ (if x ? a then x.a else b.c)
3737- · ─────────────┬────────────
3838- · ╰────────────── Consider using x.a or b.c instead of this if expression
3939-───╯
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else default\""
44+---
55+--- <temp_file_path>
66++++ <temp_file_path> [fixed]
77+@@ -1 +1 @@
88+-if x ? a then x.a else default
99++x.a or default
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else if b then c else d\""
44+---
55+--- <temp_file_path>
66++++ <temp_file_path> [fixed]
77+@@ -1 +1 @@
88+-if x ? a then x.a else if b then c else d
99++x.a or (if b then c else d)
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else b.c\""
44+---
55+--- <temp_file_path>
66++++ <temp_file_path> [fixed]
77+@@ -1 +1 @@
88+-if x ? a then x.a else b.c
99++x.a or b.c
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a.b then x.a.b else default\""
44+---
55+[W19] Warning: This `if` expression can be simplified with `or`
66+ ╭─[<temp_file_path>:1:1]
77+ │
88+ 1 │ if x ? a.b then x.a.b else default
99+ · ─────────────────┬────────────────
1010+ · ╰────────────────── Consider using x.a.b or default instead of this if expression
1111+───╯
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else default\""
44+---
55+[W19] Warning: This `if` expression can be simplified with `or`
66+ ╭─[<temp_file_path>:1:1]
77+ │
88+ 1 │ if x ? a then x.a else default
99+ · ───────────────┬──────────────
1010+ · ╰──────────────── Consider using x.a or default instead of this if expression
1111+───╯
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else if b then c else d\""
44+---
55+[W19] Warning: This `if` expression can be simplified with `or`
66+ ╭─[<temp_file_path>:1:1]
77+ │
88+ 1 │ if x ? a then x.a else if b then c else d
99+ · ────────────────────┬────────────────────
1010+ · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression
1111+───╯
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x.a ? b then x.a.b else default\""
44+---
55+[W19] Warning: This `if` expression can be simplified with `or`
66+ ╭─[<temp_file_path>:1:1]
77+ │
88+ 1 │ if x.a ? b then x.a.b else default
99+ · ─────────────────┬────────────────
1010+ · ╰────────────────── Consider using x.a.b or default instead of this if expression
1111+───╯
···11+---
22+source: bin/tests/useless_has_attr.rs
33+expression: "\"if x ? a then x.a else b.c\""
44+---
55+[W19] Warning: This `if` expression can be simplified with `or`
66+ ╭─[<temp_file_path>:1:1]
77+ │
88+ 1 │ if x ? a then x.a else b.c
99+ · ─────────────┬────────────
1010+ · ╰────────────── Consider using x.a or b.c instead of this if expression
1111+───╯
+17
bin/tests/useless_has_attr.rs
···11+mod _utils;
22+33+use macros::generate_tests;
44+55+generate_tests! {
66+ rule: useless_has_attr,
77+ expressions: [
88+ // trivial
99+ "if x ? a then x.a else default",
1010+ "if x.a ? b then x.a.b else default",
1111+ "if x ? a.b then x.a.b else default",
1212+1313+ // complex body
1414+ "if x ? a then x.a else if b then c else d",
1515+ "if x ? a then x.a else b.c",
1616+ ],
1717+}