diff options
author | Akshay <[email protected]> | 2021-10-31 09:05:26 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-31 16:05:15 +0000 |
commit | e8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch) | |
tree | 0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lints/empty_pattern.rs | |
parent | 246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff) |
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/empty_pattern.rs')
-rw-r--r-- | lib/src/lints/empty_pattern.rs | 31 |
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 @@ | |||
1 | use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, 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; |
@@ -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 | } |