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/manual_inherit.rs | |
parent | 246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff) |
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/manual_inherit.rs')
-rw-r--r-- | lib/src/lints/manual_inherit.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 0a6933c..2d119c3 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.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,30 @@ use rnix::{ | |||
7 | NodeOrToken, SyntaxElement, SyntaxKind, | 7 | NodeOrToken, SyntaxElement, SyntaxKind, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | /// ## What it does | ||
11 | /// Checks for bindings of the form `a = a`. | ||
12 | /// | ||
13 | /// ## Why is this bad? | ||
14 | /// If the aim is to bring attributes from a larger scope into | ||
15 | /// the current scope, prefer an inherit statement. | ||
16 | /// | ||
17 | /// ## Example | ||
18 | /// | ||
19 | /// ``` | ||
20 | /// let | ||
21 | /// a = 2; | ||
22 | /// in | ||
23 | /// { a = a; b = 3; } | ||
24 | /// ``` | ||
25 | /// | ||
26 | /// Try `inherit` instead: | ||
27 | /// | ||
28 | /// ``` | ||
29 | /// let | ||
30 | /// a = 2; | ||
31 | /// in | ||
32 | /// { inherit a; b = 3; } | ||
33 | /// ``` | ||
10 | #[lint( | 34 | #[lint( |
11 | name = "manual inherit", | 35 | name = "manual inherit", |
12 | note = "Assignment instead of inherit", | 36 | note = "Assignment instead of inherit", |
@@ -35,7 +59,7 @@ impl Rule for ManualInherit { | |||
35 | let at = node.text_range(); | 59 | let at = node.text_range(); |
36 | let replacement = make::inherit_stmt(&[key]).node().clone(); | 60 | let replacement = make::inherit_stmt(&[key]).node().clone(); |
37 | let message = "This assignment is better written with `inherit`"; | 61 | let message = "This assignment is better written with `inherit`"; |
38 | Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) | 62 | Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) |
39 | } else { | 63 | } else { |
40 | None | 64 | None |
41 | } | 65 | } |