aboutsummaryrefslogtreecommitdiff
path: root/bin/src/fix.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-11-20 13:27:28 +0000
committerAkshay <[email protected]>2021-11-20 13:27:28 +0000
commitf27372061a0effe3b00d400f4e577b9d9e0ad4c0 (patch)
treeedb9a9644a7ce6e8c28e937cdc5e4d62d45b4cb3 /bin/src/fix.rs
parenta5c3e679b06536bb43085b1a978854a73274af10 (diff)
add config option to fix and check
Diffstat (limited to 'bin/src/fix.rs')
-rw-r--r--bin/src/fix.rs12
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 @@
1use std::borrow::Cow; 1use std::borrow::Cow;
2 2
3use crate::LintMap;
4
3use rnix::TextRange; 5use rnix::TextRange;
4 6
5mod all; 7mod all;
6use all::all; 8use all::all_with;
7 9
8mod single; 10mod single;
9use single::single; 11use single::single;
10 12
11type Source<'a> = Cow<'a, str>; 13type Source<'a> = Cow<'a, str>;
12 14
13#[derive(Debug)]
14pub struct FixResult<'a> { 15pub 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
25impl<'a> FixResult<'a> { 27impl<'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)