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/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(); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 4d288c9404..07420d9c1d 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -251,6 +251,7 @@ impl Output { 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/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 11bb0a8bb7..880620c7ab 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -660,10 +660,11 @@ 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)); } + #[allow(clippy::needless_borrow)] #[cfg(unix)] #[test] fn test_literal_root() { @@ -675,8 +676,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)] @@ -684,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 @@ -697,8 +698,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)] @@ -707,9 +708,9 @@ 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_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)); } } 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); } diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 12c54d610a..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(format!("base64/md5_multiple_files.expected")); + .stdout_is_fixture_bytes("base64/md5_multiple_files.expected"); } #[test] 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"); 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/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; 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()); diff --git a/tests/common/util.rs b/tests/common/util.rs index 1d9786bbef..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; @@ -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('/', 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('/', MAIN_SEPARATOR_STR); log_info( "symlink", format!("{},{}", &original, &self.plus_as_string(link)),