From a9abc4fed58f166d4e4997b0cad9ec996b595ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Wed, 14 Jun 2023 18:38:11 +0200 Subject: [PATCH] Refactor: Fixed various clippy errors It should be self evident from the diff what was changed and why. This is to prepare for the flake-ification of the project. --- src/git.rs | 2 +- src/main.rs | 14 ++++++++------ src/utils/dir.rs | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/git.rs b/src/git.rs index 7e1413e..325d6fc 100644 --- a/src/git.rs +++ b/src/git.rs @@ -71,7 +71,7 @@ impl Links { let tx_path: &Path = std::path::Path::new(&self.tx); let rx_path: &Path = std::path::Path::new(&self.rx); match rx_path.try_exists() { - Ok(true) => handle_file_exists(&self, &tx_path, &rx_path), + Ok(true) => handle_file_exists(self, tx_path, rx_path), Ok(false) if rx_path.is_symlink() => { error!( "Linking {} -> {} failed: broken symlink", diff --git a/src/main.rs b/src/main.rs index 5e5532d..efedea1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,9 +36,9 @@ fn main() { let args = Args::parse(); let config = Config::new(&args.config); match &args { - args if args.license == true => println!("{}", utils::strings::INTERACTIVE_LICENSE), - args if args.warranty == true => println!("{}", utils::strings::INTERACTIVE_WARRANTY), - args if args.code_of_conduct == true => unimplemented!(), + args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE), + args if args.warranty => println!("{}", utils::strings::INTERACTIVE_WARRANTY), + args if args.code_of_conduct => unimplemented!(), _ => (), } match &args.command { @@ -46,7 +46,7 @@ fn main() { config.link_all(); } Some(Commands::Quick { msg }) => { - config.quick(&msg.as_ref().get_or_insert(&"gg: quick commit".to_string())); + config.quick(msg.as_ref().get_or_insert(&"gg: quick commit".to_string())); } Some(Commands::Clone { msg: _ }) => { config.clone_all(); @@ -61,7 +61,7 @@ fn main() { config.commit_all(); } Some(Commands::CommitMsg { msg }) => { - config.commit_all_msg(&msg.as_ref().unwrap()); + config.commit_all_msg(msg.as_ref().unwrap()); } None => (), } @@ -116,7 +116,7 @@ mod config { let test_path = current_dir() + CONFIG_TEST; let mut file = File::create(&test_path).unwrap(); let contents = serde_yaml::to_string(&config).unwrap(); - file.write(&contents.as_bytes()).unwrap(); + file.write_all(contents.as_bytes()).unwrap(); let test_config = Config::new(&test_path); assert_eq!(config, test_config); @@ -127,6 +127,7 @@ mod config { let config_path = current_dir() + CONFIG_FILE; let config = Config::new(&config_path); // FIXME This is unnecessarily terse + #[allow(clippy::bool_assert_comparison)] { assert_eq!(config.repos[0].name, "gg"); assert_eq!(config.repos[0].path, "/home/ces/.dots/"); @@ -169,6 +170,7 @@ mod repo_actions { use std::process::Command; use utils::dir::current_dir; #[test] + #[allow(clippy::redundant_clone)] fn test_repo_actions() { let test_repo_name: String = "test".to_string(); let test_repo_dir: String = (current_dir() + "/tst/").to_string(); diff --git a/src/utils/dir.rs b/src/utils/dir.rs index 92c6889..b617c3f 100644 --- a/src/utils/dir.rs +++ b/src/utils/dir.rs @@ -41,13 +41,13 @@ pub fn home_dir() -> String { /// Changes working directory into a repository. /// /// WARNING: NOT THREAD SAFE -fn change_dir_repo(path: &String, name: &String) { +fn change_dir_repo(path: &str, name: &str) { let mut full_path: String = "".to_owned(); full_path.push_str(path); full_path.push_str(name); let root = Path::new(&full_path); println!("{}", root.display()); - assert!(env::set_current_dir(&root).is_ok()); + assert!(env::set_current_dir(root).is_ok()); debug!( "Successfully changed working directory to {}!", root.display() @@ -57,9 +57,9 @@ fn change_dir_repo(path: &String, name: &String) { /// Changes working directory to outside of the repo. /// /// WARNING: NOT THREAD SAFE -fn change_dir(path: &String) { +fn change_dir(path: &str) { let root = Path::new(path); - assert!(env::set_current_dir(&root).is_ok()); + assert!(env::set_current_dir(root).is_ok()); debug!( "Successfully changed working directory to {}!", root.display()