aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/manual_inherit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lints/manual_inherit.rs')
-rw-r--r--lib/src/lints/manual_inherit.rs28
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 @@
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,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 }