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 ++--- lib/src/lints/eta_reduction.rs | 4 ++-- lib/src/lints/unquoted_splice.rs | 2 +- macros/src/metadata.rs | 2 +- 8 files changed, 14 insertions(+), 17 deletions(-) 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)] diff --git a/lib/src/lints/eta_reduction.rs b/lib/src/lints/eta_reduction.rs index 9df3f1e..454c78f 100644 --- a/lib/src/lints/eta_reduction.rs +++ b/lib/src/lints/eta_reduction.rs @@ -67,7 +67,7 @@ impl Rule for EtaReduction { let message = format!( "Found eta-reduction: `{}`", - replacement.text().to_string() + replacement.text() ); Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) } else { @@ -81,6 +81,6 @@ fn mentions_ident(ident: &Ident, node: &SyntaxNode) -> bool { if let Some(node_ident) = Ident::cast(node.clone()) { node_ident.as_str() == ident.as_str() } else { - node.children().any(|child| mentions_ident(&ident, &child)) + node.children().any(|child| mentions_ident(ident, &child)) } } diff --git a/lib/src/lints/unquoted_splice.rs b/lib/src/lints/unquoted_splice.rs index 4700d31..ce269b6 100644 --- a/lib/src/lints/unquoted_splice.rs +++ b/lib/src/lints/unquoted_splice.rs @@ -46,7 +46,7 @@ impl Rule for UnquotedSplice { if Dynamic::cast(node.clone()).is_some(); then { let at = node.text_range(); - let replacement = make::quote(&node).node().clone(); + let replacement = make::quote(node).node().clone(); let message = "Consider quoting this splice expression"; Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) } else { diff --git a/macros/src/metadata.rs b/macros/src/metadata.rs index b41eb9c..98e2a72 100644 --- a/macros/src/metadata.rs +++ b/macros/src/metadata.rs @@ -156,7 +156,7 @@ impl<'μ> LintMeta<'μ> { } pub fn generate_meta_impl(struct_name: &Ident, meta: &RawLintMeta) -> TokenStream2 { - let not_raw = LintMeta::from_raw(&meta); + let not_raw = LintMeta::from_raw(meta); let name_fn = not_raw.generate_name_fn(); let note_fn = not_raw.generate_note_fn(); let code_fn = not_raw.generate_code_fn(); -- cgit v1.2.3