diff options
author | Akshay <[email protected]> | 2021-12-29 05:23:38 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2022-01-08 10:33:10 +0000 |
commit | d1ff222bcf94152cd657233cffd8c14a45788c26 (patch) | |
tree | fb8c94daefe0384a48b503fdd4bfaff905d78e2f /bin/src/fix/all.rs | |
parent | 94a2edf57340ac3f3a2276c88a221ba3125172af (diff) |
allow for version based lints
Diffstat (limited to 'bin/src/fix/all.rs')
-rw-r--r-- | bin/src/fix/all.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/bin/src/fix/all.rs b/bin/src/fix/all.rs index 7e51d16..d7f7fff 100644 --- a/bin/src/fix/all.rs +++ b/bin/src/fix/all.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
2 | 2 | ||
3 | use lib::Report; | 3 | use lib::{session::SessionInfo, Report}; |
4 | use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; | 4 | use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
@@ -8,7 +8,11 @@ use crate::{ | |||
8 | LintMap, | 8 | LintMap, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | fn collect_fixes(source: &str, lints: &LintMap) -> Result<Vec<Report>, RnixParseErr> { | 11 | fn collect_fixes( |
12 | source: &str, | ||
13 | lints: &LintMap, | ||
14 | sess: &SessionInfo, | ||
15 | ) -> Result<Vec<Report>, RnixParseErr> { | ||
12 | let parsed = rnix::parse(source).as_result()?; | 16 | let parsed = rnix::parse(source).as_result()?; |
13 | 17 | ||
14 | Ok(parsed | 18 | Ok(parsed |
@@ -18,7 +22,7 @@ fn collect_fixes(source: &str, lints: &LintMap) -> Result<Vec<Report>, RnixParse | |||
18 | WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { | 22 | WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { |
19 | rules | 23 | rules |
20 | .iter() | 24 | .iter() |
21 | .filter_map(|rule| rule.validate(&child)) | 25 | .filter_map(|rule| rule.validate(&child, sess)) |
22 | .filter(|report| report.total_suggestion_range().is_some()) | 26 | .filter(|report| report.total_suggestion_range().is_some()) |
23 | .collect::<Vec<_>>() | 27 | .collect::<Vec<_>>() |
24 | }), | 28 | }), |
@@ -57,7 +61,7 @@ fn reorder(mut reports: Vec<Report>) -> Vec<Report> { | |||
57 | impl<'a> Iterator for FixResult<'a> { | 61 | impl<'a> Iterator for FixResult<'a> { |
58 | type Item = FixResult<'a>; | 62 | type Item = FixResult<'a>; |
59 | fn next(&mut self) -> Option<Self::Item> { | 63 | fn next(&mut self) -> Option<Self::Item> { |
60 | let all_reports = collect_fixes(&self.src, self.lints).ok()?; | 64 | let all_reports = collect_fixes(&self.src, self.lints, &self.sess).ok()?; |
61 | if all_reports.is_empty() { | 65 | if all_reports.is_empty() { |
62 | return None; | 66 | return None; |
63 | } | 67 | } |
@@ -78,13 +82,18 @@ impl<'a> Iterator for FixResult<'a> { | |||
78 | src: self.src.clone(), | 82 | src: self.src.clone(), |
79 | fixed, | 83 | fixed, |
80 | lints: self.lints, | 84 | lints: self.lints, |
85 | sess: self.sess, | ||
81 | }) | 86 | }) |
82 | } | 87 | } |
83 | } | 88 | } |
84 | 89 | ||
85 | pub fn all_with<'a>(src: &'a str, lints: &'a LintMap) -> Option<FixResult<'a>> { | 90 | pub fn all_with<'a>( |
91 | src: &'a str, | ||
92 | lints: &'a LintMap, | ||
93 | sess: &'a SessionInfo, | ||
94 | ) -> Option<FixResult<'a>> { | ||
86 | let src = Cow::from(src); | 95 | let src = Cow::from(src); |
87 | let _ = rnix::parse(&src).as_result().ok()?; | 96 | let _ = rnix::parse(&src).as_result().ok()?; |
88 | let initial = FixResult::empty(src, lints); | 97 | let initial = FixResult::empty(src, lints, sess); |
89 | initial.into_iter().last() | 98 | initial.into_iter().last() |
90 | } | 99 | } |