aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/redundant_pattern_bind.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lints/redundant_pattern_bind.rs')
-rw-r--r--lib/src/lints/redundant_pattern_bind.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/src/lints/redundant_pattern_bind.rs b/lib/src/lints/redundant_pattern_bind.rs
index aebc549..5b0711f 100644
--- a/lib/src/lints/redundant_pattern_bind.rs
+++ b/lib/src/lints/redundant_pattern_bind.rs
@@ -1,4 +1,4 @@
1use crate::{Lint, Metadata, Report, Rule, Suggestion}; 1use crate::{Metadata, Report, Rule, Suggestion};
2 2
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
@@ -7,10 +7,29 @@ use rnix::{
7 NodeOrToken, SyntaxElement, SyntaxKind, 7 NodeOrToken, SyntaxElement, SyntaxKind,
8}; 8};
9 9
10/// ## What it does
11/// Checks for binds of the form `inputs @ { ... }` in function
12/// arguments.
13///
14/// ## Why is this bad?
15/// The variadic pattern here is redundant, as it does not capture
16/// anything.
17///
18/// ## Example
19///
20/// ```
21/// inputs @ { ... }: inputs.nixpkgs
22/// ```
23///
24/// Remove the pattern altogether:
25///
26/// ```
27/// inputs: inputs.nixpkgs
28/// ```
10#[lint( 29#[lint(
11 name = "redundant pattern bind", 30 name = "redundant pattern bind",
12 note = "Found redundant pattern bind in function argument", 31 note = "Found redundant pattern bind in function argument",
13 code = 10, 32 code = 11,
14 match_with = SyntaxKind::NODE_PATTERN 33 match_with = SyntaxKind::NODE_PATTERN
15)] 34)]
16struct RedundantPatternBind; 35struct RedundantPatternBind;
@@ -32,7 +51,7 @@ impl Rule for RedundantPatternBind {
32 let at = node.text_range(); 51 let at = node.text_range();
33 let message = format!("This pattern bind is redundant, use `{}` instead", ident.as_str()); 52 let message = format!("This pattern bind is redundant, use `{}` instead", ident.as_str());
34 let replacement = ident.node().clone(); 53 let replacement = ident.node().clone();
35 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) 54 Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
36 } else { 55 } else {
37 None 56 None
38 } 57 }