diff --git a/src/filter.rs b/src/filter.rs index dc92f69..31ae814 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -98,7 +98,7 @@ impl fmt::Debug for Filter { } #[derive(Debug)] -pub struct LintResult { +pub struct LintOutcome { pub ok: bool, pub stdout: Option, pub stderr: Option, @@ -106,7 +106,7 @@ pub struct LintResult { pub trait FilterImplementation { fn tidy(&self, name: &str, path: &Path) -> Result<()>; - fn lint(&self, name: &str, path: &Path) -> Result; + fn lint(&self, name: &str, path: &Path) -> Result; fn filter_key(&self) -> &str; } @@ -139,7 +139,7 @@ impl Filter { Ok(Some(Self::path_was_changed(&full, &info)?)) } - pub fn lint(&self, path: &Path, files: &[PathBuf]) -> Result> { + pub fn lint(&self, path: &Path, files: &[PathBuf]) -> Result> { self.require_is_not_filter_type(FilterType::Tidy)?; let mut full = self.root.clone(); @@ -514,7 +514,7 @@ impl FilterImplementation for Command { } } - fn lint(&self, name: &str, path: &Path) -> Result { + fn lint(&self, name: &str, path: &Path) -> Result { let mut cmd = self.command_for_path(path, &self.lint_flags); info!( @@ -533,7 +533,7 @@ impl FilterImplementation for Command { self.expect_stderr, self.in_dir(path), ) { - Ok(result) => Ok(LintResult { + Ok(result) => Ok(LintOutcome { ok: !self.lint_failure_exit_codes.contains(&result.exit_code), stdout: result.stdout, stderr: result.stderr, @@ -583,8 +583,8 @@ mod tests { Ok(()) } - fn lint(&self, _: &str, _: &Path) -> Result { - Ok(LintResult { + fn lint(&self, _: &str, _: &Path) -> Result { + Ok(LintOutcome { ok: true, stdout: None, stderr: None, diff --git a/src/precious.rs b/src/precious.rs index bcfd29f..3ecef3e 100644 --- a/src/precious.rs +++ b/src/precious.rs @@ -51,7 +51,7 @@ impl From for Exit { } #[derive(Debug)] -struct ActionError { +struct ActionFailure { error: String, config_key: String, path: PathBuf, @@ -387,7 +387,7 @@ impl<'a> Precious<'a> { run_filter: R, ) -> Result where - R: Fn(&mut Self, Vec, &filter::Filter) -> Option>, + R: Fn(&mut Self, Vec, &filter::Filter) -> Option>, { if filters.is_empty() { return Err(PreciousError::NoFilters { @@ -403,25 +403,25 @@ impl<'a> Precious<'a> { match self.basepaths()?.paths(cli_paths)? { None => Ok(self.no_files_exit()), Some(paths) => { - let mut all_errors: Vec = vec![]; + let mut all_failures: Vec = vec![]; for f in filters { - if let Some(mut errors) = run_filter(self, paths.clone(), &f) { - all_errors.append(&mut errors); + if let Some(mut failures) = run_filter(self, paths.clone(), &f) { + all_failures.append(&mut failures); } } - Ok(self.make_exit(all_errors, action)) + Ok(self.make_exit(all_failures, action)) } } } - fn make_exit(&self, errors: Vec, action: &str) -> Exit { - let (status, error) = if errors.is_empty() { + fn make_exit(&self, failures: Vec, action: &str) -> Exit { + let (status, error) = if failures.is_empty() { (0, None) } else { let red = format!("\x1B[{}m", Color::Red.to_fg_str()); let ansi_off = "\x1B[0m"; - let plural = if errors.len() > 1 { 's' } else { '\0' }; + let plural = if failures.len() > 1 { 's' } else { '\0' }; let error = format!( "{}Error{} when {} files:{}\n{}", @@ -429,14 +429,14 @@ impl<'a> Precious<'a> { plural, action, ansi_off, - errors + failures .iter() - .map(|ae| format!( + .map(|af| format!( " {} {} [{}]\n {}\n", self.chars.bullet, - ae.path.display(), - ae.config_key, - ae.error, + af.path.display(), + af.config_key, + af.error, )) .collect::>() .join("") @@ -454,9 +454,9 @@ impl<'a> Precious<'a> { &mut self, all_paths: Vec, t: &filter::Filter, - ) -> Option> { + ) -> Option> { let runner = - |s: &Self, p: &Path, paths: &basepaths::Paths| -> Option> { + |s: &Self, p: &Path, paths: &basepaths::Paths| -> Option> { match t.tidy(p, &paths.files) { Ok(Some(true)) => { if !s.quiet { @@ -488,7 +488,7 @@ impl<'a> Precious<'a> { t.name, p.display() ); - Some(Err(ActionError { + Some(Err(ActionFailure { error: format!("{:#}", e), config_key: t.config_key(), path: p.to_owned(), @@ -504,28 +504,28 @@ impl<'a> Precious<'a> { &mut self, all_paths: Vec, l: &filter::Filter, - ) -> Option> { + ) -> Option> { let runner = |s: &Self, p: &Path, paths: &basepaths::Paths| - -> Option> { + -> Option> { match l.lint(p, &paths.files) { - Ok(Some(r)) => { - if r.ok { + Ok(Some(lo)) => { + if lo.ok { if !s.quiet { println!("{} Passed {}: {}", s.chars.lint_free, l.name, p.display()); } Some(Ok(())) } else { println!("{} Failed {}: {}", s.chars.lint_dirty, l.name, p.display()); - if let Some(s) = r.stdout { + if let Some(s) = lo.stdout { println!("{}", s); } - if let Some(s) = r.stderr { + if let Some(s) = lo.stderr { println!("{}", s); } - Some(Err(ActionError { + Some(Err(ActionFailure { error: "linting failed".into(), config_key: l.config_key(), path: p.to_owned(), @@ -540,7 +540,7 @@ impl<'a> Precious<'a> { l.name, p.display() ); - Some(Err(ActionError { + Some(Err(ActionFailure { error: format!("{:#}", e), config_key: l.config_key(), path: p.to_owned(), @@ -558,20 +558,20 @@ impl<'a> Precious<'a> { all_paths: Vec, f: &filter::Filter, runner: R, - ) -> Option> + ) -> Option> where - R: Fn(&Self, &Path, &basepaths::Paths) -> Option> + Sync, + R: Fn(&Self, &Path, &basepaths::Paths) -> Option> + Sync, { let map = self.path_map(all_paths, f); let start = Instant::now(); - let mut results: Vec> = vec![]; + let mut results: Vec> = vec![]; self.thread_pool.install(|| { results.append( &mut map .par_iter() .filter_map(|(p, paths)| runner(self, p, paths)) - .collect::>>(), + .collect::>>(), ); }); @@ -586,17 +586,17 @@ impl<'a> Precious<'a> { ); } - let errors = results + let failures = results .into_iter() .filter_map(|r| match r { Ok(_) => None, Err(e) => Some(e), }) - .collect::>(); - if errors.is_empty() { + .collect::>(); + if failures.is_empty() { None } else { - Some(errors) + Some(failures) } }