mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #1001 from jbcrail/clippy-and-spelling
Fix clippy warnings and misspellings
This commit is contained in:
commit
0a60911cdf
24 changed files with 54 additions and 59 deletions
|
@ -137,7 +137,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
}
|
||||
|
||||
pub trait StrUtils {
|
||||
/// Remove comments and trim whitespaces
|
||||
/// Remove comments and trim whitespace
|
||||
fn purify(&self) -> &Self;
|
||||
/// Like split_whitespace() but only produce 2 components
|
||||
fn split_two(&self) -> (&str, &str);
|
||||
|
|
2
src/env/env.rs
vendored
2
src/env/env.rs
vendored
|
@ -63,7 +63,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let mut item = iter.next();
|
||||
|
||||
// the for loop doesn't work here,
|
||||
// because we need sometines to read 2 items forward,
|
||||
// because we need sometimes to read 2 items forward,
|
||||
// and the iter can't be borrowed twice
|
||||
while item != None {
|
||||
let opt = item.unwrap();
|
||||
|
|
|
@ -64,7 +64,7 @@ fn rho_pollard_find_divisor(num: u64) -> u64 {
|
|||
y = rho_pollard_pseudorandom_function(y, a, b, num);
|
||||
let d = gcd(num, max(x, y) - min(x, y));
|
||||
if d == num {
|
||||
// Failure, retry with diffrent function
|
||||
// Failure, retry with different function
|
||||
x = range.ind_sample(&mut rng);
|
||||
y = x;
|
||||
a = range.ind_sample(&mut rng);
|
||||
|
|
|
@ -332,7 +332,7 @@ impl<'a> Iterator for ParagraphStream<'a> {
|
|||
|
||||
// in tagged mode, add 4 spaces of additional indenting by default
|
||||
// (gnu fmt's behavior is different: it seems to find the closest column to
|
||||
// indent_end that is divisible by 3. But honesly that behavior seems
|
||||
// indent_end that is divisible by 3. But honestly that behavior seems
|
||||
// pretty arbitrary.
|
||||
// Perhaps a better default would be 1 TABWIDTH? But ugh that's so big.
|
||||
if self.opts.tagged {
|
||||
|
|
|
@ -94,7 +94,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
/// Build a specification of the comamnd line.
|
||||
/// Build a specification of the command line.
|
||||
///
|
||||
/// Returns a getopts::Options struct.
|
||||
///
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let mut opts = getopts::Options::new();
|
||||
|
||||
// Linux-specific options, not implemented
|
||||
// opts.optflag("Z", "context", "set SELinux secutiry context" +
|
||||
// opts.optflag("Z", "context", "set SELinux security context" +
|
||||
// " of each created directory to CTX"),
|
||||
opts.optopt("m", "mode", "set file mode", "755");
|
||||
opts.optflag("p", "parents", "make parent directories as needed");
|
||||
|
|
|
@ -214,7 +214,7 @@ fn exec(tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str, make_dir: bool
|
|||
println!("{}", tmpname);
|
||||
|
||||
// CAUTION: Not to call `drop` of tmpfile, which removes the tempfile,
|
||||
// I call a dengeros function `forget`.
|
||||
// I call a dangerous function `forget`.
|
||||
forget(tmpfile);
|
||||
|
||||
0
|
||||
|
|
|
@ -52,7 +52,7 @@ pub struct Settings {
|
|||
number_separator: String
|
||||
}
|
||||
|
||||
// NumberingStyle stores which lines are to be numberd.
|
||||
// NumberingStyle stores which lines are to be numbered.
|
||||
// The possible options are:
|
||||
// 1. Number all lines
|
||||
// 2. Number only nonempty lines
|
||||
|
|
|
@ -13,7 +13,7 @@ pub struct InputDecoder<'a, I> where I: 'a {
|
|||
|
||||
/// A memory buffer, it's size is set in `new`.
|
||||
data: Vec<u8>,
|
||||
/// The numer of bytes in the buffer reserved for the peek data from `PeekRead`.
|
||||
/// The number of bytes in the buffer reserved for the peek data from `PeekRead`.
|
||||
reserved_peek_length: usize,
|
||||
|
||||
/// The number of (valid) bytes in the buffer.
|
||||
|
|
|
@ -427,7 +427,7 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output
|
|||
/// returns a reader implementing `PeekRead + Read + HasError` providing the combined input
|
||||
///
|
||||
/// `skip_bytes` is the number of bytes skipped from the input
|
||||
/// `read_bytes` is an optinal limit to the number of bytes to read
|
||||
/// `read_bytes` is an optional limit to the number of bytes to read
|
||||
fn open_input_peek_reader<'a>(input_strings: &'a Vec<String>, skip_bytes: usize,
|
||||
read_bytes: Option<usize>) -> PeekReader<PartialReader<MultifileReader<'a>>> {
|
||||
// should return "impl PeekRead + Read + HasError" when supported in (stable) rust
|
||||
|
|
|
@ -92,7 +92,7 @@ impl OutputInfo {
|
|||
/// ```
|
||||
/// In this example is additional spacing before the first and third decimal number,
|
||||
/// and there is additional spacing before the 1st, 3rd, 5th and 7th hexadecimal number.
|
||||
/// This way both the octal and decimal, aswell the decimal and hexadecimal numbers
|
||||
/// This way both the octal and decimal, as well as the decimal and hexadecimal numbers
|
||||
/// left align. Note that the alignment below both octal numbers is identical.
|
||||
///
|
||||
/// This function calculates the required spacing for a single line, given the size
|
||||
|
@ -110,7 +110,7 @@ impl OutputInfo {
|
|||
/// If the blocksize is 8, and the size of the type is 2, the spacing will be
|
||||
/// spread across position 0, 2, 4, 6. All 4 positions will get an additional
|
||||
/// space as long as there are more then 4 spaces available. If there are 2
|
||||
/// spaces available, they will be assigend to position 0 and 4. If there is
|
||||
/// spaces available, they will be assigned to position 0 and 4. If there is
|
||||
/// 1 space available, it will be assigned to position 0. This will be combined,
|
||||
/// For example 7 spaces will be assigned to position 0, 2, 4, 6 like: 3, 1, 2, 1.
|
||||
/// And 7 spaces with 2 positions will be assigned to position 0 and 4 like 4, 3.
|
||||
|
|
|
@ -317,7 +317,7 @@ pub fn parse_format_flags_str(args_str: &Vec<&'static str>) -> Result<Vec<Format
|
|||
match parse_format_flags(&args) {
|
||||
Err(e) => Err(e),
|
||||
Ok(v) => {
|
||||
// tests using this function asume add_ascii_dump is not set
|
||||
// tests using this function assume add_ascii_dump is not set
|
||||
Ok(v.into_iter()
|
||||
.inspect(|f| assert!(!f.add_ascii_dump))
|
||||
.map(|f| f.formatter_item_info)
|
||||
|
|
|
@ -39,7 +39,7 @@ fn format_flo16(f: f16) -> String {
|
|||
}
|
||||
|
||||
// formats float with 8 significant digits, eg 12345678 or -1.2345678e+12
|
||||
// always retuns a string of 14 characters
|
||||
// always returns a string of 14 characters
|
||||
fn format_flo32(f: f32) -> String {
|
||||
let width: usize = 14;
|
||||
let precision: usize = 8;
|
||||
|
|
|
@ -33,7 +33,7 @@ enum Mode {
|
|||
static NAME: &'static str = "pathchk";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
// a few global constants as used in the GNU implememntation
|
||||
// a few global constants as used in the GNU implementation
|
||||
static POSIX_PATH_MAX: usize = 256;
|
||||
static POSIX_NAME_MAX: usize = 14;
|
||||
|
||||
|
@ -207,7 +207,7 @@ fn check_searchable(path: &String) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
// check for a hypthen at the beginning of a path segment
|
||||
// check for a hyphen at the beginning of a path segment
|
||||
fn no_leading_hyphen(path_segment: &String) -> bool {
|
||||
!path_segment.starts_with('-')
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Formatter for CninetyNineHexFloatf {
|
|||
|
||||
// c99 hex has unique requirements of all floating point subs in pretty much every part of building a primitive, from prefix and suffix to need for base conversion (in all other cases if you don't have decimal you must have decimal, here it's the other way around)
|
||||
|
||||
// on the todo list is to have a trait for get_primitive that is implemented by each float formatter and can override a default. when that happens we can take the parts of get_primitive_dec specific to dec and spin them out to their own functions that can be overriden.
|
||||
// on the todo list is to have a trait for get_primitive that is implemented by each float formatter and can override a default. when that happens we can take the parts of get_primitive_dec specific to dec and spin them out to their own functions that can be overridden.
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_assignments)]
|
||||
fn get_primitive_hex(inprefix: &InPrefix,
|
||||
|
@ -93,7 +93,7 @@ fn get_primitive_hex(inprefix: &InPrefix,
|
|||
// the addition or subtraction of 4 (2**4, because 4 bits in a hex digit)
|
||||
// to the exponent.
|
||||
// decimal's going to be a little more complicated. correct simulation
|
||||
// of glibc will require after-decimal division to a specified precisino.
|
||||
// of glibc will require after-decimal division to a specified precision.
|
||||
// the difficult part of this (arrnum_int_div_step) is already implemented.
|
||||
|
||||
// the hex float name may be a bit misleading in terms of how to go about the
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn warn_expected_numeric(pf_arg: &String) {
|
|||
cli::err_msg(&format!("{}: expected a numeric value", pf_arg));
|
||||
}
|
||||
|
||||
// when character costant arguments have excess characters
|
||||
// when character constant arguments have excess characters
|
||||
// issue a warning when POSIXLY_CORRECT is not set
|
||||
fn warn_char_constant_ign(remaining_bytes: Vec<u8>) {
|
||||
match env::var("POSIXLY_CORRECT") {
|
||||
|
|
|
@ -17,7 +17,7 @@ pub trait Token {
|
|||
// at a position in a format string, and sees whether
|
||||
// it can return a token of a type it knows how to produce
|
||||
// if so, return the token, move the iterator past the
|
||||
// format string text the token repsresents, and if an
|
||||
// format string text the token represents, and if an
|
||||
// argument is used move the argument iter forward one
|
||||
|
||||
// creating token of a format string segment should also cause
|
||||
|
|
|
@ -170,7 +170,7 @@ impl UnescapedText {
|
|||
|
||||
}
|
||||
|
||||
// take an iteratator to a string,
|
||||
// take an iterator to a string,
|
||||
// and return a wrapper around a Vec<u8> of unescaped bytes
|
||||
// break on encounter of sub symbol ('%[^%]') unless called
|
||||
// through %b subst.
|
||||
|
|
|
@ -321,13 +321,12 @@ impl AtPath {
|
|||
|
||||
pub fn cleanup(&self, path: &'static str) {
|
||||
let p = &self.plus(path);
|
||||
match fs::metadata(p) {
|
||||
Ok(m) => if m.is_file() {
|
||||
if let Ok(m) = fs::metadata(p) {
|
||||
if m.is_file() {
|
||||
fs::remove_file(&p).unwrap();
|
||||
} else {
|
||||
fs::remove_dir(&p).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,21 +375,20 @@ impl TestScenario {
|
|||
// directory, use Cargo's OUT_DIR to find path to executable.
|
||||
// This allows tests to be run using profiles other than debug.
|
||||
let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME);
|
||||
PathBuf::from(AtPath::new(&Path::new(&target_dir)).root_dir_resolved())
|
||||
PathBuf::from(AtPath::new(Path::new(&target_dir)).root_dir_resolved())
|
||||
},
|
||||
util_name: String::from(util_name),
|
||||
fixtures: AtPath::new(&tmpd.as_ref().path()),
|
||||
fixtures: AtPath::new(tmpd.as_ref().path()),
|
||||
tmpd: tmpd,
|
||||
};
|
||||
let mut fixture_path_builder = env::current_dir().unwrap();
|
||||
fixture_path_builder.push(TESTS_DIR);
|
||||
fixture_path_builder.push(FIXTURES_DIR);
|
||||
fixture_path_builder.push(util_name);
|
||||
match fs::metadata(&fixture_path_builder) {
|
||||
Ok(m) => if m.is_dir() {
|
||||
if let Ok(m) = fs::metadata(&fixture_path_builder) {
|
||||
if m.is_dir() {
|
||||
recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
ts
|
||||
}
|
||||
|
@ -418,7 +416,7 @@ impl TestScenario {
|
|||
}
|
||||
}
|
||||
|
||||
/// A UCommand is a wrapper around an individual Command that provides several additional features
|
||||
/// A `UCommand` is a wrapper around an individual Command that provides several additional features
|
||||
/// 1. it has convenience functions that are more ergonomic to use for piping in stdin, spawning the command
|
||||
/// and asserting on the results.
|
||||
/// 2. it tracks arguments provided so that in test cases which may provide variations of an arg in loops
|
||||
|
@ -542,7 +540,7 @@ impl UCommand {
|
|||
.unwrap_or_else(
|
||||
|| panic!(
|
||||
"Could not take child process stdin"))
|
||||
.write_all(&input)
|
||||
.write_all(input)
|
||||
.unwrap_or_else(|e| panic!("{}", e));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ fn test_output_multi_files_print_all_chars() {
|
|||
fn test_stdin_show_nonprinting() {
|
||||
for same_param in vec!["-v", "--show-nonprinting"] {
|
||||
new_ucmd!()
|
||||
.args(&vec![same_param])
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
.stdout_only("\t^@");
|
||||
|
|
|
@ -35,7 +35,7 @@ fn test_padding_with_overflow() {
|
|||
|
||||
#[test]
|
||||
fn test_sections_and_styles() {
|
||||
for &(fixture, output) in [("section.txt",
|
||||
for &(fixture, output) in &[("section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|
||||
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
|
||||
|
@ -44,7 +44,7 @@ fn test_sections_and_styles() {
|
|||
|\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \
|
||||
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|
||||
|Nonempty.\n")]
|
||||
.iter() {
|
||||
{
|
||||
new_ucmd!()
|
||||
.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture])
|
||||
.run()
|
||||
|
|
|
@ -16,8 +16,8 @@ static ALPHA_OUT: &'static str = "
|
|||
0000033
|
||||
";
|
||||
|
||||
// XXX We could do a better job of ensuring that we have a fresh temp dir to ourself,
|
||||
// not a general one ful of other proc's leftovers.
|
||||
// XXX We could do a better job of ensuring that we have a fresh temp dir to ourselves,
|
||||
// not a general one full of other proc's leftovers.
|
||||
|
||||
// Test that od can read one file and dump with default format
|
||||
#[test]
|
||||
|
@ -29,9 +29,8 @@ fn test_file() {
|
|||
|
||||
{
|
||||
let mut f = File::create(&file).unwrap();
|
||||
match f.write_all(b"abcdefghijklmnopqrstuvwxyz\n") {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,15 +51,14 @@ fn test_2files() {
|
|||
let file1 = tmpdir.join("test1");
|
||||
let file2 = tmpdir.join("test2");
|
||||
|
||||
for &(n,a) in [(1,"a"), (2,"b")].iter() {
|
||||
for &(n,a) in &[(1,"a"), (2,"b")] {
|
||||
println!("number: {} letter:{}", n, a);
|
||||
}
|
||||
|
||||
for &(path,data)in &[(&file1, "abcdefghijklmnop"),(&file2, "qrstuvwxyz\n")] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
match f.write_all(data.as_bytes()) {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +72,7 @@ fn test_2files() {
|
|||
let _ = remove_file(file2);
|
||||
}
|
||||
|
||||
// Test that od gives non-0 exit val for filename that dosen't exist.
|
||||
// Test that od gives non-0 exit val for filename that doesn't exist.
|
||||
#[test]
|
||||
fn test_no_file() {
|
||||
let temp = env::temp_dir();
|
||||
|
@ -108,9 +106,8 @@ fn test_from_mixed() {
|
|||
let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n");
|
||||
for &(path,data)in &[(&file1, data1),(&file3, data3)] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
match f.write_all(data.as_bytes()) {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Glob {
|
|||
let mut files = self.collect();
|
||||
files.sort();
|
||||
let mut data: Vec<u8> = vec![];
|
||||
for name in files.iter() {
|
||||
for name in &files {
|
||||
data.extend(self.directory.read(name).into_bytes());
|
||||
}
|
||||
data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue