aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/empty_pattern.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lints/empty_pattern.rs')
-rw-r--r--lib/src/lints/empty_pattern.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/src/lints/empty_pattern.rs b/lib/src/lints/empty_pattern.rs
index 6fb7558..5312548 100644
--- a/lib/src/lints/empty_pattern.rs
+++ b/lib/src/lints/empty_pattern.rs
@@ -1,4 +1,4 @@
1use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; 1use crate::{make, Metadata, Report, Rule, Suggestion};
2 2
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
@@ -7,6 +7,33 @@ use rnix::{
7 NodeOrToken, SyntaxElement, SyntaxKind, 7 NodeOrToken, SyntaxElement, SyntaxKind,
8}; 8};
9 9
10/// ## What it does
11/// Checks for an empty variadic pattern: `{...}`, in a function
12/// argument.
13///
14/// ## Why is this bad?
15/// The intention with empty patterns is not instantly obvious. Prefer
16/// an underscore identifier instead, to indicate that the argument
17/// is being ignored.
18///
19/// ## Example
20///
21/// ```
22/// client = { ... }: {
23/// imports = [ self.nixosModules.irmaseal-pkg ];
24/// services.irmaseal-pkg.enable = true;
25/// };
26/// ```
27///
28/// Replace the empty variadic pattern with `_` to indicate that you
29/// intend to ignore the argument:
30///
31/// ```
32/// client = _: {
33/// imports = [ self.nixosModules.irmaseal-pkg ];
34/// services.irmaseal-pkg.enable = true;
35/// };
36/// ```
10#[lint( 37#[lint(
11 name = "empty pattern", 38 name = "empty pattern",
12 note = "Found empty pattern in function argument", 39 note = "Found empty pattern in function argument",
@@ -28,7 +55,7 @@ impl Rule for EmptyPattern {
28 let at = node.text_range(); 55 let at = node.text_range();
29 let message = "This pattern is empty, use `_` instead"; 56 let message = "This pattern is empty, use `_` instead";
30 let replacement = make::ident("_").node().clone(); 57 let replacement = make::ident("_").node().clone();
31 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) 58 Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
32 } else { 59 } else {
33 None 60 None
34 } 61 }