From 831bd7e91d1f97f565d6ea15d816e638a983ad00 Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 1 Nov 2021 22:34:22 -0400 Subject: apply clippy lints --- bin/src/config.rs | 6 +++--- bin/src/fix/single.rs | 3 +-- bin/src/lint.rs | 2 +- bin/src/main.rs | 7 +++---- bin/src/traits.rs | 5 ++--- 5 files changed, 10 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/src/config.rs b/bin/src/config.rs index 1649017..46bf60f 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -154,7 +154,7 @@ mod dirs { } fn parse_line_col(src: &str) -> Result<(usize, usize), ConfigErr> { - let parts = src.split(","); + let parts = src.split(','); match parts.collect::>().as_slice() { [line, col] => { let l = line @@ -173,7 +173,7 @@ fn parse_warning_code(src: &str) -> Result { let mut char_stream = src.chars(); let severity = char_stream .next() - .ok_or(ConfigErr::InvalidWarningCode(src.to_owned()))? + .ok_or_else(|| ConfigErr::InvalidWarningCode(src.to_owned()))? .to_ascii_lowercase(); match severity { 'w' => char_stream @@ -187,7 +187,7 @@ fn parse_warning_code(src: &str) -> Result { fn build_ignore_set(ignores: &[String]) -> Result { let mut set = GlobSetBuilder::new(); for pattern in ignores { - let glob = GlobBuilder::new(&pattern).build()?; + let glob = GlobBuilder::new(pattern).build()?; set.add(glob); } set.build() diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index 15a2ef4..b91dc45 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs @@ -40,8 +40,7 @@ fn find(offset: TextSize, src: &str) -> Result { rules .iter() .filter_map(|rule| rule.validate(&child)) - .filter(|report| report.total_suggestion_range().is_some()) - .next() + .find(|report| report.total_suggestion_range().is_some()) }), _ => None, }) diff --git a/bin/src/lint.rs b/bin/src/lint.rs index e889d31..b5856c1 100644 --- a/bin/src/lint.rs +++ b/bin/src/lint.rs @@ -16,7 +16,7 @@ pub fn lint(vfs_entry: VfsEntry) -> LintResult { let error_reports = parsed .errors() .into_iter() - .map(|e| Report::from_parse_err(e)); + .map(Report::from_parse_err); let reports = parsed .node() diff --git a/bin/src/main.rs b/bin/src/main.rs index 31f6823..4090701 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -71,7 +71,7 @@ fn _main() -> Result<(), StatixErr> { let single_fix_result = fix::single(line, col, &src)?; if single_config.diff_only { let text_diff = TextDiff::from_lines(src.as_str(), &single_fix_result.src); - let old_file = format!("{}", path_id); + let old_file = path_id.to_string(); let new_file = format!("{} [fixed]", path_id); println!( "{}", @@ -96,8 +96,7 @@ fn _main() -> Result<(), StatixErr> { } fn main() { - match _main() { - Err(e) => eprintln!("{}", e), - _ => (), + if let Err(e) = _main() { + eprintln!("{}", e); } } diff --git a/bin/src/traits.rs b/bin/src/traits.rs index a8ec70f..303d12d 100644 --- a/bin/src/traits.rs +++ b/bin/src/traits.rs @@ -101,8 +101,8 @@ fn write_errfmt( let path = vfs.file_path(file_id); for report in lint_result.reports.iter() { for diagnostic in report.diagnostics.iter() { - let line = line(diagnostic.at.start(), &src); - let col = column(diagnostic.at.start(), &src); + let line = line(diagnostic.at.start(), src); + let col = column(diagnostic.at.start(), src); writeln!( writer, "{filename}>{linenumber}:{columnnumber}:{errortype}:{errornumber}:{errormessage}", @@ -131,7 +131,6 @@ mod json { use lib::Severity; use rnix::TextRange; use serde::Serialize; - use serde_json; use vfs::ReadOnlyVfs; #[derive(Serialize)] -- cgit v1.2.3