From a254edfcd27f1bba5eb7eacb11bfcd077bd1af16 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 30 Jan 2022 12:10:21 +0530 Subject: new lint: faster_zipattrswith --- bin/tests/data/faster_zipattrswith.nix | 13 +++++++++++++ bin/tests/main.rs | 5 +++-- bin/tests/snapshots/main__faster_zipattrswith.snap | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 bin/tests/data/faster_zipattrswith.nix create mode 100644 bin/tests/snapshots/main__faster_zipattrswith.snap (limited to 'bin') diff --git a/bin/tests/data/faster_zipattrswith.nix b/bin/tests/data/faster_zipattrswith.nix new file mode 100644 index 0000000..2612995 --- /dev/null +++ b/bin/tests/data/faster_zipattrswith.nix @@ -0,0 +1,13 @@ +{ + # trivial case + _ = lib.zipAttrsWith (name: values: values) [{ a = 1; } { a = 2; b = 3; }]; + + # offer lint heuristically on this too + _ = nixpkgs.lib.zipAttrsWith (name: values: values) [{ a = 1; } { a = 2; b = 3; }]; + + # do not lint on `builtins` + _ = builtins.zipAttrsWith (name: values: values) [ + { a = 1; } + { a = 2; b = 3; } + ]; +} diff --git a/bin/tests/main.rs b/bin/tests/main.rs index 89d58e7..2c4b521 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs @@ -19,7 +19,7 @@ mod util { test_lint!($($tail)*); }; ($tname:ident) => { - test_lint!($tname => session_info!("2.5")); + test_lint!($tname => session_info!("2.6")); }; ($tname:ident => $sess:expr) => { #[test] @@ -61,5 +61,6 @@ test_lint! { unquoted_uri, deprecated_is_null, empty_inherit, - faster_groupby => session_info!("2.5") + faster_groupby => session_info!("2.5"), + faster_zipattrswith => session_info!("2.6") } diff --git a/bin/tests/snapshots/main__faster_zipattrswith.snap b/bin/tests/snapshots/main__faster_zipattrswith.snap new file mode 100644 index 0000000..6b21322 --- /dev/null +++ b/bin/tests/snapshots/main__faster_zipattrswith.snap @@ -0,0 +1,20 @@ +--- +source: bin/tests/main.rs +expression: "&out" + +--- +[W16] Warning: Found lib.zipAttrsWith + ╭─[data/faster_zipattrswith.nix:3:7] + │ + 3 │ _ = lib.zipAttrsWith (name: values: values) [{ a = 1; } { a = 2; b = 3; }]; + · ────────┬─────── + · ╰───────── Prefer builtins.zipAttrsWith over lib.zipAttrsWith +───╯ +[W16] Warning: Found lib.zipAttrsWith + ╭─[data/faster_zipattrswith.nix:6:7] + │ + 6 │ _ = nixpkgs.lib.zipAttrsWith (name: values: values) [{ a = 1; } { a = 2; b = 3; }]; + · ────────────┬─────────── + · ╰───────────── Prefer builtins.zipAttrsWith over nixpkgs.lib.zipAttrsWith +───╯ + -- cgit v1.2.3