aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/tests/data/useless_has_attr.nix1
-rw-r--r--bin/tests/snapshots/main__useless_has_attr.snap7
-rw-r--r--lib/src/lints/useless_has_attr.rs3
3 files changed, 10 insertions, 1 deletions
diff --git a/bin/tests/data/useless_has_attr.nix b/bin/tests/data/useless_has_attr.nix
index f4c9fd5..10966ac 100644
--- a/bin/tests/data/useless_has_attr.nix
+++ b/bin/tests/data/useless_has_attr.nix
@@ -6,4 +6,5 @@
6 6
7 # complex body 7 # complex body
8 (if x ? a then x.a else if b then c else d) 8 (if x ? a then x.a else if b then c else d)
9 (if x ? a then x.a else b.c)
9] 10]
diff --git a/bin/tests/snapshots/main__useless_has_attr.snap b/bin/tests/snapshots/main__useless_has_attr.snap
index df72eaf..d9b5ac8 100644
--- a/bin/tests/snapshots/main__useless_has_attr.snap
+++ b/bin/tests/snapshots/main__useless_has_attr.snap
@@ -31,4 +31,11 @@ expression: "&out"
31 · ────────────────────┬──────────────────── 31 · ────────────────────┬────────────────────
32 · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression 32 · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression
33───╯ 33───╯
34[W19] Warning: This `if` expression can be simplified with `or`
35 ╭─[data/useless_has_attr.nix:9:4]
36
37 9 │ (if x ? a then x.a else b.c)
38 · ─────────────┬────────────
39 · ╰────────────── Consider using x.a or b.c instead of this if expression
40───╯
34 41
diff --git a/lib/src/lints/useless_has_attr.rs b/lib/src/lints/useless_has_attr.rs
index aae560a..2dbdb5b 100644
--- a/lib/src/lints/useless_has_attr.rs
+++ b/lib/src/lints/useless_has_attr.rs
@@ -63,7 +63,8 @@ impl Rule for UselessHasAttr {
63 | SyntaxKind::NODE_PAREN 63 | SyntaxKind::NODE_PAREN
64 | SyntaxKind::NODE_STRING 64 | SyntaxKind::NODE_STRING
65 | SyntaxKind::NODE_ATTR_SET 65 | SyntaxKind::NODE_ATTR_SET
66 | SyntaxKind::NODE_IDENT => default_expr, 66 | SyntaxKind::NODE_IDENT
67 | SyntaxKind::NODE_SELECT => default_expr,
67 _ => make::parenthesize(&default_expr).node().clone(), 68 _ => make::parenthesize(&default_expr).node().clone(),
68 }; 69 };
69 let replacement = make::or_default(&set, &attr_path, &default_with_parens).node().clone(); 70 let replacement = make::or_default(&set, &attr_path, &default_with_parens).node().clone();