From a22c5025d7e9ac043d26038f8415afeddd5616ec Mon Sep 17 00:00:00 2001 From: veeso Date: Wed, 17 Aug 2022 10:33:31 +0200 Subject: [PATCH] lint --- Cargo.toml | 2 +- src/config/bookmarks.rs | 4 ++-- src/config/params.rs | 2 +- src/config/themes.rs | 2 +- src/explorer/mod.rs | 14 +++++++------- src/filetransfer/mod.rs | 2 +- src/host/mod.rs | 12 ++++++------ src/system/config_client.rs | 2 +- src/system/environment.rs | 8 ++++---- src/system/keys/filestorage.rs | 2 +- src/system/keys/mod.rs | 2 +- src/system/sshkey_storage.rs | 2 +- src/ui/activities/auth/mod.rs | 6 +++--- src/ui/activities/filetransfer/misc.rs | 2 +- src/ui/activities/filetransfer/update.rs | 12 ++++++------ src/ui/activities/filetransfer/view.rs | 4 ++-- src/ui/activities/setup/components/config.rs | 2 +- src/ui/activities/setup/mod.rs | 12 ++++++------ src/utils/crypto.rs | 2 +- src/utils/fmt.rs | 6 +++--- src/utils/path.rs | 4 ++-- 21 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 40b1d3e..ca1f581 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -authors = ["Christian Visintin"] +authors = ["Christian Visintin "] categories = ["command-line-utilities"] description = "termscp is a feature rich terminal file transfer and explorer with support for SCP/SFTP/FTP/S3" edition = "2021" diff --git a/src/config/bookmarks.rs b/src/config/bookmarks.rs index 5e1dc0d..46d148d 100644 --- a/src/config/bookmarks.rs +++ b/src/config/bookmarks.rs @@ -19,7 +19,7 @@ pub struct UserHosts { } /// Bookmark describes a single bookmark entry in the user hosts storage -#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] +#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] pub struct Bookmark { #[serde( deserialize_with = "deserialize_protocol", @@ -41,7 +41,7 @@ pub struct Bookmark { } /// Connection parameters for Aws s3 protocol -#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Default)] +#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Default)] pub struct S3Params { pub bucket: String, pub region: Option, diff --git a/src/config/params.rs b/src/config/params.rs index 3594c4e..e99df84 100644 --- a/src/config/params.rs +++ b/src/config/params.rs @@ -106,7 +106,7 @@ mod tests { assert_eq!(ui.file_fmt, Some(String::from("{NAME}"))); let cfg: UserConfig = UserConfig { user_interface: ui, - remote: remote, + remote, }; assert_eq!( *cfg.remote diff --git a/src/config/themes.rs b/src/config/themes.rs index b86d096..472a8ba 100644 --- a/src/config/themes.rs +++ b/src/config/themes.rs @@ -12,7 +12,7 @@ use tuirealm::tui::style::Color; /// ### Theme /// /// Theme contains all the colors lookup table for termscp -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct Theme { // -- auth #[serde( diff --git a/src/explorer/mod.rs b/src/explorer/mod.rs index 40298fa..84adb57 100644 --- a/src/explorer/mod.rs +++ b/src/explorer/mod.rs @@ -25,7 +25,7 @@ bitflags! { } /// FileSorting defines the criteria for sorting files -#[derive(Copy, Clone, PartialEq, std::fmt::Debug)] +#[derive(Copy, Clone, PartialEq, Eq, std::fmt::Debug)] pub enum FileSorting { Name, ModifyTime, @@ -34,7 +34,7 @@ pub enum FileSorting { } /// GroupDirs defines how directories should be grouped in sorting files -#[derive(PartialEq, std::fmt::Debug)] +#[derive(PartialEq, Eq, std::fmt::Debug)] pub enum GroupDirs { First, Last, @@ -318,8 +318,8 @@ mod tests { explorer.stack_size = 2; explorer.dirstack = VecDeque::with_capacity(2); // Push dir - explorer.pushd(&Path::new("/tmp")); - explorer.pushd(&Path::new("/home/omar")); + explorer.pushd(Path::new("/tmp")); + explorer.pushd(Path::new("/home/omar")); // Pop assert_eq!(explorer.popd().unwrap(), PathBuf::from("/home/omar")); assert_eq!(explorer.dirstack.len(), 1); @@ -328,9 +328,9 @@ mod tests { // Dirstack is empty now assert!(explorer.popd().is_none()); // Exceed limit - explorer.pushd(&Path::new("/tmp")); - explorer.pushd(&Path::new("/home/omar")); - explorer.pushd(&Path::new("/dev")); + explorer.pushd(Path::new("/tmp")); + explorer.pushd(Path::new("/home/omar")); + explorer.pushd(Path::new("/dev")); assert_eq!(explorer.dirstack.len(), 2); assert_eq!(*explorer.dirstack.get(1).unwrap(), PathBuf::from("/dev")); assert_eq!( diff --git a/src/filetransfer/mod.rs b/src/filetransfer/mod.rs index 8a2138a..a5c9501 100644 --- a/src/filetransfer/mod.rs +++ b/src/filetransfer/mod.rs @@ -11,7 +11,7 @@ pub use params::{FileTransferParams, ProtocolParams}; /// This enum defines the different transfer protocol available in termscp -#[derive(PartialEq, Debug, Clone, Copy)] +#[derive(PartialEq, Eq, Debug, Clone, Copy)] pub enum FileTransferProtocol { Sftp, Scp, diff --git a/src/host/mod.rs b/src/host/mod.rs index 75e1a57..a64c0f0 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -654,7 +654,7 @@ mod tests { let entries = std::fs::read_dir(PathBuf::from("/dev").as_path()).unwrap(); let mut counter: usize = 0; for _ in entries { - counter = counter + 1; + counter += 1; } assert_eq!(host.files.len(), counter); } @@ -696,7 +696,7 @@ mod tests { let entries = std::fs::read_dir(PathBuf::from("/dev").as_path()).unwrap(); let mut counter: usize = 0; for _ in entries { - counter = counter + 1; + counter += 1; } assert_eq!(host.list_dir().len(), counter); } @@ -709,10 +709,10 @@ mod tests { assert!(host.change_wrkdir(new_dir.as_path()).is_ok()); // Verify new files // Scan dir - let entries = std::fs::read_dir(PathBuf::from(new_dir).as_path()).unwrap(); + let entries = std::fs::read_dir(new_dir.as_path()).unwrap(); let mut counter: usize = 0; for _ in entries { - counter = counter + 1; + counter += 1; } assert_eq!(host.files.len(), counter); } @@ -793,7 +793,7 @@ mod tests { let files: Vec = host.list_dir(); // Verify files let file_0: &File = files.get(0).unwrap(); - if file_0.name() == String::from("foo.txt") { + if file_0.name() == *"foo.txt" { assert!(file_0.metadata.symlink.is_none()); } else { assert_eq!( @@ -803,7 +803,7 @@ mod tests { } // Verify simlink let file_1: &File = files.get(1).unwrap(); - if file_1.name() == String::from("bar.txt") { + if file_1.name() == *"bar.txt" { assert_eq!( file_1.metadata.symlink.as_ref().unwrap(), &PathBuf::from(format!("{}/foo.txt", tmpdir.path().display())) diff --git a/src/system/config_client.rs b/src/system/config_client.rs index 42052c3..6ac81f4 100644 --- a/src/system/config_client.rs +++ b/src/system/config_client.rs @@ -491,7 +491,7 @@ mod tests { // Verify client has updated parameters assert_eq!(client.get_default_protocol(), FileTransferProtocol::Scp); assert_eq!(client.get_text_editor(), PathBuf::from("/usr/bin/vim")); - let mut expected_key_path: PathBuf = key_path.clone(); + let mut expected_key_path: PathBuf = key_path; expected_key_path.push("pi@192.168.1.31.key"); assert_eq!( client.get_ssh_key("pi@192.168.1.31").unwrap().unwrap(), diff --git a/src/system/environment.rs b/src/system/environment.rs index 1914412..7839bf1 100644 --- a/src/system/environment.rs +++ b/src/system/environment.rs @@ -126,7 +126,7 @@ mod tests { #[serial] fn test_system_environment_get_bookmarks_paths() { assert_eq!( - get_bookmarks_paths(&Path::new("/home/omar/.config/termscp/")), + get_bookmarks_paths(Path::new("/home/omar/.config/termscp/")), PathBuf::from("/home/omar/.config/termscp/bookmarks.toml"), ); } @@ -135,7 +135,7 @@ mod tests { #[serial] fn test_system_environment_get_config_paths() { assert_eq!( - get_config_paths(&Path::new("/home/omar/.config/termscp/")), + get_config_paths(Path::new("/home/omar/.config/termscp/")), ( PathBuf::from("/home/omar/.config/termscp/config.toml"), PathBuf::from("/home/omar/.config/termscp/.ssh/") @@ -147,7 +147,7 @@ mod tests { #[serial] fn test_system_environment_get_log_paths() { assert_eq!( - get_log_paths(&Path::new("/home/omar/.config/termscp/")), + get_log_paths(Path::new("/home/omar/.config/termscp/")), PathBuf::from("/home/omar/.config/termscp/termscp.log"), ); } @@ -156,7 +156,7 @@ mod tests { #[serial] fn test_system_environment_get_theme_path() { assert_eq!( - get_theme_path(&Path::new("/home/omar/.config/termscp/")), + get_theme_path(Path::new("/home/omar/.config/termscp/")), PathBuf::from("/home/omar/.config/termscp/theme.toml"), ); } diff --git a/src/system/keys/filestorage.rs b/src/system/keys/filestorage.rs index ee6a7d3..7d2b318 100644 --- a/src/system/keys/filestorage.rs +++ b/src/system/keys/filestorage.rs @@ -96,7 +96,7 @@ mod tests { #[test] fn test_system_keys_filestorage_make_dir() { - let storage: FileStorage = FileStorage::new(&Path::new("/tmp/")); + let storage: FileStorage = FileStorage::new(Path::new("/tmp/")); assert_eq!( storage.make_file_path("bookmarks").as_path(), Path::new("/tmp/.bookmarks.key") diff --git a/src/system/keys/mod.rs b/src/system/keys/mod.rs index a2186ba..10f3597 100644 --- a/src/system/keys/mod.rs +++ b/src/system/keys/mod.rs @@ -10,7 +10,7 @@ pub mod keyringstorage; use thiserror::Error; /// defines the error type for the `KeyStorage` -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error, PartialEq, Eq)] pub enum KeyStorageError { #[cfg(feature = "with-keyring")] #[error("Key has a bad syntax")] diff --git a/src/system/sshkey_storage.rs b/src/system/sshkey_storage.rs index c16f190..1b3cace 100644 --- a/src/system/sshkey_storage.rs +++ b/src/system/sshkey_storage.rs @@ -93,7 +93,7 @@ mod tests { // Create ssh key storage let storage: SshKeyStorage = SshKeyStorage::from(&client); // Verify key exists - let mut exp_key_path: PathBuf = key_path.clone(); + let mut exp_key_path: PathBuf = key_path; exp_key_path.push("pi@192.168.1.31.key"); assert_eq!( *storage.resolve("192.168.1.31", "pi").unwrap(), diff --git a/src/ui/activities/auth/mod.rs b/src/ui/activities/auth/mod.rs index 07620a8..c32295b 100644 --- a/src/ui/activities/auth/mod.rs +++ b/src/ui/activities/auth/mod.rs @@ -60,14 +60,14 @@ pub enum Id { WindowSizeError, } -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub enum Msg { Form(FormMsg), Ui(UiMsg), None, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum FormMsg { Connect, DeleteBookmark, @@ -81,7 +81,7 @@ pub enum FormMsg { SaveBookmark, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum UiMsg { AddressBlurDown, AddressBlurUp, diff --git a/src/ui/activities/filetransfer/misc.rs b/src/ui/activities/filetransfer/misc.rs index f16e9c1..fc78a78 100644 --- a/src/ui/activities/filetransfer/misc.rs +++ b/src/ui/activities/filetransfer/misc.rs @@ -208,7 +208,7 @@ impl FileTransferActivity { Ok(h) => { let hostname: String = h.as_os_str().to_string_lossy().to_string(); let tokens: Vec<&str> = hostname.split('.').collect(); - String::from(*tokens.get(0).unwrap_or(&"localhost")) + String::from(*tokens.first().unwrap_or(&"localhost")) } Err(_) => String::from("localhost"), }; diff --git a/src/ui/activities/filetransfer/update.rs b/src/ui/activities/filetransfer/update.rs index 103085e..04dff97 100644 --- a/src/ui/activities/filetransfer/update.rs +++ b/src/ui/activities/filetransfer/update.rs @@ -102,7 +102,7 @@ impl FileTransferActivity { self.action_submit_local(entry); // Update file list if sync if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_remote_filelist(); + self.update_remote_filelist(); } self.update_local_filelist(); } @@ -112,7 +112,7 @@ impl FileTransferActivity { self.action_submit_remote(entry); // Update file list if sync if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_local_filelist(); + self.update_local_filelist(); } self.update_remote_filelist(); } @@ -161,7 +161,7 @@ impl FileTransferActivity { FileExplorerTab::Local => { self.action_go_to_local_upper_dir(); if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_remote_filelist(); + self.update_remote_filelist(); } // Reload file list component self.update_local_filelist() @@ -169,7 +169,7 @@ impl FileTransferActivity { FileExplorerTab::Remote => { self.action_go_to_remote_upper_dir(); if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_local_filelist(); + self.update_local_filelist(); } // Reload file list component self.update_remote_filelist() @@ -182,7 +182,7 @@ impl FileTransferActivity { FileExplorerTab::Local => { self.action_go_to_previous_local_dir(); if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_remote_filelist(); + self.update_remote_filelist(); } // Reload file list component self.update_local_filelist() @@ -190,7 +190,7 @@ impl FileTransferActivity { FileExplorerTab::Remote => { self.action_go_to_previous_remote_dir(); if self.browser.sync_browsing && self.browser.found().is_none() { - let _ = self.update_local_filelist(); + self.update_local_filelist(); } // Reload file list component self.update_remote_filelist() diff --git a/src/ui/activities/filetransfer/view.rs b/src/ui/activities/filetransfer/view.rs index f104b2b..c69d973 100644 --- a/src/ui/activities/filetransfer/view.rs +++ b/src/ui/activities/filetransfer/view.rs @@ -80,8 +80,8 @@ impl FileTransferActivity { self.refresh_local_status_bar(); self.refresh_remote_status_bar(); // Update components - let _ = self.update_local_filelist(); - let _ = self.update_remote_filelist(); + self.update_local_filelist(); + self.update_remote_filelist(); // Global listener self.mount_global_listener(); // Give focus to local explorer diff --git a/src/ui/activities/setup/components/config.rs b/src/ui/activities/setup/components/config.rs index 3f75557..ed41f05 100644 --- a/src/ui/activities/setup/components/config.rs +++ b/src/ui/activities/setup/components/config.rs @@ -278,7 +278,7 @@ impl NotificationsThreshold { parse_bytesize(bytes).is_some() } fn char_valid(_input: &str, incoming: char) -> bool { - incoming.is_digit(10) || ['B', 'K', 'M', 'G', 'T', 'P'].contains(&incoming) + incoming.is_ascii_digit() || ['B', 'K', 'M', 'G', 'T', 'P'].contains(&incoming) } Self { component: Input::default() diff --git a/src/ui/activities/setup/mod.rs b/src/ui/activities/setup/mod.rs index 2b7c5b9..e0b9940 100644 --- a/src/ui/activities/setup/mod.rs +++ b/src/ui/activities/setup/mod.rs @@ -99,7 +99,7 @@ pub enum IdTheme { TransferTitle2, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Msg { Common(CommonMsg), Config(ConfigMsg), @@ -108,7 +108,7 @@ pub enum Msg { None, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum CommonMsg { ChangeLayout, CloseErrorPopup, @@ -125,7 +125,7 @@ pub enum CommonMsg { WindowResized, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum ConfigMsg { CheckUpdatesBlurDown, CheckUpdatesBlurUp, @@ -152,7 +152,7 @@ pub enum ConfigMsg { TextEditorBlurUp, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum SshMsg { CloseDelSshKeyPopup, CloseNewSshKeyPopup, @@ -165,7 +165,7 @@ pub enum SshMsg { SshUsernameBlur, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum ThemeMsg { AuthAddressBlurDown, AuthAddressBlurUp, @@ -230,7 +230,7 @@ const STORE_CONFIG_CHANGED: &str = "SETUP_CONFIG_CHANGED"; /// ### ViewLayout /// /// Current view layout -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] pub enum ViewLayout { SetupForm, SshKeys, diff --git a/src/utils/crypto.rs b/src/utils/crypto.rs index 62eaee5..6cc8b13 100644 --- a/src/utils/crypto.rs +++ b/src/utils/crypto.rs @@ -32,7 +32,7 @@ mod tests { fn test_utils_crypto_aes128() { let key: &str = "MYSUPERSECRETKEY"; let input: &str = "Hello world!"; - let secret: String = aes128_b64_crypt(&key, input); + let secret: String = aes128_b64_crypt(key, input); assert_eq!(secret.as_str(), "z4Z6LpcpYqBW4+bkIok+5A=="); assert_eq!( aes128_b64_decrypt(key, secret.as_str()) diff --git a/src/utils/fmt.rs b/src/utils/fmt.rs index 3822102..044bc64 100644 --- a/src/utils/fmt.rs +++ b/src/utils/fmt.rs @@ -300,7 +300,7 @@ mod tests { #[test] fn test_utils_fmt_time() { - let system_time: SystemTime = SystemTime::from(SystemTime::UNIX_EPOCH); + let system_time: SystemTime = SystemTime::UNIX_EPOCH; assert_eq!( fmt_time(system_time, "%Y-%m-%d"), String::from("1970-01-01") @@ -326,12 +326,12 @@ mod tests { #[test] #[cfg(target_family = "unix")] fn test_utils_fmt_path_elide() { - let p: &Path = &Path::new("/develop/pippo"); + let p: &Path = Path::new("/develop/pippo"); // Under max size assert_eq!(fmt_path_elide(p, 16), String::from("/develop/pippo")); // Above max size, only one ancestor assert_eq!(fmt_path_elide(p, 8), String::from("/develop/pippo")); - let p: &Path = &Path::new("/develop/pippo/foo/bar"); + let p: &Path = Path::new("/develop/pippo/foo/bar"); assert_eq!(fmt_path_elide(p, 16), String::from("/develop/…/foo/bar")); } diff --git a/src/utils/path.rs b/src/utils/path.rs index db6f36e..5c162be 100644 --- a/src/utils/path.rs +++ b/src/utils/path.rs @@ -94,11 +94,11 @@ mod test { #[test] fn absolutize_path() { assert_eq!( - absolutize(&Path::new("/home/omar"), &Path::new("readme.txt")).as_path(), + absolutize(Path::new("/home/omar"), Path::new("readme.txt")).as_path(), Path::new("/home/omar/readme.txt") ); assert_eq!( - absolutize(&Path::new("/home/omar"), &Path::new("/tmp/readme.txt")).as_path(), + absolutize(Path::new("/home/omar"), Path::new("/tmp/readme.txt")).as_path(), Path::new("/tmp/readme.txt") ); }