diff --git a/Cargo.toml b/Cargo.toml index 6b0e983..4bc5993 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,9 +123,14 @@ unused_lifetimes = "warn" [lints.clippy] complexity = { level = "warn", priority = -1 } correctness = { level = "warn", priority = -1 } +cloned_instead_of_copied = "warn" +implicit_clone = "warn" +manual_string_new = "warn" perf = { level = "warn", priority = -1 } +redundant_closure_for_method_calls = "warn" style = { level = "warn", priority = -1 } suspicious = { level = "warn", priority = -1 } +unnested_or_patterns = "warn" [profile.dev] incremental = true diff --git a/src/system/sshkey_storage.rs b/src/system/sshkey_storage.rs index 7cf8236..d34e2a9 100644 --- a/src/system/sshkey_storage.rs +++ b/src/system/sshkey_storage.rs @@ -40,7 +40,7 @@ impl SshKeyStorage { /// Resolve host via termscp ssh keys storage fn resolve_host_in_termscp_storage(&self, host: &str, username: &str) -> Option<&Path> { let key: String = Self::make_mapkey(host, username); - self.hosts.get(&key).map(|x| x.as_path()) + self.hosts.get(&key).map(PathBuf::as_path) } /// Resolve host via ssh2 configuration diff --git a/src/system/watcher.rs b/src/system/watcher.rs index c465e10..b927f3b 100644 --- a/src/system/watcher.rs +++ b/src/system/watcher.rs @@ -160,7 +160,7 @@ impl FsWatcher { /// Returns the list of watched paths pub fn watched_paths(&self) -> Vec<&Path> { - Vec::from_iter(self.paths.keys().map(|x| x.as_path())) + Vec::from_iter(self.paths.keys().map(PathBuf::as_path)) } /// Unwatch provided path. diff --git a/src/ui/activities/auth/components/form.rs b/src/ui/activities/auth/components/form.rs index 608e51b..742f12d 100644 --- a/src/ui/activities/auth/components/form.rs +++ b/src/ui/activities/auth/components/form.rs @@ -97,7 +97,7 @@ fn handle_input_ev( code: Key::Enter, .. }) => Some(Msg::Form(FormMsg::Connect)), Event::Keyboard(KeyEvent { - code: Key::Char('c') | Key::Char('h') | Key::Char('r') | Key::Char('s'), + code: Key::Char('c' | 'h' | 'r' | 's'), modifiers: KeyModifiers::CONTROL, }) => Some(Msg::None), Event::Keyboard(KeyEvent { diff --git a/src/ui/activities/filetransfer/actions/change_dir.rs b/src/ui/activities/filetransfer/actions/change_dir.rs index e138df6..eda35d9 100644 --- a/src/ui/activities/filetransfer/actions/change_dir.rs +++ b/src/ui/activities/filetransfer/actions/change_dir.rs @@ -3,7 +3,7 @@ //! `filetransfer_activity` is the module which implements the Filetransfer activity, which is the main activity afterall // locals -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use remotefs::File; @@ -163,9 +163,9 @@ impl FileTransferActivity { // NOTE: tab and methods are switched on purpose (we resolve from the opposite side) SyncBrowsingDestination::ParentDir => { if is_local { - self.remote().wrkdir.parent().map(|x| x.to_path_buf()) + self.remote().wrkdir.parent().map(Path::to_path_buf) } else { - self.host_bridge().wrkdir.parent().map(|x| x.to_path_buf()) + self.host_bridge().wrkdir.parent().map(Path::to_path_buf) } } SyncBrowsingDestination::PreviousDir => { diff --git a/src/ui/activities/filetransfer/actions/exec.rs b/src/ui/activities/filetransfer/actions/exec.rs index dc9009a..2c9a149 100644 --- a/src/ui/activities/filetransfer/actions/exec.rs +++ b/src/ui/activities/filetransfer/actions/exec.rs @@ -29,9 +29,9 @@ impl FromStr for Command { Err("cd command requires a path".to_string()) } } - Some("exit") | Some("logout") => Ok(Command::Exit), + Some("exit" | "logout") => Ok(Command::Exit), Some(_) => Ok(Command::Exec(s.to_string())), - None => Err("".to_string()), + None => Err(String::new()), } } } @@ -43,7 +43,7 @@ impl FileTransferActivity { fn action_exec(&mut self, cmd: String) { if cmd.is_empty() { - self.print_terminal("".to_string()); + self.print_terminal(String::new()); return; } diff --git a/src/ui/activities/filetransfer/actions/save.rs b/src/ui/activities/filetransfer/actions/save.rs index b20461d..d7e131a 100644 --- a/src/ui/activities/filetransfer/actions/save.rs +++ b/src/ui/activities/filetransfer/actions/save.rs @@ -191,8 +191,9 @@ impl FileTransferActivity { Msg::PendingAction(PendingActionMsg::ReplaceSkipAll), Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll), ]), - Msg::PendingAction(PendingActionMsg::ReplaceOverwrite) - | Msg::PendingAction(PendingActionMsg::ReplaceOverwriteAll) + Msg::PendingAction( + PendingActionMsg::ReplaceOverwrite | PendingActionMsg::ReplaceOverwriteAll + ) ) { trace!("User wants to replace file"); self.umount_radio_replace(); diff --git a/src/ui/activities/filetransfer/components/log.rs b/src/ui/activities/filetransfer/components/log.rs index 1930acc..fc4e770 100644 --- a/src/ui/activities/filetransfer/components/log.rs +++ b/src/ui/activities/filetransfer/components/log.rs @@ -87,7 +87,11 @@ impl MockComponent for Log { self.props.set(attr, value); if matches!(attr, Attribute::Content) { self.states.set_list_len( - match self.props.get(Attribute::Content).map(|x| x.unwrap_table()) { + match self + .props + .get(Attribute::Content) + .map(AttrValue::unwrap_table) + { Some(spans) => spans.len(), _ => 0, }, diff --git a/src/ui/activities/filetransfer/components/popups/chmod.rs b/src/ui/activities/filetransfer/components/popups/chmod.rs index 110df37..91f037f 100644 --- a/src/ui/activities/filetransfer/components/popups/chmod.rs +++ b/src/ui/activities/filetransfer/components/popups/chmod.rs @@ -127,7 +127,7 @@ impl ChmodPopup { let values: Vec = state .unwrap_vec() .into_iter() - .map(|x| x.unwrap_usize()) + .map(StateValue::unwrap_usize) .collect(); UnixPexClass::new( @@ -161,7 +161,7 @@ impl MockComponent for ChmodPopup { fn perform(&mut self, cmd: Cmd) -> CmdResult { match cmd { - Cmd::Move(Direction::Left) | Cmd::Move(Direction::Right) => { + Cmd::Move(Direction::Left | Direction::Right) => { self.get_active_checkbox().perform(cmd) } Cmd::Move(Direction::Up) => { diff --git a/src/ui/activities/filetransfer/components/popups/goto.rs b/src/ui/activities/filetransfer/components/popups/goto.rs index 4797ed5..4837156 100644 --- a/src/ui/activities/filetransfer/components/popups/goto.rs +++ b/src/ui/activities/filetransfer/components/popups/goto.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use tui_realm_stdlib::Input; use tuirealm::command::{Cmd, CmdResult, Direction, Position}; use tuirealm::event::{Key, KeyEvent}; -use tuirealm::props::{Alignment, BorderType, Borders, Color, InputType, Style}; +use tuirealm::props::{Alignment, BorderType, Borders, Color, InputType, PropValue, Style}; use tuirealm::{ AttrValue, Attribute, Component, Event, MockComponent, NoUserEvent, State, StateValue, }; @@ -92,7 +92,7 @@ impl OwnStates { match (&self.search, &self.last_suggestion) { (_, Some(s)) => s.clone(), (Some(s), _) => s.clone(), - _ => "".to_string(), + _ => String::new(), } } @@ -125,14 +125,14 @@ impl OwnStates { if !suggestions.is_empty() { let suggestion; if let Some(last_suggestion) = self.last_suggestion.take() { - suggestion = suggestions + suggestion = (*suggestions .iter() .skip_while(|f| **f != &last_suggestion) .nth(1) - .unwrap_or_else(|| suggestions.first().unwrap()) - .to_string(); + .unwrap_or_else(|| suggestions.first().unwrap())) + .clone(); } else { - suggestion = suggestions.first().map(|x| x.to_string()).unwrap(); + suggestion = suggestions.first().map(ToString::to_string).unwrap(); } debug!("Suggested: {suggestion}"); @@ -154,7 +154,7 @@ impl OwnStates { let p = PathBuf::from(input_as_path); let parent = p .parent() - .map(|p| p.to_path_buf()) + .map(Path::to_path_buf) .unwrap_or_else(|| PathBuf::from("/")); // if path is `.`, then return None @@ -209,7 +209,7 @@ impl MockComponent for GotoPopup { .unwrap_payload() .unwrap_vec() .into_iter() - .map(|x| x.unwrap_str()) + .map(PropValue::unwrap_str) .collect(); self.states.set_files(files); diff --git a/src/ui/activities/filetransfer/components/terminal/component.rs b/src/ui/activities/filetransfer/components/terminal/component.rs index 1339653..e06c6d9 100644 --- a/src/ui/activities/filetransfer/components/terminal/component.rs +++ b/src/ui/activities/filetransfer/components/terminal/component.rs @@ -96,22 +96,22 @@ impl MockComponent for TerminalComponent { let title = self .query(Attribute::Title) - .map(|value| value.unwrap_string()) + .map(AttrValue::unwrap_string) .unwrap_or_else(|| "Terminal".to_string()); let fg = self .query(Attribute::Foreground) - .map(|value| value.unwrap_color()) + .map(AttrValue::unwrap_color) .unwrap_or(tuirealm::ratatui::style::Color::Reset); let bg = self .query(Attribute::Background) - .map(|value| value.unwrap_color()) + .map(AttrValue::unwrap_color) .unwrap_or(tuirealm::ratatui::style::Color::Reset); let border_color = self .query(Attribute::Borders) - .map(|value| value.unwrap_color()) + .map(AttrValue::unwrap_color) .unwrap_or(tuirealm::ratatui::style::Color::Reset); let terminal = PseudoTerminal::new(self.parser.screen()) diff --git a/src/ui/activities/filetransfer/components/transfer/file_list.rs b/src/ui/activities/filetransfer/components/transfer/file_list.rs index e84b3a4..9cdc1d3 100644 --- a/src/ui/activities/filetransfer/components/transfer/file_list.rs +++ b/src/ui/activities/filetransfer/components/transfer/file_list.rs @@ -136,7 +136,7 @@ impl FileList { fn has_dot_dot(&self) -> bool { self.props .get(Attribute::Custom(PROP_DOT_DOT)) - .map(|x| x.unwrap_flag()) + .map(AttrValue::unwrap_flag) .unwrap_or(false) } } @@ -169,7 +169,7 @@ impl MockComponent for FileList { let list_items: Vec = match self .props .get(Attribute::Content) - .map(|x| x.unwrap_table()) + .map(AttrValue::unwrap_table) { Some(table) => init_table_iter .iter() @@ -195,7 +195,7 @@ impl MockComponent for FileList { let highlighted_color = self .props .get(Attribute::HighlightedColor) - .map(|x| x.unwrap_color()); + .map(AttrValue::unwrap_color); let modifiers = match focus { true => TextModifiers::REVERSED, false => TextModifiers::empty(), @@ -220,7 +220,11 @@ impl MockComponent for FileList { self.props.set(attr, value); if matches!(attr, Attribute::Content) { self.states.init_list_states( - match self.props.get(Attribute::Content).map(|x| x.unwrap_table()) { + match self + .props + .get(Attribute::Content) + .map(AttrValue::unwrap_table) + { Some(line) => line.len(), _ => 0, }, diff --git a/src/ui/activities/filetransfer/misc/filelist.rs b/src/ui/activities/filetransfer/misc/filelist.rs index 37579a5..10355bc 100644 --- a/src/ui/activities/filetransfer/misc/filelist.rs +++ b/src/ui/activities/filetransfer/misc/filelist.rs @@ -91,7 +91,7 @@ impl FileTransferActivity { .username() .map(|u| format!("{TERM_CYAN}{u}{TERM_RESET}@")) }) - .unwrap_or("".to_string()); + .unwrap_or_default(); let hostname = self.get_hostbridge_hostname(); format!( "{username}{TERM_GREEN}{hostname}:{TERM_YELLOW}{}{TERM_RESET}$ ", @@ -111,7 +111,7 @@ impl FileTransferActivity { .username() .map(|u| format!("{TERM_CYAN}{u}{TERM_RESET}@")) }) - .unwrap_or("".to_string()); + .unwrap_or_default(); let hostname = self.get_remote_hostname(); let fmt_path = fmt_path_elide_ex( self.remote().wrkdir.as_path(), diff --git a/src/ui/activities/filetransfer/update.rs b/src/ui/activities/filetransfer/update.rs index 10b514f..27137b1 100644 --- a/src/ui/activities/filetransfer/update.rs +++ b/src/ui/activities/filetransfer/update.rs @@ -457,7 +457,7 @@ impl FileTransferActivity { SelectedFile::One(file) => { format!("changing mode for {}…", file.name()) } - SelectedFile::None => "".to_string(), + SelectedFile::None => String::new(), }, ); } diff --git a/src/ui/activities/setup/components/config.rs b/src/ui/activities/setup/components/config.rs index 56cb8c4..5aee069 100644 --- a/src/ui/activities/setup/components/config.rs +++ b/src/ui/activities/setup/components/config.rs @@ -469,7 +469,7 @@ fn handle_input_ev( } Event::Keyboard(KeyEvent { // NOTE: escaped control sequence - code: Key::Char('h') | Key::Char('r') | Key::Char('s'), + code: Key::Char('h' | 'r' | 's'), modifiers: KeyModifiers::CONTROL, }) => Some(Msg::None), Event::Keyboard(KeyEvent { diff --git a/src/ui/activities/setup/components/ssh.rs b/src/ui/activities/setup/components/ssh.rs index b4258bd..c0bafa2 100644 --- a/src/ui/activities/setup/components/ssh.rs +++ b/src/ui/activities/setup/components/ssh.rs @@ -226,7 +226,7 @@ impl Component for SshHost { } Event::Keyboard(KeyEvent { // NOTE: escaped control sequence - code: Key::Char('h') | Key::Char('r') | Key::Char('s'), + code: Key::Char('h' | 'r' | 's'), modifiers: KeyModifiers::CONTROL, }) => Some(Msg::None), Event::Keyboard(KeyEvent { diff --git a/src/ui/activities/setup/components/theme.rs b/src/ui/activities/setup/components/theme.rs index fcafde5..ef0ecad 100644 --- a/src/ui/activities/setup/components/theme.rs +++ b/src/ui/activities/setup/components/theme.rs @@ -872,7 +872,7 @@ impl Component for InputColor { } Event::Keyboard(KeyEvent { // NOTE: escaped control sequence - code: Key::Char('h') | Key::Char('r') | Key::Char('s'), + code: Key::Char('h' | 'r' | 's'), modifiers: KeyModifiers::CONTROL, }) => Some(Msg::None), Event::Keyboard(KeyEvent {