diff options
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 | } |