From f8f42197e0acbeb38d0e4fc2645596d2985fc424 Mon Sep 17 00:00:00 2001 From: Angel-Mario Savin Date: Tue, 17 Nov 2026 11:47:57 +0200 Subject: [PATCH] Make cargo clippy pass with -D warnings and run it in CI Fixes the seven warnings left: a needless borrow twice, a manual starts_with, test helpers after the test module, a clone to make a slice, and a loop over one element. The closure clippy calls redundant in highlight.rs is needed for a lifetime, so that lint is allowed on that line with the reason. CI runs `just lint` on all three platforms, so warnings can't come back unnoticed. Closes #100 --- .github/workflows/ci.yml | 4 ++++ src/editor/display.rs | 19 +++++++++---------- src/editor/highlight.rs | 2 ++ src/editor/keys.rs | 4 ++-- src/editor/pairs.rs | 2 +- src/files.rs | 18 ++++++++---------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae44159..0b11dfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - uses: Swatinem/rust-cache@v2 - name: System libraries (Linux; Rune's Wayland and keyboard backends, and Vulkan) if: runner.os == 'Linux' @@ -23,6 +25,8 @@ jobs: run: cargo build --locked - name: Install just uses: taiki-e/install-action@just + - name: Lint + run: just lint - name: Install Claude Code CLI (for the mod tests) run: npm install -g @anthropic-ai/claude-code@2.1.309 - name: Tests (app unit tests, then mod tests) diff --git a/src/editor/display.rs b/src/editor/display.rs index 97b2f70..b891980 100644 --- a/src/editor/display.rs +++ b/src/editor/display.rs @@ -337,6 +337,15 @@ impl Editor { mod tests { use super::*; + impl Editor { + /// Lay out at the width tests set by hand. + fn relayout_with_width(&mut self) { + let lines = self.buffer.line_count(); + let old = self.rows.breaks.len(); + self.rows.rewrap(&self.buffer, 0, old, lines, &self.folds); + } + } + #[test] fn a_long_line_wraps_after_the_last_space_that_fits_and_keeps_its_indent() { assert_eq!(wrap("short", 10), (vec![], 0)); @@ -439,13 +448,3 @@ mod tests { assert!(e.hidden(6) && e.hidden(7)); } } - -#[cfg(test)] -impl Editor { - /// Lay out at the width tests set by hand. - fn relayout_with_width(&mut self) { - let lines = self.buffer.line_count(); - let old = self.rows.breaks.len(); - self.rows.rewrap(&self.buffer, 0, old, lines, &self.folds); - } -} diff --git a/src/editor/highlight.rs b/src/editor/highlight.rs index c8ecade..f954d3d 100644 --- a/src/editor/highlight.rs +++ b/src/editor/highlight.rs @@ -103,6 +103,8 @@ fn injected(name: &str) -> Option<&'static HighlightConfiguration> { pub fn highlight(language: &str, text: &str) -> Option>> { let config = configs().get(language)?; let mut highlighter = Highlighter::new(); + // The closure isn't redundant: passed bare, `injected` ties its result to the highlighter's lifetime and won't compile. + #[allow(clippy::redundant_closure)] let events = highlighter.highlight(config, text.as_bytes(), None, |name| injected(name)).ok()?; let starts: Vec = std::iter::once(0).chain(text.match_indices('\n').map(|(i, _)| i + 1)).collect(); let mut lines: Vec> = vec![vec![]; starts.len()]; diff --git a/src/editor/keys.rs b/src/editor/keys.rs index b57e415..fbb7f70 100644 --- a/src/editor/keys.rs +++ b/src/editor/keys.rs @@ -92,11 +92,11 @@ impl Editor { true } ("c", false) => { - tx.copy(&self.take_for_clipboard(false)); + tx.copy(self.take_for_clipboard(false)); true } ("x", false) => { - tx.copy(&self.take_for_clipboard(true)); + tx.copy(self.take_for_clipboard(true)); true } ("v", false) => { diff --git a/src/editor/pairs.rs b/src/editor/pairs.rs index e7abbbe..45e4cd7 100644 --- a/src/editor/pairs.rs +++ b/src/editor/pairs.rs @@ -49,7 +49,7 @@ impl Editor { /// The closer `c` is already next to the caret: move past it instead of typing another. fn step_over(&mut self, c: char, at: Pos) -> bool { let line = self.buffer.line(at.line); - if line[at.col..].chars().next() != Some(c) || escaped(&line[..at.col]) { + if !line[at.col..].starts_with(c) || escaped(&line[..at.col]) { return false; } let Some(&(open, close)) = PAIRS.iter().find(|(_, cl)| *cl == c) else { return false }; diff --git a/src/files.rs b/src/files.rs index ef8e967..95c7484 100644 --- a/src/files.rs +++ b/src/files.rs @@ -682,7 +682,7 @@ mod tests { let total = 1; } ").unwrap(); - let hits = search(&[file.clone()], "total", 100, &|| false); + let hits = search(std::slice::from_ref(&file), "total", 100, &|| false); assert_eq!(hits, [Hit { path: file.clone(), line: 1, text: "let total = 1;".into() }]); let Ok(Contents::Text { text, .. }) = read(&file) else { panic!("readable") }; assert_eq!(text.lines().nth(hits[0].line).unwrap().trim(), hits[0].text, "the editor has the same line there"); @@ -780,15 +780,13 @@ nothing fn tabs_after_the_indent_are_shown_too() { let tmp = tempfile::tempdir().unwrap(); let p = tmp.path().join("a.go"); - for (file, shown, why) in [ - ("type A struct {\n\tName\tstring\n\tId\tint\n}\n", "type A struct {\n Name string\n Id int\n}\n", "tabs that align"), - ] { - fs::write(&p, file).unwrap(); - let Contents::Text { text, format, stamp: s } = read(&p).unwrap() else { panic!("not text") }; - assert_eq!(text, shown, "{why}"); - save(&p, &text, format, Some(s)).unwrap(); - assert_eq!(fs::read_to_string(&p).unwrap(), file, "{why}: saved unchanged"); - } + // Tabs that align. + let file = "type A struct {\n\tName\tstring\n\tId\tint\n}\n"; + fs::write(&p, file).unwrap(); + let Contents::Text { text, format, stamp: s } = read(&p).unwrap() else { panic!("not text") }; + assert_eq!(text, "type A struct {\n Name string\n Id int\n}\n"); + save(&p, &text, format, Some(s)).unwrap(); + assert_eq!(fs::read_to_string(&p).unwrap(), file, "saved unchanged"); // A line edited by hand keeps the tabs of its indent, not the ones inside it. fs::write(&p, "type A struct {\n\tName\tstring\n}\n").unwrap(); let Contents::Text { format, stamp: s, .. } = read(&p).unwrap() else { panic!("not text") };