From d5671a5590e3185be45e7580e5aaaa06effa4b9f Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 21 Feb 2026 19:03:18 -0500 Subject: [PATCH] Fix clide lints. --- build.rs | 2 +- src/gui/filesystem.rs | 8 ++++---- src/main.rs | 2 +- src/tui/about.rs | 4 ++-- src/tui/app.rs | 47 +++++++++++++++++++++---------------------- src/tui/editor.rs | 5 ++--- src/tui/explorer.rs | 32 ++++++++++++++--------------- src/tui/menu_bar.rs | 7 +++---- 8 files changed, 51 insertions(+), 56 deletions(-) diff --git a/build.rs b/build.rs index fce6777..325c73b 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,7 @@ use cxx_qt_build::{CxxQtBuilder, QmlModule}; fn main() { - CxxQtBuilder::new_qml_module(QmlModule::new("clide.module").qml_files(&[ + CxxQtBuilder::new_qml_module(QmlModule::new("clide.module").qml_files([ "qml/ClideApplicationView.qml", "qml/ClideEditorView.qml", "qml/ClideExplorerView.qml", diff --git a/src/gui/filesystem.rs b/src/gui/filesystem.rs index 3528cfe..4f64599 100644 --- a/src/gui/filesystem.rs +++ b/src/gui/filesystem.rs @@ -76,7 +76,7 @@ impl qobject::FileSystem { return QString::default(); } let meta = fs::metadata(path.to_string()) - .expect(format!("Failed to get file metadata {path:?}").as_str()); + .unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}")); if !meta.is_file() { warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file"); return QString::default(); @@ -114,7 +114,7 @@ impl qobject::FileSystem { output.push_str("\n"); QString::from(output) } else { - return QString::default(); + QString::default() } } @@ -126,7 +126,7 @@ impl qobject::FileSystem { fn set_directory(self: std::pin::Pin<&mut Self>, path: &QString) -> QModelIndex { if !path.is_empty() && fs::metadata(path.to_string()) - .expect(format!("Failed to get metadata for path {path:?}").as_str()) + .unwrap_or_else(|_| panic!("Failed to get metadata for path {path:?}")) .is_dir() { self.set_root_path(path) @@ -147,7 +147,7 @@ impl qobject::FileSystem { if Path::new(&str).is_dir() { // Ensures directories are given a folder icon and not mistakenly resolved to a language. // For example, a directory named `cpp` would otherwise return a C++ icon. - return QString::from(FileIcon::from("dir/").to_string()) + return QString::from(FileIcon::from("dir/").to_string()); } let icon = FileIcon::from(str); QString::from(icon.to_string()) diff --git a/src/main.rs b/src/main.rs index c975f90..80ef06c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,7 @@ fn main() -> Result<()> { RunMode::Gui => { trace!(target:"main()", "Starting GUI in a new process"); Command::new(std::env::current_exe()?) - .args(&["--gui", app_context.path.to_str().unwrap()]) + .args(["--gui", app_context.path.to_str().unwrap()]) .stdout(Stdio::null()) .stderr(Stdio::null()) .stdin(Stdio::null()) diff --git a/src/tui/about.rs b/src/tui/about.rs index 7b53b7b..878d6d8 100644 --- a/src/tui/about.rs +++ b/src/tui/about.rs @@ -68,8 +68,8 @@ impl Widget for About { .map(|l| Line::from(Span::raw(*l))) .collect(); - Clear::default().render(kilroy_rect, buf); - Clear::default().render(chunks[1], buf); + Clear.render(kilroy_rect, buf); + Clear.render(chunks[1], buf); Paragraph::new(about_lines) .block( Block::default() diff --git a/src/tui/app.rs b/src/tui/app.rs index d5569eb..730acc1 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -3,7 +3,6 @@ // SPDX-License-Identifier: GNU General Public License v3.0 or later use crate::tui::about::About; -use crate::tui::app::AppComponent::{AppEditor, AppExplorer, AppLogger}; use crate::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState}; use crate::tui::editor_tab::EditorTab; use crate::tui::explorer::Explorer; @@ -26,7 +25,7 @@ use std::time::Duration; #[derive(Debug, Clone, Copy, PartialEq)] pub enum AppComponent { - AppEditor, + Editor, AppExplorer, AppLogger, AppMenuBar, @@ -51,7 +50,7 @@ impl<'a> App<'a> { explorer: Explorer::new(&root_path)?, logger: Logger::new(), menu_bar: MenuBar::new(), - last_active: AppEditor, + last_active: AppComponent::Editor, about: false, }; Ok(app) @@ -87,7 +86,7 @@ impl<'a> App<'a> { fn draw_bottom_status(&self, area: Rect, buf: &mut Buffer) { // Determine help text from the most recently focused component. let help = match self.last_active { - AppEditor => match self.editor_tab.current_editor() { + AppComponent::Editor => match self.editor_tab.current_editor() { Some(editor) => editor.component_state.help_text.clone(), None => { if !self.editor_tab.is_empty() { @@ -96,9 +95,9 @@ impl<'a> App<'a> { "Failed to get current Editor while getting widget help text".to_string() } }, - AppExplorer => self.explorer.component_state.help_text.clone(), - AppLogger => self.logger.component_state.help_text.clone(), - AppMenuBar => self.menu_bar.component_state.help_text.clone(), + AppComponent::AppExplorer => self.explorer.component_state.help_text.clone(), + AppComponent::AppLogger => self.logger.component_state.help_text.clone(), + AppComponent::AppMenuBar => self.menu_bar.component_state.help_text.clone(), }; Paragraph::new( concat!( @@ -132,15 +131,15 @@ impl<'a> App<'a> { info!(target:Self::ID, "Changing widget focus to {:?}", focus); self.clear_focus(); match focus { - AppEditor => match self.editor_tab.current_editor_mut() { + AppComponent::Editor => match self.editor_tab.current_editor_mut() { None => { error!(target:Self::ID, "Failed to get current Editor while changing focus") } Some(editor) => editor.component_state.set_focus(Focus::Active), }, - AppExplorer => self.explorer.component_state.set_focus(Focus::Active), - AppLogger => self.logger.component_state.set_focus(Focus::Active), - AppMenuBar => self.menu_bar.component_state.set_focus(Focus::Active), + AppComponent::AppExplorer => self.explorer.component_state.set_focus(Focus::Active), + AppComponent::AppLogger => self.logger.component_state.set_focus(Focus::Active), + AppComponent::AppMenuBar => self.menu_bar.component_state.set_focus(Focus::Active), } self.last_active = focus; } @@ -255,21 +254,21 @@ impl<'a> Component for App<'a> { } // Handle events for all components. let action = match self.last_active { - AppEditor => self.editor_tab.handle_event(event.clone())?, - AppExplorer => self.explorer.handle_event(event.clone())?, - AppLogger => self.logger.handle_event(event.clone())?, + AppComponent::Editor => self.editor_tab.handle_event(event.clone())?, + AppComponent::AppExplorer => self.explorer.handle_event(event.clone())?, + AppComponent::AppLogger => self.logger.handle_event(event.clone())?, AppMenuBar => self.menu_bar.handle_event(event.clone())?, }; // Components should always handle mouse events for click interaction. - if let Some(mouse) = event.as_mouse_event() { - if mouse.kind == MouseEventKind::Down(MouseButton::Left) { - if let Some(editor) = self.editor_tab.current_editor_mut() { - editor.handle_mouse_events(mouse)?; - } - self.explorer.handle_mouse_events(mouse)?; - self.logger.handle_mouse_events(mouse)?; + if let Some(mouse) = event.as_mouse_event() + && mouse.kind == MouseEventKind::Down(MouseButton::Left) + { + if let Some(editor) = self.editor_tab.current_editor_mut() { + editor.handle_mouse_events(mouse)?; } + self.explorer.handle_mouse_events(mouse)?; + self.logger.handle_mouse_events(mouse)?; } // Handle actions returned from widgets that may need context on other widgets or app state. @@ -349,7 +348,7 @@ impl<'a> Component for App<'a> { kind: KeyEventKind::Press, state: _state, } => { - self.change_focus(AppExplorer); + self.change_focus(AppComponent::AppExplorer); Ok(Action::Handled) } KeyEvent { @@ -358,7 +357,7 @@ impl<'a> Component for App<'a> { kind: KeyEventKind::Press, state: _state, } => { - self.change_focus(AppEditor); + self.change_focus(AppComponent::Editor); Ok(Action::Handled) } KeyEvent { @@ -367,7 +366,7 @@ impl<'a> Component for App<'a> { kind: KeyEventKind::Press, state: _state, } => { - self.change_focus(AppLogger); + self.change_focus(AppComponent::AppLogger); Ok(Action::Handled) } KeyEvent { diff --git a/src/tui/editor.rs b/src/tui/editor.rs index 0c20d3e..294e8bd 100644 --- a/src/tui/editor.rs +++ b/src/tui/editor.rs @@ -115,9 +115,8 @@ impl Component for Editor { fn handle_event(&mut self, event: Event) -> Result { if let Some(key_event) = event.as_key_event() { // Handle events here that should not be passed on to the vim emulation handler. - match self.handle_key_events(key_event)? { - Action::Handled => return Ok(Action::Handled), - _ => {} + if let Action::Handled = self.handle_key_events(key_event)? { + return Ok(Action::Handled) } } self.event_handler.on_event(event, &mut self.state); diff --git a/src/tui/explorer.rs b/src/tui/explorer.rs index 03ccfa6..9ac817e 100644 --- a/src/tui/explorer.rs +++ b/src/tui/explorer.rs @@ -4,7 +4,8 @@ use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState}; use anyhow::{Context, Result, bail}; -use log::{trace}; +use libclide::fs::entry_meta::EntryMeta; +use log::trace; use ratatui::buffer::Buffer; use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind}; use ratatui::layout::{Alignment, Position, Rect}; @@ -14,7 +15,6 @@ use ratatui::widgets::{Block, Borders, StatefulWidget, Widget}; use std::fs; use std::path::{Path, PathBuf}; use tui_tree_widget::{Tree, TreeItem, TreeState}; -use libclide::fs::entry_meta::EntryMeta; #[derive(Debug)] pub struct Explorer<'a> { @@ -30,8 +30,8 @@ impl<'a> Explorer<'a> { pub fn new(path: &PathBuf) -> Result { trace!(target:Self::ID, "Building {}", Self::ID); let explorer = Explorer { - root_path: EntryMeta::new(&path)?, - tree_items: Self::build_tree_from_path(path.to_owned())?, + root_path: EntryMeta::new(path)?, + tree_items: Self::build_tree_from_path(path)?, tree_state: TreeState::default(), component_state: ComponentState::default().with_help_text(concat!( "(↑/k)/(↓/j): Select item | ←/h: Close folder | →/l: Open folder |", @@ -96,7 +96,7 @@ impl<'a> Explorer<'a> { impl<'a> Widget for &mut Explorer<'a> { fn render(self, area: Rect, buf: &mut Buffer) { - if let Ok(tree) = Tree::new(&self.tree_items.children()) { + if let Ok(tree) = Tree::new(self.tree_items.children()) { StatefulWidget::render( tree.block( Block::default() @@ -130,23 +130,21 @@ impl<'a> Component for Explorer<'a> { _ => {} } } - if let Some(mouse_event) = event.as_mouse_event() { - match self.handle_mouse_events(mouse_event)? { - Action::Handled => return Ok(Action::Handled), - _ => {} - } + if let Some(mouse_event) = event.as_mouse_event() + && let Action::Handled = self.handle_mouse_events(mouse_event)? + { + return Ok(Action::Handled); } Ok(Action::Pass) } fn handle_key_events(&mut self, key: KeyEvent) -> Result { - if key.code == KeyCode::Enter { - if let Ok(selected) = self.selected() { - if Path::new(&selected).is_file() { - return Ok(Action::OpenTab); - } - } - // Otherwise fall through and handle Enter in the next match case. + if key.code == KeyCode::Enter + && let Ok(selected) = self.selected() + && Path::new(&selected).is_file() + { + // Open a tab if the selected item is a file. + return Ok(Action::OpenTab); } let changed = match key.code { diff --git a/src/tui/menu_bar.rs b/src/tui/menu_bar.rs index 129d83a..f872584 100644 --- a/src/tui/menu_bar.rs +++ b/src/tui/menu_bar.rs @@ -131,7 +131,7 @@ impl MenuBar { opened: MenuBarItem, ) { let popup_area = Self::rect_under_option(title_bar_anchor, area, 27, 10); - Clear::default().render(popup_area, buf); + Clear.render(popup_area, buf); let options = opened.options().iter().map(|i| ListItem::new(i.id())); StatefulWidget::render( List::new(options) @@ -150,15 +150,14 @@ impl MenuBar { } fn rect_under_option(anchor: Rect, area: Rect, width: u16, height: u16) -> Rect { - let rect = Rect { + Rect { x: anchor.x, y: anchor.y + anchor.height, width: width.min(area.width), height, - }; + } // TODO: X offset for item option? It's fine as-is, but it might look nicer. // trace!(target:Self::ID, "Building Rect under MenuBar popup {}", rect); - rect } }