From fb6a02b1f6b962682a5473cb5596c4ea5169726d Mon Sep 17 00:00:00 2001 From: Pete Moore Date: Wed, 18 Nov 2026 17:45:01 +0100 Subject: [PATCH] fix: Address new clippy warnings Newer stable Rust (1.100) adds or enables clippy lints that fail the 'lint and test' task with -D warnings: question_mark, collapsible_match, byte_char_slices, map_or-to-unwrap_or and unnecessary_unwrap. --- rust-code-analysis-cli/src/main.rs | 10 +++++----- src/metrics/cyclomatic.rs | 13 ++++++------- src/node.rs | 6 +----- src/tools.rs | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/rust-code-analysis-cli/src/main.rs b/rust-code-analysis-cli/src/main.rs index 728029297..f9c5c0b4b 100644 --- a/rust-code-analysis-cli/src/main.rs +++ b/rust-code-analysis-cli/src/main.rs @@ -64,7 +64,7 @@ fn mk_globset(elems: Vec) -> GlobSet { globset.add(glob); } }); - globset.build().map_or(GlobSet::empty(), |globset| globset) + globset.build().unwrap_or(GlobSet::empty()) } fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> { @@ -132,17 +132,17 @@ fn act_on_file(path: PathBuf, cfg: &Config) -> std::io::Result<()> { line_end: cfg.line_end, }; action::(&language, source, &path, pr, cfg) - } else if cfg.count_lock.is_some() { + } else if let Some(count_lock) = &cfg.count_lock { let cfg = CountCfg { filters: cfg.count_filter.clone(), - stats: cfg.count_lock.as_ref().unwrap().clone(), + stats: count_lock.clone(), }; action::(&language, source, &path, pr, cfg) - } else if cfg.preproc_lock.is_some() { + } else if let Some(preproc_lock) = &cfg.preproc_lock { if let Some(language) = guess_language(&source, &path).0 && language == LANG::Cpp { - let mut results = cfg.preproc_lock.as_ref().unwrap().lock().unwrap(); + let mut results = preproc_lock.lock().unwrap(); preprocess( &PreprocParser::new(source, &path, None), &path, diff --git a/src/metrics/cyclomatic.rs b/src/metrics/cyclomatic.rs index 3bbc93a65..b2047d120 100644 --- a/src/metrics/cyclomatic.rs +++ b/src/metrics/cyclomatic.rs @@ -117,13 +117,12 @@ impl Cyclomatic for PythonCode { If | Elif | For | While | Except | With | Assert | And | Or => { stats.cyclomatic += 1.; } - Else => { - if node.has_ancestors( - |node| matches!(node.kind_id().into(), ForStatement | WhileStatement), - |node| node.kind_id() == ElseClause, - ) { - stats.cyclomatic += 1.; - } + Else if node.has_ancestors( + |node| matches!(node.kind_id().into(), ForStatement | WhileStatement), + |node| node.kind_id() == ElseClause, + ) => + { + stats.cyclomatic += 1.; } _ => {} } diff --git a/src/node.rs b/src/node.rs index 49b8df104..b20fe63c5 100644 --- a/src/node.rs +++ b/src/node.rs @@ -138,11 +138,7 @@ impl<'a> Node<'a> { let mut level = level; let mut node = *self; while level != 0 { - if let Some(parent) = node.parent() { - node = parent; - } else { - return None; - } + node = node.parent()?; level -= 1; } diff --git a/src/tools.rs b/src/tools.rs index 17d6f9869..24d577db5 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -57,9 +57,9 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result>> { let mut start = vec![0; 64.min(file_size)]; let start = if file.read_exact(&mut start).is_ok() { // Skip the bom if one - if start[..2] == [b'\xFE', b'\xFF'] || start[..2] == [b'\xFF', b'\xFE'] { + if start[..2] == *b"\xFE\xFF" || start[..2] == *b"\xFF\xFE" { &start[2..] - } else if start[..3] == [b'\xEF', b'\xBB', b'\xBF'] { + } else if start[..3] == *b"\xEF\xBB\xBF" { &start[3..] } else { &start