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_from.rs | |
parent | 246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff) |
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/manual_inherit_from.rs')
-rw-r--r-- | lib/src/lints/manual_inherit_from.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs index 794aaf9..8d0f539 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, 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 = someAttr.a`. | ||
12 | /// | ||
13 | /// ## Why is this bad? | ||
14 | /// If the aim is to extract or bring attributes of an attrset into | ||
15 | /// scope, prefer an inherit statement. | ||
16 | /// | ||
17 | /// ## Example | ||
18 | /// | ||
19 | /// ``` | ||
20 | /// let | ||
21 | /// mtl = pkgs.haskellPackages.mtl; | ||
22 | /// in | ||
23 | /// null | ||
24 | /// ``` | ||
25 | /// | ||
26 | /// Try `inherit` instead: | ||
27 | /// | ||
28 | /// ``` | ||
29 | /// let | ||
30 | /// inherit (pkgs.haskellPackages) mtl; | ||
31 | /// in | ||
32 | /// null | ||
33 | /// ``` | ||
10 | #[lint( | 34 | #[lint( |
11 | name = "manual inherit from", | 35 | name = "manual inherit from", |
12 | note = "Assignment instead of inherit from", | 36 | note = "Assignment instead of inherit from", |
@@ -40,7 +64,7 @@ impl Rule for ManualInherit { | |||
40 | make::inherit_from_stmt(set, &[key]).node().clone() | 64 | make::inherit_from_stmt(set, &[key]).node().clone() |
41 | }; | 65 | }; |
42 | let message = "This assignment is better written with `inherit`"; | 66 | let message = "This assignment is better written with `inherit`"; |
43 | Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) | 67 | Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) |
44 | } else { | 68 | } else { |
45 | None | 69 | None |
46 | } | 70 | } |