aboutsummaryrefslogtreecommitdiff
path: root/bin/src/fix.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-12-29 05:23:38 +0000
committerAkshay <[email protected]>2022-01-08 10:33:10 +0000
commitd1ff222bcf94152cd657233cffd8c14a45788c26 (patch)
treefb8c94daefe0384a48b503fdd4bfaff905d78e2f /bin/src/fix.rs
parent94a2edf57340ac3f3a2276c88a221ba3125172af (diff)
allow for version based lints
Diffstat (limited to 'bin/src/fix.rs')
-rw-r--r--bin/src/fix.rs30
1 files changed, 27 insertions, 3 deletions
diff --git a/bin/src/fix.rs b/bin/src/fix.rs
index a035379..4b2ce0c 100644
--- a/bin/src/fix.rs
+++ b/bin/src/fix.rs
@@ -2,6 +2,7 @@ use std::borrow::Cow;
2 2
3use crate::LintMap; 3use crate::LintMap;
4 4
5use lib::session::SessionInfo;
5use rnix::TextRange; 6use rnix::TextRange;
6 7
7mod all; 8mod all;
@@ -16,6 +17,7 @@ pub struct FixResult<'a> {
16 pub src: Source<'a>, 17 pub src: Source<'a>,
17 pub fixed: Vec<Fixed>, 18 pub fixed: Vec<Fixed>,
18 pub lints: &'a LintMap, 19 pub lints: &'a LintMap,
20 pub sess: &'a SessionInfo,
19} 21}
20 22
21#[derive(Debug, Clone)] 23#[derive(Debug, Clone)]
@@ -25,11 +27,12 @@ pub struct Fixed {
25} 27}
26 28
27impl<'a> FixResult<'a> { 29impl<'a> FixResult<'a> {
28 fn empty(src: Source<'a>, lints: &'a LintMap) -> Self { 30 fn empty(src: Source<'a>, lints: &'a LintMap, sess: &'a SessionInfo) -> Self {
29 Self { 31 Self {
30 src, 32 src,
31 fixed: Vec::new(), 33 fixed: Vec::new(),
32 lints, 34 lints,
35 sess,
33 } 36 }
34 } 37 }
35} 38}
@@ -40,15 +43,27 @@ pub mod main {
40 use crate::{ 43 use crate::{
41 config::{Fix as FixConfig, FixOut, Single as SingleConfig}, 44 config::{Fix as FixConfig, FixOut, Single as SingleConfig},
42 err::{FixErr, StatixErr}, 45 err::{FixErr, StatixErr},
46 utils,
43 }; 47 };
44 48
49 use lib::session::{SessionInfo, Version};
45 use similar::TextDiff; 50 use similar::TextDiff;
46 51
47 pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> { 52 pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> {
48 let vfs = fix_config.vfs()?; 53 let vfs = fix_config.vfs()?;
49 let lints = fix_config.lints()?; 54 let lints = fix_config.lints()?;
55
56 let version = utils::get_version_info()
57 .unwrap()
58 .parse::<Version>()
59 .unwrap();
60 let session = SessionInfo::from_version(version);
61
50 for entry in vfs.iter() { 62 for entry in vfs.iter() {
51 match (fix_config.out(), super::all_with(entry.contents, &lints)) { 63 match (
64 fix_config.out(),
65 super::all_with(entry.contents, &lints, &session),
66 ) {
52 (FixOut::Diff, fix_result) => { 67 (FixOut::Diff, fix_result) => {
53 let src = fix_result 68 let src = fix_result
54 .map(|r| r.src) 69 .map(|r| r.src)
@@ -87,7 +102,16 @@ pub mod main {
87 let original_src = entry.contents; 102 let original_src = entry.contents;
88 let (line, col) = single_config.position; 103 let (line, col) = single_config.position;
89 104
90 match (single_config.out(), super::single(line, col, original_src)) { 105 let version = utils::get_version_info()
106 .unwrap()
107 .parse::<Version>()
108 .unwrap();
109 let session = SessionInfo::from_version(version);
110
111 match (
112 single_config.out(),
113 super::single(line, col, original_src, &session),
114 ) {
91 (FixOut::Diff, single_result) => { 115 (FixOut::Diff, single_result) => {
92 let fixed_src = single_result 116 let fixed_src = single_result
93 .map(|r| r.src) 117 .map(|r| r.src)