aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/manual_inherit_from.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-28 03:20:36 +0100
committerAkshay <[email protected]>2021-10-28 03:20:36 +0100
commit3c9a675b9d776bf2210803d582e9af88f9df2631 (patch)
tree6b3b88fe4040cc904922b4b084442dbcf20495ae /lib/src/lints/manual_inherit_from.rs
parent8eccf15964e09c2e024710512e671c6b1b88e885 (diff)
fix fp with manual_inherit and manual_inherit_from
the lint also needed to validate if the length of the path component was exactly one, and not just check if the first component matches the value.
Diffstat (limited to 'lib/src/lints/manual_inherit_from.rs')
-rw-r--r--lib/src/lints/manual_inherit_from.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs
index 2bff5f8..355ed8a 100644
--- a/lib/src/lints/manual_inherit_from.rs
+++ b/lib/src/lints/manual_inherit_from.rs
@@ -3,7 +3,7 @@ use crate::{make, Lint, Metadata, Report, Rule, Suggestion};
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
5use rnix::{ 5use rnix::{
6 types::{KeyValue, Ident, Select, TypedNode, TokenWrapper}, 6 types::{Ident, KeyValue, Select, TokenWrapper, TypedNode},
7 NodeOrToken, SyntaxElement, SyntaxKind, 7 NodeOrToken, SyntaxElement, SyntaxKind,
8}; 8};
9 9
@@ -20,8 +20,9 @@ impl Rule for ManualInherit {
20 if_chain! { 20 if_chain! {
21 if let NodeOrToken::Node(node) = node; 21 if let NodeOrToken::Node(node) = node;
22 if let Some(key_value_stmt) = KeyValue::cast(node.clone()); 22 if let Some(key_value_stmt) = KeyValue::cast(node.clone());
23 if let Some(key_path) = key_value_stmt.key(); 23 if let mut key_path = key_value_stmt.key()?.path();
24 if let Some(key_node) = key_path.path().next(); 24 if let Some(key_node) = key_path.next();
25 if key_path.next().is_none();
25 if let Some(key) = Ident::cast(key_node); 26 if let Some(key) = Ident::cast(key_node);
26 27
27 if let Some(value_node) = key_value_stmt.value(); 28 if let Some(value_node) = key_value_stmt.value();
@@ -35,7 +36,7 @@ impl Rule for ManualInherit {
35 let at = node.text_range(); 36 let at = node.text_range();
36 let replacement = { 37 let replacement = {
37 let set = value.set()?; 38 let set = value.set()?;
38 make::inherit_from_stmt(set, &[key]).node().clone() 39 make::inherit_from_stmt(set, &[key]).node().clone()
39 }; 40 };
40 let message = "This assignment is better written with `inherit`"; 41 let message = "This assignment is better written with `inherit`";
41 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) 42 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement)))
@@ -45,5 +46,3 @@ impl Rule for ManualInherit {
45 } 46 }
46 } 47 }
47} 48}
48
49