aboutsummaryrefslogtreecommitdiff
path: root/bin/tests
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-02-20 05:25:20 +0000
committerAkshay <[email protected]>2022-02-20 05:31:36 +0000
commitc7874ec26d6499a1196ce23432beb33764490dec (patch)
tree226b8dce61e5f7580be9de7ebde72212bb94f682 /bin/tests
parente8130a90dca048d195603281f72e1af0b4f7ccc6 (diff)
new lint: useless_has_attr
Diffstat (limited to 'bin/tests')
-rw-r--r--bin/tests/data/useless_has_attr.nix9
-rw-r--r--bin/tests/main.rs3
-rw-r--r--bin/tests/snapshots/main__useless_has_attr.snap34
3 files changed, 45 insertions, 1 deletions
diff --git a/bin/tests/data/useless_has_attr.nix b/bin/tests/data/useless_has_attr.nix
new file mode 100644
index 0000000..f4c9fd5
--- /dev/null
+++ b/bin/tests/data/useless_has_attr.nix
@@ -0,0 +1,9 @@
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]
diff --git a/bin/tests/main.rs b/bin/tests/main.rs
index 3403f65..3425cfa 100644
--- a/bin/tests/main.rs
+++ b/bin/tests/main.rs
@@ -64,5 +64,6 @@ test_lint! {
64 faster_groupby => session_info!("2.5"), 64 faster_groupby => session_info!("2.5"),
65 faster_zipattrswith => session_info!("2.6"), 65 faster_zipattrswith => session_info!("2.6"),
66 deprecated_to_path => session_info!("2.4"), 66 deprecated_to_path => session_info!("2.4"),
67 bool_simplification 67 bool_simplification,
68 useless_has_attr
68} 69}
diff --git a/bin/tests/snapshots/main__useless_has_attr.snap b/bin/tests/snapshots/main__useless_has_attr.snap
new file mode 100644
index 0000000..df72eaf
--- /dev/null
+++ b/bin/tests/snapshots/main__useless_has_attr.snap
@@ -0,0 +1,34 @@
1---
2source: bin/tests/main.rs
3expression: "&out"
4
5---
6[W19] Warning: This `if` expression can be simplified with `or`
7 ╭─[data/useless_has_attr.nix:3:4]
8
9 3 │ (if x ? a then x.a else default)
10 · ───────────────┬──────────────
11 · ╰──────────────── Consider using x.a or default instead of this if expression
12───╯
13[W19] Warning: This `if` expression can be simplified with `or`
14 ╭─[data/useless_has_attr.nix:4:4]
15
16 4 │ (if x.a ? b then x.a.b else default)
17 · ─────────────────┬────────────────
18 · ╰────────────────── Consider using x.a.b or default instead of this if expression
19───╯
20[W19] Warning: This `if` expression can be simplified with `or`
21 ╭─[data/useless_has_attr.nix:5:4]
22
23 5 │ (if x ? a.b then x.a.b else default)
24 · ─────────────────┬────────────────
25 · ╰────────────────── Consider using x.a.b or default instead of this if expression
26───╯
27[W19] Warning: This `if` expression can be simplified with `or`
28 ╭─[data/useless_has_attr.nix:8:4]
29
30 8 │ (if x ? a then x.a else if b then c else d)
31 · ────────────────────┬────────────────────
32 · ╰────────────────────── Consider using x.a or (if b then c else d) instead of this if expression
33───╯
34