From 20d195988de1014517ff1a1c8c1041cff5f88e05 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 26 Oct 2021 19:18:28 +0530 Subject: set internal crates to 0.0.0, bump to v0.2.0 --- bin/src/config.rs | 3 ++- bin/src/err.rs | 2 +- bin/src/fix.rs | 5 ++++- bin/src/fix/all.rs | 4 ++-- bin/src/fix/single.rs | 14 ++++++++------ bin/src/main.rs | 31 ++++++++++++++++++------------- 6 files changed, 35 insertions(+), 24 deletions(-) (limited to 'bin/src') diff --git a/bin/src/config.rs b/bin/src/config.rs index 8ddfb4a..c856a59 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -234,9 +234,10 @@ impl FromStr for OutFormat { match value.to_ascii_lowercase().as_str() { #[cfg(feature = "json")] "json" => Ok(Self::Json), + #[cfg(not(feature = "json"))] + "json" => Err("statix was not compiled with the `json` feature flag"), "errfmt" => Ok(Self::Errfmt), "stderr" => Ok(Self::StdErr), - "json" => Err("statix was not compiled with the `json` feature flag"), _ => Err("unknown output format, try: json, errfmt"), } } diff --git a/bin/src/err.rs b/bin/src/err.rs index 5f71b57..53c3222 100644 --- a/bin/src/err.rs +++ b/bin/src/err.rs @@ -11,7 +11,7 @@ pub enum ConfigErr { #[error("path error: {0}")] InvalidPath(#[from] io::Error), #[error("unable to parse `{0}` as line and column")] - InvalidPosition(String) + InvalidPosition(String), } #[derive(Error, Debug)] diff --git a/bin/src/fix.rs b/bin/src/fix.rs index a7ddc4f..c378c13 100644 --- a/bin/src/fix.rs +++ b/bin/src/fix.rs @@ -24,6 +24,9 @@ pub struct Fixed { impl<'a> FixResult<'a> { fn empty(src: Source<'a>) -> Self { - Self { src, fixed: Vec::new() } + Self { + src, + fixed: Vec::new(), + } } } 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; use lib::{Report, LINTS}; use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; -use crate::fix::{Fixed, FixResult}; +use crate::fix::{FixResult, Fixed}; fn collect_fixes(source: &str) -> Result, RnixParseErr> { let parsed = rnix::parse(source).as_result()?; @@ -73,7 +73,7 @@ impl<'a> Iterator for FixResult<'a> { Some(FixResult { src: self.src.clone(), - fixed + fixed, }) } } 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<'δ> { fn pos_to_byte(line: usize, col: usize, src: &str) -> Result { let mut byte: TextSize = TextSize::of(""); - for (l, _) in src.split_inclusive('\n').zip(1..).take_while(|(_, i)| i < &line) { + for (l, _) in src + .split_inclusive('\n') + .zip(1..) + .take_while(|(_, i)| i < &line) + { byte += TextSize::of(l); } byte += TextSize::try_from(col).map_err(|_| SingleFixErr::Conversion(col))?; @@ -45,8 +49,8 @@ fn find(offset: TextSize, src: &str) -> Result { } else { None } - }, - _ => None + } + _ => None, }) .flatten() .next() @@ -60,7 +64,5 @@ pub fn single(line: usize, col: usize, src: &str) -> Result Result<(), StatixErr> { match opts.cmd { SubCommand::Check(check_config) => { let vfs = check_config.vfs()?; - let (lints, errors): (Vec<_>, Vec<_>) = vfs.iter().map(lint::lint).partition(Result::is_ok); + let (lints, errors): (Vec<_>, Vec<_>) = + vfs.iter().map(lint::lint).partition(Result::is_ok); let lint_results = lints.into_iter().map(Result::unwrap); let errors = errors.into_iter().map(Result::unwrap_err); @@ -28,7 +32,7 @@ fn _main() -> Result<(), StatixErr> { errors.for_each(|e| { eprintln!("{}", e); }); - }, + } SubCommand::Fix(fix_config) => { let vfs = fix_config.vfs()?; for entry in vfs.iter() { @@ -40,17 +44,17 @@ fn _main() -> Result<(), StatixErr> { println!( "{}", text_diff - .unified_diff() - .context_radius(4) - .header(&old_file, &new_file) - ); + .unified_diff() + .context_radius(4) + .header(&old_file, &new_file) + ); } else { let path = entry.file_path; std::fs::write(path, &*fix_result.src).map_err(FixErr::InvalidPath)?; } } } - }, + } SubCommand::Single(single_config) => { let path = single_config.target; let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; @@ -63,12 +67,13 @@ fn _main() -> Result<(), StatixErr> { println!( "{}", text_diff - .unified_diff() - .context_radius(4) - .header(&old_file, &new_file) - ); + .unified_diff() + .context_radius(4) + .header(&old_file, &new_file) + ); } else { - std::fs::write(&path, &*single_fix_result.src).map_err(SingleFixErr::InvalidPath)?; + std::fs::write(&path, &*single_fix_result.src) + .map_err(SingleFixErr::InvalidPath)?; } } } -- cgit v1.2.3