From e8130a90dca048d195603281f72e1af0b4f7ccc6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 20 Feb 2022 09:37:32 +0530 Subject: new lint: bool_simplification TODO: add more patterns to this --- bin/tests/data/bool_simplification.nix | 7 +++++++ bin/tests/main.rs | 3 ++- bin/tests/snapshots/main__bool_simplification.snap | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 bin/tests/data/bool_simplification.nix create mode 100644 bin/tests/snapshots/main__bool_simplification.snap (limited to 'bin') diff --git a/bin/tests/data/bool_simplification.nix b/bin/tests/data/bool_simplification.nix new file mode 100644 index 0000000..64c2c7a --- /dev/null +++ b/bin/tests/data/bool_simplification.nix @@ -0,0 +1,7 @@ +let + _ = !(a == b); + # do not match here + _ = !(a != b); + _ = a != b; +in + null diff --git a/bin/tests/main.rs b/bin/tests/main.rs index bec64d2..3403f65 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs @@ -63,5 +63,6 @@ test_lint! { empty_inherit, faster_groupby => session_info!("2.5"), faster_zipattrswith => session_info!("2.6"), - deprecated_to_path => session_info!("2.4") + deprecated_to_path => session_info!("2.4"), + bool_simplification } diff --git a/bin/tests/snapshots/main__bool_simplification.snap b/bin/tests/snapshots/main__bool_simplification.snap new file mode 100644 index 0000000..9e3c991 --- /dev/null +++ b/bin/tests/snapshots/main__bool_simplification.snap @@ -0,0 +1,13 @@ +--- +source: bin/tests/main.rs +expression: "&out" + +--- +[W18] Warning: This boolean expression can be simplified + ╭─[data/bool_simplification.nix:2:7] + │ + 2 │ _ = !(a == b); + · ────┬──── + · ╰────── Try != instead of !(... == ...) +───╯ + -- cgit v1.2.3