diff options
author | Akshay <[email protected]> | 2021-11-20 13:27:28 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-11-20 13:27:28 +0000 |
commit | f27372061a0effe3b00d400f4e577b9d9e0ad4c0 (patch) | |
tree | edb9a9644a7ce6e8c28e937cdc5e4d62d45b4cb3 /bin/src/fix.rs | |
parent | a5c3e679b06536bb43085b1a978854a73274af10 (diff) |
add config option to fix and check
Diffstat (limited to 'bin/src/fix.rs')
-rw-r--r-- | bin/src/fix.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/bin/src/fix.rs b/bin/src/fix.rs index e4ea94d..4268567 100644 --- a/bin/src/fix.rs +++ b/bin/src/fix.rs | |||
@@ -1,19 +1,21 @@ | |||
1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
2 | 2 | ||
3 | use crate::LintMap; | ||
4 | |||
3 | use rnix::TextRange; | 5 | use rnix::TextRange; |
4 | 6 | ||
5 | mod all; | 7 | mod all; |
6 | use all::all; | 8 | use all::all_with; |
7 | 9 | ||
8 | mod single; | 10 | mod single; |
9 | use single::single; | 11 | use single::single; |
10 | 12 | ||
11 | type Source<'a> = Cow<'a, str>; | 13 | type Source<'a> = Cow<'a, str>; |
12 | 14 | ||
13 | #[derive(Debug)] | ||
14 | pub struct FixResult<'a> { | 15 | pub struct FixResult<'a> { |
15 | pub src: Source<'a>, | 16 | pub src: Source<'a>, |
16 | pub fixed: Vec<Fixed>, | 17 | pub fixed: Vec<Fixed>, |
18 | pub lints: &'a LintMap, | ||
17 | } | 19 | } |
18 | 20 | ||
19 | #[derive(Debug, Clone)] | 21 | #[derive(Debug, Clone)] |
@@ -23,10 +25,11 @@ pub struct Fixed { | |||
23 | } | 25 | } |
24 | 26 | ||
25 | impl<'a> FixResult<'a> { | 27 | impl<'a> FixResult<'a> { |
26 | fn empty(src: Source<'a>) -> Self { | 28 | fn empty(src: Source<'a>, lints: &'a LintMap) -> Self { |
27 | Self { | 29 | Self { |
28 | src, | 30 | src, |
29 | fixed: Vec::new(), | 31 | fixed: Vec::new(), |
32 | lints, | ||
30 | } | 33 | } |
31 | } | 34 | } |
32 | } | 35 | } |
@@ -43,8 +46,9 @@ pub mod main { | |||
43 | 46 | ||
44 | pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> { | 47 | pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> { |
45 | let vfs = fix_config.vfs()?; | 48 | let vfs = fix_config.vfs()?; |
49 | let lints = fix_config.lints()?; | ||
46 | for entry in vfs.iter() { | 50 | for entry in vfs.iter() { |
47 | match (fix_config.out(), super::all(entry.contents)) { | 51 | match (fix_config.out(), super::all_with(entry.contents, &lints)) { |
48 | (FixOut::Diff, fix_result) => { | 52 | (FixOut::Diff, fix_result) => { |
49 | let src = fix_result | 53 | let src = fix_result |
50 | .map(|r| r.src) | 54 | .map(|r| r.src) |