From 0987a3ac903382d29158f1586d4455f320da6790 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Feb 2024 11:23:22 +0200 Subject: [PATCH] solved some clippy issues --- Cargo.toml | 2 +- README.md | 2 +- src/auth.rs | 12 ++++++------ src/commands.rs | 2 +- src/dependency_downloader.rs | 2 +- src/janitor.rs | 6 +++--- src/lock.rs | 8 ++++---- src/remote.rs | 16 ++++++++-------- src/utils.rs | 3 ++- src/versioning.rs | 8 ++++---- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d546acf..1840df0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soldeer" -version = "0.2.0" +version = "0.2.1" edition = "2021" authors = ["m4rio"] license = "MIT" diff --git a/README.md b/README.md index 19b2c78..83162bd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This project was started to solve the following issues: - github versioning of the releases is a pain and not all the projects are using it correctly -## Version 0.2.0 +## Version 0.2.1 ### WARNING diff --git a/src/auth.rs b/src/auth.rs index ce1c736..64ab824 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -38,9 +38,9 @@ pub async fn login() { print!("ℹ️ If you do not have an account, please go to soldeer.xyz to create one.\n📧 Please enter your email: "); std::io::stdout().flush().unwrap(); let mut email = String::new(); - match io::stdin().read_line(&mut email) { - Ok(_) => {} - Err(_) => {} + if io::stdin().read_line(&mut email).is_err() { + println!("Invalid email"); + exit(500); } email = email.trim().to_string().to_ascii_lowercase(); @@ -55,7 +55,7 @@ pub async fn login() { let login: Login = Login { email: email.unwrap().to_string(), - password: password, + password, }; let url = format!("{}/api/v1/auth/login", crate::BASE_URL); @@ -85,12 +85,12 @@ pub async fn login() { println!("Authentication failed. Invalid email or password"); exit(500); } - println!("Authentication failed. {}", response.status().to_string()); + println!("Authentication failed. {}", response.status()); exit(500); } } Err(error) => { - println!("Login failed with error {}", error.to_string()); + println!("Login failed {}", error); exit(500); } } diff --git a/src/commands.rs b/src/commands.rs index 9645b28..b2a7fd9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -57,7 +57,7 @@ pub struct Login {} #[derive(Debug, Clone, Parser)] #[clap( - about = "Push a dependency to the central repository. The PATH_TO_DEPENDENCY is optional and if not provided, the current directory will be used.", + about = "Push a dependency to the repository. The PATH_TO_DEPENDENCY is optional and if not provided, the current directory will be used. \nExample: If the directory is /home/soldeer/my_project and you do not specify the PATH_TO_DEPENDENCY, \nthe files inside the /home/soldeer/my_project will be pushed to the repository. \nIf you specify the PATH_TO_DEPENDENCY, the files inside the specified directory will be pushed to the repository. \nExample: soldeer push dependency~version /home/soldeer/my_project", after_help = "For more information, read the README.md", override_usage = "soldeer push ~ [PATH_TO_DEPENDENCY]" )] diff --git a/src/dependency_downloader.rs b/src/dependency_downloader.rs index 2e55bf2..92bc6f7 100644 --- a/src/dependency_downloader.rs +++ b/src/dependency_downloader.rs @@ -178,6 +178,6 @@ mod tests { assert!(result.is_ok()); let result: Result<(), MissingDependencies> = healthcheck_dependency("@openzeppelin-contracts", "2.3.0"); - assert!(!result.is_err()); + assert!(result.is_ok()); } } diff --git a/src/janitor.rs b/src/janitor.rs index 340e430..53a0f80 100644 --- a/src/janitor.rs +++ b/src/janitor.rs @@ -128,7 +128,7 @@ mod tests { let _ = unzip_dependency(&dependencies[0].name, &dependencies[0].version); let result: Result<(), MissingDependencies> = healthcheck_dependency("@openzeppelin-contracts", "2.3.0"); - assert!(!result.is_err()); + assert!(result.is_ok()); clean_dependency_directory(); } @@ -146,7 +146,7 @@ mod tests { let _ = unzip_dependency(&dependencies[0].name, &dependencies[0].version); let result: Result<(), MissingDependencies> = cleanup_dependency("@openzeppelin-contracts", "2.3.0"); - assert!(!result.is_err()); + assert!(result.is_ok()); clean_dependency_directory(); } @@ -183,7 +183,7 @@ mod tests { let _ = aw!(download_dependencies(&dependencies, false)); let _ = unzip_dependency(&dependencies[0].name, &dependencies[0].version); let result: Result<(), MissingDependencies> = cleanup_after(&dependencies); - assert!(!result.is_err()); + assert!(result.is_ok()); clean_dependency_directory(); } diff --git a/src/lock.rs b/src/lock.rs index fdef23c..98ae45c 100644 --- a/src/lock.rs +++ b/src/lock.rs @@ -130,7 +130,7 @@ fn sha256_digest(dependency_name: &str, dependency_version: &str) -> String { #[cfg(test)] fn sha256_digest(_dependency_name: &str, _dependency_version: &str) -> String { - return "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016".to_string(); + "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016".to_string() } #[derive(Debug, Clone)] @@ -177,7 +177,7 @@ version = "0.6.5" source = "registry+https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@prb-test~0.6.5.zip" checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016" "#; - File::create(&lock_file) + File::create(lock_file) .unwrap() .write_all(lock_contents.as_bytes()) .unwrap(); @@ -194,7 +194,7 @@ checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016" url: "https://github.com/mario-eth/soldeer-versions/raw/main/all_versions/@openzeppelin-contracts~2.3.0.zip".to_string(), }); let _result: Vec = lock_check(&dependencies).unwrap(); - assert_eq!(lock_file.exists(), false); + assert!(!lock_file.exists()); } #[test] @@ -234,7 +234,7 @@ checksum = "5019418b1e9128185398870f77a42e51d624c44315bb1572e7545be51d707016" assert_eq!(result.len(), 1); assert_eq!(result[0].name, "@openzeppelin-contracts"); assert_eq!(result[0].version, "2.4.0"); - fs::remove_file(&lock_file).unwrap(); + fs::remove_file(lock_file).unwrap(); } #[test] diff --git a/src/remote.rs b/src/remote.rs index 19c5b81..5f42cc6 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -27,23 +27,23 @@ pub async fn get_dependency_url_remote( match revision { Ok(revision) => { if revision.data.is_empty() { - println!("Dependency not found, please check the dependency name"); + println!("Dependency not found, please check the dependency name and version"); exit(500); } - return revision.data[0].clone().url; + revision.data[0].clone().url } Err(error) => { - println!("Error getting dependency {}", error.to_string()); + println!("Error getting dependency {}", error); exit(500); } } } else { - println!("Dependency not found, please check the dependency name"); + println!("Dependency not found, please check the dependency name and version"); exit(500); } } Err(error) => { - println!("Error getting dependency {}", error.to_string()); + println!("Error getting dependency {}", error); exit(500); } } @@ -69,10 +69,10 @@ pub async fn get_project_id(dependency_name: &String) -> String { println!("Project not found, please check the dependency name (project name) or create a new project on https://soldeer.xyz"); exit(500); } - return project.data[0].id.to_string(); + project.data[0].id.to_string() } Err(error) => { - println!("Error getting dependency {}", error.to_string()); + println!("Error getting dependency {}", error); exit(500); } } @@ -82,7 +82,7 @@ pub async fn get_project_id(dependency_name: &String) -> String { } } Err(error) => { - println!("Error getting dependency {}", error.to_string()); + println!("Error getting dependency {}", error); exit(500); } } diff --git a/src/utils.rs b/src/utils.rs index 7bc7d12..a026aaf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -50,9 +50,10 @@ pub fn read_file(path: String) -> Result, std::io::Error> { pub fn define_security_file_location() -> String { let custom_security_file = option_env!("SOLDEER_LOGIN_FILE"); if custom_security_file.is_some() - && custom_security_file.unwrap().len() > 0 + && !custom_security_file.unwrap().is_empty() && Path::new(custom_security_file.unwrap()).exists() { + #[allow(clippy::unnecessary_unwrap)] return String::from(custom_security_file.unwrap()); } let home = home_dir(); diff --git a/src/versioning.rs b/src/versioning.rs index 03b0cd0..66ffc8b 100644 --- a/src/versioning.rs +++ b/src/versioning.rs @@ -80,12 +80,12 @@ pub async fn push_version( } fn zip_file( - root_directory_path: &PathBuf, + root_directory_path: &Path, files_to_copy: &Vec, file_name: &String, ) -> Result { let zip_file_path = root_directory_path.join(file_name.to_owned() + ".zip"); - let file = File::create(&zip_file_path.to_str().unwrap()).unwrap(); + let file = File::create(zip_file_path.to_str().unwrap()).unwrap(); let mut zip = ZipWriter::new(file); let options = FileOptions::default().compression_method(CompressionMethod::DEFLATE); @@ -114,7 +114,7 @@ fn zip_file( Ok(zip_file_path) } -fn filter_filles_to_copy(root_directory_path: &PathBuf) -> Vec { +fn filter_filles_to_copy(root_directory_path: &Path) -> Vec { let ignore_files: Vec = read_ignore_file(); let root_directory: &str = &(root_directory_path.to_str().unwrap().to_owned() + "/"); @@ -167,7 +167,7 @@ fn read_ignore_file() -> Vec { } async fn push_to_repo( - zip_file: &PathBuf, + zip_file: &Path, dependency_name: String, dependency_version: String, ) -> Result<(), PushError> {