From 21d6eab847f7cd579fd469245068ea0055903dd0 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:36:48 +0800 Subject: [PATCH 01/16] lint: fix lint `clippy::suspicious_open_options` --- src/uu/sort/src/sort.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 4d288c9404..01c87a0c1c 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -254,6 +254,7 @@ impl Output { let file = OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(name) .map_err(|e| SortError::OpenFailed { path: name.to_owned(), From 63d92cdbdad89c7aae26660c30d96be087549ea4 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:46:24 +0800 Subject: [PATCH 02/16] lint: fix `clippy::useless_vec` in `unit_tests.rs` --- src/uu/dd/src/parseargs/unit_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index c6ff990c3a..baeafdd56a 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -13,6 +13,7 @@ use crate::parseargs::Parser; use crate::StatusLevel; #[cfg(not(any(target_os = "linux", target_os = "android")))] +#[allow(clippy::useless_vec)] #[test] fn unimplemented_flags_should_error_non_linux() { let mut succeeded = Vec::new(); @@ -55,6 +56,7 @@ fn unimplemented_flags_should_error_non_linux() { } #[test] +#[allow(clippy::useless_vec)] fn unimplemented_flags_should_error() { let mut succeeded = Vec::new(); From 0bb179311dc3ccb54f7d54ed4e7b05c1d005ac4d Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:47:57 +0800 Subject: [PATCH 03/16] lint: fix `clippy::bool_assert_comparison` in `perms.rs` --- src/uucore/src/lib/features/perms.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 11bb0a8bb7..ede61abc83 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -660,8 +660,8 @@ mod tests { assert_eq!(path.to_str(), Some("")); // The main point to test here is that we don't crash. // The result should be 'false', to avoid unnecessary and confusing warnings. - assert_eq!(false, is_root(&path, false)); - assert_eq!(false, is_root(&path, true)); + assert!(!is_root(&path, false)); + assert!(!is_root(&path, true)); } #[cfg(unix)] @@ -675,8 +675,8 @@ mod tests { "cfg(unix) but using non-unix path delimiters?!" ); // Must return true, this is the main scenario that --preserve-root shall prevent. - assert_eq!(true, is_root(&path, false)); - assert_eq!(true, is_root(&path, true)); + assert!(is_root(&path, false)); + assert!(is_root(&path, true)); } #[cfg(unix)] @@ -697,8 +697,8 @@ mod tests { // chown: it is dangerous to operate recursively on 'slink-to-root/' (same as '/') // chown: use --no-preserve-root to override this failsafe // [$? = 1] - assert_eq!(true, is_root(&symlink_path_slash, false)); - assert_eq!(true, is_root(&symlink_path_slash, true)); + assert!(is_root(&symlink_path_slash, false)); + assert!(is_root(&symlink_path_slash, true)); } #[cfg(unix)] @@ -709,7 +709,7 @@ mod tests { let symlink_path = temp_dir.path().join("symlink"); unix::fs::symlink(&PathBuf::from("/"), &symlink_path).unwrap(); // Only return true we're about to "accidentally" recurse on "/". - assert_eq!(false, is_root(&symlink_path, false)); - assert_eq!(true, is_root(&symlink_path, true)); + assert!(!is_root(&symlink_path, false)); + assert!(is_root(&symlink_path, true)); } } From 72b7266f719aa99cc6c6a83e11dbcd0007a86793 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:50:23 +0800 Subject: [PATCH 04/16] lint: allow `clippy::needless_borrow` in `perms.rs` --- src/uucore/src/lib/features/perms.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index ede61abc83..54372f4957 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -664,6 +664,7 @@ mod tests { assert!(!is_root(&path, true)); } + #[allow(clippy::needless_borrow)] #[cfg(unix)] #[test] fn test_literal_root() { From b66d6dffcf6437da6d350c31d1991ff3cd58784d Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:53:32 +0800 Subject: [PATCH 05/16] lint: fix `clippy::needless_borrows_for_generic_args` in `perms.rs` --- src/uucore/src/lib/features/perms.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 54372f4957..c94b80b114 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -685,7 +685,7 @@ mod tests { fn test_symlink_slash() { let temp_dir = tempdir().unwrap(); let symlink_path = temp_dir.path().join("symlink"); - unix::fs::symlink(&PathBuf::from("/"), &symlink_path).unwrap(); + unix::fs::symlink(PathBuf::from("/"), &symlink_path).unwrap(); let symlink_path_slash = temp_dir.path().join("symlink/"); // Must return true, we're about to "accidentally" recurse on "/", // since "symlink/" always counts as an already-entered directory @@ -708,7 +708,7 @@ mod tests { // This covers both the commandline-argument case and the recursion case. let temp_dir = tempdir().unwrap(); let symlink_path = temp_dir.path().join("symlink"); - unix::fs::symlink(&PathBuf::from("/"), &symlink_path).unwrap(); + unix::fs::symlink(PathBuf::from("/"), &symlink_path).unwrap(); // Only return true we're about to "accidentally" recurse on "/". assert!(!is_root(&symlink_path, false)); assert!(is_root(&symlink_path, true)); From eb3fac3567b8308ddca398e0b4a1c3d01e6fc603 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:54:37 +0800 Subject: [PATCH 06/16] lint: fix `clippy::needless_borrows_for_generic_args` in `perms.rs` --- src/uucore/src/lib/features/perms.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index c94b80b114..880620c7ab 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -685,7 +685,7 @@ mod tests { fn test_symlink_slash() { let temp_dir = tempdir().unwrap(); let symlink_path = temp_dir.path().join("symlink"); - unix::fs::symlink(PathBuf::from("/"), &symlink_path).unwrap(); + unix::fs::symlink(PathBuf::from("/"), symlink_path).unwrap(); let symlink_path_slash = temp_dir.path().join("symlink/"); // Must return true, we're about to "accidentally" recurse on "/", // since "symlink/" always counts as an already-entered directory From ee09f276a42077edb41c8cc2d98e53dfd8f6067a Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:55:36 +0800 Subject: [PATCH 07/16] lint: fix `clippy::useless_format` in `test_cksum.rs` --- tests/by-util/test_cksum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 12c54d610a..9a4f7858e0 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -397,7 +397,7 @@ fn test_base64_multiple_files() { .arg("alice_in_wonderland.txt") .succeeds() .no_stderr() - .stdout_is_fixture_bytes(format!("base64/md5_multiple_files.expected")); + .stdout_is_fixture_bytes("base64/md5_multiple_files.expected".to_string()); } #[test] From fd3640482b58659e59ff652f031f6e3a2d0bc93c Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Thu, 21 Mar 2024 23:56:40 +0800 Subject: [PATCH 08/16] lint: fix `clippy::unnecessary_to_owned` in `test_cksum.rs` --- tests/by-util/test_cksum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 9a4f7858e0..818b7e7992 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -397,7 +397,7 @@ fn test_base64_multiple_files() { .arg("alice_in_wonderland.txt") .succeeds() .no_stderr() - .stdout_is_fixture_bytes("base64/md5_multiple_files.expected".to_string()); + .stdout_is_fixture_bytes("base64/md5_multiple_files.expected"); } #[test] From 2b5e7caf8bc635eb7e242da587d0d01f9911b1da Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Fri, 22 Mar 2024 00:02:04 +0800 Subject: [PATCH 09/16] lint: fix `clippy::manual_str_repeat` in `parse_glob.rs` --- src/uucore/src/lib/parser/parse_glob.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/parser/parse_glob.rs b/src/uucore/src/lib/parser/parse_glob.rs index a4e12f467a..100d2edf56 100644 --- a/src/uucore/src/lib/parser/parse_glob.rs +++ b/src/uucore/src/lib/parser/parse_glob.rs @@ -97,7 +97,7 @@ mod tests { // test that we don't look for closing square brackets unnecessarily // Verifies issue #5584 - let chars = std::iter::repeat("^[").take(174571).collect::(); + let chars = "^[".repeat(174571); assert_eq!(fix_negation(chars.as_str()), chars); } From 48e376e1e023f6b629a2f4166a279ceaac2d4123 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Fri, 22 Mar 2024 00:42:33 +0800 Subject: [PATCH 10/16] lint: allow `clippy::suspicious_open_options` in `sort.rs` --- src/uu/sort/src/sort.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 01c87a0c1c..75c0bed873 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -247,6 +247,7 @@ pub struct Output { } impl Output { + #[allow(clippy::suspicious_open_options)] fn new(name: Option<&str>) -> UResult { let file = if let Some(name) = name { // This is different from `File::create()` because we don't truncate the output yet. @@ -254,7 +255,6 @@ impl Output { let file = OpenOptions::new() .write(true) .create(true) - .truncate(true) .open(name) .map_err(|e| SortError::OpenFailed { path: name.to_owned(), From ef8c3793701a4261a070be84fa288147872981d3 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Fri, 22 Mar 2024 17:38:54 +0800 Subject: [PATCH 11/16] lint: fix `clippy::redundant_clone` of `test_dd.rs` `test_cp.rs` --- tests/by-util/test_cp.rs | 2 +- tests/by-util/test_dd.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index fc955db4c9..e3b373da19 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -3306,7 +3306,7 @@ fn test_symbolic_link_file() { #[test] fn test_src_base_dot() { let ts = TestScenario::new(util_name!()); - let at = ts.fixtures.clone(); + let at = &ts.fixtures; at.mkdir("x"); at.mkdir("y"); ts.ucmd() diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 213ab51384..a3b007909e 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -1641,7 +1641,7 @@ fn test_seek_past_dev() { fn test_reading_partial_blocks_from_fifo() { // Create the FIFO. let ts = TestScenario::new(util_name!()); - let at = ts.fixtures.clone(); + let at = &ts.fixtures; at.mkfifo("fifo"); let fifoname = at.plus_as_string("fifo"); @@ -1682,7 +1682,7 @@ fn test_reading_partial_blocks_from_fifo() { fn test_reading_partial_blocks_from_fifo_unbuffered() { // Create the FIFO. let ts = TestScenario::new(util_name!()); - let at = ts.fixtures.clone(); + let at = ts.fixtures; at.mkfifo("fifo"); let fifoname = at.plus_as_string("fifo"); From d21dc125d0eeb224f426acac2e6f7102e99460f6 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Sat, 23 Mar 2024 16:49:35 +0800 Subject: [PATCH 12/16] lint: fix `clippy::suspicious_open_options` of project. --- .clippy.toml | 2 +- src/uu/sort/src/sort.rs | 2 +- tests/by-util/test_env.rs | 1 + tests/common/random.rs | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 814e40b696..b1552463ed 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1,2 +1,2 @@ msrv = "1.70.0" -cognitive-complexity-threshold = 10 +cognitive-complexity-threshold = 24 diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 75c0bed873..07420d9c1d 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -247,11 +247,11 @@ pub struct Output { } impl Output { - #[allow(clippy::suspicious_open_options)] fn new(name: Option<&str>) -> UResult { let file = if let Some(name) = name { // This is different from `File::create()` because we don't truncate the output yet. // This allows using the output file as an input file. + #[allow(clippy::suspicious_open_options)] let file = OpenOptions::new() .write(true) .create(true) diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 28ba97ad66..13535e4161 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -445,6 +445,7 @@ macro_rules! compare_with_gnu { } #[test] +#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign fn test_env_with_gnu_reference_parsing_errors() { let ts = TestScenario::new(util_name!()); diff --git a/tests/common/random.rs b/tests/common/random.rs index 42b6eaa770..82a58578ee 100644 --- a/tests/common/random.rs +++ b/tests/common/random.rs @@ -208,6 +208,7 @@ mod tests { } #[test] + #[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign fn test_random_string_generate_with_delimiter_should_end_with_delimiter() { let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 1); assert_eq!(1, random_string.len()); @@ -251,6 +252,7 @@ mod tests { } #[test] + #[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign fn test_random_string_generate_with_delimiter_should_not_end_with_delimiter() { let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 1); assert_eq!(1, random_string.len()); From 1484d0688759033b6fc63538f4fa06288553db92 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Sat, 23 Mar 2024 16:56:43 +0800 Subject: [PATCH 13/16] lint: fix `clippy::manual_main_separator_str` for `util.rs` on Windows cfg. --- tests/common/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 1d9786bbef..81c9e16271 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1016,7 +1016,7 @@ impl AtPath { pub fn relative_symlink_file(&self, original: &str, link: &str) { #[cfg(windows)] - let original = original.replace('/', &MAIN_SEPARATOR.to_string()); + let original = original.replace('/', std::path::MAIN_SEPARATOR_STR); log_info( "symlink", format!("{},{}", &original, &self.plus_as_string(link)), @@ -1038,7 +1038,7 @@ impl AtPath { pub fn relative_symlink_dir(&self, original: &str, link: &str) { #[cfg(windows)] - let original = original.replace('/', &MAIN_SEPARATOR.to_string()); + let original = original.replace('/', std::path::MAIN_SEPARATOR_STR); log_info( "symlink", format!("{},{}", &original, &self.plus_as_string(link)), From 6f5dfa3c460f4cf25df221b22760cc805ad6d9be Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Sat, 23 Mar 2024 17:02:32 +0800 Subject: [PATCH 14/16] lint: fix `unused_imports` of `util.rs` --- tests/common/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 81c9e16271..6ec65ff7f3 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1016,7 +1016,7 @@ impl AtPath { pub fn relative_symlink_file(&self, original: &str, link: &str) { #[cfg(windows)] - let original = original.replace('/', std::path::MAIN_SEPARATOR_STR); + let original = original.replace('/', MAIN_SEPARATOR_STR); log_info( "symlink", format!("{},{}", &original, &self.plus_as_string(link)), @@ -1038,7 +1038,7 @@ impl AtPath { pub fn relative_symlink_dir(&self, original: &str, link: &str) { #[cfg(windows)] - let original = original.replace('/', std::path::MAIN_SEPARATOR_STR); + let original = original.replace('/', MAIN_SEPARATOR_STR); log_info( "symlink", format!("{},{}", &original, &self.plus_as_string(link)), From a61761f090351f797d622cee62bf7f0701b210f6 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Sat, 23 Mar 2024 17:13:07 +0800 Subject: [PATCH 15/16] util: fix compile failed on Windows. Use `std::path::MAIN_SEPARATOR_STR` instead of `std::path::MAIN_SEPARATOR` --- tests/common/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 6ec65ff7f3..19ef8317af 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -33,7 +33,7 @@ use std::os::unix::process::ExitStatusExt; #[cfg(windows)] use std::os::windows::fs::{symlink_dir, symlink_file}; #[cfg(windows)] -use std::path::MAIN_SEPARATOR; +use std::path::MAIN_SEPARATOR_STR; use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; From 29d14cba51dd13389987cbe0df7647c71f961a91 Mon Sep 17 00:00:00 2001 From: Krysztal112233 Date: Sat, 23 Mar 2024 17:23:22 +0800 Subject: [PATCH 16/16] lint: fix `unused_imports` on freebsd target. --- tests/by-util/test_touch.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index 50e2f4fe55..5910da7f8a 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -5,7 +5,9 @@ // spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime use crate::common::util::{AtPath, TestScenario}; -use filetime::{set_symlink_file_times, FileTime}; +#[cfg(not(target_os = "freebsd"))] +use filetime::set_symlink_file_times; +use filetime::FileTime; use std::fs::remove_file; use std::path::PathBuf;