diff --git a/bin/tests/data/faster_groupby.nix b/bin/tests/data/faster_groupby.nix deleted file mode 100644 index 30d1031..0000000 --- a/bin/tests/data/faster_groupby.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - # trivial case - _ = lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 ]; - - # offer lint heuristically on this too - _ = nixpkgs.lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 ]; - - # do not lint on `builtins` - _ = builtins.groupBy (x: x.name) [ - { name = "foo"; idx = 1; } - { name = "foo"; idx = 2; } - { name = "bar"; idx = 1; } - { name = "bar"; idx = 2; } - ]; -} diff --git a/bin/tests/data/faster_zipattrswith.nix b/bin/tests/data/faster_zipattrswith.nix deleted file mode 100644 index 2612995..0000000 --- a/bin/tests/data/faster_zipattrswith.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - # 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 27ea399..cf85740 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs @@ -80,8 +80,6 @@ test_lint! { redundant_pattern_bind, unquoted_uri, empty_inherit, - faster_groupby => session_info!("2.5"), - faster_zipattrswith => session_info!("2.6"), deprecated_to_path => session_info!("2.4"), bool_simplification, useless_has_attr, diff --git a/bin/tests/snapshots/main__faster_groupby_fix.snap b/bin/tests/snapshots/main__faster_groupby_fix.snap deleted file mode 100644 index 47d5963..0000000 --- a/bin/tests/snapshots/main__faster_groupby_fix.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "& stdout" ---- - diff --git a/bin/tests/snapshots/main__faster_groupby_lint.snap b/bin/tests/snapshots/main__faster_groupby_lint.snap deleted file mode 100644 index 99ea5da..0000000 --- a/bin/tests/snapshots/main__faster_groupby_lint.snap +++ /dev/null @@ -1,18 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "& out" ---- -[W15] Warning: Found lib.groupBy - ╭─[data/faster_groupby.nix:3:7] - │ - 3 │ _ = lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 ]; - · ─────┬───── - · ╰─────── Prefer builtins.groupBy over lib.groupBy -───╯ -[W15] Warning: Found lib.groupBy - ╭─[data/faster_groupby.nix:6:7] - │ - 6 │ _ = nixpkgs.lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 ]; - · ─────────┬───────── - · ╰─────────── Prefer builtins.groupBy over nixpkgs.lib.groupBy -───╯ diff --git a/bin/tests/snapshots/main__faster_zipattrswith_fix.snap b/bin/tests/snapshots/main__faster_zipattrswith_fix.snap deleted file mode 100644 index 47d5963..0000000 --- a/bin/tests/snapshots/main__faster_zipattrswith_fix.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "& stdout" ---- - diff --git a/bin/tests/snapshots/main__faster_zipattrswith_lint.snap b/bin/tests/snapshots/main__faster_zipattrswith_lint.snap deleted file mode 100644 index 1b22f83..0000000 --- a/bin/tests/snapshots/main__faster_zipattrswith_lint.snap +++ /dev/null @@ -1,18 +0,0 @@ ---- -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 -───╯ diff --git a/lib/src/lints.rs b/lib/src/lints.rs index 754e03e..285c48b 100644 --- a/lib/src/lints.rs +++ b/lib/src/lints.rs @@ -14,8 +14,6 @@ lints! { redundant_pattern_bind, unquoted_uri, empty_inherit, - faster_groupby, - faster_zipattrswith, deprecated_to_path, bool_simplification, useless_has_attr, diff --git a/lib/src/lints/faster_groupby.rs b/lib/src/lints/faster_groupby.rs deleted file mode 100644 index 619af3d..0000000 --- a/lib/src/lints/faster_groupby.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::{ - make, - session::{SessionInfo, Version}, - Metadata, Report, Rule, Suggestion, -}; - -use if_chain::if_chain; -use macros::lint; -use rnix::{ - types::{Select, TypedNode}, - NodeOrToken, SyntaxElement, SyntaxKind, -}; - -/// ## What it does -/// Checks for `lib.groupBy`. -/// -/// ## Why is this bad? -/// Nix 2.5 introduces `builtins.groupBy` which is faster and does -/// not require a lib import. -/// -/// ## Example -/// -/// ```nix -/// lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 6 ]; -/// # { big = [ 3 4 5 6 ]; small = [ 1 2 ]; } -/// ``` -/// -/// Replace `lib.groupBy` with `builtins.groupBy`: -/// -/// ```nix -/// builtins.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 6 ]; -/// ``` -#[lint( - name = "faster_groupby", - note = "Found lib.groupBy", - code = 15, - match_with = SyntaxKind::NODE_SELECT -)] -struct FasterGroupBy; - -impl Rule for FasterGroupBy { - fn validate(&self, node: &SyntaxElement, sess: &SessionInfo) -> Option { - let lint_version = "2.5".parse::().unwrap(); - if_chain! { - if sess.version() >= &lint_version; - if let NodeOrToken::Node(node) = node; - if let Some(select_expr) = Select::cast(node.clone()); - if let Some(select_from) = select_expr.set(); - if let Some(group_by_attr) = select_expr.index(); - - // a heuristic to lint on nixpkgs.lib.groupBy - // and lib.groupBy and its variants - if select_from.text() != "builtins"; - if group_by_attr.text() == "groupBy"; - - then { - let at = node.text_range(); - let replacement = { - let builtins = make::ident("builtins"); - make::select(builtins.node(), &group_by_attr).node().clone() - }; - let message = format!("Prefer `builtins.groupBy` over `{}.groupBy`", select_from); - Some( - self.report() - .suggest(at, message, Suggestion::new(at, replacement)), - ) - } else { - None - } - } - } -} diff --git a/lib/src/lints/faster_zipattrswith.rs b/lib/src/lints/faster_zipattrswith.rs deleted file mode 100644 index 23faf5e..0000000 --- a/lib/src/lints/faster_zipattrswith.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::{ - make, - session::{SessionInfo, Version}, - Metadata, Report, Rule, Suggestion, -}; - -use if_chain::if_chain; -use macros::lint; -use rnix::{ - types::{Select, TypedNode}, - NodeOrToken, SyntaxElement, SyntaxKind, -}; - -/// ## What it does -/// Checks for `lib.zipAttrsWith`. -/// -/// ## Why is this bad? -/// Nix 2.6 introduces `builtins.zipAttrsWith` which is faster and does -/// not require a lib import. -/// -/// ## Example -/// -/// ```nix -/// lib.zipAttrsWith (name: values: values) [ {a = "x";} {a = "y"; b = "z";} ] -/// # { a = ["x" "y"]; b = ["z"] } -/// ``` -/// -/// Replace `lib.zipAttrsWith` with `builtins.zipAttrsWith`: -/// -/// ```nix -/// builtins.zipAttrsWith (name: values: values) [ {a = "x";} {a = "y"; b = "z";} ] -/// ``` -#[lint( - name = "faster_zipattrswith", - note = "Found lib.zipAttrsWith", - code = 16, - match_with = SyntaxKind::NODE_SELECT -)] -struct FasterZipAttrsWith; - -impl Rule for FasterZipAttrsWith { - fn validate(&self, node: &SyntaxElement, sess: &SessionInfo) -> Option { - let lint_version = "2.6".parse::().unwrap(); - if_chain! { - if sess.version() >= &lint_version; - if let NodeOrToken::Node(node) = node; - if let Some(select_expr) = Select::cast(node.clone()); - if let Some(select_from) = select_expr.set(); - if let Some(zip_attrs_with) = select_expr.index(); - - // a heuristic to lint on nixpkgs.lib.zipAttrsWith - // and lib.zipAttrsWith and its variants - if select_from.text() != "builtins"; - if zip_attrs_with.text() == "zipAttrsWith"; - - then { - let at = node.text_range(); - let replacement = { - let builtins = make::ident("builtins"); - make::select(builtins.node(), &zip_attrs_with).node().clone() - }; - let message = format!("Prefer `builtins.zipAttrsWith` over `{}.zipAttrsWith`", select_from); - Some( - self.report() - .suggest(at, message, Suggestion::new(at, replacement)), - ) - } else { - None - } - } - } -} diff --git a/readme.md b/readme.md index c0ed513..8bdbbc7 100644 --- a/readme.md +++ b/readme.md @@ -137,8 +137,6 @@ empty_pattern redundant_pattern_bind unquoted_uri empty_inherit -faster_groupby -faster_zipattrswith deprecated_to_path bool_simplification useless_has_attr