diff options
Diffstat (limited to 'bin/src/fix')
-rw-r--r-- | bin/src/fix/all.rs | 4 | ||||
-rw-r--r-- | bin/src/fix/single.rs | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/bin/src/fix/all.rs b/bin/src/fix/all.rs index 8c0770d..7f04f2c 100644 --- a/bin/src/fix/all.rs +++ b/bin/src/fix/all.rs | |||
@@ -3,7 +3,7 @@ use std::borrow::Cow; | |||
3 | use lib::{Report, LINTS}; | 3 | use lib::{Report, LINTS}; |
4 | use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; | 4 | use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; |
5 | 5 | ||
6 | use crate::fix::{Fixed, FixResult}; | 6 | use crate::fix::{FixResult, Fixed}; |
7 | 7 | ||
8 | fn collect_fixes(source: &str) -> Result<Vec<Report>, RnixParseErr> { | 8 | fn collect_fixes(source: &str) -> Result<Vec<Report>, RnixParseErr> { |
9 | let parsed = rnix::parse(source).as_result()?; | 9 | let parsed = rnix::parse(source).as_result()?; |
@@ -73,7 +73,7 @@ impl<'a> Iterator for FixResult<'a> { | |||
73 | 73 | ||
74 | Some(FixResult { | 74 | Some(FixResult { |
75 | src: self.src.clone(), | 75 | src: self.src.clone(), |
76 | fixed | 76 | fixed, |
77 | }) | 77 | }) |
78 | } | 78 | } |
79 | } | 79 | } |
diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index 24b5c51..c09c710 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs | |||
@@ -12,7 +12,11 @@ pub struct SingleFixResult<'δ> { | |||
12 | 12 | ||
13 | fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFixErr> { | 13 | fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFixErr> { |
14 | let mut byte: TextSize = TextSize::of(""); | 14 | let mut byte: TextSize = TextSize::of(""); |
15 | for (l, _) in src.split_inclusive('\n').zip(1..).take_while(|(_, i)| i < &line) { | 15 | for (l, _) in src |
16 | .split_inclusive('\n') | ||
17 | .zip(1..) | ||
18 | .take_while(|(_, i)| i < &line) | ||
19 | { | ||
16 | byte += TextSize::of(l); | 20 | byte += TextSize::of(l); |
17 | } | 21 | } |
18 | byte += TextSize::try_from(col).map_err(|_| SingleFixErr::Conversion(col))?; | 22 | byte += TextSize::try_from(col).map_err(|_| SingleFixErr::Conversion(col))?; |
@@ -45,8 +49,8 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> { | |||
45 | } else { | 49 | } else { |
46 | None | 50 | None |
47 | } | 51 | } |
48 | }, | 52 | } |
49 | _ => None | 53 | _ => None, |
50 | }) | 54 | }) |
51 | .flatten() | 55 | .flatten() |
52 | .next() | 56 | .next() |
@@ -60,7 +64,5 @@ pub fn single(line: usize, col: usize, src: &str) -> Result<SingleFixResult, Sin | |||
60 | 64 | ||
61 | report.apply(src.to_mut()); | 65 | report.apply(src.to_mut()); |
62 | 66 | ||
63 | Ok(SingleFixResult { | 67 | Ok(SingleFixResult { src }) |
64 | src | ||
65 | }) | ||
66 | } | 68 | } |