diff options
-rw-r--r-- | bin/src/fix/single.rs | 16 | ||||
-rw-r--r-- | bin/src/main.rs | 7 | ||||
-rw-r--r-- | lib/src/lib.rs | 1 | ||||
-rw-r--r-- | lib/src/lints/manual_inherit.rs | 9 | ||||
-rw-r--r-- | lib/src/lints/manual_inherit_from.rs | 11 |
5 files changed, 24 insertions, 20 deletions
diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index 4d492f8..15a2ef4 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs | |||
@@ -36,15 +36,13 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> { | |||
36 | .node() | 36 | .node() |
37 | .preorder_with_tokens() | 37 | .preorder_with_tokens() |
38 | .filter_map(|event| match event { | 38 | .filter_map(|event| match event { |
39 | WalkEvent::Enter(child) => { | 39 | WalkEvent::Enter(child) => LINTS.get(&child.kind()).map(|rules| { |
40 | LINTS.get(&child.kind()).map(|rules| { | 40 | rules |
41 | rules | 41 | .iter() |
42 | .iter() | 42 | .filter_map(|rule| rule.validate(&child)) |
43 | .filter_map(|rule| rule.validate(&child)) | 43 | .filter(|report| report.total_suggestion_range().is_some()) |
44 | .filter(|report| report.total_suggestion_range().is_some()) | 44 | .next() |
45 | .next() | 45 | }), |
46 | }) | ||
47 | } | ||
48 | _ => None, | 46 | _ => None, |
49 | }) | 47 | }) |
50 | .flatten() | 48 | .flatten() |
diff --git a/bin/src/main.rs b/bin/src/main.rs index 9e9c8ac..c5d0626 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs | |||
@@ -60,7 +60,12 @@ fn _main() -> Result<(), StatixErr> { | |||
60 | let src = if let Some(path) = &single_config.target { | 60 | let src = if let Some(path) = &single_config.target { |
61 | std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)? | 61 | std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)? |
62 | } else { | 62 | } else { |
63 | io::stdin().lock().lines().map(|l| l.unwrap()).collect::<Vec<String>>().join("\n") | 63 | io::stdin() |
64 | .lock() | ||
65 | .lines() | ||
66 | .map(|l| l.unwrap()) | ||
67 | .collect::<Vec<String>>() | ||
68 | .join("\n") | ||
64 | }; | 69 | }; |
65 | 70 | ||
66 | let path_id = if let Some(path) = &single_config.target { | 71 | let path_id = if let Some(path) = &single_config.target { |
diff --git a/lib/src/lib.rs b/lib/src/lib.rs index c2f24c6..753e5c1 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | #![recursion_limit = "1024"] | ||
1 | mod lints; | 2 | mod lints; |
2 | mod make; | 3 | mod make; |
3 | 4 | ||
diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 69f032b..0a6933c 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.rs | |||
@@ -3,7 +3,7 @@ use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; | |||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
5 | use rnix::{ | 5 | use rnix::{ |
6 | types::{KeyValue, Ident, TypedNode, TokenWrapper}, | 6 | types::{Ident, KeyValue, TokenWrapper, TypedNode}, |
7 | NodeOrToken, SyntaxElement, SyntaxKind, | 7 | NodeOrToken, SyntaxElement, SyntaxKind, |
8 | }; | 8 | }; |
9 | 9 | ||
@@ -20,8 +20,10 @@ 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 | // ensure that path has exactly one component | ||
26 | if key_path.next().is_none(); | ||
25 | if let Some(key) = Ident::cast(key_node); | 27 | if let Some(key) = Ident::cast(key_node); |
26 | 28 | ||
27 | if let Some(value_node) = key_value_stmt.value(); | 29 | if let Some(value_node) = key_value_stmt.value(); |
@@ -40,4 +42,3 @@ impl Rule for ManualInherit { | |||
40 | } | 42 | } |
41 | } | 43 | } |
42 | } | 44 | } |
43 | |||
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}; | |||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
5 | use rnix::{ | 5 | use 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 | |||