diff options
Diffstat (limited to 'lib/src/lints')
-rw-r--r-- | lib/src/lints/bool_comparison.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/collapsible_let_in.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/deprecated_is_null.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/empty_inherit.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/empty_let_in.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/empty_pattern.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/eta_reduction.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/faster_groupby.rs | 72 | ||||
-rw-r--r-- | lib/src/lints/legacy_let_syntax.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/manual_inherit.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/manual_inherit_from.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/redundant_pattern_bind.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/unquoted_splice.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/unquoted_uri.rs | 4 | ||||
-rw-r--r-- | lib/src/lints/useless_parens.rs | 4 |
15 files changed, 100 insertions, 28 deletions
diff --git a/lib/src/lints/bool_comparison.rs b/lib/src/lints/bool_comparison.rs index ed1e8bb..ef7f5d2 100644 --- a/lib/src/lints/bool_comparison.rs +++ b/lib/src/lints/bool_comparison.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -35,7 +35,7 @@ use rnix::{ | |||
35 | struct BoolComparison; | 35 | struct BoolComparison; |
36 | 36 | ||
37 | impl Rule for BoolComparison { | 37 | impl Rule for BoolComparison { |
38 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 38 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
39 | if_chain! { | 39 | if_chain! { |
40 | if let NodeOrToken::Node(node) = node; | 40 | if let NodeOrToken::Node(node) = node; |
41 | if let Some(bin_expr) = BinOp::cast(node.clone()); | 41 | if let Some(bin_expr) = BinOp::cast(node.clone()); |
diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index aa7e5a7..1c04d9c 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -45,7 +45,7 @@ use rowan::Direction; | |||
45 | struct CollapsibleLetIn; | 45 | struct CollapsibleLetIn; |
46 | 46 | ||
47 | impl Rule for CollapsibleLetIn { | 47 | impl Rule for CollapsibleLetIn { |
48 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 48 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
49 | if_chain! { | 49 | if_chain! { |
50 | if let NodeOrToken::Node(node) = node; | 50 | if let NodeOrToken::Node(node) = node; |
51 | if let Some(let_in_expr) = LetIn::cast(node.clone()); | 51 | if let Some(let_in_expr) = LetIn::cast(node.clone()); |
diff --git a/lib/src/lints/deprecated_is_null.rs b/lib/src/lints/deprecated_is_null.rs index c814e87..9e7c293 100644 --- a/lib/src/lints/deprecated_is_null.rs +++ b/lib/src/lints/deprecated_is_null.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -35,7 +35,7 @@ use rnix::{ | |||
35 | struct DeprecatedIsNull; | 35 | struct DeprecatedIsNull; |
36 | 36 | ||
37 | impl Rule for DeprecatedIsNull { | 37 | impl Rule for DeprecatedIsNull { |
38 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 38 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
39 | if_chain! { | 39 | if_chain! { |
40 | if let NodeOrToken::Node(node) = node; | 40 | if let NodeOrToken::Node(node) = node; |
41 | if let Some(apply) = Apply::cast(node.clone()); | 41 | if let Some(apply) = Apply::cast(node.clone()); |
diff --git a/lib/src/lints/empty_inherit.rs b/lib/src/lints/empty_inherit.rs index 9ae4cf2..871c218 100644 --- a/lib/src/lints/empty_inherit.rs +++ b/lib/src/lints/empty_inherit.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, utils, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, utils, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -29,7 +29,7 @@ use rnix::{ | |||
29 | struct EmptyInherit; | 29 | struct EmptyInherit; |
30 | 30 | ||
31 | impl Rule for EmptyInherit { | 31 | impl Rule for EmptyInherit { |
32 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 32 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
33 | if_chain! { | 33 | if_chain! { |
34 | if let NodeOrToken::Node(node) = node; | 34 | if let NodeOrToken::Node(node) = node; |
35 | if let Some(inherit_stmt) = Inherit::cast(node.clone()); | 35 | if let Some(inherit_stmt) = Inherit::cast(node.clone()); |
diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index d33d0ae..e42f658 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{Metadata, Report, Rule, Suggestion}; | 1 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -34,7 +34,7 @@ use rnix::{ | |||
34 | struct EmptyLetIn; | 34 | struct EmptyLetIn; |
35 | 35 | ||
36 | impl Rule for EmptyLetIn { | 36 | impl Rule for EmptyLetIn { |
37 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 37 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
38 | if_chain! { | 38 | if_chain! { |
39 | if let NodeOrToken::Node(node) = node; | 39 | if let NodeOrToken::Node(node) = node; |
40 | if let Some(let_in_expr) = LetIn::cast(node.clone()); | 40 | if let Some(let_in_expr) = LetIn::cast(node.clone()); |
diff --git a/lib/src/lints/empty_pattern.rs b/lib/src/lints/empty_pattern.rs index f66a3b1..e03708b 100644 --- a/lib/src/lints/empty_pattern.rs +++ b/lib/src/lints/empty_pattern.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -43,7 +43,7 @@ use rnix::{ | |||
43 | struct EmptyPattern; | 43 | struct EmptyPattern; |
44 | 44 | ||
45 | impl Rule for EmptyPattern { | 45 | impl Rule for EmptyPattern { |
46 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 46 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
47 | if_chain! { | 47 | if_chain! { |
48 | if let NodeOrToken::Node(node) = node; | 48 | if let NodeOrToken::Node(node) = node; |
49 | if let Some(pattern) = Pattern::cast(node.clone()); | 49 | if let Some(pattern) = Pattern::cast(node.clone()); |
diff --git a/lib/src/lints/eta_reduction.rs b/lib/src/lints/eta_reduction.rs index 580f4a0..8e9d2a3 100644 --- a/lib/src/lints/eta_reduction.rs +++ b/lib/src/lints/eta_reduction.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{Metadata, Report, Rule, Suggestion}; | 1 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -42,7 +42,7 @@ use rnix::{ | |||
42 | struct EtaReduction; | 42 | struct EtaReduction; |
43 | 43 | ||
44 | impl Rule for EtaReduction { | 44 | impl Rule for EtaReduction { |
45 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 45 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
46 | if_chain! { | 46 | if_chain! { |
47 | if let NodeOrToken::Node(node) = node; | 47 | if let NodeOrToken::Node(node) = node; |
48 | if let Some(lambda_expr) = Lambda::cast(node.clone()); | 48 | if let Some(lambda_expr) = Lambda::cast(node.clone()); |
diff --git a/lib/src/lints/faster_groupby.rs b/lib/src/lints/faster_groupby.rs new file mode 100644 index 0000000..c496125 --- /dev/null +++ b/lib/src/lints/faster_groupby.rs | |||
@@ -0,0 +1,72 @@ | |||
1 | use crate::{ | ||
2 | make, | ||
3 | session::{SessionInfo, Version}, | ||
4 | Metadata, Report, Rule, Suggestion, | ||
5 | }; | ||
6 | |||
7 | use if_chain::if_chain; | ||
8 | use macros::lint; | ||
9 | use rnix::{ | ||
10 | types::{Select, TypedNode}, | ||
11 | NodeOrToken, SyntaxElement, SyntaxKind, | ||
12 | }; | ||
13 | |||
14 | /// ## What it does | ||
15 | /// Checks for `lib.groupBy`. | ||
16 | /// | ||
17 | /// ## Why is this bad? | ||
18 | /// Nix 2.5 introduces `builtins.groupBy` which is faster and does | ||
19 | /// not require a lib import. | ||
20 | /// | ||
21 | /// ## Example | ||
22 | /// | ||
23 | /// ```nix | ||
24 | /// lib.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 6 ]; | ||
25 | /// # { big = [ 3 4 5 6 ]; small = [ 1 2 ]; } | ||
26 | /// ``` | ||
27 | /// | ||
28 | /// Replace `lib.groupBy` with `builtins.groupBy`: | ||
29 | /// | ||
30 | /// ``` | ||
31 | /// builtins.groupBy (x: if x > 2 then "big" else "small") [ 1 2 3 4 5 6 ]; | ||
32 | /// ``` | ||
33 | #[lint( | ||
34 | name = "faster_groupby", | ||
35 | note = "Found lib.groupBy", | ||
36 | code = 15, | ||
37 | match_with = SyntaxKind::NODE_SELECT | ||
38 | )] | ||
39 | struct FasterGroupBy; | ||
40 | |||
41 | impl Rule for FasterGroupBy { | ||
42 | fn validate(&self, node: &SyntaxElement, sess: &SessionInfo) -> Option<Report> { | ||
43 | let lint_version = "nix (Nix) 2.5".parse::<Version>().unwrap(); | ||
44 | if_chain! { | ||
45 | if sess.version() >= &lint_version; | ||
46 | if let NodeOrToken::Node(node) = node; | ||
47 | if let Some(select_expr) = Select::cast(node.clone()); | ||
48 | if let Some(select_from) = select_expr.set(); | ||
49 | if let Some(group_by_attr) = select_expr.index(); | ||
50 | |||
51 | // a heuristic to lint on nixpkgs.lib.groupBy | ||
52 | // and lib.groupBy and its variants | ||
53 | if select_from.text().to_string() != "builtins"; | ||
54 | if group_by_attr.text().to_string() == "groupBy"; | ||
55 | |||
56 | then { | ||
57 | let at = node.text_range(); | ||
58 | let replacement = { | ||
59 | let builtins = make::ident("builtins"); | ||
60 | make::select(builtins.node(), &group_by_attr).node().clone() | ||
61 | }; | ||
62 | let message = format!("Prefer `builtins.groupBy` over `{}.groupBy`", select_from); | ||
63 | Some( | ||
64 | self.report() | ||
65 | .suggest(at, message, Suggestion::new(at, replacement)), | ||
66 | ) | ||
67 | } else { | ||
68 | None | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/lib/src/lints/legacy_let_syntax.rs b/lib/src/lints/legacy_let_syntax.rs index 5d0028b..e0b8980 100644 --- a/lib/src/lints/legacy_let_syntax.rs +++ b/lib/src/lints/legacy_let_syntax.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -44,7 +44,7 @@ use rnix::{ | |||
44 | struct ManualInherit; | 44 | struct ManualInherit; |
45 | 45 | ||
46 | impl Rule for ManualInherit { | 46 | impl Rule for ManualInherit { |
47 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 47 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
48 | if_chain! { | 48 | if_chain! { |
49 | if let NodeOrToken::Node(node) = node; | 49 | if let NodeOrToken::Node(node) = node; |
50 | if let Some(legacy_let) = LegacyLet::cast(node.clone()); | 50 | if let Some(legacy_let) = LegacyLet::cast(node.clone()); |
diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 7717dc9..4fddce5 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -40,7 +40,7 @@ use rnix::{ | |||
40 | struct ManualInherit; | 40 | struct ManualInherit; |
41 | 41 | ||
42 | impl Rule for ManualInherit { | 42 | impl Rule for ManualInherit { |
43 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 43 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
44 | if_chain! { | 44 | if_chain! { |
45 | if let NodeOrToken::Node(node) = node; | 45 | if let NodeOrToken::Node(node) = node; |
46 | if let Some(key_value_stmt) = KeyValue::cast(node.clone()); | 46 | if let Some(key_value_stmt) = KeyValue::cast(node.clone()); |
diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs index 05d6bc8..a62a6c7 100644 --- a/lib/src/lints/manual_inherit_from.rs +++ b/lib/src/lints/manual_inherit_from.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -40,7 +40,7 @@ use rnix::{ | |||
40 | struct ManualInherit; | 40 | struct ManualInherit; |
41 | 41 | ||
42 | impl Rule for ManualInherit { | 42 | impl Rule for ManualInherit { |
43 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 43 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
44 | if_chain! { | 44 | if_chain! { |
45 | if let NodeOrToken::Node(node) = node; | 45 | if let NodeOrToken::Node(node) = node; |
46 | if let Some(key_value_stmt) = KeyValue::cast(node.clone()); | 46 | if let Some(key_value_stmt) = KeyValue::cast(node.clone()); |
diff --git a/lib/src/lints/redundant_pattern_bind.rs b/lib/src/lints/redundant_pattern_bind.rs index 88ce4b0..56957ce 100644 --- a/lib/src/lints/redundant_pattern_bind.rs +++ b/lib/src/lints/redundant_pattern_bind.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{Metadata, Report, Rule, Suggestion}; | 1 | use crate::{session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -35,7 +35,7 @@ use rnix::{ | |||
35 | struct RedundantPatternBind; | 35 | struct RedundantPatternBind; |
36 | 36 | ||
37 | impl Rule for RedundantPatternBind { | 37 | impl Rule for RedundantPatternBind { |
38 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 38 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
39 | if_chain! { | 39 | if_chain! { |
40 | if let NodeOrToken::Node(node) = node; | 40 | if let NodeOrToken::Node(node) = node; |
41 | if let Some(pattern) = Pattern::cast(node.clone()); | 41 | if let Some(pattern) = Pattern::cast(node.clone()); |
diff --git a/lib/src/lints/unquoted_splice.rs b/lib/src/lints/unquoted_splice.rs index 7649fbc..ba1641a 100644 --- a/lib/src/lints/unquoted_splice.rs +++ b/lib/src/lints/unquoted_splice.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -40,7 +40,7 @@ use rnix::{ | |||
40 | struct UnquotedSplice; | 40 | struct UnquotedSplice; |
41 | 41 | ||
42 | impl Rule for UnquotedSplice { | 42 | impl Rule for UnquotedSplice { |
43 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 43 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
44 | if_chain! { | 44 | if_chain! { |
45 | if let NodeOrToken::Node(node) = node; | 45 | if let NodeOrToken::Node(node) = node; |
46 | if Dynamic::cast(node.clone()).is_some(); | 46 | if Dynamic::cast(node.clone()).is_some(); |
diff --git a/lib/src/lints/unquoted_uri.rs b/lib/src/lints/unquoted_uri.rs index 8835338..440b278 100644 --- a/lib/src/lints/unquoted_uri.rs +++ b/lib/src/lints/unquoted_uri.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -46,7 +46,7 @@ use rnix::{types::TypedNode, NodeOrToken, SyntaxElement, SyntaxKind}; | |||
46 | struct UnquotedUri; | 46 | struct UnquotedUri; |
47 | 47 | ||
48 | impl Rule for UnquotedUri { | 48 | impl Rule for UnquotedUri { |
49 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 49 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
50 | if_chain! { | 50 | if_chain! { |
51 | if let NodeOrToken::Token(token) = node; | 51 | if let NodeOrToken::Token(token) = node; |
52 | then { | 52 | then { |
diff --git a/lib/src/lints/useless_parens.rs b/lib/src/lints/useless_parens.rs index 09d6f04..9cba4b3 100644 --- a/lib/src/lints/useless_parens.rs +++ b/lib/src/lints/useless_parens.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{Diagnostic, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{session::SessionInfo, Diagnostic, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -45,7 +45,7 @@ use rnix::{ | |||
45 | struct UselessParens; | 45 | struct UselessParens; |
46 | 46 | ||
47 | impl Rule for UselessParens { | 47 | impl Rule for UselessParens { |
48 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | 48 | fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { |
49 | if_chain! { | 49 | if_chain! { |
50 | if let NodeOrToken::Node(node) = node; | 50 | if let NodeOrToken::Node(node) = node; |
51 | if let Some(parsed_type_node) = ParsedType::cast(node.clone()); | 51 | if let Some(parsed_type_node) = ParsedType::cast(node.clone()); |