diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..66d2a5f5a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +# https://pre-commit.com +repos: + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: cargo-check + - id: clippy + - id: fmt diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 4b0f19038..7c6a86b4c 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -9,10 +9,10 @@ extern crate uucore; use clap::{App, Arg}; +use retain_mut::RetainMut; use std::fs::OpenOptions; use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write}; use std::path::{Path, PathBuf}; -use retain_mut::RetainMut; #[cfg(unix)] use uucore::libc; @@ -98,19 +98,19 @@ fn tee(options: Options) -> Result<()> { .files .clone() .into_iter() - .map(|file| - NamedWriter { - name: file.clone(), - inner: open(file, options.append), - } - ) + .map(|file| NamedWriter { + name: file.clone(), + inner: open(file, options.append), + }) .collect(); - - writers.insert(0, NamedWriter { - name: "'standard output'".to_owned(), - inner: Box::new(stdout()), - }); + writers.insert( + 0, + NamedWriter { + name: "'standard output'".to_owned(), + inner: Box::new(stdout()), + }, + ); let mut output = MultiWriter::new(writers); let input = &mut NamedReader { @@ -119,8 +119,7 @@ fn tee(options: Options) -> Result<()> { // TODO: replaced generic 'copy' call to be able to stop copying // if all outputs are closed (due to errors) - if copy(input, &mut output).is_err() || output.flush().is_err() || - output.error_occured() { + if copy(input, &mut output).is_err() || output.flush().is_err() || output.error_occured() { Err(Error::new(ErrorKind::Other, "")) } else { Ok(()) @@ -150,7 +149,7 @@ struct MultiWriter { } impl MultiWriter { - fn new (writers: Vec) -> Self { + fn new(writers: Vec) -> Self { Self { initial_len: writers.len(), writers, @@ -170,7 +169,7 @@ impl Write for MultiWriter { show_info!("{}: {}", writer.name, f.to_string()); false } - _ => true + _ => true, } }); Ok(buf.len()) @@ -184,7 +183,7 @@ impl Write for MultiWriter { show_info!("{}: {}", writer.name, f.to_string()); false } - _ => true + _ => true, } }); Ok(()) diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index d01beccc2..3bc12f0b6 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -38,10 +38,7 @@ fn test_posix_mode() { // fail on long path new_ucmd!() - .args(&[ - "-p", - &"dir".repeat(libc::PATH_MAX as usize + 1).as_str(), - ]) + .args(&["-p", &"dir".repeat(libc::PATH_MAX as usize + 1).as_str()]) .fails() .no_stdout(); @@ -79,10 +76,7 @@ fn test_posix_special() { // fail on long path new_ucmd!() - .args(&[ - "-P", - &"dir".repeat(libc::PATH_MAX as usize + 1).as_str(), - ]) + .args(&["-P", &"dir".repeat(libc::PATH_MAX as usize + 1).as_str()]) .fails() .no_stdout(); @@ -107,7 +101,10 @@ fn test_posix_all() { // test the posix special mode // accept some reasonable default - new_ucmd!().args(&["-p", "-P", "dir/file"]).succeeds().no_stdout(); + new_ucmd!() + .args(&["-p", "-P", "dir/file"]) + .succeeds() + .no_stdout(); // accept non-leading hyphen new_ucmd!() @@ -136,10 +133,16 @@ fn test_posix_all() { .no_stdout(); // fail on non-portable chars - new_ucmd!().args(&["-p", "-P", "dir#/$file"]).fails().no_stdout(); + new_ucmd!() + .args(&["-p", "-P", "dir#/$file"]) + .fails() + .no_stdout(); // fail on leading hyphen char - new_ucmd!().args(&["-p", "-P", "dir/-file"]).fails().no_stdout(); + new_ucmd!() + .args(&["-p", "-P", "dir/-file"]) + .fails() + .no_stdout(); // fail on empty path new_ucmd!().args(&["-p", "-P", ""]).fails().no_stdout(); @@ -149,8 +152,5 @@ fn test_posix_all() { fn test_args_parsing() { // fail on no args let empty_args: [String; 0] = []; - new_ucmd!() - .args(&empty_args) - .fails() - .no_stdout(); -} \ No newline at end of file + new_ucmd!().args(&empty_args).fails().no_stdout(); +} diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 40cc6839a..149d509c5 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -177,7 +177,7 @@ fn test_rm_directory_without_flag() { let dir = "test_rm_directory_without_flag_dir"; at.mkdir(dir); - + let result = ucmd.arg(dir).fails(); println!("{}", result.stderr); assert!(result