From f8e96150f81d20848b5285acd6b4ef95045a31d4 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Fri, 4 Jun 2021 00:49:06 +0200 Subject: [PATCH] fix clippy warnings and spelling * add some missing LICENSE headers --- src/uu/du/src/du.rs | 20 +++++++++++--------- src/uu/head/src/head.rs | 5 +++++ src/uu/head/src/parse.rs | 5 +++++ src/uu/od/src/od.rs | 2 +- src/uu/od/src/parse_nrofbytes.rs | 6 +++--- src/uu/sort/src/sort.rs | 2 +- src/uu/tail/src/tail.rs | 1 - src/uu/truncate/src/truncate.rs | 2 +- src/uucore/src/lib/lib.rs | 2 +- src/uucore/src/lib/parser/parse_size.rs | 4 +++- tests/by-util/test_du.rs | 5 +++++ tests/by-util/test_head.rs | 7 ++++++- tests/by-util/test_od.rs | 5 +++++ tests/by-util/test_sort.rs | 5 +++++ tests/by-util/test_split.rs | 5 +++++ tests/by-util/test_tail.rs | 7 +++++++ tests/by-util/test_truncate.rs | 7 +++++++ 17 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 25ef47af3..c2d764ebf 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -1,9 +1,9 @@ -// This file is part of the uutils coreutils package. -// -// (c) Derek Chiang -// -// For the full copyright and license information, please view the LICENSE -// file that was distributed with this source code. +// * This file is part of the uutils coreutils package. +// * +// * (c) Derek Chiang +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. #[macro_use] extern crate uucore; @@ -25,6 +25,8 @@ use std::os::unix::fs::MetadataExt; use std::os::windows::fs::MetadataExt; #[cfg(windows)] use std::os::windows::io::AsRawHandle; +#[cfg(windows)] +use std::path::Path; use std::path::PathBuf; use std::time::{Duration, UNIX_EPOCH}; use uucore::parse_size::{parse_size, ParseSizeError}; @@ -161,7 +163,7 @@ fn birth_u64(meta: &Metadata) -> Option { } #[cfg(windows)] -fn get_size_on_disk(path: &PathBuf) -> u64 { +fn get_size_on_disk(path: &Path) -> u64 { let mut size_on_disk = 0; // bind file so it stays in scope until end of function @@ -193,7 +195,7 @@ fn get_size_on_disk(path: &PathBuf) -> u64 { } #[cfg(windows)] -fn get_file_info(path: &PathBuf) -> Option { +fn get_file_info(path: &Path) -> Option { let mut result = None; let file = match fs::File::open(path) { @@ -709,7 +711,7 @@ Try '{} --help' for more information.", fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String { // NOTE: // GNU's du echos affected flag, -B or --block-size (-t or --threshold), depending user's selection - // GNU's du distinguishs between "invalid (suffix in) argument" + // GNU's du does distinguish between "invalid (suffix in) argument" match error { ParseSizeError::ParseFailure(_) => format!("invalid --{} argument '{}'", option, s), ParseSizeError::SizeTooBig(_) => format!("--{} argument '{}' too large", option, s), diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index d671ed665..2c13ed37d 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + // spell-checker:ignore (vars) zlines use clap::{crate_version, App, Arg}; diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index 6631dba0e..7e36594b5 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + use std::ffi::OsString; use uucore::parse_size::{parse_size, ParseSizeError}; diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 080630b71..1a592f622 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -643,7 +643,7 @@ fn open_input_peek_reader( fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String { // NOTE: // GNU's od echos affected flag, -N or --read-bytes (-j or --skip-bytes, etc.), depending user's selection - // GNU's od distinguishs between "invalid (suffix in) argument" + // GNU's od does distinguish between "invalid (suffix in) argument" match error { ParseSizeError::ParseFailure(_) => format!("invalid --{} argument '{}'", option, s), ParseSizeError::SizeTooBig(_) => format!("--{} argument '{}' too large", option, s), diff --git a/src/uu/od/src/parse_nrofbytes.rs b/src/uu/od/src/parse_nrofbytes.rs index e51e15d39..d6329c60a 100644 --- a/src/uu/od/src/parse_nrofbytes.rs +++ b/src/uu/od/src/parse_nrofbytes.rs @@ -71,7 +71,7 @@ pub fn parse_number_of_bytes(s: &str) -> Result { }; factor .checked_mul(multiply) - .ok_or(ParseSizeError::SizeTooBig(s.to_string())) + .ok_or_else(|| ParseSizeError::SizeTooBig(s.to_string())) } #[test] @@ -80,12 +80,12 @@ fn test_parse_number_of_bytes() { assert_eq!(8, parse_number_of_bytes("010").unwrap()); assert_eq!(8 * 512, parse_number_of_bytes("010b").unwrap()); assert_eq!(8 * 1024, parse_number_of_bytes("010k").unwrap()); - assert_eq!(8 * 1048576, parse_number_of_bytes("010m").unwrap()); + assert_eq!(8 * 1_048_576, parse_number_of_bytes("010m").unwrap()); // hex input assert_eq!(15, parse_number_of_bytes("0xf").unwrap()); assert_eq!(15, parse_number_of_bytes("0XF").unwrap()); assert_eq!(27, parse_number_of_bytes("0x1b").unwrap()); assert_eq!(16 * 1024, parse_number_of_bytes("0x10k").unwrap()); - assert_eq!(16 * 1048576, parse_number_of_bytes("0x10m").unwrap()); + assert_eq!(16 * 1_048_576, parse_number_of_bytes("0x10m").unwrap()); } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index fca974dbd..9ec90519f 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1567,7 +1567,7 @@ fn open(path: impl AsRef) -> Box { fn format_error_message(error: ParseSizeError, s: &str, option: &str) -> String { // NOTE: // GNU's sort echos affected flag, -S or --buffer-size, depending user's selection - // GNU's sort distinguishs between "invalid (suffix in) argument" + // GNU's sort does distinguish between "invalid (suffix in) argument" match error { ParseSizeError::ParseFailure(_) => format!("invalid --{} argument '{}'", option, s), ParseSizeError::SizeTooBig(_) => format!("--{} argument '{}' too large", option, s), diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 76c799621..75cc43db1 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -5,7 +5,6 @@ // * // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -// * // spell-checker:ignore (ToDO) seekable seek'd tail'ing ringbuffer ringbuf diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index 78167ed77..8f02be874 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "cannot stat '{}': No such file or directory", - reference.unwrap_or("".to_string()) + reference.unwrap_or_else(|| "".to_string()) ); // TODO: fix '--no-create' see test_reference and test_truncate_bytes_size } _ => crash!(1, "{}", e.to_string()), diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 84adeeb34..f765b7b3e 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -22,7 +22,7 @@ pub extern crate winapi; mod features; // feature-gated code modules mod macros; // crate macros (macro_rules-type; exported to `crate::...`) mod mods; // core cross-platform modules -mod parser; // string parsing moduls +mod parser; // string parsing modules // * cross-platform modules pub use crate::mods::backup_control; diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index 12c410e57..58213adef 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -3,6 +3,8 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. +// spell-checker:ignore (ToDO) hdsf ghead gtail + use std::convert::TryFrom; use std::error::Error; use std::fmt; @@ -77,7 +79,7 @@ pub fn parse_size(size: &str) -> Result { }; number .checked_mul(factor) - .ok_or(ParseSizeError::size_too_big(size)) + .ok_or_else(|| ParseSizeError::size_too_big(size)) } #[derive(Debug, PartialEq, Eq)] diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 2c656ced5..e4dd95ae1 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + // spell-checker:ignore (paths) sublink subwords use crate::common::util::*; diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index 6a2cdf1cd..2c4b66696 100755 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -1,4 +1,9 @@ -// spell-checker:ignore (words) bogusfile emptyfile +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + +// spell-checker:ignore (words) bogusfile emptyfile abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu use crate::common::util::*; diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index 3d34e47a1..53b471dba 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + extern crate unindent; use self::unindent::*; diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 204145719..3d1cfe120 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + // spell-checker:ignore (words) ints use crate::common::util::*; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 53b545200..a1350534f 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -1,3 +1,8 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + extern crate rand; extern crate regex; diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index c296e2763..8478944e2 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -1,3 +1,10 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + +// spell-checker:ignore (ToDO) abcdefghijklmnopqrstuvwxyz efghijklmnopqrstuvwxyz vwxyz emptyfile + extern crate tail; use crate::common::util::*; diff --git a/tests/by-util/test_truncate.rs b/tests/by-util/test_truncate.rs index 72f7f780b..2da59035e 100644 --- a/tests/by-util/test_truncate.rs +++ b/tests/by-util/test_truncate.rs @@ -1,3 +1,10 @@ +// * This file is part of the uutils coreutils package. +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. + +// spell-checker:ignore (words) RFILE + use crate::common::util::*; use std::io::{Seek, SeekFrom, Write};