From 1a9e778b61f01ab6683681f52afb5f31027c2b27 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Wed, 2 Apr 2025 17:30:14 -0700 Subject: [PATCH 1/2] Format imports using Module granularity https://rust-lang.github.io/rustfmt/\?version\=v1.8.0\&search\=\#imports_granularity --- awk/src/interpreter/array.rs | 7 +++---- awk/src/interpreter/format.rs | 3 ++- awk/src/interpreter/io.rs | 13 ++++++------- awk/src/interpreter/string.rs | 4 +++- awk/src/program.rs | 3 ++- calc/bc.rs | 9 ++++----- calc/bc_util/interpreter.rs | 13 ++++++------- calc/bc_util/number.rs | 3 ++- datetime/tests/time/mod.rs | 6 ++---- dev/strip.rs | 13 ++++--------- display/more.rs | 9 ++++++++- display/printf.rs | 14 ++++++-------- file/magic.rs | 12 +++++------- file/tests/file/mod.rs | 3 ++- fs/df.rs | 4 +++- ftw/src/dir.rs | 18 ++++++++---------- ftw/src/lib.rs | 21 +++++++++------------ ftw/tests/integration.rs | 13 ++++++------- ftw/tests/integration2.rs | 10 ++++++++-- i18n/gencat.rs | 18 ++++++++---------- i18n/iconv.rs | 25 ++++++++++--------------- i18n/iconv_lib/ascii.rs | 3 ++- i18n/iconv_lib/utf_16.rs | 6 ++---- i18n/iconv_lib/utf_32.rs | 3 ++- i18n/iconv_lib/utf_8.rs | 3 ++- i18n/tests/gencat/mod.rs | 3 ++- i18n/tests/iconv/mod.rs | 3 ++- m4/build.rs | 10 ++++------ m4/src/input.rs | 10 ++++------ m4/src/lib.rs | 6 +++++- m4/src/macros/builtin.rs | 3 ++- m4/src/macros/eval.rs | 24 ++++++++++-------------- m4/src/macros/mod.rs | 8 +++----- m4/src/macros/trace.rs | 8 +++----- m4/src/macros/user_defined.rs | 6 ++---- m4/src/output.rs | 12 ++++++------ m4/src/state.rs | 19 +++++++++++-------- m4/test-manager/src/main.rs | 5 ++++- make/src/lib.rs | 12 ++++++------ make/src/main.rs | 11 +++++------ make/src/rule.rs | 25 ++++++++++--------------- make/src/signal_handler.rs | 3 ++- make/src/special_target.rs | 9 ++++----- make/tests/integration.rs | 6 ++++-- make/tests/parser.rs | 6 ++++-- process/batch.rs | 17 +++++++---------- process/env.rs | 3 +-- process/fuser.rs | 18 +++++++++--------- process/tests/fuser/basic.rs | 5 ++++- process/tests/fuser/tcp.rs | 8 +++----- process/tests/fuser/udp.rs | 4 +++- process/tests/fuser/unix.rs | 9 +++------ process/tests/fuser/with_user.rs | 5 ++++- process/tests/timeout/mod.rs | 10 ++++------ rustfmt.toml | 6 ++++++ sh/src/builtin/control_flow.rs | 3 +-- sh/src/builtin/kill.rs | 3 +-- sh/src/shell/mod.rs | 3 +-- text/diff.rs | 15 +++++++-------- text/diff_util/dir_data.rs | 12 +++++------- text/diff_util/dir_diff.rs | 14 +++++++++----- text/diff_util/file_data.rs | 7 ++++++- text/diff_util/file_diff.rs | 30 +++++++++++++----------------- text/diff_util/functions.rs | 10 ++++------ text/grep.rs | 12 +++++------- text/sed.rs | 18 ++++++++---------- text/sort.rs | 9 +++------ text/tests/diff-tests.rs | 5 ++++- text/tests/head/mod.rs | 15 ++++++++------- text/wc.rs | 10 ++++------ tree/chgrp.rs | 5 ++++- tree/chmod.rs | 4 +++- tree/common/mod.rs | 21 +++++++++------------ tree/ls.rs | 19 +++++++++---------- tree/ls_util/entry.rs | 16 ++++++---------- tree/mv.rs | 15 +++++++-------- tree/readlink.rs | 6 ++---- tree/rm.rs | 13 ++++++------- tree/tests/chgrp/mod.rs | 17 ++++++----------- tree/tests/chmod/mod.rs | 7 +++---- tree/tests/cp/mod.rs | 7 ++----- tree/tests/ls/mod.rs | 3 +-- tree/tests/mv/mod.rs | 7 ++----- tree/tests/rm/mod.rs | 6 ++---- tree/tests/tree-tests-umask.rs | 10 ++++------ users/newgrp.rs | 12 +++++------- users/talk.rs | 27 ++++++++++++--------------- users/write.rs | 3 +-- xform/tests/compress/mod.rs | 12 ++++-------- xform/tests/uue/mod.rs | 8 +++----- 90 files changed, 422 insertions(+), 472 deletions(-) create mode 100644 rustfmt.toml diff --git a/awk/src/interpreter/array.rs b/awk/src/interpreter/array.rs index 07b91d4f4..b2bbadf94 100644 --- a/awk/src/interpreter/array.rs +++ b/awk/src/interpreter/array.rs @@ -7,10 +7,9 @@ // SPDX-License-Identifier: MIT // -use std::{ - collections::{hash_map::Entry, HashMap}, - rc::Rc, -}; +use std::collections::hash_map::Entry; +use std::collections::HashMap; +use std::rc::Rc; use super::AwkValue; diff --git a/awk/src/interpreter/format.rs b/awk/src/interpreter/format.rs index 4ed673206..d4415a324 100644 --- a/awk/src/interpreter/format.rs +++ b/awk/src/interpreter/format.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{fmt::Write, str::Chars}; +use std::fmt::Write; +use std::str::Chars; const BASE_8_DIGITS: [char; 8] = ['0', '1', '2', '3', '4', '5', '6', '7']; const BASE_10_DIGITS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; diff --git a/awk/src/interpreter/io.rs b/awk/src/interpreter/io.rs index da70f376c..71933bd31 100644 --- a/awk/src/interpreter/io.rs +++ b/awk/src/interpreter/io.rs @@ -8,13 +8,12 @@ // use core::panic; -use std::{ - collections::{hash_map::Entry, HashMap}, - ffi::CString, - fs::File, - io::{BufReader, Bytes, Read, Write}, - rc::Rc, -}; +use std::collections::hash_map::Entry; +use std::collections::HashMap; +use std::ffi::CString; +use std::fs::File; +use std::io::{BufReader, Bytes, Read, Write}; +use std::rc::Rc; use super::string::AwkString; diff --git a/awk/src/interpreter/string.rs b/awk/src/interpreter/string.rs index ea8f49c58..9eafea979 100644 --- a/awk/src/interpreter/string.rs +++ b/awk/src/interpreter/string.rs @@ -8,7 +8,9 @@ // use core::fmt; -use std::{ffi::CString, ops::Deref, rc::Rc}; +use std::ffi::CString; +use std::ops::Deref; +use std::rc::Rc; #[cfg_attr(test, derive(Debug))] #[derive(Clone, PartialEq)] diff --git a/awk/src/program.rs b/awk/src/program.rs index b0efbd388..57c13c30a 100644 --- a/awk/src/program.rs +++ b/awk/src/program.rs @@ -8,7 +8,8 @@ // use crate::regex::Regex; -use std::{collections::HashMap, rc::Rc}; +use std::collections::HashMap; +use std::rc::Rc; pub type VarId = u32; diff --git a/calc/bc.rs b/calc/bc.rs index 399ff3a01..56952f648 100644 --- a/calc/bc.rs +++ b/calc/bc.rs @@ -9,14 +9,13 @@ use std::ffi::OsString; -use bc_util::{ - interpreter::{ExecutionResult, Interpreter}, - parser::parse_program, -}; +use bc_util::interpreter::{ExecutionResult, Interpreter}; +use bc_util::parser::parse_program; use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use rustyline::{error::ReadlineError, DefaultEditor, Result}; +use rustyline::error::ReadlineError; +use rustyline::{DefaultEditor, Result}; mod bc_util; diff --git a/calc/bc_util/interpreter.rs b/calc/bc_util/interpreter.rs index 72d83a584..7321565fa 100644 --- a/calc/bc_util/interpreter.rs +++ b/calc/bc_util/interpreter.rs @@ -7,17 +7,16 @@ // SPDX-License-Identifier: MIT // -use std::{fmt::Write, rc::Rc}; +use std::fmt::Write; +use std::rc::Rc; use crate::bc_util::instructions::Variable; -use super::{ - instructions::{ - BuiltinFunction, ConditionInstruction, ExprInstruction, Function, FunctionArgument, - NamedExpr, Program, Register, StmtInstruction, - }, - number::Number, +use super::instructions::{ + BuiltinFunction, ConditionInstruction, ExprInstruction, Function, FunctionArgument, NamedExpr, + Program, Register, StmtInstruction, }; +use super::number::Number; #[derive(Debug)] struct ErrorCall { diff --git a/calc/bc_util/number.rs b/calc/bc_util/number.rs index e18007409..3071b7256 100644 --- a/calc/bc_util/number.rs +++ b/calc/bc_util/number.rs @@ -1,4 +1,5 @@ -use bigdecimal::{num_bigint::BigInt, BigDecimal, Num, One, Signed, ToPrimitive, Zero}; +use bigdecimal::num_bigint::BigInt; +use bigdecimal::{BigDecimal, Num, One, Signed, ToPrimitive, Zero}; /// Converts a character to a number /// # Panics diff --git a/datetime/tests/time/mod.rs b/datetime/tests/time/mod.rs index 7d4b0e4b1..e2e8c0710 100644 --- a/datetime/tests/time/mod.rs +++ b/datetime/tests/time/mod.rs @@ -7,10 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{ - io::Write, - process::{Command, Output, Stdio}, -}; +use std::io::Write; +use std::process::{Command, Output, Stdio}; use plib::testing::TestPlan; diff --git a/dev/strip.rs b/dev/strip.rs index be1ec6c4c..a3d228757 100644 --- a/dev/strip.rs +++ b/dev/strip.rs @@ -9,15 +9,10 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use object::{ - archive, - build::elf::{Builder, Section, SectionData}, - elf, -}; -use std::{ - ffi::{OsStr, OsString}, - io::Read, -}; +use object::build::elf::{Builder, Section, SectionData}; +use object::{archive, elf}; +use std::ffi::{OsStr, OsString}; +use std::io::Read; #[derive(Parser)] #[command(version, about = gettext("strip - remove unnecessary information from strippable files"))] diff --git a/display/more.rs b/display/more.rs index ff6b606ac..e1397bfde 100644 --- a/display/more.rs +++ b/display/more.rs @@ -25,7 +25,14 @@ use std::str::FromStr; use std::sync::mpsc::{channel, Receiver, TryRecvError}; use std::sync::Mutex; use std::time::Duration; -use termion::{clear::*, cursor::*, event::*, input::*, raw::*, screen::*, style::*, *}; +use termion::clear::*; +use termion::cursor::*; +use termion::event::*; +use termion::input::*; +use termion::raw::*; +use termion::screen::*; +use termion::style::*; +use termion::*; const LINES_PER_PAGE: u16 = 24; const NUM_COLUMNS: u16 = 80; diff --git a/display/printf.rs b/display/printf.rs index bb9112952..422d9a95d 100644 --- a/display/printf.rs +++ b/display/printf.rs @@ -12,14 +12,12 @@ // use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use std::{ - error::Error, - io::{self, Write}, - iter::Peekable, - os::unix::ffi::OsStrExt, - process::ExitCode, - slice::Iter, -}; +use std::error::Error; +use std::io::{self, Write}; +use std::iter::Peekable; +use std::os::unix::ffi::OsStrExt; +use std::process::ExitCode; +use std::slice::Iter; // the following structure is a printf format conversion specifier struct ConvSpec { diff --git a/file/magic.rs b/file/magic.rs index 2b29fa8ea..019575687 100644 --- a/file/magic.rs +++ b/file/magic.rs @@ -8,13 +8,11 @@ // use regex::Regex; -use std::{ - error::Error, - fmt, - fs::File, - io::{self, BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom}, - path::PathBuf, -}; +use std::error::Error; +use std::fmt; +use std::fs::File; +use std::io::{self, BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom}; +use std::path::PathBuf; #[cfg(target_os = "macos")] /// Default raw (text based) magic file diff --git a/file/tests/file/mod.rs b/file/tests/file/mod.rs index 5a9f7ba79..6b4958952 100644 --- a/file/tests/file/mod.rs +++ b/file/tests/file/mod.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{env, path::PathBuf}; +use std::env; +use std::path::PathBuf; use plib::testing::{run_test, TestPlan}; diff --git a/fs/df.rs b/fs/df.rs index 76e14246f..687e2017f 100644 --- a/fs/df.rs +++ b/fs/df.rs @@ -17,7 +17,9 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; #[cfg(target_os = "macos")] use std::ffi::CStr; -use std::{cmp, ffi::CString, fmt::Display, io}; +use std::ffi::CString; +use std::fmt::Display; +use std::{cmp, io}; #[derive(Parser)] #[command(version, about = gettext("df - report free storage space"))] diff --git a/ftw/src/dir.rs b/ftw/src/dir.rs index 991b1b462..d17f5b875 100644 --- a/ftw/src/dir.rs +++ b/ftw/src/dir.rs @@ -1,14 +1,12 @@ use crate::{open_long_filename, Error, ErrorKind, FileDescriptor}; -use std::{ - cell::{RefCell, RefMut}, - collections::HashSet, - ffi::{CStr, CString}, - io, - marker::PhantomData, - os::unix::ffi::OsStrExt as _, - path::PathBuf, - rc::Rc, -}; +use std::cell::{RefCell, RefMut}; +use std::collections::HashSet; +use std::ffi::{CStr, CString}; +use std::io; +use std::marker::PhantomData; +use std::os::unix::ffi::OsStrExt as _; +use std::path::PathBuf; +use std::rc::Rc; // Not to be used publically. The public interface for a directory entry is `Entry`. pub struct EntryInternal<'a> { diff --git a/ftw/src/lib.rs b/ftw/src/lib.rs index 50b5dc222..ff95b2f26 100644 --- a/ftw/src/lib.rs +++ b/ftw/src/lib.rs @@ -1,18 +1,15 @@ mod dir; use dir::{DeferredDir, HybridDir, OwnedDir}; -use std::{ - ffi::{CStr, CString, OsStr}, - fmt, io, - mem::MaybeUninit, - ops::Deref, - os::{ - fd::{AsRawFd, RawFd}, - unix::{self, ffi::OsStrExt}, - }, - path::{Path, PathBuf}, - rc::Rc, -}; +use std::ffi::{CStr, CString, OsStr}; +use std::mem::MaybeUninit; +use std::ops::Deref; +use std::os::fd::{AsRawFd, RawFd}; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::{self}; +use std::path::{Path, PathBuf}; +use std::rc::Rc; +use std::{fmt, io}; /// Type of error to be handled by the `err_reporter` of `traverse_directory`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/ftw/tests/integration.rs b/ftw/tests/integration.rs index bb8d1ce91..e912d3f19 100644 --- a/ftw/tests/integration.rs +++ b/ftw/tests/integration.rs @@ -1,10 +1,9 @@ -use std::{ - collections::HashSet, - ffi::CString, - fs, io, - os::{fd::AsRawFd, unix}, - path::{Path, PathBuf}, -}; +use std::collections::HashSet; +use std::ffi::CString; +use std::os::fd::AsRawFd; +use std::os::unix; +use std::path::{Path, PathBuf}; +use std::{fs, io}; const DIR_HIERARCHY_DEPTH: usize = 300; diff --git a/ftw/tests/integration2.rs b/ftw/tests/integration2.rs index 465437327..0a5cb50d6 100644 --- a/ftw/tests/integration2.rs +++ b/ftw/tests/integration2.rs @@ -1,5 +1,11 @@ -use rand::{distributions::Standard, rngs::StdRng, Rng, SeedableRng}; -use std::{ffi::CString, fs, io, os::fd::AsRawFd, path::Path, path::PathBuf, sync::Mutex}; +use rand::distributions::Standard; +use rand::rngs::StdRng; +use rand::{Rng, SeedableRng}; +use std::ffi::CString; +use std::os::fd::AsRawFd; +use std::path::{Path, PathBuf}; +use std::sync::Mutex; +use std::{fs, io}; static GLOBAL_MUTEX: Mutex<()> = Mutex::new(()); diff --git a/i18n/gencat.rs b/i18n/gencat.rs index a796cf56b..3c17d888c 100644 --- a/i18n/gencat.rs +++ b/i18n/gencat.rs @@ -2,16 +2,14 @@ use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian, WriteBytesExt} use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use plib::io::input_stream; -use std::{ - cell::RefCell, - collections::BTreeMap, - fmt::Display, - fs::File, - io::{self, Cursor, Read, Seek, Write}, - num::ParseIntError, - path::PathBuf, - rc::Rc, -}; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::fmt::Display; +use std::fs::File; +use std::io::{self, Cursor, Read, Seek, Write}; +use std::num::ParseIntError; +use std::path::PathBuf; +use std::rc::Rc; const NL_SETMAX: u32 = 255; //max set number(the limits.h defines it and is mentioned in POSIX specification) const NL_SETD: u32 = 1; // the default set number for the messages that are not in any set diff --git a/i18n/iconv.rs b/i18n/iconv.rs index b1e3c3c10..6982aec3b 100644 --- a/i18n/iconv.rs +++ b/i18n/iconv.rs @@ -9,22 +9,17 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use iconv_lib::{ - ascii, - utf_16::{self, UTF16Variant}, - utf_32::{self, UTF32Variant}, - utf_8, -}; +use iconv_lib::utf_16::{self, UTF16Variant}; +use iconv_lib::utf_32::{self, UTF32Variant}; +use iconv_lib::{ascii, utf_8}; use plib::io::input_stream; -use std::{ - collections::HashMap, - env, - fs::File, - io::{self, BufRead, BufReader, Read, Write}, - path::{Path, PathBuf}, - process::exit, - str::FromStr, -}; +use std::collections::HashMap; +use std::env; +use std::fs::File; +use std::io::{self, BufRead, BufReader, Read, Write}; +use std::path::{Path, PathBuf}; +use std::process::exit; +use std::str::FromStr; use strum::IntoEnumIterator; use strum_macros::{Display, EnumIter, EnumString}; diff --git a/i18n/iconv_lib/ascii.rs b/i18n/iconv_lib/ascii.rs index 675cf5381..ec1e79449 100644 --- a/i18n/iconv_lib/ascii.rs +++ b/i18n/iconv_lib/ascii.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{iter, process::exit}; +use std::iter; +use std::process::exit; // Convert ASCII to UCS-4 pub fn to_ucs4 + 'static>( diff --git a/i18n/iconv_lib/utf_16.rs b/i18n/iconv_lib/utf_16.rs index d3f498fe1..03ee26535 100644 --- a/i18n/iconv_lib/utf_16.rs +++ b/i18n/iconv_lib/utf_16.rs @@ -8,10 +8,8 @@ // use byteorder::{BigEndian, ByteOrder, LittleEndian}; -use std::{ - iter::{self}, - process::exit, -}; +use std::iter::{self}; +use std::process::exit; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UTF16Variant { diff --git a/i18n/iconv_lib/utf_32.rs b/i18n/iconv_lib/utf_32.rs index f1dec4c95..f4ffacd7b 100644 --- a/i18n/iconv_lib/utf_32.rs +++ b/i18n/iconv_lib/utf_32.rs @@ -8,7 +8,8 @@ // use byteorder::{BigEndian, ByteOrder, LittleEndian}; -use std::{iter, process::exit}; +use std::iter; +use std::process::exit; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UTF32Variant { diff --git a/i18n/iconv_lib/utf_8.rs b/i18n/iconv_lib/utf_8.rs index 17e1543e2..a3a612a0d 100644 --- a/i18n/iconv_lib/utf_8.rs +++ b/i18n/iconv_lib/utf_8.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{iter, process::exit}; +use std::iter; +use std::process::exit; /// Convert UTF-8 to UCS-4 pub fn to_ucs4 + 'static>( diff --git a/i18n/tests/gencat/mod.rs b/i18n/tests/gencat/mod.rs index 5c4fbf0ae..b91ea591c 100644 --- a/i18n/tests/gencat/mod.rs +++ b/i18n/tests/gencat/mod.rs @@ -9,8 +9,9 @@ use plib::testing::{run_test_u8, TestPlanU8}; use std::env; +use std::fs::File; +use std::io::Read; use std::path::PathBuf; -use std::{fs::File, io::Read}; fn gencat_test(args: &[&str], expected_output: Vec, expected_error: Vec) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/i18n/tests/iconv/mod.rs b/i18n/tests/iconv/mod.rs index 47b63ca70..7e9d17905 100644 --- a/i18n/tests/iconv/mod.rs +++ b/i18n/tests/iconv/mod.rs @@ -10,8 +10,9 @@ #![allow(non_snake_case)] use plib::testing::{run_test_u8, TestPlanU8}; use std::env; +use std::fs::File; +use std::io::Read; use std::path::PathBuf; -use std::{fs::File, io::Read}; fn iconv_test(args: &[&str], input: Vec, expected_output: Vec, expected_error: Vec) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/m4/build.rs b/m4/build.rs index 4a767b2ca..898e9687b 100644 --- a/m4/build.rs +++ b/m4/build.rs @@ -1,9 +1,7 @@ -use std::{ - collections::BTreeMap, - fs::read_dir, - os::unix::ffi::OsStrExt, - path::{Path, PathBuf}, -}; +use std::collections::BTreeMap; +use std::fs::read_dir; +use std::os::unix::ffi::OsStrExt; +use std::path::{Path, PathBuf}; use m4_test_manager::TestSnapshot; diff --git a/m4/src/input.rs b/m4/src/input.rs index 1d77535c9..842982eef 100644 --- a/m4/src/input.rs +++ b/m4/src/input.rs @@ -1,9 +1,7 @@ -use std::{ - cell::RefCell, - io::{Read, Write}, - path::PathBuf, - rc::Rc, -}; +use std::cell::RefCell; +use std::io::{Read, Write}; +use std::path::PathBuf; +use std::rc::Rc; use crate::EOF; diff --git a/m4/src/lib.rs b/m4/src/lib.rs index eb4ff4dcd..9ec433c33 100644 --- a/m4/src/lib.rs +++ b/m4/src/lib.rs @@ -3,7 +3,11 @@ use input::{Input, InputRead}; use lexer::MacroName; use macros::MacroDefinition; use state::State; -use std::{cell::RefCell, ffi::OsStr, io::Write, path::PathBuf, rc::Rc}; +use std::cell::RefCell; +use std::ffi::OsStr; +use std::io::Write; +use std::path::PathBuf; +use std::rc::Rc; pub mod error; mod input; diff --git a/m4/src/macros/builtin.rs b/m4/src/macros/builtin.rs index 22b492843..352712700 100644 --- a/m4/src/macros/builtin.rs +++ b/m4/src/macros/builtin.rs @@ -1,8 +1,9 @@ use std::ffi::{OsStr, OsString}; +use std::io::Write; use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::path::PathBuf; use std::process::ExitStatus; -use std::{io::Write, rc::Rc}; +use std::rc::Rc; use super::eval::parse_integer; use super::{MacroDefinitionImplementation, MacroImplementation}; diff --git a/m4/src/macros/eval.rs b/m4/src/macros/eval.rs index 4368361fb..90d4336bc 100644 --- a/m4/src/macros/eval.rs +++ b/m4/src/macros/eval.rs @@ -1,20 +1,16 @@ use std::io::Write; -use nom::{ - branch::alt, - bytes::complete::{tag, take_while}, - combinator::fail, - error::FromExternalError, - sequence::{delimited, tuple}, - IResult, -}; +use nom::branch::alt; +use nom::bytes::complete::{tag, take_while}; +use nom::combinator::fail; +use nom::error::FromExternalError; +use nom::sequence::{delimited, tuple}; +use nom::IResult; -use crate::{ - lexer::is_whitespace, - precedence::{self, binary_op, unary_op, Assoc, Operation}, - state::{StackFrame, State}, - Result, -}; +use crate::lexer::is_whitespace; +use crate::precedence::{self, binary_op, unary_op, Assoc, Operation}; +use crate::state::{StackFrame, State}; +use crate::Result; use super::MacroImplementation; diff --git a/m4/src/macros/mod.rs b/m4/src/macros/mod.rs index 683f5da03..fcef2de15 100644 --- a/m4/src/macros/mod.rs +++ b/m4/src/macros/mod.rs @@ -10,11 +10,9 @@ use eval::EvalMacro; use trace::{TraceoffMacro, TraceonMacro}; use user_defined::UserDefinedMacro; -use crate::{ - lexer::{MacroName, MacroParseConfig}, - state::{StackFrame, State}, - Result, -}; +use crate::lexer::{MacroName, MacroParseConfig}; +use crate::state::{StackFrame, State}; +use crate::Result; macro_rules! macro_enums { ( diff --git a/m4/src/macros/trace.rs b/m4/src/macros/trace.rs index 0cad52461..cb5c80e9e 100644 --- a/m4/src/macros/trace.rs +++ b/m4/src/macros/trace.rs @@ -1,10 +1,8 @@ use std::io::Write; -use crate::{ - lexer::MacroName, - state::{StackFrame, State}, - Result, -}; +use crate::lexer::MacroName; +use crate::state::{StackFrame, State}; +use crate::Result; use super::MacroImplementation; diff --git a/m4/src/macros/user_defined.rs b/m4/src/macros/user_defined.rs index efe702833..438823d0c 100644 --- a/m4/src/macros/user_defined.rs +++ b/m4/src/macros/user_defined.rs @@ -1,9 +1,7 @@ use std::io::Write; -use crate::{ - state::{StackFrame, State}, - Result, -}; +use crate::state::{StackFrame, State}; +use crate::Result; use super::MacroImplementation; diff --git a/m4/src/output.rs b/m4/src/output.rs index 8f4a1dda3..3da5235fd 100644 --- a/m4/src/output.rs +++ b/m4/src/output.rs @@ -1,9 +1,9 @@ -use crate::{error::Result, input::InputStateRef, state::StackFrame}; -use std::{ - cell::RefCell, - io::{Seek, Write}, - rc::Rc, -}; +use crate::error::Result; +use crate::input::InputStateRef; +use crate::state::StackFrame; +use std::cell::RefCell; +use std::io::{Seek, Write}; +use std::rc::Rc; #[derive(Default)] pub struct OutputState { diff --git a/m4/src/state.rs b/m4/src/state.rs index 39450e5b0..ed0bca0ee 100644 --- a/m4/src/state.rs +++ b/m4/src/state.rs @@ -1,12 +1,15 @@ -use std::{cell::RefCell, collections::HashMap, io::Write, process::ExitStatus, rc::Rc}; +use std::cell::RefCell; +use std::collections::HashMap; +use std::io::Write; +use std::process::ExitStatus; +use std::rc::Rc; -use crate::{ - input::{Input, InputState, InputStateRef}, - lexer::{is_alphnumeric, MacroName, ParseConfig}, - macros::{trace::Trace, BuiltinMacro, MacroDefinition}, - output::{Output, OutputState}, - EOF, -}; +use crate::input::{Input, InputState, InputStateRef}; +use crate::lexer::{is_alphnumeric, MacroName, ParseConfig}; +use crate::macros::trace::Trace; +use crate::macros::{BuiltinMacro, MacroDefinition}; +use crate::output::{Output, OutputState}; +use crate::EOF; pub struct State { pub macro_definitions: HashMap>>, diff --git a/m4/test-manager/src/main.rs b/m4/test-manager/src/main.rs index 5f35924aa..bf98acc73 100644 --- a/m4/test-manager/src/main.rs +++ b/m4/test-manager/src/main.rs @@ -1,4 +1,7 @@ -use std::{io::Write, os::unix::ffi::OsStrExt, path::PathBuf, process::Stdio}; +use std::io::Write; +use std::os::unix::ffi::OsStrExt; +use std::path::PathBuf; +use std::process::Stdio; use clap::Parser; use m4_test_manager::TestSnapshot; diff --git a/make/src/lib.rs b/make/src/lib.rs index 74abb027c..811393a88 100644 --- a/make/src/lib.rs +++ b/make/src/lib.rs @@ -14,18 +14,18 @@ pub mod rule; pub mod signal_handler; pub mod special_target; -use std::{ - collections::HashSet, - fs::{self}, - time::SystemTime, -}; +use std::collections::HashSet; +use std::fs::{self}; +use std::time::SystemTime; use parser::{Makefile, VariableDefinition}; use crate::special_target::InferenceTarget; use config::Config; use error_code::ErrorCode::{self, *}; -use rule::{prerequisite::Prerequisite, target::Target, Rule}; +use rule::prerequisite::Prerequisite; +use rule::target::Target; +use rule::Rule; use special_target::SpecialTarget; /// The default shell variable name. diff --git a/make/src/main.rs b/make/src/main.rs index f4eaa4abe..6a9795b18 100644 --- a/make/src/main.rs +++ b/make/src/main.rs @@ -19,12 +19,11 @@ use clap::Parser; use const_format::formatcp; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use posixutils_make::{ - config::Config, - error_code::ErrorCode::{self, *}, - parser::{preprocessor::ENV_MACROS, Makefile}, - Make, -}; +use posixutils_make::config::Config; +use posixutils_make::error_code::ErrorCode::{self, *}; +use posixutils_make::parser::preprocessor::ENV_MACROS; +use posixutils_make::parser::Makefile; +use posixutils_make::Make; const MAKEFILE_NAME: [&str; 2] = ["makefile", "Makefile"]; const MAKEFILE_PATH: [&str; 2] = [ diff --git a/make/src/rule.rs b/make/src/rule.rs index fe25cb045..a28b6915f 100644 --- a/make/src/rule.rs +++ b/make/src/rule.rs @@ -12,28 +12,23 @@ pub mod prerequisite; pub mod recipe; pub mod target; -use crate::{ - config::Config as GlobalConfig, - error_code::ErrorCode::{self, *}, - parser::{Rule as ParsedRule, VariableDefinition}, - signal_handler, DEFAULT_SHELL, DEFAULT_SHELL_VAR, -}; +use crate::config::Config as GlobalConfig; +use crate::error_code::ErrorCode::{self, *}; +use crate::parser::{Rule as ParsedRule, VariableDefinition}; +use crate::{signal_handler, DEFAULT_SHELL, DEFAULT_SHELL_VAR}; use config::Config; use gettextrs::gettext; use prerequisite::Prerequisite; use recipe::config::Config as RecipeConfig; use recipe::Recipe; -use std::collections::VecDeque; +use std::collections::{HashMap, VecDeque}; +use std::env; +use std::fs::{File, FileTimes}; use std::io::ErrorKind; use std::path::PathBuf; -use std::{ - collections::HashMap, - env, - fs::{File, FileTimes}, - process::{self, Command}, - sync::{Arc, LazyLock, Mutex}, - time::SystemTime, -}; +use std::process::{self, Command}; +use std::sync::{Arc, LazyLock, Mutex}; +use std::time::SystemTime; use target::Target; type LazyArcMutex = LazyLock>>; diff --git a/make/src/signal_handler.rs b/make/src/signal_handler.rs index e8775c601..43138c62c 100644 --- a/make/src/signal_handler.rs +++ b/make/src/signal_handler.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use std::{fs::remove_file, process}; +use std::fs::remove_file; +use std::process; use crate::rule::INTERRUPT_FLAG; use gettextrs::gettext; diff --git a/make/src/special_target.rs b/make/src/special_target.rs index ed4a4bfbd..5329e676a 100644 --- a/make/src/special_target.rs +++ b/make/src/special_target.rs @@ -10,11 +10,10 @@ use core::fmt; use std::collections::BTreeSet; -use crate::{ - error_code::ErrorCode, - rule::{target::Target, Rule}, - Make, -}; +use crate::error_code::ErrorCode; +use crate::rule::target::Target; +use crate::rule::Rule; +use crate::Make; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum SpecialTarget { diff --git a/make/tests/integration.rs b/make/tests/integration.rs index 9a583df0c..ddda6dd30 100644 --- a/make/tests/integration.rs +++ b/make/tests/integration.rs @@ -373,7 +373,8 @@ mod target_behavior { use super::*; use libc::{kill, SIGINT}; use posixutils_make::parser::parse::ParseError; - use std::{thread, time::Duration}; + use std::thread; + use std::time::Duration; #[test] fn no_targets() { @@ -579,7 +580,8 @@ mod special_targets { use libc::{kill, SIGINT}; use posixutils_make::special_target; use std::fs::remove_dir; - use std::{fs, thread, time::Duration}; + use std::time::Duration; + use std::{fs, thread}; #[test] fn default() { diff --git a/make/tests/parser.rs b/make/tests/parser.rs index 70090c7a4..024f10999 100644 --- a/make/tests/parser.rs +++ b/make/tests/parser.rs @@ -32,7 +32,8 @@ all: } mod lex { - use posixutils_make::parser::{lex::lex, SyntaxKind::*}; + use posixutils_make::parser::lex::lex; + use posixutils_make::parser::SyntaxKind::*; #[test] fn test_empty() { @@ -256,8 +257,9 @@ endif } mod parse { + use posixutils_make::parser::parse::parse; use posixutils_make::parser::preprocessor::preprocess; - use posixutils_make::parser::{parse::parse, Makefile}; + use posixutils_make::parser::Makefile; use rowan::ast::AstNode; #[test] diff --git a/process/batch.rs b/process/batch.rs index 4e440ae38..8c43f8099 100644 --- a/process/batch.rs +++ b/process/batch.rs @@ -11,16 +11,13 @@ use chrono::{DateTime, Local, TimeZone, Utc}; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use libc::{getlogin, getpwnam, passwd}; -use std::{ - collections::HashSet, - env, - ffi::{CStr, CString}, - fs::{self}, - io::{BufRead, Read, Seek, Write}, - os::unix::fs::PermissionsExt, - path::{Path, PathBuf}, - process, -}; +use std::collections::HashSet; +use std::ffi::{CStr, CString}; +use std::fs::{self}; +use std::io::{BufRead, Read, Seek, Write}; +use std::os::unix::fs::PermissionsExt; +use std::path::{Path, PathBuf}; +use std::{env, process}; #[cfg(target_os = "linux")] const SPOOL_DIRECTORIES: &[&str] = &[ diff --git a/process/env.rs b/process/env.rs index 3884ed5b9..4a4988790 100644 --- a/process/env.rs +++ b/process/env.rs @@ -8,10 +8,9 @@ // use std::collections::HashMap; -use std::env; -use std::io; use std::os::unix::process::CommandExt; use std::process::{Command, Stdio}; +use std::{env, io}; use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; diff --git a/process/fuser.rs b/process/fuser.rs index fffdb7e83..f1f3dc92e 100644 --- a/process/fuser.rs +++ b/process/fuser.rs @@ -144,14 +144,12 @@ mod linux { use super::*; use libc::fstat; - use std::{ - env, - fs::{self, File}, - io::{BufRead, Error, ErrorKind}, - net::{IpAddr, Ipv4Addr, UdpSocket}, - os::unix::io::AsRawFd, - path::Component, - }; + use std::env; + use std::fs::{self, File}; + use std::io::{BufRead, Error, ErrorKind}; + use std::net::{IpAddr, Ipv4Addr, UdpSocket}; + use std::os::unix::io::AsRawFd; + use std::path::Component; const PROC_PATH: &str = "/proc"; const PROC_MOUNTS: &str = "/proc/mounts"; @@ -1225,7 +1223,9 @@ mod macos { include!(concat!(env!("OUT_DIR"), "/osx_libproc_bindings.rs")); } use libc::{c_char, c_int, c_void}; - use std::{ffi::CString, os::unix::ffi::OsStrExt, ptr}; + use std::ffi::CString; + use std::os::unix::ffi::OsStrExt; + use std::ptr; // similar to list_pids_ret() below, there are two cases when 0 is returned, one when there are // no pids, and the other when there is an error diff --git a/process/tests/fuser/basic.rs b/process/tests/fuser/basic.rs index 507a112f0..c81e28ab2 100644 --- a/process/tests/fuser/basic.rs +++ b/process/tests/fuser/basic.rs @@ -1,6 +1,9 @@ mod basic { use crate::fuser::fuser_test; - use std::{fs::File, path::PathBuf, process::Command, str}; + use std::fs::File; + use std::path::PathBuf; + use std::process::Command; + use std::str; /// Tests the basic functionality of `fuser` by ensuring it can find the PID of a process. /// diff --git a/process/tests/fuser/tcp.rs b/process/tests/fuser/tcp.rs index 722c23b4c..ae89cc09d 100644 --- a/process/tests/fuser/tcp.rs +++ b/process/tests/fuser/tcp.rs @@ -1,11 +1,9 @@ #[cfg(test)] mod tcp { use crate::fuser::fuser_test; - use std::{ - io, - net::{TcpListener, TcpStream}, - process::Command, - }; + use std::io; + use std::net::{TcpListener, TcpStream}; + use std::process::Command; /// Starts a TCP server on a predefined local address and port. /// diff --git a/process/tests/fuser/udp.rs b/process/tests/fuser/udp.rs index a600914f1..33dba2113 100644 --- a/process/tests/fuser/udp.rs +++ b/process/tests/fuser/udp.rs @@ -1,7 +1,9 @@ #[cfg(test)] mod udp { use crate::fuser::fuser_test; - use std::{io, net::UdpSocket, process::Command}; + use std::io; + use std::net::UdpSocket; + use std::process::Command; /// Waits for a UDP server to become available by sending a dummy message to the specified port. /// diff --git a/process/tests/fuser/unix.rs b/process/tests/fuser/unix.rs index c871332b9..03799eea5 100644 --- a/process/tests/fuser/unix.rs +++ b/process/tests/fuser/unix.rs @@ -1,11 +1,8 @@ mod unix { use crate::fuser::fuser_test; - use std::{ - fs, - os::unix::net::{UnixListener, UnixStream}, - process::Command, - thread, - }; + use std::os::unix::net::{UnixListener, UnixStream}; + use std::process::Command; + use std::{fs, thread}; /// Starts a Unix socket server at the specified socket path. /// diff --git a/process/tests/fuser/with_user.rs b/process/tests/fuser/with_user.rs index 1d4d09299..101c26e61 100644 --- a/process/tests/fuser/with_user.rs +++ b/process/tests/fuser/with_user.rs @@ -1,7 +1,10 @@ mod with_user { use crate::fuser::fuser_test; use libc::uid_t; - use std::{ffi::CStr, fs::File, io, process::Command, str}; + use std::ffi::CStr; + use std::fs::File; + use std::process::Command; + use std::{io, str}; /// Retrieves the user name of the process owner by process ID on Linux. /// diff --git a/process/tests/timeout/mod.rs b/process/tests/timeout/mod.rs index d26596426..6bd986448 100644 --- a/process/tests/timeout/mod.rs +++ b/process/tests/timeout/mod.rs @@ -7,12 +7,10 @@ // SPDX-License-Identifier: MIT // -use std::{ - io::Write, - process::{Command, Output, Stdio}, - thread, - time::Duration, -}; +use std::io::Write; +use std::process::{Command, Output, Stdio}; +use std::thread; +use std::time::Duration; use sysinfo::System; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..7feb9d421 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,6 @@ +# configuration for https://rust-lang.github.io/rustfmt/ + +## unstable options require running with `cargo +nightly fmt` + +# Module granularity gives better diffs +imports_granularity = "Module" diff --git a/sh/src/builtin/control_flow.rs b/sh/src/builtin/control_flow.rs index 43bbac739..40bbabaf9 100644 --- a/sh/src/builtin/control_flow.rs +++ b/sh/src/builtin/control_flow.rs @@ -9,8 +9,7 @@ use crate::builtin::{skip_option_terminator, BuiltinResult, SpecialBuiltinUtility}; use crate::shell::opened_files::OpenedFiles; -use crate::shell::ControlFlowState; -use crate::shell::Shell; +use crate::shell::{ControlFlowState, Shell}; fn loop_control_flow( args: &[String], diff --git a/sh/src/builtin/kill.rs b/sh/src/builtin/kill.rs index 13c93be79..2256c222e 100644 --- a/sh/src/builtin/kill.rs +++ b/sh/src/builtin/kill.rs @@ -11,8 +11,7 @@ use crate::builtin::{parse_pid, skip_option_terminator, BuiltinResult, BuiltinUt use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; use crate::signals::{Signal, SIGNALS}; -use nix::sys::signal::kill; -use nix::sys::signal::Signal as NixSignal; +use nix::sys::signal::{kill, Signal as NixSignal}; use std::str::FromStr; enum KillArgs<'a> { diff --git a/sh/src/shell/mod.rs b/sh/src/shell/mod.rs index a484b61c9..696aec1a7 100644 --- a/sh/src/shell/mod.rs +++ b/sh/src/shell/mod.rs @@ -34,8 +34,7 @@ use crate::utils::{ use crate::wordexp::{expand_word, expand_word_to_string, word_to_pattern}; use nix::errno::Errno; use nix::libc; -use nix::sys::signal::kill; -use nix::sys::signal::Signal as NixSignal; +use nix::sys::signal::{kill, Signal as NixSignal}; use nix::sys::wait::{WaitPidFlag, WaitStatus}; use nix::unistd::{getcwd, getpgid, getpgrp, getpid, getppid, setpgid, tcsetpgrp, ForkResult, Pid}; use std::collections::HashMap; diff --git a/text/diff.rs b/text/diff.rs index c3fd8d984..79216530d 100644 --- a/text/diff.rs +++ b/text/diff.rs @@ -14,16 +14,15 @@ mod diff_util; -use std::{fs, io, path::PathBuf}; +use std::path::PathBuf; +use std::{fs, io}; use clap::Parser; -use diff_util::{ - common::{FormatOptions, OutputFormat}, - diff_exit_status::DiffExitStatus, - dir_diff::DirDiff, - file_diff::FileDiff, - functions::check_existance, -}; +use diff_util::common::{FormatOptions, OutputFormat}; +use diff_util::diff_exit_status::DiffExitStatus; +use diff_util::dir_diff::DirDiff; +use diff_util::file_diff::FileDiff; +use diff_util::functions::check_existance; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; /// diff - compare two files diff --git a/text/diff_util/dir_data.rs b/text/diff_util/dir_data.rs index 221cb0c58..6702f07ec 100755 --- a/text/diff_util/dir_data.rs +++ b/text/diff_util/dir_data.rs @@ -1,10 +1,8 @@ -use std::{ - collections::HashMap, - ffi::OsString, - fs::{self, DirEntry}, - io, - path::PathBuf, -}; +use std::collections::HashMap; +use std::ffi::OsString; +use std::fs::{self, DirEntry}; +use std::io; +use std::path::PathBuf; use super::constants::*; diff --git a/text/diff_util/dir_diff.rs b/text/diff_util/dir_diff.rs index 1e6892ba3..5ae56f724 100755 --- a/text/diff_util/dir_diff.rs +++ b/text/diff_util/dir_diff.rs @@ -1,10 +1,14 @@ -use std::{collections::HashSet, ffi::OsString, io, path::PathBuf}; +use std::collections::HashSet; +use std::ffi::OsString; +use std::io; +use std::path::PathBuf; -use crate::diff_util::{ - constants::COULD_NOT_UNWRAP_FILENAME, diff_exit_status::DiffExitStatus, file_diff::FileDiff, -}; +use crate::diff_util::constants::COULD_NOT_UNWRAP_FILENAME; +use crate::diff_util::diff_exit_status::DiffExitStatus; +use crate::diff_util::file_diff::FileDiff; -use super::{common::FormatOptions, dir_data::DirData}; +use super::common::FormatOptions; +use super::dir_data::DirData; pub struct DirDiff<'a> { dir1: &'a mut DirData, diff --git a/text/diff_util/file_data.rs b/text/diff_util/file_data.rs index f4f225813..08220a8b8 100755 --- a/text/diff_util/file_data.rs +++ b/text/diff_util/file_data.rs @@ -1,4 +1,9 @@ -use std::{fs::File, io, mem::take, path::PathBuf, str::from_utf8, time::SystemTime}; +use std::fs::File; +use std::io; +use std::mem::take; +use std::path::PathBuf; +use std::str::from_utf8; +use std::time::SystemTime; use super::constants::COULD_NOT_UNWRAP_FILENAME; diff --git a/text/diff_util/file_diff.rs b/text/diff_util/file_diff.rs index 16f98e332..fc669d29c 100755 --- a/text/diff_util/file_diff.rs +++ b/text/diff_util/file_diff.rs @@ -1,23 +1,19 @@ -use super::{ - common::{FormatOptions, OutputFormat}, - constants::COULD_NOT_UNWRAP_FILENAME, - diff_exit_status::DiffExitStatus, - file_data::{FileData, LineReader}, - functions::{check_existance, is_binary, system_time_to_rfc2822}, - hunks::Hunks, -}; +use super::common::{FormatOptions, OutputFormat}; +use super::constants::COULD_NOT_UNWRAP_FILENAME; +use super::diff_exit_status::DiffExitStatus; +use super::file_data::{FileData, LineReader}; +use super::functions::{check_existance, is_binary, system_time_to_rfc2822}; +use super::hunks::Hunks; use crate::diff_util::constants::NO_NEW_LINE_AT_END_OF_FILE; -use std::{ - cmp::Reverse, - collections::HashMap, - fmt::Write, - fs::{read_to_string, File}, - io::{self, BufReader, Read}, - os::unix::fs::MetadataExt, - path::PathBuf, -}; +use std::cmp::Reverse; +use std::collections::HashMap; +use std::fmt::Write; +use std::fs::{read_to_string, File}; +use std::io::{self, BufReader, Read}; +use std::os::unix::fs::MetadataExt; +use std::path::PathBuf; pub struct FileDiff<'a> { file1: &'a mut FileData<'a>, diff --git a/text/diff_util/functions.rs b/text/diff_util/functions.rs index e6c2c806d..54d395a7f 100755 --- a/text/diff_util/functions.rs +++ b/text/diff_util/functions.rs @@ -1,10 +1,8 @@ use chrono::{DateTime, Local}; -use std::{ - fs::File, - io::{self, Read}, - path::{Path, PathBuf}, - time::SystemTime, -}; +use std::fs::File; +use std::io::{self, Read}; +use std::path::{Path, PathBuf}; +use std::time::SystemTime; use super::constants::UTF8_NOT_ALLOWED_BYTES; use crate::diff_util::constants::COULD_NOT_UNWRAP_FILENAME; diff --git a/text/grep.rs b/text/grep.rs index 5ee38227d..35baaa74a 100644 --- a/text/grep.rs +++ b/text/grep.rs @@ -10,13 +10,11 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use libc::{regcomp, regex_t, regexec, regfree, REG_EXTENDED, REG_ICASE, REG_NOMATCH}; -use std::{ - ffi::CString, - fs::File, - io::{self, BufRead, BufReader}, - path::{Path, PathBuf}, - ptr, -}; +use std::ffi::CString; +use std::fs::File; +use std::io::{self, BufRead, BufReader}; +use std::path::{Path, PathBuf}; +use std::ptr; /// grep - search a file for a pattern. #[derive(Parser)] diff --git a/text/sed.rs b/text/sed.rs index 7c4376c98..0e8246527 100644 --- a/text/sed.rs +++ b/text/sed.rs @@ -13,17 +13,15 @@ use libc::{ ioctl, regcomp, regex_t, regexec, regmatch_t, winsize, REG_EXTENDED, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, }; +use std::collections::{HashMap, HashSet}; +use std::ffi::CString; +use std::fmt::{self, Debug}; +use std::fs::File; +use std::io::{BufRead, BufReader, Error, ErrorKind, Write}; +use std::mem::MaybeUninit; +use std::ops::Range; +use std::path::PathBuf; use std::sync::Mutex; -use std::{ - collections::{HashMap, HashSet}, - ffi::CString, - fmt::{self, Debug}, - fs::File, - io::{BufRead, BufReader, Error, ErrorKind, Write}, - mem::MaybeUninit, - ops::Range, - path::PathBuf, -}; static ERE: Mutex = Mutex::new(false); diff --git a/text/sort.rs b/text/sort.rs index c0012bf0b..b3320d116 100644 --- a/text/sort.rs +++ b/text/sort.rs @@ -9,12 +9,9 @@ use std::cmp::Ordering; -use std::io::{ErrorKind, Read}; -use std::{ - fs::File, - io::{self, BufRead, BufWriter, Error, Write}, - path::PathBuf, -}; +use std::fs::File; +use std::io::{self, BufRead, BufWriter, Error, ErrorKind, Read, Write}; +use std::path::PathBuf; use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; diff --git a/text/tests/diff-tests.rs b/text/tests/diff-tests.rs index 8f159c23b..522b4785d 100644 --- a/text/tests/diff-tests.rs +++ b/text/tests/diff-tests.rs @@ -13,7 +13,10 @@ mod constants; use constants::{EXIT_STATUS_DIFFERENCE, EXIT_STATUS_NO_DIFFERENCE}; use plib::testing::{run_test, TestPlan}; -use std::{collections::HashMap, path::PathBuf, process::Stdio, sync::LazyLock}; +use std::collections::HashMap; +use std::path::PathBuf; +use std::process::Stdio; +use std::sync::LazyLock; fn diff_test(args: &[&str], expected_output: &str, expected_diff_exit_status: u8) { let str_args = args.iter().cloned().map(str::to_owned).collect(); diff --git a/text/tests/head/mod.rs b/text/tests/head/mod.rs index e739ff34d..1c28d9327 100644 --- a/text/tests/head/mod.rs +++ b/text/tests/head/mod.rs @@ -9,7 +9,8 @@ // use plib::testing::{run_test, TestPlan}; -use rand::{seq::SliceRandom, thread_rng}; +use rand::seq::SliceRandom; +use rand::thread_rng; /* #region Normal tests */ fn head_test(n: Option<&str>, c: Option<&str>, test_data: &str, expected_output: &str) { @@ -122,12 +123,12 @@ fn test_head_c() { /* #region Property-based tests */ mod property_tests { use plib::testing::run_test_base; - use proptest::{prelude::TestCaseError, prop_assert, test_runner::TestRunner}; - use std::{ - sync::mpsc::{self, RecvTimeoutError}, - thread::{self}, - time::Duration, - }; + use proptest::prelude::TestCaseError; + use proptest::prop_assert; + use proptest::test_runner::TestRunner; + use std::sync::mpsc::{self, RecvTimeoutError}; + use std::thread::{self}; + use std::time::Duration; fn get_test_runner(cases: u32) -> TestRunner { TestRunner::new(proptest::test_runner::Config { diff --git a/text/wc.rs b/text/wc.rs index 807b15fdd..805bd0cb4 100644 --- a/text/wc.rs +++ b/text/wc.rs @@ -7,12 +7,10 @@ // SPDX-License-Identifier: MIT // -use std::{ - ffi::OsStr, - io::{self, Read}, - ops::AddAssign, - path::PathBuf, -}; +use std::ffi::OsStr; +use std::io::{self, Read}; +use std::ops::AddAssign; +use std::path::PathBuf; use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; diff --git a/tree/chgrp.rs b/tree/chgrp.rs index 77a8806a8..df1570c2c 100644 --- a/tree/chgrp.rs +++ b/tree/chgrp.rs @@ -12,7 +12,10 @@ mod common; use self::common::error_string; use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use std::{cell::RefCell, ffi::CString, io, os::unix::fs::MetadataExt}; +use std::cell::RefCell; +use std::ffi::CString; +use std::io; +use std::os::unix::fs::MetadataExt; /// chgrp - change file group ownership #[derive(Parser)] diff --git a/tree/chmod.rs b/tree/chmod.rs index d9fa17a87..d0371b04e 100644 --- a/tree/chmod.rs +++ b/tree/chmod.rs @@ -14,7 +14,9 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use modestr::ChmodMode; use plib::modestr; -use std::{cell::RefCell, io, os::unix::fs::MetadataExt}; +use std::cell::RefCell; +use std::io; +use std::os::unix::fs::MetadataExt; /// chmod - change the file modes #[derive(Parser)] diff --git a/tree/common/mod.rs b/tree/common/mod.rs index f0008e182..64be53cd4 100644 --- a/tree/common/mod.rs +++ b/tree/common/mod.rs @@ -6,18 +6,15 @@ use ftw::{self, traverse_directory}; use gettextrs::gettext; -use std::{ - cell::RefCell, - collections::{HashMap, HashSet}, - ffi::{CStr, CString, OsStr}, - fs, io, - mem::MaybeUninit, - os::{ - fd::{AsRawFd, FromRawFd}, - unix::{ffi::OsStrExt, fs::MetadataExt}, - }, - path::{Path, PathBuf}, -}; +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::{CStr, CString, OsStr}; +use std::mem::MaybeUninit; +use std::os::fd::{AsRawFd, FromRawFd}; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::MetadataExt; +use std::path::{Path, PathBuf}; +use std::{fs, io}; pub type InodeMap = HashMap<(u64, u64), (ftw::FileDescriptor, CString)>; diff --git a/tree/ls.rs b/tree/ls.rs index 0bea323b7..3363e91fb 100644 --- a/tree/ls.rs +++ b/tree/ls.rs @@ -13,16 +13,15 @@ use self::ls_util::{ls_from_utf8_lossy, Entry, LongFormatPadding, MultiColumnPad use clap::{CommandFactory, FromArgMatches, Parser}; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use plib::platform::P_WINSIZE_REQUEST_CODE; -use std::{ - collections::HashMap, - ffi::{CString, OsStr}, - io, - mem::MaybeUninit, - os::unix::{ffi::OsStrExt, fs::MetadataExt}, - path::{Path, PathBuf}, - process::ExitCode, - sync::atomic::{AtomicU8, Ordering}, -}; +use std::collections::HashMap; +use std::ffi::{CString, OsStr}; +use std::io; +use std::mem::MaybeUninit; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::MetadataExt; +use std::path::{Path, PathBuf}; +use std::process::ExitCode; +use std::sync::atomic::{AtomicU8, Ordering}; /// ls - list directory contents #[derive(Parser)] diff --git a/tree/ls_util/entry.rs b/tree/ls_util/entry.rs index c85d223c0..c014c357d 100644 --- a/tree/ls_util/entry.rs +++ b/tree/ls_util/entry.rs @@ -13,16 +13,12 @@ use crate::{ DATE_TIME_FORMAT_OLD_OR_FUTURE, DATE_TIME_FORMAT_RECENT, }; use chrono::{DateTime, Local}; -use std::{ - cmp::Ordering, - ffi::{CStr, OsStr, OsString}, - io, - os::unix::{ - ffi::OsStrExt, - fs::{FileTypeExt, MetadataExt}, - }, - time::{Duration, SystemTime}, -}; +use std::cmp::Ordering; +use std::ffi::{CStr, OsStr, OsString}; +use std::io; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::{FileTypeExt, MetadataExt}; +use std::time::{Duration, SystemTime}; enum FileInfo { Size(u64), diff --git a/tree/mv.rs b/tree/mv.rs index dbb4380d0..4fb598cce 100644 --- a/tree/mv.rs +++ b/tree/mv.rs @@ -14,14 +14,13 @@ use self::common::{copy_file, error_string}; use clap::Parser; use common::CopyConfig; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use std::{ - collections::{HashMap, HashSet}, - ffi::CString, - fs, - io::{self, IsTerminal}, - os::unix::{ffi::OsStrExt, fs::MetadataExt}, - path::{Path, PathBuf}, -}; +use std::collections::{HashMap, HashSet}; +use std::ffi::CString; +use std::fs; +use std::io::{self, IsTerminal}; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::MetadataExt; +use std::path::{Path, PathBuf}; /// mv - move files #[derive(Parser)] diff --git a/tree/readlink.rs b/tree/readlink.rs index 18ade5795..36a82dac4 100644 --- a/tree/readlink.rs +++ b/tree/readlink.rs @@ -11,10 +11,8 @@ use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::error::Error; use std::fs; -use std::io::Write; -use std::io::{stderr, stdout, ErrorKind}; -use std::path::PathBuf; -use std::path::{Component, Path}; +use std::io::{stderr, stdout, ErrorKind, Write}; +use std::path::{Component, Path, PathBuf}; /// readlink — display the contents of a symbolic link #[derive(Parser)] diff --git a/tree/rm.rs b/tree/rm.rs index 1437ca2f7..2e0bb74e7 100644 --- a/tree/rm.rs +++ b/tree/rm.rs @@ -13,13 +13,12 @@ use self::common::error_string; use clap::Parser; use ftw::{self, traverse_directory}; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use std::{ - ffi::CString, - fs, - io::{self, IsTerminal}, - os::unix::{ffi::OsStrExt, fs::MetadataExt}, - path::{Path, PathBuf}, -}; +use std::ffi::CString; +use std::fs; +use std::io::{self, IsTerminal}; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::MetadataExt; +use std::path::{Path, PathBuf}; /// rm - remove directory entries #[derive(Parser)] diff --git a/tree/tests/chgrp/mod.rs b/tree/tests/chgrp/mod.rs index 67975f932..2d0590958 100644 --- a/tree/tests/chgrp/mod.rs +++ b/tree/tests/chgrp/mod.rs @@ -8,17 +8,12 @@ // use plib::testing::{run_test, TestPlan}; -use std::{ - ffi::{CStr, CString}, - fs, io, - os::unix::{ - self, - fs::{MetadataExt, PermissionsExt}, - }, - sync::{Once, RwLock}, - thread, - time::Duration, -}; +use std::ffi::{CStr, CString}; +use std::os::unix::fs::{MetadataExt, PermissionsExt}; +use std::os::unix::{self}; +use std::sync::{Once, RwLock}; +use std::time::Duration; +use std::{fs, io, thread}; fn chgrp_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/chmod/mod.rs b/tree/tests/chmod/mod.rs index 7b02b6b00..3caf38940 100644 --- a/tree/tests/chmod/mod.rs +++ b/tree/tests/chmod/mod.rs @@ -8,10 +8,9 @@ // use plib::testing::{run_test, TestPlan}; -use std::{ - fs, - os::unix::{self, fs::PermissionsExt}, -}; +use std::fs; +use std::os::unix::fs::PermissionsExt; +use std::os::unix::{self}; fn chmod_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/cp/mod.rs b/tree/tests/cp/mod.rs index 6ccc0d97a..d9c62089c 100644 --- a/tree/tests/cp/mod.rs +++ b/tree/tests/cp/mod.rs @@ -10,11 +10,8 @@ use plib::testing::{run_test, TestPlan}; use std::ffi::CString; use std::io::{Read, Write}; -use std::os::unix::fs::FileTypeExt; -use std::os::unix::{ - self, - fs::{MetadataExt, PermissionsExt}, -}; +use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; +use std::os::unix::{self}; use std::path::Path; use std::process::{Command, Stdio}; use std::{fs, io}; diff --git a/tree/tests/ls/mod.rs b/tree/tests/ls/mod.rs index 284f18bd8..ff02d1115 100644 --- a/tree/tests/ls/mod.rs +++ b/tree/tests/ls/mod.rs @@ -10,12 +10,11 @@ use plib::testing::{run_test, run_test_with_checker, TestPlan}; use regex::Regex; use std::ffi::CString; -use std::fs; use std::io::{self, Write}; use std::os::unix::fs::MetadataExt; use std::path::Path; -use std::thread; use std::time::Duration; +use std::{fs, thread}; fn get_errno() -> i32 { io::Error::last_os_error().raw_os_error().unwrap() diff --git a/tree/tests/mv/mod.rs b/tree/tests/mv/mod.rs index 01ff29b81..34d07a85a 100644 --- a/tree/tests/mv/mod.rs +++ b/tree/tests/mv/mod.rs @@ -11,11 +11,8 @@ use plib::testing::{run_test, TestPlan}; use std::ffi::CString; use std::fs::{self, Permissions}; use std::io::{self, Read, Write}; -use std::os::unix::fs::FileTypeExt; -use std::os::unix::{ - self, - fs::{MetadataExt, PermissionsExt}, -}; +use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; +use std::os::unix::{self}; use std::path::Path; use std::process::{Command, Stdio}; diff --git a/tree/tests/rm/mod.rs b/tree/tests/rm/mod.rs index f8496dc39..aa6c99499 100644 --- a/tree/tests/rm/mod.rs +++ b/tree/tests/rm/mod.rs @@ -11,10 +11,8 @@ use plib::testing::{run_test, run_test_with_checker, TestPlan}; use std::ffi::CString; use std::fs; use std::io::{self, Write}; -use std::os::unix::{ - self, - fs::{DirBuilderExt, MetadataExt, PermissionsExt}, -}; +use std::os::unix::fs::{DirBuilderExt, MetadataExt, PermissionsExt}; +use std::os::unix::{self}; use std::path::Path; use std::process::{Command, Stdio}; diff --git a/tree/tests/tree-tests-umask.rs b/tree/tests/tree-tests-umask.rs index f5bd4c331..78c24de0f 100644 --- a/tree/tests/tree-tests-umask.rs +++ b/tree/tests/tree-tests-umask.rs @@ -12,12 +12,10 @@ //! different per-process umask than those in `tree-tests.rs`. use plib::testing::{run_test, TestPlan}; -use std::{ - fs, - os::unix::fs::{DirBuilderExt, MetadataExt, PermissionsExt}, - path::Path, - sync::Mutex, -}; +use std::fs; +use std::os::unix::fs::{DirBuilderExt, MetadataExt, PermissionsExt}; +use std::path::Path; +use std::sync::Mutex; static UMASK_SETTER: Mutex = Mutex::new(UmaskSetter); diff --git a/users/newgrp.rs b/users/newgrp.rs index a9623f0d0..6b84e5fc1 100644 --- a/users/newgrp.rs +++ b/users/newgrp.rs @@ -7,7 +7,8 @@ // SPDX-License-Identifier: MIT // -use clap::{error::ErrorKind, Parser}; +use clap::error::ErrorKind; +use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use libc::{ getgid, getgrnam, getgroups, getlogin, getpwnam, getpwuid, getuid, gid_t, passwd, setegid, @@ -20,12 +21,9 @@ use libc::{ECHO, ECHONL, TCSANOW}; use libcrypt_rs::Crypt; use plib::group::Group; -use std::{ - env, - ffi::{CStr, CString}, - io, - process::{self, Command}, -}; +use std::ffi::{CStr, CString}; +use std::process::{self, Command}; +use std::{env, io}; #[cfg(target_os = "linux")] use std::{ diff --git a/users/talk.rs b/users/talk.rs index 3521970d2..fe0c6d27f 100644 --- a/users/talk.rs +++ b/users/talk.rs @@ -6,7 +6,8 @@ // SPDX-License-Identifier: MIT // -use clap::{error::ErrorKind, Parser}; +use clap::error::ErrorKind; +use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use thiserror::Error; @@ -19,21 +20,17 @@ use libc::{ STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, }; -use std::{ - char, - ffi::{CStr, CString}, - io::{self, Cursor, Error, IsTerminal, Write}, - mem::{size_of, zeroed}, - net::{ - self, AddrParseError, Ipv4Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener, - TcpStream, UdpSocket, - }, - os::fd::AsRawFd, - process, ptr, - sync::{Arc, LazyLock, Mutex}, - thread, - time::{Duration, Instant}, +use std::ffi::{CStr, CString}; +use std::io::{self, Cursor, Error, IsTerminal, Write}; +use std::mem::{size_of, zeroed}; +use std::net::{ + self, AddrParseError, Ipv4Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener, TcpStream, + UdpSocket, }; +use std::os::fd::AsRawFd; +use std::sync::{Arc, LazyLock, Mutex}; +use std::time::{Duration, Instant}; +use std::{char, process, ptr, thread}; #[derive(Parser)] #[command(version, about=gettext("talk - talk to another user"))] diff --git a/users/write.rs b/users/write.rs index 934cc362c..0a817ce63 100644 --- a/users/write.rs +++ b/users/write.rs @@ -13,8 +13,7 @@ use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleC use plib::{curuser, platform, utmpx}; use std::fs::{self, OpenOptions}; use std::io::{self, BufRead, Write}; -use std::os::unix::fs::MetadataExt; -use std::os::unix::fs::PermissionsExt; +use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::process::exit; const ALERT_CHAR: char = '\u{07}'; diff --git a/xform/tests/compress/mod.rs b/xform/tests/compress/mod.rs index cdd00915e..5e48b5f1d 100644 --- a/xform/tests/compress/mod.rs +++ b/xform/tests/compress/mod.rs @@ -8,10 +8,8 @@ // use plib::testing::{run_test, TestPlan}; -use std::{ - fs::{remove_file, File}, - io::Read, -}; +use std::fs::{remove_file, File}; +use std::io::Read; fn compress_test(args: &[&str], expected_output: &str, expected_error: &str) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); @@ -41,9 +39,8 @@ fn uncompress_test(args: &[&str], expected_output: &str, expected_error: &str) { #[test] fn magic_header_compress_file() { - use std::env; - use std::fs; use std::path::PathBuf; + use std::{env, fs}; const MAGIC_HEADER: [u8; 2] = [0x1F, 0x9D]; @@ -84,9 +81,8 @@ fn magic_header_compress_file() { #[test] fn compression_compress_file() { - use std::env; - use std::fs; use std::path::PathBuf; + use std::{env, fs}; // Get the directory of the Cargo project let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); diff --git a/xform/tests/uue/mod.rs b/xform/tests/uue/mod.rs index 022a39bcb..cecb21de4 100644 --- a/xform/tests/uue/mod.rs +++ b/xform/tests/uue/mod.rs @@ -8,11 +8,9 @@ // use plib::testing::{run_test, TestPlan}; -use std::{ - fs::{File, Permissions}, - io::Read, - os::unix::fs::PermissionsExt, -}; +use std::fs::{File, Permissions}; +use std::io::Read; +use std::os::unix::fs::PermissionsExt; const RWX: u32 = 0o7; const UUCODE_PERMISSION_PLACEHOLDER: &str = "#PERM#"; From b4996cd824ec83b125552301fae461599c7171b0 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Wed, 2 Apr 2025 17:31:24 -0700 Subject: [PATCH 2/2] Group imports StdExternalCrate https://rust-lang.github.io/rustfmt//\?version%5C\=v1.8.0%5C\&search%5C\=%5C\&version\=v1.8.0\&search\=\#group_imports --- awk/src/compiler.rs | 21 ++++++++++--------- awk/src/interpreter/mod.rs | 27 ++++++++++++------------ awk/src/main.rs | 12 ++++++----- awk/src/program.rs | 3 ++- calc/bc.rs | 1 - calc/bc_util/interpreter.rs | 3 +-- calc/bc_util/parser.rs | 7 ++++--- datetime/sleep.rs | 3 ++- dev/ar.rs | 7 ++++--- dev/nm.rs | 10 ++++----- dev/strip.rs | 5 +++-- dev/tests/dev-tests.rs | 3 ++- display/echo.rs | 3 ++- display/more.rs | 11 +++++----- display/printf.rs | 3 ++- file/magic.rs | 3 ++- fs/df.rs | 11 +++++----- ftw/src/dir.rs | 3 ++- ftw/src/lib.rs | 3 ++- ftw/tests/integration2.rs | 7 ++++--- i18n/gencat.rs | 9 ++++---- i18n/iconv.rs | 13 ++++++------ i18n/iconv_lib/utf_16.rs | 3 ++- i18n/iconv_lib/utf_32.rs | 3 ++- i18n/tests/gencat/mod.rs | 3 ++- i18n/tests/iconv/mod.rs | 3 ++- m4/src/lib.rs | 11 +++++----- m4/src/macros/builtin.rs | 4 ++-- m4/src/macros/eval.rs | 3 +-- m4/src/macros/trace.rs | 3 +-- m4/src/macros/user_defined.rs | 3 +-- m4/src/output.rs | 7 ++++--- m4/tests/integration_test.rs | 7 ++++--- make/src/error_code.rs | 3 ++- make/src/lib.rs | 6 +++--- make/src/main.rs | 1 - make/src/parser/lex.rs | 2 +- make/src/parser/parse.rs | 11 +++++----- make/src/rule.rs | 20 ++++++++++-------- make/src/rule/target.rs | 3 ++- make/src/signal_handler.rs | 3 ++- make/src/special_target.rs | 3 ++- make/tests/integration.rs | 17 ++++++++------- plib/src/group.rs | 3 ++- plib/src/utmpx.rs | 3 ++- process/batch.rs | 8 ++++---- process/fuser.rs | 10 +++++---- process/tests/fuser/basic.rs | 3 ++- process/tests/fuser/mod.rs | 3 ++- process/tests/fuser/tcp.rs | 3 ++- process/tests/fuser/udp.rs | 3 ++- process/tests/fuser/unix.rs | 3 ++- process/tests/fuser/with_user.rs | 6 ++++-- rustfmt.toml | 1 + sccs/tests/what/mod.rs | 3 ++- screen/osdata.rs | 14 ++++++------- sh/src/builtin/bg.rs | 3 ++- sh/src/builtin/cd.rs | 9 ++++---- sh/src/builtin/dot.rs | 3 ++- sh/src/builtin/fc.rs | 12 ++++++----- sh/src/builtin/fg.rs | 3 ++- sh/src/builtin/kill.rs | 6 ++++-- sh/src/builtin/mod.rs | 8 +++++--- sh/src/builtin/read.rs | 10 +++++---- sh/src/builtin/set.rs | 3 ++- sh/src/builtin/times.rs | 5 +++-- sh/src/builtin/trap.rs | 5 +++-- sh/src/builtin/ulimit.rs | 8 +++++--- sh/src/builtin/wait.rs | 5 +++-- sh/src/cli/terminal.rs | 7 ++++--- sh/src/cli/vi/mod.rs | 7 ++++--- sh/src/jobs.rs | 6 ++++-- sh/src/main.rs | 18 ++++++++-------- sh/src/parse/command.rs | 5 +++-- sh/src/parse/command_parser.rs | 5 +++-- sh/src/parse/lexer/command_lexer.rs | 5 +++-- sh/src/parse/lexer/mod.rs | 3 ++- sh/src/parse/lexer/word_lexer.rs | 5 +++-- sh/src/parse/word.rs | 3 ++- sh/src/parse/word_parser.rs | 3 ++- sh/src/pattern/mod.rs | 3 ++- sh/src/pattern/regex.rs | 6 ++++-- sh/src/shell/environment.rs | 3 ++- sh/src/shell/history.rs | 3 ++- sh/src/shell/mod.rs | 32 +++++++++++++++-------------- sh/src/shell/opened_files.rs | 10 +++++---- sh/src/signals.rs | 10 +++++---- sh/src/utils.rs | 16 ++++++++------- sh/src/wordexp/arithmetic.rs | 7 ++++--- sh/src/wordexp/mod.rs | 3 ++- sh/src/wordexp/parameter.rs | 3 ++- sh/src/wordexp/pathname.rs | 10 +++++---- sh/src/wordexp/tilde.rs | 9 +++++--- sh/tests/integration.rs | 3 ++- sys/ipcs.rs | 6 ++++-- sys/psmacos.rs | 3 ++- sys/tests/getconf/mod.rs | 3 ++- text/comm.rs | 5 +++-- text/csplit.rs | 7 ++++--- text/cut.rs | 2 +- text/diff_util/dir_diff.rs | 5 ++--- text/diff_util/file_diff.rs | 17 ++++++++------- text/diff_util/functions.rs | 3 ++- text/diff_util/hunks.rs | 3 +-- text/grep.rs | 7 ++++--- text/join.rs | 5 +++-- text/nl.rs | 7 ++++--- text/paste.rs | 5 +++-- text/pr_util/args.rs | 10 +++++---- text/pr_util/line_iterator.rs | 3 ++- text/pr_util/page_iterator.rs | 3 ++- text/sed.rs | 13 ++++++------ text/sort.rs | 1 - text/tests/comm/mod.rs | 3 ++- text/tests/diff-tests.rs | 5 +++-- text/tests/fold/mod.rs | 3 ++- text/tests/head/mod.rs | 7 ++++--- text/tests/paste/mod.rs | 3 ++- text/tests/pr/mod.rs | 5 +++-- text/tr.rs | 8 +++++--- text/unexpand.rs | 5 +++-- text/uniq.rs | 5 +++-- tree/chgrp.rs | 8 +++++--- tree/chmod.rs | 10 +++++---- tree/chown.rs | 5 +++-- tree/common/mod.rs | 5 +++-- tree/cp.rs | 8 +++++--- tree/du.rs | 5 +++-- tree/link.rs | 3 ++- tree/ln.rs | 5 +++-- tree/ls.rs | 10 +++++---- tree/ls_util/entry.rs | 14 +++++++------ tree/mkdir.rs | 7 ++++--- tree/mkfifo.rs | 3 ++- tree/mv.rs | 10 +++++---- tree/readlink.rs | 5 +++-- tree/rm.rs | 10 +++++---- tree/rmdir.rs | 5 +++-- tree/tests/chgrp/mod.rs | 3 ++- tree/tests/chmod/mod.rs | 3 ++- tree/tests/cp/mod.rs | 3 ++- tree/tests/link/mod.rs | 3 ++- tree/tests/ls/mod.rs | 5 +++-- tree/tests/mkdir/mod.rs | 3 ++- tree/tests/mv/mod.rs | 3 ++- tree/tests/readlink/mod.rs | 3 ++- tree/tests/rm/mod.rs | 3 ++- tree/tests/rmdir/mod.rs | 3 ++- tree/tests/tree-tests-umask.rs | 3 ++- tree/tests/unlink/mod.rs | 3 ++- tree/unlink.rs | 3 ++- users/id.rs | 5 +++-- users/mesg.rs | 5 +++-- users/newgrp.rs | 22 +++++++++----------- users/pwd.rs | 5 +++-- users/talk.rs | 27 ++++++++++++------------ users/tty.rs | 3 ++- users/write.rs | 9 ++++---- xform/cksum.rs | 5 +++-- xform/compress.rs | 7 ++++--- xform/tests/compress/mod.rs | 3 ++- xform/tests/uue/mod.rs | 3 ++- xform/uncompress.rs | 5 +++-- xform/uudecode.rs | 7 ++++--- xform/uuencode.rs | 7 ++++--- 165 files changed, 598 insertions(+), 436 deletions(-) diff --git a/awk/src/compiler.rs b/awk/src/compiler.rs index 4f6c2e38f..4b76ddb36 100644 --- a/awk/src/compiler.rs +++ b/awk/src/compiler.rs @@ -9,16 +9,6 @@ #![allow(clippy::result_large_err)] -use crate::program::{ - Action, AwkRule, BuiltinFunction, Constant, DebugInfo, Function, OpCode, Pattern, Program, - SourceLocation, SpecialVar, VarId, -}; -use crate::regex::Regex; - -use pest::error::InputLocation; -use pest::iterators::{Pair, Pairs}; -use pest::pratt_parser::{Assoc, Op, PrattParser}; -use pest::Parser; use std::cell::{Cell, RefCell}; use std::collections::HashMap; use std::ffi::CString; @@ -27,6 +17,17 @@ use std::rc::Rc; use std::str::Chars; use std::sync::LazyLock; +use pest::error::InputLocation; +use pest::iterators::{Pair, Pairs}; +use pest::pratt_parser::{Assoc, Op, PrattParser}; +use pest::Parser; + +use crate::program::{ + Action, AwkRule, BuiltinFunction, Constant, DebugInfo, Function, OpCode, Pattern, Program, + SourceLocation, SpecialVar, VarId, +}; +use crate::regex::Regex; + struct BuiltinFunctionInfo { function: BuiltinFunction, min_args: u16, diff --git a/awk/src/interpreter/mod.rs b/awk/src/interpreter/mod.rs index e5fbb478b..6695567b8 100644 --- a/awk/src/interpreter/mod.rs +++ b/awk/src/interpreter/mod.rs @@ -7,7 +7,21 @@ // SPDX-License-Identifier: MIT // +use std::cell::{RefCell, UnsafeCell}; +use std::collections::HashMap; +use std::ffi::CString; +use std::fmt::Write; +use std::iter; +use std::marker::PhantomData; +use std::rc::Rc; +use std::time::SystemTime; + use array::{Array, KeyIterator, ValueIndex}; +use format::{ + fmt_write_decimal_float, fmt_write_float_general, fmt_write_hex_float, + fmt_write_scientific_float, fmt_write_signed, fmt_write_string, fmt_write_unsigned, + parse_conversion_specifier_args, IntegerFormat, +}; use io::{ EmptyRecordReader, FileStream, ReadFiles, ReadPipes, RecordReader, RecordSeparator, StdinRecordReader, WriteFiles, WritePipes, @@ -22,19 +36,6 @@ use crate::program::{ SpecialVar, }; use crate::regex::Regex; -use format::{ - fmt_write_decimal_float, fmt_write_float_general, fmt_write_hex_float, - fmt_write_scientific_float, fmt_write_signed, fmt_write_string, fmt_write_unsigned, - parse_conversion_specifier_args, IntegerFormat, -}; -use std::cell::{RefCell, UnsafeCell}; -use std::collections::HashMap; -use std::ffi::CString; -use std::fmt::Write; -use std::iter; -use std::marker::PhantomData; -use std::rc::Rc; -use std::time::SystemTime; mod array; mod format; diff --git a/awk/src/main.rs b/awk/src/main.rs index ee785598c..6a5319f9c 100644 --- a/awk/src/main.rs +++ b/awk/src/main.rs @@ -7,15 +7,17 @@ // SPDX-License-Identifier: MIT // -use crate::compiler::compile_program; -use crate::interpreter::interpret; -use clap::Parser; -use compiler::SourceFile; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::error::Error; use std::fmt::Display; use std::io::Read; +use clap::Parser; +use compiler::SourceFile; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +use crate::compiler::compile_program; +use crate::interpreter::interpret; + mod compiler; mod interpreter; mod program; diff --git a/awk/src/program.rs b/awk/src/program.rs index 57c13c30a..2317194dd 100644 --- a/awk/src/program.rs +++ b/awk/src/program.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use crate::regex::Regex; use std::collections::HashMap; use std::rc::Rc; +use crate::regex::Regex; + pub type VarId = u32; #[cfg_attr(test, derive(Debug))] diff --git a/calc/bc.rs b/calc/bc.rs index 56952f648..b02cc0f49 100644 --- a/calc/bc.rs +++ b/calc/bc.rs @@ -12,7 +12,6 @@ use std::ffi::OsString; use bc_util::interpreter::{ExecutionResult, Interpreter}; use bc_util::parser::parse_program; use clap::Parser; - use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use rustyline::error::ReadlineError; use rustyline::{DefaultEditor, Result}; diff --git a/calc/bc_util/interpreter.rs b/calc/bc_util/interpreter.rs index 7321565fa..8efe97bd1 100644 --- a/calc/bc_util/interpreter.rs +++ b/calc/bc_util/interpreter.rs @@ -10,13 +10,12 @@ use std::fmt::Write; use std::rc::Rc; -use crate::bc_util::instructions::Variable; - use super::instructions::{ BuiltinFunction, ConditionInstruction, ExprInstruction, Function, FunctionArgument, NamedExpr, Program, Register, StmtInstruction, }; use super::number::Number; +use crate::bc_util::instructions::Variable; #[derive(Debug)] struct ErrorCall { diff --git a/calc/bc_util/parser.rs b/calc/bc_util/parser.rs index 2764e9706..fc481c560 100644 --- a/calc/bc_util/parser.rs +++ b/calc/bc_util/parser.rs @@ -7,14 +7,15 @@ // SPDX-License-Identifier: MIT // -use super::instructions::*; +use std::rc::Rc; +use std::sync::LazyLock; use pest::error::InputLocation; use pest::iterators::Pair; use pest::pratt_parser::{Assoc, Op, PrattParser}; use pest::{Parser, Position}; -use std::rc::Rc; -use std::sync::LazyLock; + +use super::instructions::*; static PRATT_PARSER: LazyLock> = LazyLock::new(|| { // Precedence is defined lowest to highest diff --git a/datetime/sleep.rs b/datetime/sleep.rs index d9324b8dc..539144551 100644 --- a/datetime/sleep.rs +++ b/datetime/sleep.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // +use std::{thread, time}; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use std::{thread, time}; #[derive(Parser)] #[command(version, about = gettext("sleep - suspend execution for an interval"))] diff --git a/dev/ar.rs b/dev/ar.rs index d1bd164dd..8a0d51553 100644 --- a/dev/ar.rs +++ b/dev/ar.rs @@ -7,15 +7,16 @@ // SPDX-License-Identifier: MIT // -use chrono::DateTime; -use clap::{Parser, Subcommand}; -use object::{Object, ObjectSymbol, SymbolKind}; use std::ffi::{OsStr, OsString}; use std::io::{stdout, Write}; use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::os::unix::fs::MetadataExt; use std::path::Path; +use chrono::DateTime; +use clap::{Parser, Subcommand}; +use object::{Object, ObjectSymbol, SymbolKind}; + #[derive(clap::Args)] #[group(required = false, multiple = false)] struct InsertArgs { diff --git a/dev/nm.rs b/dev/nm.rs index 02da0b1b1..14978343d 100644 --- a/dev/nm.rs +++ b/dev/nm.rs @@ -11,16 +11,16 @@ // - sort output // +use std::collections::HashMap; +use std::fs; + +use clap::{Parser, ValueEnum}; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use object::{ Object, ObjectSection, ObjectSymbol, SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection, }; -use clap::{Parser, ValueEnum}; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use std::collections::HashMap; -use std::fs; - #[derive(ValueEnum, Clone)] enum OutputType { D, diff --git a/dev/strip.rs b/dev/strip.rs index a3d228757..9e4bdf78f 100644 --- a/dev/strip.rs +++ b/dev/strip.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // +use std::ffi::{OsStr, OsString}; +use std::io::Read; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use object::build::elf::{Builder, Section, SectionData}; use object::{archive, elf}; -use std::ffi::{OsStr, OsString}; -use std::io::Read; #[derive(Parser)] #[command(version, about = gettext("strip - remove unnecessary information from strippable files"))] diff --git a/dev/tests/dev-tests.rs b/dev/tests/dev-tests.rs index 835d3f302..32d3ba060 100644 --- a/dev/tests/dev-tests.rs +++ b/dev/tests/dev-tests.rs @@ -1,6 +1,7 @@ +use std::fs; + use object::{Object, ObjectSection, ObjectSymbol}; use plib::testing::{run_test, run_test_with_checker, TestPlan}; -use std::fs; fn ar_compare_test( args: &[&str], diff --git a/display/echo.rs b/display/echo.rs index 2b04e9874..e63693e81 100644 --- a/display/echo.rs +++ b/display/echo.rs @@ -13,9 +13,10 @@ // Write an 8-bit value that is the 0, 1, 2 or 3-digit octal number _num_. // -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::io::{self, Write}; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + fn translate_str(skip_nl: bool, s: &str) -> String { let mut output = String::with_capacity(s.len()); diff --git a/display/more.rs b/display/more.rs index e1397bfde..5f8a20554 100644 --- a/display/more.rs +++ b/display/more.rs @@ -7,11 +7,6 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use libc::{ - getegid, getgid, getuid, regcomp, regex_t, regexec, setgid, setuid, REG_ICASE, REG_NOMATCH, -}; use std::collections::HashMap; use std::ffi::CString; use std::fs::File; @@ -25,6 +20,12 @@ use std::str::FromStr; use std::sync::mpsc::{channel, Receiver, TryRecvError}; use std::sync::Mutex; use std::time::Duration; + +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use libc::{ + getegid, getgid, getuid, regcomp, regex_t, regexec, setgid, setuid, REG_ICASE, REG_NOMATCH, +}; use termion::clear::*; use termion::cursor::*; use termion::event::*; diff --git a/display/printf.rs b/display/printf.rs index 422d9a95d..2533da889 100644 --- a/display/printf.rs +++ b/display/printf.rs @@ -11,7 +11,6 @@ // - fix bug: zero padding does not work for negative numbers // -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::error::Error; use std::io::{self, Write}; use std::iter::Peekable; @@ -19,6 +18,8 @@ use std::os::unix::ffi::OsStrExt; use std::process::ExitCode; use std::slice::Iter; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + // the following structure is a printf format conversion specifier struct ConvSpec { // the conversion specifier character diff --git a/file/magic.rs b/file/magic.rs index 019575687..4bb78dd14 100644 --- a/file/magic.rs +++ b/file/magic.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // -use regex::Regex; use std::error::Error; use std::fmt; use std::fs::File; use std::io::{self, BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom}; use std::path::PathBuf; +use regex::Regex; + #[cfg(target_os = "macos")] /// Default raw (text based) magic file pub const DEFAULT_MAGIC_FILE: &str = "/usr/share/file/magic/magic"; diff --git a/fs/df.rs b/fs/df.rs index 687e2017f..96574cbf2 100644 --- a/fs/df.rs +++ b/fs/df.rs @@ -10,17 +10,18 @@ #[cfg(target_os = "linux")] mod mntent; -#[cfg(target_os = "linux")] -use crate::mntent::MountTable; - -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; #[cfg(target_os = "macos")] use std::ffi::CStr; use std::ffi::CString; use std::fmt::Display; use std::{cmp, io}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +#[cfg(target_os = "linux")] +use crate::mntent::MountTable; + #[derive(Parser)] #[command(version, about = gettext("df - report free storage space"))] struct Args { diff --git a/ftw/src/dir.rs b/ftw/src/dir.rs index d17f5b875..9fa3e7588 100644 --- a/ftw/src/dir.rs +++ b/ftw/src/dir.rs @@ -1,4 +1,3 @@ -use crate::{open_long_filename, Error, ErrorKind, FileDescriptor}; use std::cell::{RefCell, RefMut}; use std::collections::HashSet; use std::ffi::{CStr, CString}; @@ -8,6 +7,8 @@ use std::os::unix::ffi::OsStrExt as _; use std::path::PathBuf; use std::rc::Rc; +use crate::{open_long_filename, Error, ErrorKind, FileDescriptor}; + // Not to be used publically. The public interface for a directory entry is `Entry`. pub struct EntryInternal<'a> { dirent: *mut libc::dirent, diff --git a/ftw/src/lib.rs b/ftw/src/lib.rs index ff95b2f26..fad3fce5f 100644 --- a/ftw/src/lib.rs +++ b/ftw/src/lib.rs @@ -1,6 +1,5 @@ mod dir; -use dir::{DeferredDir, HybridDir, OwnedDir}; use std::ffi::{CStr, CString, OsStr}; use std::mem::MaybeUninit; use std::ops::Deref; @@ -11,6 +10,8 @@ use std::path::{Path, PathBuf}; use std::rc::Rc; use std::{fmt, io}; +use dir::{DeferredDir, HybridDir, OwnedDir}; + /// Type of error to be handled by the `err_reporter` of `traverse_directory`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ErrorKind { diff --git a/ftw/tests/integration2.rs b/ftw/tests/integration2.rs index 0a5cb50d6..3a7bd53d5 100644 --- a/ftw/tests/integration2.rs +++ b/ftw/tests/integration2.rs @@ -1,12 +1,13 @@ -use rand::distributions::Standard; -use rand::rngs::StdRng; -use rand::{Rng, SeedableRng}; use std::ffi::CString; use std::os::fd::AsRawFd; use std::path::{Path, PathBuf}; use std::sync::Mutex; use std::{fs, io}; +use rand::distributions::Standard; +use rand::rngs::StdRng; +use rand::{Rng, SeedableRng}; + static GLOBAL_MUTEX: Mutex<()> = Mutex::new(()); fn count_open_fds() -> usize { diff --git a/i18n/gencat.rs b/i18n/gencat.rs index 3c17d888c..f302c7bac 100644 --- a/i18n/gencat.rs +++ b/i18n/gencat.rs @@ -1,7 +1,3 @@ -use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian, WriteBytesExt}; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use plib::io::input_stream; use std::cell::RefCell; use std::collections::BTreeMap; use std::fmt::Display; @@ -11,6 +7,11 @@ use std::num::ParseIntError; use std::path::PathBuf; use std::rc::Rc; +use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian, WriteBytesExt}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use plib::io::input_stream; + const NL_SETMAX: u32 = 255; //max set number(the limits.h defines it and is mentioned in POSIX specification) const NL_SETD: u32 = 1; // the default set number for the messages that are not in any set const GLIBC_MAGIC: u32 = 0x960408de; diff --git a/i18n/iconv.rs b/i18n/iconv.rs index 6982aec3b..ee4ba996a 100644 --- a/i18n/iconv.rs +++ b/i18n/iconv.rs @@ -7,12 +7,6 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use iconv_lib::utf_16::{self, UTF16Variant}; -use iconv_lib::utf_32::{self, UTF32Variant}; -use iconv_lib::{ascii, utf_8}; -use plib::io::input_stream; use std::collections::HashMap; use std::env; use std::fs::File; @@ -20,6 +14,13 @@ use std::io::{self, BufRead, BufReader, Read, Write}; use std::path::{Path, PathBuf}; use std::process::exit; use std::str::FromStr; + +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use iconv_lib::utf_16::{self, UTF16Variant}; +use iconv_lib::utf_32::{self, UTF32Variant}; +use iconv_lib::{ascii, utf_8}; +use plib::io::input_stream; use strum::IntoEnumIterator; use strum_macros::{Display, EnumIter, EnumString}; diff --git a/i18n/iconv_lib/utf_16.rs b/i18n/iconv_lib/utf_16.rs index 03ee26535..e8a655c91 100644 --- a/i18n/iconv_lib/utf_16.rs +++ b/i18n/iconv_lib/utf_16.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use byteorder::{BigEndian, ByteOrder, LittleEndian}; use std::iter::{self}; use std::process::exit; +use byteorder::{BigEndian, ByteOrder, LittleEndian}; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UTF16Variant { UTF16LE, diff --git a/i18n/iconv_lib/utf_32.rs b/i18n/iconv_lib/utf_32.rs index f4ffacd7b..d12f20333 100644 --- a/i18n/iconv_lib/utf_32.rs +++ b/i18n/iconv_lib/utf_32.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use byteorder::{BigEndian, ByteOrder, LittleEndian}; use std::iter; use std::process::exit; +use byteorder::{BigEndian, ByteOrder, LittleEndian}; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum UTF32Variant { UTF32LE, diff --git a/i18n/tests/gencat/mod.rs b/i18n/tests/gencat/mod.rs index b91ea591c..dd5785389 100644 --- a/i18n/tests/gencat/mod.rs +++ b/i18n/tests/gencat/mod.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test_u8, TestPlanU8}; use std::env; use std::fs::File; use std::io::Read; use std::path::PathBuf; +use plib::testing::{run_test_u8, TestPlanU8}; + fn gencat_test(args: &[&str], expected_output: Vec, expected_error: Vec) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); run_test_u8(TestPlanU8 { diff --git a/i18n/tests/iconv/mod.rs b/i18n/tests/iconv/mod.rs index 7e9d17905..bb1831668 100644 --- a/i18n/tests/iconv/mod.rs +++ b/i18n/tests/iconv/mod.rs @@ -8,12 +8,13 @@ // #![allow(non_snake_case)] -use plib::testing::{run_test_u8, TestPlanU8}; use std::env; use std::fs::File; use std::io::Read; use std::path::PathBuf; +use plib::testing::{run_test_u8, TestPlanU8}; + fn iconv_test(args: &[&str], input: Vec, expected_output: Vec, expected_error: Vec) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); run_test_u8(TestPlanU8 { diff --git a/m4/src/lib.rs b/m4/src/lib.rs index 9ec433c33..7515e4963 100644 --- a/m4/src/lib.rs +++ b/m4/src/lib.rs @@ -1,14 +1,15 @@ -use error::{Error, ErrorKind, Result}; -use input::{Input, InputRead}; -use lexer::MacroName; -use macros::MacroDefinition; -use state::State; use std::cell::RefCell; use std::ffi::OsStr; use std::io::Write; use std::path::PathBuf; use std::rc::Rc; +use error::{Error, ErrorKind, Result}; +use input::{Input, InputRead}; +use lexer::MacroName; +use macros::MacroDefinition; +use state::State; + pub mod error; mod input; mod lexer; diff --git a/m4/src/macros/builtin.rs b/m4/src/macros/builtin.rs index 352712700..d5427c2a1 100644 --- a/m4/src/macros/builtin.rs +++ b/m4/src/macros/builtin.rs @@ -5,11 +5,11 @@ use std::path::PathBuf; use std::process::ExitStatus; use std::rc::Rc; -use super::eval::parse_integer; -use super::{MacroDefinitionImplementation, MacroImplementation}; use nom::error::{ContextError, FromExternalError}; use nom::IResult; +use super::eval::parse_integer; +use super::{MacroDefinitionImplementation, MacroImplementation}; use crate::error::{Result, ResultExt}; use crate::input::{Input, InputRead}; use crate::lexer::{MacroName, MacroParseConfig, DEFAULT_QUOTE_CLOSE_TAG, DEFAULT_QUOTE_OPEN_TAG}; diff --git a/m4/src/macros/eval.rs b/m4/src/macros/eval.rs index 90d4336bc..97d604cd0 100644 --- a/m4/src/macros/eval.rs +++ b/m4/src/macros/eval.rs @@ -7,13 +7,12 @@ use nom::error::FromExternalError; use nom::sequence::{delimited, tuple}; use nom::IResult; +use super::MacroImplementation; use crate::lexer::is_whitespace; use crate::precedence::{self, binary_op, unary_op, Assoc, Operation}; use crate::state::{StackFrame, State}; use crate::Result; -use super::MacroImplementation; - pub struct EvalMacro; impl MacroImplementation for EvalMacro { diff --git a/m4/src/macros/trace.rs b/m4/src/macros/trace.rs index cb5c80e9e..f020a17e0 100644 --- a/m4/src/macros/trace.rs +++ b/m4/src/macros/trace.rs @@ -1,11 +1,10 @@ use std::io::Write; +use super::MacroImplementation; use crate::lexer::MacroName; use crate::state::{StackFrame, State}; use crate::Result; -use super::MacroImplementation; - pub struct TraceoffMacro; impl MacroImplementation for TraceoffMacro { diff --git a/m4/src/macros/user_defined.rs b/m4/src/macros/user_defined.rs index 438823d0c..2aa1d56e2 100644 --- a/m4/src/macros/user_defined.rs +++ b/m4/src/macros/user_defined.rs @@ -1,10 +1,9 @@ use std::io::Write; +use super::MacroImplementation; use crate::state::{StackFrame, State}; use crate::Result; -use super::MacroImplementation; - /// Arguments are positionally defined and referenced. The string "$1" in the defining text shall /// be replaced by the first argument. Systems shall support at least nine arguments; only the /// first nine can be referenced, using the strings "$1" to "$9", inclusive. The string "$0" is diff --git a/m4/src/output.rs b/m4/src/output.rs index 3da5235fd..16a4da70e 100644 --- a/m4/src/output.rs +++ b/m4/src/output.rs @@ -1,10 +1,11 @@ -use crate::error::Result; -use crate::input::InputStateRef; -use crate::state::StackFrame; use std::cell::RefCell; use std::io::{Seek, Write}; use std::rc::Rc; +use crate::error::Result; +use crate::input::InputStateRef; +use crate::state::StackFrame; + #[derive(Default)] pub struct OutputState { pub output: OutputRef, diff --git a/m4/tests/integration_test.rs b/m4/tests/integration_test.rs index e3497ec4e..02af2b1a5 100644 --- a/m4/tests/integration_test.rs +++ b/m4/tests/integration_test.rs @@ -2,15 +2,16 @@ //! You can regenerate the tests (which are based on the fixtures in `fixtures/integration_tests/`) //! using the following command: //! `cargo run -p m4-test-manager update-snapshots` -use m4_test_manager::TestSnapshot; -use posixutils_m4::error::GetExitCode; -use similar_asserts::assert_eq; use std::fs::read_to_string; use std::os::unix::ffi::OsStrExt; use std::os::unix::process::ExitStatusExt; use std::path::Path; use std::process::ExitStatus; +use m4_test_manager::TestSnapshot; +use posixutils_m4::error::GetExitCode; +use similar_asserts::assert_eq; + fn init() { let _ = env_logger::builder() .is_test(true) diff --git a/make/src/error_code.rs b/make/src/error_code.rs index 23f642f60..d52cc0527 100644 --- a/make/src/error_code.rs +++ b/make/src/error_code.rs @@ -10,9 +10,10 @@ use core::fmt; use std::io; +use gettextrs::gettext; + use crate::parser::parse::ParseError; use crate::special_target::Error; -use gettextrs::gettext; /// Represents the error codes that can be returned by the make utility #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/make/src/lib.rs b/make/src/lib.rs index 811393a88..0ae06db09 100644 --- a/make/src/lib.rs +++ b/make/src/lib.rs @@ -18,16 +18,16 @@ use std::collections::HashSet; use std::fs::{self}; use std::time::SystemTime; -use parser::{Makefile, VariableDefinition}; - -use crate::special_target::InferenceTarget; use config::Config; use error_code::ErrorCode::{self, *}; +use parser::{Makefile, VariableDefinition}; use rule::prerequisite::Prerequisite; use rule::target::Target; use rule::Rule; use special_target::SpecialTarget; +use crate::special_target::InferenceTarget; + /// The default shell variable name. const DEFAULT_SHELL_VAR: &str = "SHELL"; diff --git a/make/src/main.rs b/make/src/main.rs index 6a9795b18..d4bbdf4e5 100644 --- a/make/src/main.rs +++ b/make/src/main.rs @@ -18,7 +18,6 @@ use std::{env, fs, io, process}; use clap::Parser; use const_format::formatcp; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; - use posixutils_make::config::Config; use posixutils_make::error_code::ErrorCode::{self, *}; use posixutils_make::parser::preprocessor::ENV_MACROS; diff --git a/make/src/parser/lex.rs b/make/src/parser/lex.rs index 8dd1496d2..7b78ed8ef 100644 --- a/make/src/parser/lex.rs +++ b/make/src/parser/lex.rs @@ -1,9 +1,9 @@ -use super::SyntaxKind; use std::collections::HashMap; use std::iter::Peekable; use std::str::Chars; use std::sync::LazyLock; +use super::SyntaxKind; use crate::parser::SyntaxKind::{EXPORT, INCLUDE}; static KEYWORDS: LazyLock> = LazyLock::new(|| HashMap::from_iter([("include", INCLUDE), ("export", EXPORT)])); diff --git a/make/src/parser/parse.rs b/make/src/parser/parse.rs index e9335216d..139b943f8 100644 --- a/make/src/parser/parse.rs +++ b/make/src/parser/parse.rs @@ -6,11 +6,12 @@ // SPDX-License-Identifier: MIT // -use crate::parser::lex::lex; -use rowan::ast::AstNode; use std::str::FromStr; +use rowan::ast::AstNode; + use super::SyntaxKind::*; +use crate::parser::lex::lex; #[derive(Debug)] pub enum Error { @@ -73,14 +74,14 @@ impl rowan::Language for Lang { /// GreenNode is an immutable tree, which is cheap to change, /// but doesn't contain offsets and parent pointers. use rowan::GreenNode; - -use super::SyntaxKind; -use crate::parser::preprocessor::preprocess; /// You can construct GreenNodes by hand, but a builder /// is helpful for top-down parsers: it maintains a stack /// of currently in-progress nodes use rowan::GreenNodeBuilder; +use super::SyntaxKind; +use crate::parser::preprocessor::preprocess; + /// The parse results are stored as a "green tree". /// We'll discuss working with the results later #[derive(Debug)] diff --git a/make/src/rule.rs b/make/src/rule.rs index a28b6915f..89a8d3d29 100644 --- a/make/src/rule.rs +++ b/make/src/rule.rs @@ -12,15 +12,6 @@ pub mod prerequisite; pub mod recipe; pub mod target; -use crate::config::Config as GlobalConfig; -use crate::error_code::ErrorCode::{self, *}; -use crate::parser::{Rule as ParsedRule, VariableDefinition}; -use crate::{signal_handler, DEFAULT_SHELL, DEFAULT_SHELL_VAR}; -use config::Config; -use gettextrs::gettext; -use prerequisite::Prerequisite; -use recipe::config::Config as RecipeConfig; -use recipe::Recipe; use std::collections::{HashMap, VecDeque}; use std::env; use std::fs::{File, FileTimes}; @@ -29,8 +20,19 @@ use std::path::PathBuf; use std::process::{self, Command}; use std::sync::{Arc, LazyLock, Mutex}; use std::time::SystemTime; + +use config::Config; +use gettextrs::gettext; +use prerequisite::Prerequisite; +use recipe::config::Config as RecipeConfig; +use recipe::Recipe; use target::Target; +use crate::config::Config as GlobalConfig; +use crate::error_code::ErrorCode::{self, *}; +use crate::parser::{Rule as ParsedRule, VariableDefinition}; +use crate::{signal_handler, DEFAULT_SHELL, DEFAULT_SHELL_VAR}; + type LazyArcMutex = LazyLock>>; pub static INTERRUPT_FLAG: LazyArcMutex> = diff --git a/make/src/rule/target.rs b/make/src/rule/target.rs index 17a5c5706..9c2961d10 100644 --- a/make/src/rule/target.rs +++ b/make/src/rule/target.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use crate::special_target::SpecialTarget; use core::fmt; +use crate::special_target::SpecialTarget; + #[derive(Debug, Clone, PartialEq, Eq, Hash)] /// A target for a rule. pub enum Target { diff --git a/make/src/signal_handler.rs b/make/src/signal_handler.rs index 43138c62c..20a57284a 100644 --- a/make/src/signal_handler.rs +++ b/make/src/signal_handler.rs @@ -10,10 +10,11 @@ use std::fs::remove_file; use std::process; -use crate::rule::INTERRUPT_FLAG; use gettextrs::gettext; use libc::{signal, SIGHUP, SIGINT, SIGQUIT, SIGTERM}; +use crate::rule::INTERRUPT_FLAG; + /// Handles incoming signals by setting the interrupt flag and exiting the process. pub fn handle_signals(signal_code: libc::c_int) { let interrupt_flag = INTERRUPT_FLAG.lock().unwrap(); diff --git a/make/src/special_target.rs b/make/src/special_target.rs index 5329e676a..9d3103e4e 100644 --- a/make/src/special_target.rs +++ b/make/src/special_target.rs @@ -26,10 +26,11 @@ pub enum SpecialTarget { Silent, Suffixes, } -use crate::config::Config; use gettextrs::gettext; use SpecialTarget::*; +use crate::config::Config; + impl SpecialTarget { // could be automated with `strum` pub const COUNT: usize = 8; diff --git a/make/tests/integration.rs b/make/tests/integration.rs index ddda6dd30..a39ca1a58 100644 --- a/make/tests/integration.rs +++ b/make/tests/integration.rs @@ -13,7 +13,6 @@ use std::io::Write; use std::process::{Child, Command, Stdio}; use plib::testing::{run_test, run_test_base, TestPlan}; - use posixutils_make::error_code::ErrorCode; pub fn run_test_not_comparing_error_message(plan: TestPlan) { @@ -370,12 +369,14 @@ mod macros { } mod target_behavior { - use super::*; - use libc::{kill, SIGINT}; - use posixutils_make::parser::parse::ParseError; use std::thread; use std::time::Duration; + use libc::{kill, SIGINT}; + use posixutils_make::parser::parse::ParseError; + + use super::*; + #[test] fn no_targets() { run_test_helper( @@ -576,13 +577,15 @@ mod recipes { } mod special_targets { - use super::*; - use libc::{kill, SIGINT}; - use posixutils_make::special_target; use std::fs::remove_dir; use std::time::Duration; use std::{fs, thread}; + use libc::{kill, SIGINT}; + use posixutils_make::special_target; + + use super::*; + #[test] fn default() { run_test_helper( diff --git a/plib/src/group.rs b/plib/src/group.rs index d4f5b0ef8..3084bd40d 100644 --- a/plib/src/group.rs +++ b/plib/src/group.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use libc::{endgrent, getgrent, setgrent}; use std::ffi::CStr; use std::ptr; +use libc::{endgrent, getgrent, setgrent}; + pub struct Group { pub name: String, pub passwd: String, diff --git a/plib/src/utmpx.rs b/plib/src/utmpx.rs index 271e57e42..6c973545e 100644 --- a/plib/src/utmpx.rs +++ b/plib/src/utmpx.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use crate::platform::{self, endutxent, getutxent, setutxent}; use std::ffi::CStr; +use crate::platform::{self, endutxent, getutxent, setutxent}; + pub struct Utmpx { pub user: String, pub id: String, diff --git a/process/batch.rs b/process/batch.rs index 8c43f8099..02015f22e 100644 --- a/process/batch.rs +++ b/process/batch.rs @@ -7,10 +7,6 @@ // SPDX-License-Identifier: MIT // -use chrono::{DateTime, Local, TimeZone, Utc}; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use libc::{getlogin, getpwnam, passwd}; - use std::collections::HashSet; use std::ffi::{CStr, CString}; use std::fs::{self}; @@ -19,6 +15,10 @@ use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; use std::{env, process}; +use chrono::{DateTime, Local, TimeZone, Utc}; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; +use libc::{getlogin, getpwnam, passwd}; + #[cfg(target_os = "linux")] const SPOOL_DIRECTORIES: &[&str] = &[ "/var/spool/cron/atjobs/", diff --git a/process/fuser.rs b/process/fuser.rs index f1f3dc92e..6c4ff99f8 100644 --- a/process/fuser.rs +++ b/process/fuser.rs @@ -141,15 +141,16 @@ impl Names { #[cfg(target_os = "linux")] mod linux { - use super::*; - - use libc::fstat; use std::env; use std::fs::{self, File}; use std::io::{BufRead, Error, ErrorKind}; use std::net::{IpAddr, Ipv4Addr, UdpSocket}; use std::os::unix::io::AsRawFd; use std::path::Component; + + use libc::fstat; + + use super::*; const PROC_PATH: &str = "/proc"; const PROC_MOUNTS: &str = "/proc/mounts"; @@ -1222,11 +1223,12 @@ mod macos { pub mod osx_libproc_bindings { include!(concat!(env!("OUT_DIR"), "/osx_libproc_bindings.rs")); } - use libc::{c_char, c_int, c_void}; use std::ffi::CString; use std::os::unix::ffi::OsStrExt; use std::ptr; + use libc::{c_char, c_int, c_void}; + // similar to list_pids_ret() below, there are two cases when 0 is returned, one when there are // no pids, and the other when there is an error // when `errno` is set to indicate an error in the input type, the return value is 0 diff --git a/process/tests/fuser/basic.rs b/process/tests/fuser/basic.rs index c81e28ab2..826562ec7 100644 --- a/process/tests/fuser/basic.rs +++ b/process/tests/fuser/basic.rs @@ -1,10 +1,11 @@ mod basic { - use crate::fuser::fuser_test; use std::fs::File; use std::path::PathBuf; use std::process::Command; use std::str; + use crate::fuser::fuser_test; + /// Tests the basic functionality of `fuser` by ensuring it can find the PID of a process. /// /// **Setup:** diff --git a/process/tests/fuser/mod.rs b/process/tests/fuser/mod.rs index 85b6d82a2..4f8ad998e 100644 --- a/process/tests/fuser/mod.rs +++ b/process/tests/fuser/mod.rs @@ -1,6 +1,7 @@ -use plib::testing::{run_test_with_checker, TestPlan}; use std::process::Output; +use plib::testing::{run_test_with_checker, TestPlan}; + mod basic; #[cfg(target_os = "linux")] mod tcp; diff --git a/process/tests/fuser/tcp.rs b/process/tests/fuser/tcp.rs index ae89cc09d..78b63adb7 100644 --- a/process/tests/fuser/tcp.rs +++ b/process/tests/fuser/tcp.rs @@ -1,10 +1,11 @@ #[cfg(test)] mod tcp { - use crate::fuser::fuser_test; use std::io; use std::net::{TcpListener, TcpStream}; use std::process::Command; + use crate::fuser::fuser_test; + /// Starts a TCP server on a predefined local address and port. /// /// **Returns:** diff --git a/process/tests/fuser/udp.rs b/process/tests/fuser/udp.rs index 33dba2113..d2b299dbc 100644 --- a/process/tests/fuser/udp.rs +++ b/process/tests/fuser/udp.rs @@ -1,10 +1,11 @@ #[cfg(test)] mod udp { - use crate::fuser::fuser_test; use std::io; use std::net::UdpSocket; use std::process::Command; + use crate::fuser::fuser_test; + /// Waits for a UDP server to become available by sending a dummy message to the specified port. /// /// **Arguments:** diff --git a/process/tests/fuser/unix.rs b/process/tests/fuser/unix.rs index 03799eea5..e0de04efe 100644 --- a/process/tests/fuser/unix.rs +++ b/process/tests/fuser/unix.rs @@ -1,9 +1,10 @@ mod unix { - use crate::fuser::fuser_test; use std::os::unix::net::{UnixListener, UnixStream}; use std::process::Command; use std::{fs, thread}; + use crate::fuser::fuser_test; + /// Starts a Unix socket server at the specified socket path. /// /// **Arguments:** diff --git a/process/tests/fuser/with_user.rs b/process/tests/fuser/with_user.rs index 101c26e61..ffaaeaaaa 100644 --- a/process/tests/fuser/with_user.rs +++ b/process/tests/fuser/with_user.rs @@ -1,11 +1,13 @@ mod with_user { - use crate::fuser::fuser_test; - use libc::uid_t; use std::ffi::CStr; use std::fs::File; use std::process::Command; use std::{io, str}; + use libc::uid_t; + + use crate::fuser::fuser_test; + /// Retrieves the user name of the process owner by process ID on Linux. /// /// **Arguments:** diff --git a/rustfmt.toml b/rustfmt.toml index 7feb9d421..89623da30 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,3 +4,4 @@ # Module granularity gives better diffs imports_granularity = "Module" +group_imports = "StdExternalCrate" diff --git a/sccs/tests/what/mod.rs b/sccs/tests/what/mod.rs index ac07b259e..958728a49 100644 --- a/sccs/tests/what/mod.rs +++ b/sccs/tests/what/mod.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::path::PathBuf; +use plib::testing::{run_test, TestPlan}; + fn test_file_path(file_name: &str) -> PathBuf { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests"); diff --git a/screen/osdata.rs b/screen/osdata.rs index c5ef97da0..3b9d8c5e4 100644 --- a/screen/osdata.rs +++ b/screen/osdata.rs @@ -9,6 +9,12 @@ use std::collections::HashMap; +#[cfg(target_os = "linux")] +use termios::os::linux::{ + BS0, BS1, BSDLY, CR0, CR1, CR2, CR3, CRDLY, ECHOCTL, ECHOKE, ECHOPRT, FF0, FF1, FFDLY, FLUSHO, + IMAXBEL, IUTF8, NL0, NL1, NLDLY, OFDEL, OFILL, PENDIN, TAB0, TAB1, TAB2, TAB3, TABDLY, VT0, + VT1, VTDLY, +}; #[cfg(target_os = "macos")] use termios::os::macos::{ ALTWERASE, BS0, BS1, BSDLY, CCAR_OFLOW, CCTS_OFLOW, CDSR_OFLOW, CDTR_IFLOW, CR0, CR1, CR2, CR3, @@ -16,14 +22,6 @@ use termios::os::macos::{ NLDLY, NOKERNINFO, OFDEL, OFILL, ONOEOT, OXTABS, PENDIN, TAB0, TAB1, TAB2, TAB3, TABDLY, VT0, VT1, VTDLY, }; - -#[cfg(target_os = "linux")] -use termios::os::linux::{ - BS0, BS1, BSDLY, CR0, CR1, CR2, CR3, CRDLY, ECHOCTL, ECHOKE, ECHOPRT, FF0, FF1, FFDLY, FLUSHO, - IMAXBEL, IUTF8, NL0, NL1, NLDLY, OFDEL, OFILL, PENDIN, TAB0, TAB1, TAB2, TAB3, TABDLY, VT0, - VT1, VTDLY, -}; - use termios::*; pub fn load_speeds() -> HashMap<&'static str, speed_t> { diff --git a/sh/src/builtin/bg.rs b/sh/src/builtin/bg.rs index c848010b5..a216c84bf 100644 --- a/sh/src/builtin/bg.rs +++ b/sh/src/builtin/bg.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use nix::sys::signal::kill; + use crate::builtin::{skip_option_terminator, BuiltinResult, BuiltinUtility}; use crate::jobs::{parse_job_id, Job, JobState}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::sys::signal::kill; fn run_background_job( arg: &str, diff --git a/sh/src/builtin/cd.rs b/sh/src/builtin/cd.rs index 419dafd91..7f09bd446 100644 --- a/sh/src/builtin/cd.rs +++ b/sh/src/builtin/cd.rs @@ -7,15 +7,16 @@ // SPDX-License-Identifier: MIT // -use crate::builtin::{BuiltinResult, BuiltinUtility}; -use crate::option_parser::OptionParser; -use crate::shell::opened_files::OpenedFiles; -use crate::shell::Shell; use std::ffi::{OsStr, OsString}; use std::fmt::Display; use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::path::PathBuf; +use crate::builtin::{BuiltinResult, BuiltinUtility}; +use crate::option_parser::OptionParser; +use crate::shell::opened_files::OpenedFiles; +use crate::shell::Shell; + #[derive(Debug, PartialEq, Eq)] enum CdArgs<'a> { ChangeDir { diff --git a/sh/src/builtin/dot.rs b/sh/src/builtin/dot.rs index 1096ec53c..3c098c4fd 100644 --- a/sh/src/builtin/dot.rs +++ b/sh/src/builtin/dot.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use std::path::Path; + use crate::builtin::{skip_option_terminator, BuiltinResult, SpecialBuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::{execute_file_as_script, ScriptExecutionError, Shell}; use crate::utils::find_command; -use std::path::Path; pub struct Dot; diff --git a/sh/src/builtin/fc.rs b/sh/src/builtin/fc.rs index c6720213b..b0f0060a6 100644 --- a/sh/src/builtin/fc.rs +++ b/sh/src/builtin/fc.rs @@ -7,16 +7,18 @@ // SPDX-License-Identifier: MIT // +use std::fs::File; +use std::io::Read; +use std::os::fd::{FromRawFd, OwnedFd}; +use std::path::PathBuf; + +use nix::unistd::mkstemp; + use crate::builtin::{BuiltinError, BuiltinResult, BuiltinUtility}; use crate::option_parser::OptionParser; use crate::shell::history::EndPoint; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::unistd::mkstemp; -use std::fs::File; -use std::io::Read; -use std::os::fd::{FromRawFd, OwnedFd}; -use std::path::PathBuf; #[derive(Debug, Eq, PartialEq)] struct Replace<'s> { diff --git a/sh/src/builtin/fg.rs b/sh/src/builtin/fg.rs index 9640a710c..4c40f81a2 100644 --- a/sh/src/builtin/fg.rs +++ b/sh/src/builtin/fg.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use nix::sys::signal::kill; + use crate::builtin::{skip_option_terminator, BuiltinResult, BuiltinUtility}; use crate::jobs::{parse_job_id, Job, JobId, JobState}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::sys::signal::kill; fn run_foreground_job( shell: &mut Shell, diff --git a/sh/src/builtin/kill.rs b/sh/src/builtin/kill.rs index 2256c222e..a6becd348 100644 --- a/sh/src/builtin/kill.rs +++ b/sh/src/builtin/kill.rs @@ -7,12 +7,14 @@ // SPDX-License-Identifier: MIT // +use std::str::FromStr; + +use nix::sys::signal::{kill, Signal as NixSignal}; + use crate::builtin::{parse_pid, skip_option_terminator, BuiltinResult, BuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; use crate::signals::{Signal, SIGNALS}; -use nix::sys::signal::{kill, Signal as NixSignal}; -use std::str::FromStr; enum KillArgs<'a> { SendSignal { diff --git a/sh/src/builtin/mod.rs b/sh/src/builtin/mod.rs index 0f75ff9b4..027a51fb3 100644 --- a/sh/src/builtin/mod.rs +++ b/sh/src/builtin/mod.rs @@ -7,6 +7,11 @@ // SPDX-License-Identifier: MIT // +use std::fmt::{Display, Formatter}; + +use nix::libc::pid_t; +use nix::unistd::Pid; + use crate::builtin::alias::AliasBuiltin; use crate::builtin::bg::Bg; use crate::builtin::cd::Cd; @@ -40,9 +45,6 @@ use crate::shell::environment::CannotModifyReadonly; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; use crate::utils::OsError; -use nix::libc::pid_t; -use nix::unistd::Pid; -use std::fmt::{Display, Formatter}; pub mod alias; mod bg; diff --git a/sh/src/builtin/read.rs b/sh/src/builtin/read.rs index 6935ab748..c8f628735 100644 --- a/sh/src/builtin/read.rs +++ b/sh/src/builtin/read.rs @@ -7,16 +7,18 @@ // SPDX-License-Identifier: MIT // +use std::os::fd::{AsRawFd, RawFd}; +use std::time::Duration; + +use atty::Stream; +use nix::errno::Errno; + use crate::builtin::{BuiltinError, BuiltinResult, BuiltinUtility}; use crate::option_parser::OptionParser; use crate::shell::opened_files::{OpenedFile, OpenedFiles, STDIN_FILENO}; use crate::shell::Shell; use crate::wordexp::expanded_word::ExpandedWord; use crate::wordexp::split_fields; -use atty::Stream; -use nix::errno::Errno; -use std::os::fd::{AsRawFd, RawFd}; -use std::time::Duration; fn bytes_to_string(bytes: Vec) -> Result { String::from_utf8(bytes.to_vec()).map_err(|_| "read: invalid UTF-8".into()) diff --git a/sh/src/builtin/set.rs b/sh/src/builtin/set.rs index a70718d9f..ce127d3ab 100644 --- a/sh/src/builtin/set.rs +++ b/sh/src/builtin/set.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use std::ffi::CString; + use crate::builtin::{BuiltinResult, SpecialBuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; use crate::utils::strcoll; -use std::ffi::CString; pub struct SetSpecialBuiltin; diff --git a/sh/src/builtin/times.rs b/sh/src/builtin/times.rs index 07ad93ac6..82ddd5652 100644 --- a/sh/src/builtin/times.rs +++ b/sh/src/builtin/times.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use nix::libc::suseconds_t; +use nix::sys::resource::{getrusage, UsageWho}; + use crate::builtin::{skip_option_terminator, BuiltinResult, SpecialBuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::libc::suseconds_t; -use nix::sys::resource::{getrusage, UsageWho}; fn seconds_to_minutes(seconds: f32) -> i32 { seconds as i32 / 60 } diff --git a/sh/src/builtin/trap.rs b/sh/src/builtin/trap.rs index 08996477b..f9a7d4a9c 100644 --- a/sh/src/builtin/trap.rs +++ b/sh/src/builtin/trap.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // +use std::fmt::Display; +use std::str::FromStr; + use crate::builtin::{BuiltinError, BuiltinResult, SpecialBuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; use crate::signals::Signal; -use std::fmt::Display; -use std::str::FromStr; #[derive(Clone, PartialEq, Eq)] pub enum TrapAction { diff --git a/sh/src/builtin/ulimit.rs b/sh/src/builtin/ulimit.rs index dedda9dd0..ccbb7e295 100644 --- a/sh/src/builtin/ulimit.rs +++ b/sh/src/builtin/ulimit.rs @@ -7,13 +7,15 @@ // SPDX-License-Identifier: MIT // +use std::fmt::Display; + +use nix::libc::{rlim_t, RLIM_INFINITY}; +use nix::sys::resource::Resource; + use crate::builtin::{BuiltinResult, BuiltinUtility}; use crate::option_parser::OptionParser; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::libc::{rlim_t, RLIM_INFINITY}; -use nix::sys::resource::Resource; -use std::fmt::Display; #[derive(Debug, PartialEq, Eq, Clone, Copy)] enum ResourceLimit { diff --git a/sh/src/builtin/wait.rs b/sh/src/builtin/wait.rs index 0f1edd701..c9eccdf61 100644 --- a/sh/src/builtin/wait.rs +++ b/sh/src/builtin/wait.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use nix::errno::Errno; +use nix::unistd::Pid; + use crate::builtin::{parse_pid, skip_option_terminator, BuiltinResult, BuiltinUtility}; use crate::shell::opened_files::OpenedFiles; use crate::shell::Shell; -use nix::errno::Errno; -use nix::unistd::Pid; fn wait_for_pid(pid: Pid, shell: &mut Shell) -> i32 { match shell.wait_child_process(pid) { diff --git a/sh/src/cli/terminal.rs b/sh/src/cli/terminal.rs index a2b5e2db2..64b4301ce 100644 --- a/sh/src/cli/terminal.rs +++ b/sh/src/cli/terminal.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // -use atty::Stream; -use nix::sys::termios; -use nix::sys::termios::{LocalFlags, Termios}; use std::io; use std::io::Read; use std::os::fd::AsFd; +use atty::Stream; +use nix::sys::termios; +use nix::sys::termios::{LocalFlags, Termios}; + #[derive(Clone)] pub struct Terminal { base_settings: Option, diff --git a/sh/src/cli/vi/mod.rs b/sh/src/cli/vi/mod.rs index 37ced06e3..4b6736885 100644 --- a/sh/src/cli/vi/mod.rs +++ b/sh/src/cli/vi/mod.rs @@ -10,6 +10,10 @@ mod cursor; mod word; +use std::borrow::Cow; +use std::ffi::OsString; +use std::path::Path; + use crate::cli::vi::cursor::{Cursor, MotionCommand, MotionError}; use crate::cli::vi::word::{current_bigword, BigWordIter}; use crate::parse::word_parser::parse_word; @@ -18,9 +22,6 @@ use crate::shell::history::History; use crate::shell::Shell; use crate::wordexp::expand_word; use crate::wordexp::pathname::glob; -use std::borrow::Cow; -use std::ffi::OsString; -use std::path::Path; #[derive(Clone)] enum CommandOp { diff --git a/sh/src/jobs.rs b/sh/src/jobs.rs index a15017995..f61dc3f05 100644 --- a/sh/src/jobs.rs +++ b/sh/src/jobs.rs @@ -7,10 +7,12 @@ // SPDX-License-Identifier: MIT // -use crate::utils::{signal_to_exit_status, waitpid, OsResult}; +use std::fmt::{Display, Formatter, Write}; + use nix::sys::wait::{WaitPidFlag, WaitStatus}; use nix::unistd::Pid; -use std::fmt::{Display, Formatter, Write}; + +use crate::utils::{signal_to_exit_status, waitpid, OsResult}; #[derive(Clone, Copy, PartialEq, Eq)] pub enum JobPosition { diff --git a/sh/src/main.rs b/sh/src/main.rs index 9240c5d5b..7965d6c5d 100644 --- a/sh/src/main.rs +++ b/sh/src/main.rs @@ -7,6 +7,16 @@ // SPDX-License-Identifier: MIT // +use std::error::Error; +use std::io; +use std::io::Write; +use std::os::fd::AsFd; +use std::time::Duration; + +use cli::terminal::read_nonblocking_char; +use cli::vi::{Action, ViEditor}; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + use crate::cli::args::{parse_args, ExecutionMode}; use crate::cli::terminal::is_attached_to_terminal; use crate::cli::{clear_line, set_cursor_pos}; @@ -15,14 +25,6 @@ use crate::signals::{ handle_signal_ignore, handle_signal_write_to_signal_buffer, setup_signal_handling, Signal, }; use crate::utils::is_process_in_foreground; -use cli::terminal::read_nonblocking_char; -use cli::vi::{Action, ViEditor}; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use std::error::Error; -use std::io; -use std::io::Write; -use std::os::fd::AsFd; -use std::time::Duration; mod builtin; mod cli; diff --git a/sh/src/parse/command.rs b/sh/src/parse/command.rs index e7082a4f0..35f61e9d7 100644 --- a/sh/src/parse/command.rs +++ b/sh/src/parse/command.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use crate::nonempty::NonEmpty; -use crate::parse::word::WordPair; use std::fmt::{Debug, Display, Formatter, Write}; use std::rc::Rc; +use crate::nonempty::NonEmpty; +use crate::parse::word::WordPair; + pub type Name = Rc; #[derive(Debug, PartialEq, Clone, Copy)] diff --git a/sh/src/parse/command_parser.rs b/sh/src/parse/command_parser.rs index b2bb4d6ba..66d55cb2e 100644 --- a/sh/src/parse/command_parser.rs +++ b/sh/src/parse/command_parser.rs @@ -7,6 +7,9 @@ // SPDX-License-Identifier: MIT // +use std::borrow::Cow; +use std::rc::Rc; + use crate::nonempty::NonEmpty; use crate::parse::command::{ Assignment, CaseItem, Command, CommandType, CompleteCommand, CompoundCommand, Conjunction, @@ -20,8 +23,6 @@ use crate::parse::word::{ }; use crate::parse::word_parser::parse_word_pair; use crate::parse::{AliasTable, ParseResult, ParserError}; -use std::borrow::Cow; -use std::rc::Rc; pub fn is_valid_name(name: &str) -> bool { name.starts_with(|c: char| c.is_ascii_alphabetic() || c == '_') diff --git a/sh/src/parse/lexer/command_lexer.rs b/sh/src/parse/lexer/command_lexer.rs index 1094d3141..f7caf1b0b 100644 --- a/sh/src/parse/lexer/command_lexer.rs +++ b/sh/src/parse/lexer/command_lexer.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use crate::parse::lexer::{is_blank, remove_delimiter_from_here_document, HereDocument, Lexer}; -use crate::parse::ParseResult; use std::borrow::Cow; use std::fmt::{Display, Formatter}; +use crate::parse::lexer::{is_blank, remove_delimiter_from_here_document, HereDocument, Lexer}; +use crate::parse::ParseResult; + #[derive(Clone, Debug, Default)] struct IndexIter { pos: usize, diff --git a/sh/src/parse/lexer/mod.rs b/sh/src/parse/lexer/mod.rs index abd232fcc..0053bdbff 100644 --- a/sh/src/parse/lexer/mod.rs +++ b/sh/src/parse/lexer/mod.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // +use std::borrow::Cow; + use crate::parse::lexer::word_lexer::remove_quotes; use crate::parse::{ParseResult, ParserError}; -use std::borrow::Cow; pub mod command_lexer; pub mod word_lexer; diff --git a/sh/src/parse/lexer/word_lexer.rs b/sh/src/parse/lexer/word_lexer.rs index ce6e33ab6..1b92cd30c 100644 --- a/sh/src/parse/lexer/word_lexer.rs +++ b/sh/src/parse/lexer/word_lexer.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use crate::parse::lexer::Lexer; -use crate::parse::ParseResult; use std::borrow::Cow; use std::fmt::{Display, Formatter}; use std::str::CharIndices; +use crate::parse::lexer::Lexer; +use crate::parse::ParseResult; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum WordToken<'src> { DoubleQuote, diff --git a/sh/src/parse/word.rs b/sh/src/parse/word.rs index 6253d4c40..e51fe5b24 100644 --- a/sh/src/parse/word.rs +++ b/sh/src/parse/word.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use crate::parse::command::Name; use std::fmt::{Display, Formatter}; +use crate::parse::command::Name; + #[derive(Debug, Clone, PartialEq)] pub enum SpecialParameter { At, diff --git a/sh/src/parse/word_parser.rs b/sh/src/parse/word_parser.rs index 1eb2c14f1..50f804771 100644 --- a/sh/src/parse/word_parser.rs +++ b/sh/src/parse/word_parser.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // +use std::rc::Rc; + use crate::parse::lexer::word_lexer::{WordLexer, WordToken}; use crate::parse::word::{ Parameter, ParameterExpansion, SpecialParameter, Word, WordPair, WordPart, }; use crate::parse::{ParseResult, ParserError}; -use std::rc::Rc; struct WordParser<'src> { lexer: WordLexer<'src>, diff --git a/sh/src/pattern/mod.rs b/sh/src/pattern/mod.rs index 1350d984f..32517c96c 100644 --- a/sh/src/pattern/mod.rs +++ b/sh/src/pattern/mod.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // +use std::ffi::{CStr, CString}; + use crate::pattern::parse::{parse_pattern, PatternItem}; use crate::pattern::regex::{parsed_pattern_to_regex, Regex}; use crate::wordexp::expanded_word::ExpandedWord; -use std::ffi::{CStr, CString}; mod parse; mod regex; diff --git a/sh/src/pattern/regex.rs b/sh/src/pattern/regex.rs index 5d80956f3..38284dc5d 100644 --- a/sh/src/pattern/regex.rs +++ b/sh/src/pattern/regex.rs @@ -7,13 +7,15 @@ // SPDX-License-Identifier: MIT // -use crate::pattern::parse::{BracketExpression, BracketItem, PatternItem, RangeEndpoint}; use core::fmt; -use nix::libc; use std::ffi::{CStr, CString}; use std::fmt::{Formatter, Write}; use std::ptr; +use nix::libc; + +use crate::pattern::parse::{BracketExpression, BracketItem, PatternItem, RangeEndpoint}; + fn regex_compilation_result( status_integer: libc::c_int, regex: &libc::regex_t, diff --git a/sh/src/shell/environment.rs b/sh/src/shell/environment.rs index c2d1cc9fc..267b3c38c 100644 --- a/sh/src/shell/environment.rs +++ b/sh/src/shell/environment.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use crate::shell::Display; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::fmt::Formatter; +use crate::shell::Display; + #[derive(Clone, Default)] pub struct Value { /// `None` if `Value` is unset diff --git a/sh/src/shell/history.rs b/sh/src/shell/history.rs index 358db98a4..c5f7eb2d2 100644 --- a/sh/src/shell/history.rs +++ b/sh/src/shell/history.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use crate::shell::environment::Environment; use std::collections::VecDeque; use std::io::ErrorKind; use std::path::Path; +use crate::shell::environment::Environment; + #[derive(Debug, Eq, PartialEq)] pub enum EndPoint<'s> { // one based diff --git a/sh/src/shell/mod.rs b/sh/src/shell/mod.rs index 696aec1a7..9bf16d1e5 100644 --- a/sh/src/shell/mod.rs +++ b/sh/src/shell/mod.rs @@ -7,6 +7,23 @@ // SPDX-License-Identifier: MIT // +use std::collections::HashMap; +use std::ffi::{CString, OsString}; +use std::fmt::{Display, Formatter}; +use std::fs::File; +use std::io; +use std::io::{read_to_string, Read}; +use std::os::fd::{AsFd, AsRawFd, IntoRawFd}; +use std::path::Path; +use std::rc::Rc; +use std::time::Duration; + +use nix::errno::Errno; +use nix::libc; +use nix::sys::signal::{kill, Signal as NixSignal}; +use nix::sys::wait::{WaitPidFlag, WaitStatus}; +use nix::unistd::{getcwd, getpgid, getpgrp, getpid, getppid, setpgid, tcsetpgrp, ForkResult, Pid}; + use crate::builtin::set::SetOptions; use crate::builtin::trap::TrapAction; use crate::builtin::{ @@ -32,21 +49,6 @@ use crate::utils::{ waitpid, ExecError, OsError, OsResult, }; use crate::wordexp::{expand_word, expand_word_to_string, word_to_pattern}; -use nix::errno::Errno; -use nix::libc; -use nix::sys::signal::{kill, Signal as NixSignal}; -use nix::sys::wait::{WaitPidFlag, WaitStatus}; -use nix::unistd::{getcwd, getpgid, getpgrp, getpid, getppid, setpgid, tcsetpgrp, ForkResult, Pid}; -use std::collections::HashMap; -use std::ffi::{CString, OsString}; -use std::fmt::{Display, Formatter}; -use std::fs::File; -use std::io; -use std::io::{read_to_string, Read}; -use std::os::fd::{AsFd, AsRawFd, IntoRawFd}; -use std::path::Path; -use std::rc::Rc; -use std::time::Duration; pub mod environment; pub mod history; diff --git a/sh/src/shell/opened_files.rs b/sh/src/shell/opened_files.rs index 9afbb3301..ebb1c43d8 100644 --- a/sh/src/shell/opened_files.rs +++ b/sh/src/shell/opened_files.rs @@ -7,10 +7,6 @@ // SPDX-License-Identifier: MIT // -use crate::parse::command::{IORedirectionKind, Redirection, RedirectionKind}; -use crate::shell::{CommandExecutionError, Shell}; -use crate::wordexp::expand_word_to_string; -use nix::libc; use std::collections::HashMap; use std::fs::File; use std::io::Write; @@ -18,6 +14,12 @@ use std::os::unix::fs::OpenOptionsExt; use std::path::Path; use std::rc::Rc; +use nix::libc; + +use crate::parse::command::{IORedirectionKind, Redirection, RedirectionKind}; +use crate::shell::{CommandExecutionError, Shell}; +use crate::wordexp::expand_word_to_string; + pub const STDIN_FILENO: u32 = libc::STDIN_FILENO as u32; pub const STDOUT_FILENO: u32 = libc::STDOUT_FILENO as u32; pub const STDERR_FILENO: u32 = libc::STDERR_FILENO as u32; diff --git a/sh/src/signals.rs b/sh/src/signals.rs index 26dc86081..53e48f2b9 100644 --- a/sh/src/signals.rs +++ b/sh/src/signals.rs @@ -7,14 +7,16 @@ // SPDX-License-Identifier: MIT // -use crate::builtin::trap::TrapAction; +use std::fmt::{Display, Formatter}; +use std::os::fd::{AsRawFd, BorrowedFd, IntoRawFd, RawFd}; +use std::str::FromStr; + use nix::errno::Errno; use nix::libc; use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal as NixSignal}; use nix::unistd::{read, write}; -use std::fmt::{Display, Formatter}; -use std::os::fd::{AsRawFd, BorrowedFd, IntoRawFd, RawFd}; -use std::str::FromStr; + +use crate::builtin::trap::TrapAction; #[derive(Clone, Copy, PartialEq, Eq)] pub enum Signal { diff --git a/sh/src/utils.rs b/sh/src/utils.rs index f21c380a3..cb1802cd3 100644 --- a/sh/src/utils.rs +++ b/sh/src/utils.rs @@ -7,13 +7,6 @@ // SPDX-License-Identifier: MIT // -use crate::shell::environment::Environment; -use crate::shell::opened_files::{OpenedFile, OpenedFiles}; -use nix::errno::Errno; -use nix::libc; -use nix::sys::signal::Signal as NixSignal; -use nix::sys::wait::{WaitPidFlag, WaitStatus}; -use nix::unistd::{execve, tcgetpgrp, ForkResult, Pid}; use std::convert::Infallible; use std::ffi::{CStr, CString, OsString}; use std::fmt::{Display, Formatter}; @@ -22,6 +15,15 @@ use std::os::fd::{AsFd, AsRawFd, OwnedFd, RawFd}; use std::os::unix::ffi::OsStringExt; use std::path::PathBuf; +use nix::errno::Errno; +use nix::libc; +use nix::sys::signal::Signal as NixSignal; +use nix::sys::wait::{WaitPidFlag, WaitStatus}; +use nix::unistd::{execve, tcgetpgrp, ForkResult, Pid}; + +use crate::shell::environment::Environment; +use crate::shell::opened_files::{OpenedFile, OpenedFiles}; + pub const DEFAULT_PATH: &str = "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."; pub fn strcoll(lhs: &CStr, rhs: &CStr) -> std::cmp::Ordering { diff --git a/sh/src/wordexp/arithmetic.rs b/sh/src/wordexp/arithmetic.rs index b4f067a76..c76640a92 100644 --- a/sh/src/wordexp/arithmetic.rs +++ b/sh/src/wordexp/arithmetic.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // +use std::fmt::{Display, Formatter}; +use std::iter::Peekable; +use std::str::CharIndices; + use crate::parse::word::Word; use crate::shell::{CommandExecutionError, Shell}; use crate::wordexp::expanded_word::ExpandedWord; use crate::wordexp::{expand_word_to_string, ExpansionResult}; -use std::fmt::{Display, Formatter}; -use std::iter::Peekable; -use std::str::CharIndices; enum UnaryOperator { Plus, diff --git a/sh/src/wordexp/mod.rs b/sh/src/wordexp/mod.rs index 75549df29..8a98ec4c6 100644 --- a/sh/src/wordexp/mod.rs +++ b/sh/src/wordexp/mod.rs @@ -7,6 +7,8 @@ // SPDX-License-Identifier: MIT // +use std::path::Path; + use crate::parse::word::{Word, WordPart}; use crate::pattern::{FilenamePattern, Pattern}; use crate::shell::{CommandExecutionError, Shell}; @@ -15,7 +17,6 @@ use crate::wordexp::expanded_word::{ExpandedWord, ExpandedWordPart}; use crate::wordexp::parameter::expand_parameter_into; use crate::wordexp::pathname::glob; use crate::wordexp::tilde::tilde_expansion; -use std::path::Path; mod arithmetic; pub mod expanded_word; diff --git a/sh/src/wordexp/parameter.rs b/sh/src/wordexp/parameter.rs index 1c530613b..537322090 100644 --- a/sh/src/wordexp/parameter.rs +++ b/sh/src/wordexp/parameter.rs @@ -329,12 +329,13 @@ pub fn expand_parameter_into( #[cfg(test)] mod tests { + use nix::unistd::Pid; + use super::*; use crate::jobs::JobState; use crate::parse::word::test_utils::unquoted_literal; use crate::parse::word::Word; use crate::wordexp::expanded_word::ExpandedWordPart; - use nix::unistd::Pid; fn shell_with_env(env: &[(&str, &str)]) -> Shell { let mut shell = Shell::default(); diff --git a/sh/src/wordexp/pathname.rs b/sh/src/wordexp/pathname.rs index 4eb9d819f..036ee6358 100644 --- a/sh/src/wordexp/pathname.rs +++ b/sh/src/wordexp/pathname.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use crate::pattern::FilenamePattern; -use crate::utils::strcoll; use std::ffi::{CString, OsStr, OsString}; use std::os::unix::ffi::OsStringExt; use std::path::{Path, PathBuf}; +use crate::pattern::FilenamePattern; +use crate::utils::strcoll; + #[derive(Debug, PartialEq, Eq)] enum DirEntry { /// filename @@ -163,11 +164,12 @@ pub fn glob(pattern: &FilenamePattern, starting_directory: &Path) -> Vec; enum FileSystemNode { diff --git a/sh/src/wordexp/tilde.rs b/sh/src/wordexp/tilde.rs index 42b6fc832..9349af344 100644 --- a/sh/src/wordexp/tilde.rs +++ b/sh/src/wordexp/tilde.rs @@ -7,10 +7,12 @@ // SPDX-License-Identifier: MIT // +use std::ffi::{c_char, CStr, CString}; + +use nix::libc; + use crate::parse::word::{Word, WordPart}; use crate::shell::environment::Environment; -use nix::libc; -use std::ffi::{c_char, CStr, CString}; fn is_portable_filename_character(c: char) -> bool { // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282 @@ -150,10 +152,11 @@ pub fn tilde_expansion( #[cfg(test)] mod tests { + use std::collections::HashMap; + use super::*; use crate::parse::word::test_utils::{quoted_literal, unquoted_literal}; use crate::shell::environment::Value; - use std::collections::HashMap; #[derive(Default)] diff --git a/sh/tests/integration.rs b/sh/tests/integration.rs index 046b53278..0d7edaa6a 100644 --- a/sh/tests/integration.rs +++ b/sh/tests/integration.rs @@ -1,8 +1,9 @@ -use plib::testing::{run_test, run_test_with_checker, TestPlan}; use std::path::Path; use std::process::Output; use std::sync::atomic::{AtomicBool, Ordering}; +use plib::testing::{run_test, run_test_with_checker, TestPlan}; + static SETTING_TEST_VARS: AtomicBool = AtomicBool::new(false); static TEST_VARS_ARE_SET: AtomicBool = AtomicBool::new(false); diff --git a/sys/ipcs.rs b/sys/ipcs.rs index e4fa40445..228dfa09f 100644 --- a/sys/ipcs.rs +++ b/sys/ipcs.rs @@ -124,9 +124,10 @@ fn display_message_queues(_args: &Args) { } fn display_shared_memory(_args: &Args) { - use libc::{shmctl, shmid_ds, IPC_STAT}; use std::ffi::CStr; + use libc::{shmctl, shmid_ds, IPC_STAT}; + #[cfg(target_os = "macos")] const SHM_INFO: libc::c_int = 14; // SHM_INFO is typically 14 in Linux but this is not standard @@ -183,9 +184,10 @@ fn display_shared_memory(_args: &Args) { } fn display_semaphores(_args: &Args) { - use libc::{semctl, semid_ds, IPC_STAT}; use std::ffi::CStr; + use libc::{semctl, semid_ds, IPC_STAT}; + let mut semid: i32 = 0; let mut sem_ds: semid_ds = unsafe { std::mem::zeroed() }; diff --git a/sys/psmacos.rs b/sys/psmacos.rs index 07321c0c3..6ce24caab 100644 --- a/sys/psmacos.rs +++ b/sys/psmacos.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use libc::{c_int, c_void, getsid, pid_t, proc_listallpids, proc_pidinfo, proc_pidpath}; use std::ffi::CStr; use std::fs; use std::io::Error; use std::os::unix::fs::MetadataExt; +use libc::{c_int, c_void, getsid, pid_t, proc_listallpids, proc_pidinfo, proc_pidpath}; + const PROC_PIDPATHINFO_MAXSIZE: usize = 4096; pub struct ProcessInfo { diff --git a/sys/tests/getconf/mod.rs b/sys/tests/getconf/mod.rs index 91564bf9c..1b73d3070 100644 --- a/sys/tests/getconf/mod.rs +++ b/sys/tests/getconf/mod.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test_with_checker, TestPlan}; use std::process::Output; +use plib::testing::{run_test_with_checker, TestPlan}; + fn run_getconf_test(args: Vec<&str>, expected_exit_code: i32, check_fn: fn(&TestPlan, &Output)) { let plan = TestPlan { cmd: "getconf".to_string(), diff --git a/text/comm.rs b/text/comm.rs index 81a45cc1e..d175abf50 100644 --- a/text/comm.rs +++ b/text/comm.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::fs; use std::io::{self, BufRead, Write}; use std::path::PathBuf; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + const NO1: u32 = 1 << 0; const NO2: u32 = 1 << 1; const NODUP: u32 = 1 << 2; diff --git a/text/csplit.rs b/text/csplit.rs index c4e12b377..7279aa9d9 100644 --- a/text/csplit.rs +++ b/text/csplit.rs @@ -10,13 +10,14 @@ // - err on line num == 0 // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use regex::Regex; use std::fs::{self, File, OpenOptions}; use std::io::{self, BufRead, Error, ErrorKind, Read, Write}; use std::path::PathBuf; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; +use regex::Regex; + /// csplit - split files based on context #[derive(Parser)] #[command(version, about)] diff --git a/text/cut.rs b/text/cut.rs index a54a95b41..254fc31b9 100644 --- a/text/cut.rs +++ b/text/cut.rs @@ -8,10 +8,10 @@ // use std::io::{self, BufRead, Error, ErrorKind, Read}; +use std::path::PathBuf; use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use std::path::PathBuf; /// Cut - cut out selected fields of each line of a file #[derive(Parser, Clone)] diff --git a/text/diff_util/dir_diff.rs b/text/diff_util/dir_diff.rs index 5ae56f724..273e4d89a 100755 --- a/text/diff_util/dir_diff.rs +++ b/text/diff_util/dir_diff.rs @@ -3,13 +3,12 @@ use std::ffi::OsString; use std::io; use std::path::PathBuf; +use super::common::FormatOptions; +use super::dir_data::DirData; use crate::diff_util::constants::COULD_NOT_UNWRAP_FILENAME; use crate::diff_util::diff_exit_status::DiffExitStatus; use crate::diff_util::file_diff::FileDiff; -use super::common::FormatOptions; -use super::dir_data::DirData; - pub struct DirDiff<'a> { dir1: &'a mut DirData, dir2: &'a mut DirData, diff --git a/text/diff_util/file_diff.rs b/text/diff_util/file_diff.rs index fc669d29c..cfa540854 100755 --- a/text/diff_util/file_diff.rs +++ b/text/diff_util/file_diff.rs @@ -1,12 +1,3 @@ -use super::common::{FormatOptions, OutputFormat}; -use super::constants::COULD_NOT_UNWRAP_FILENAME; -use super::diff_exit_status::DiffExitStatus; -use super::file_data::{FileData, LineReader}; -use super::functions::{check_existance, is_binary, system_time_to_rfc2822}; -use super::hunks::Hunks; - -use crate::diff_util::constants::NO_NEW_LINE_AT_END_OF_FILE; - use std::cmp::Reverse; use std::collections::HashMap; use std::fmt::Write; @@ -15,6 +6,14 @@ use std::io::{self, BufReader, Read}; use std::os::unix::fs::MetadataExt; use std::path::PathBuf; +use super::common::{FormatOptions, OutputFormat}; +use super::constants::COULD_NOT_UNWRAP_FILENAME; +use super::diff_exit_status::DiffExitStatus; +use super::file_data::{FileData, LineReader}; +use super::functions::{check_existance, is_binary, system_time_to_rfc2822}; +use super::hunks::Hunks; +use crate::diff_util::constants::NO_NEW_LINE_AT_END_OF_FILE; + pub struct FileDiff<'a> { file1: &'a mut FileData<'a>, file2: &'a mut FileData<'a>, diff --git a/text/diff_util/functions.rs b/text/diff_util/functions.rs index 54d395a7f..225266616 100755 --- a/text/diff_util/functions.rs +++ b/text/diff_util/functions.rs @@ -1,9 +1,10 @@ -use chrono::{DateTime, Local}; use std::fs::File; use std::io::{self, Read}; use std::path::{Path, PathBuf}; use std::time::SystemTime; +use chrono::{DateTime, Local}; + use super::constants::UTF8_NOT_ALLOWED_BYTES; use crate::diff_util::constants::COULD_NOT_UNWRAP_FILENAME; diff --git a/text/diff_util/hunks.rs b/text/diff_util/hunks.rs index b86e4485b..e11fc107d 100755 --- a/text/diff_util/hunks.rs +++ b/text/diff_util/hunks.rs @@ -1,6 +1,5 @@ -use crate::diff_util::constants::NO_NEW_LINE_AT_END_OF_FILE; - use super::file_data::FileData; +use crate::diff_util::constants::NO_NEW_LINE_AT_END_OF_FILE; #[derive(Clone, Default)] pub enum Change { diff --git a/text/grep.rs b/text/grep.rs index 35baaa74a..229fac2a2 100644 --- a/text/grep.rs +++ b/text/grep.rs @@ -7,15 +7,16 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use libc::{regcomp, regex_t, regexec, regfree, REG_EXTENDED, REG_ICASE, REG_NOMATCH}; use std::ffi::CString; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::{Path, PathBuf}; use std::ptr; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; +use libc::{regcomp, regex_t, regexec, regfree, REG_EXTENDED, REG_ICASE, REG_NOMATCH}; + /// grep - search a file for a pattern. #[derive(Parser)] #[command(version, about)] diff --git a/text/join.rs b/text/join.rs index 63e1a9ffc..82dceb518 100644 --- a/text/join.rs +++ b/text/join.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::collections::HashMap; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::PathBuf; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// join - relational database operator #[derive(Parser)] #[command(version, about)] diff --git a/text/nl.rs b/text/nl.rs index bf45b7310..99ed97390 100644 --- a/text/nl.rs +++ b/text/nl.rs @@ -7,15 +7,16 @@ // SPDX-License-Identifier: MIT // -use clap::{Parser, ValueEnum}; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use regex::Regex; use std::fs; use std::io::{self, BufRead, Read}; use std::path::PathBuf; use std::process::ExitCode; use std::str::FromStr; +use clap::{Parser, ValueEnum}; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; +use regex::Regex; + /// nl - line numbering filter #[derive(Parser)] #[command(version, about, disable_help_flag = true)] diff --git a/text/paste.rs b/text/paste.rs index e63564ef8..0103fa58b 100644 --- a/text/paste.rs +++ b/text/paste.rs @@ -10,8 +10,6 @@ // TODO: // - improve: don't open all files at once in --serial mode -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::cell::{OnceCell, RefCell}; use std::error::Error; use std::fs::File; @@ -20,6 +18,9 @@ use std::iter::Cycle; use std::rc::Rc; use std::slice::Iter; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// paste - merge corresponding or subsequent lines of files #[derive(Parser)] #[command(version, about)] diff --git a/text/pr_util/args.rs b/text/pr_util/args.rs index 2544dab43..6615aa17b 100644 --- a/text/pr_util/args.rs +++ b/text/pr_util/args.rs @@ -7,14 +7,16 @@ // SPDX-License-Identifier: MIT // +use std::path::PathBuf; +use std::str::FromStr; + +use clap::Parser; +use regex::Regex; + use crate::{ DEFAULT_PAGE_LENGTH, DEFAULT_PAGE_WIDTH, DEFAULT_TAB_WIDTH, NUM_LINES_HEADER_FOOTER, PAGE_WIDTH_IF_HAS_SEPARATOR, TAB, }; -use clap::Parser; -use regex::Regex; -use std::path::PathBuf; -use std::str::FromStr; /// pr - print files #[derive(Parser)] diff --git a/text/pr_util/line_iterator.rs b/text/pr_util/line_iterator.rs index f9ef45840..d3136c705 100644 --- a/text/pr_util/line_iterator.rs +++ b/text/pr_util/line_iterator.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use crate::{Line, FORM_FEED}; use std::collections::VecDeque; use std::io::{self, BufRead, BufReader, Read}; +use crate::{Line, FORM_FEED}; + /// Iterator that splits the stream on `\n` or form-feed. pub struct LineBreakIterator { reader: BufReader>, diff --git a/text/pr_util/page_iterator.rs b/text/pr_util/page_iterator.rs index ae9727b96..64347f5ed 100644 --- a/text/pr_util/page_iterator.rs +++ b/text/pr_util/page_iterator.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // +use std::io::Read; + use super::LineBreakIterator; use crate::{Line, Page}; -use std::io::Read; /// Iterator over whole pages. pub struct PageIterator { diff --git a/text/sed.rs b/text/sed.rs index 0e8246527..ec4478d1d 100644 --- a/text/sed.rs +++ b/text/sed.rs @@ -7,12 +7,6 @@ // SPDX-License-Identifier: MIT // -use clap::{command, Parser}; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use libc::{ - ioctl, regcomp, regex_t, regexec, regmatch_t, winsize, REG_EXTENDED, STDERR_FILENO, - STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, -}; use std::collections::{HashMap, HashSet}; use std::ffi::CString; use std::fmt::{self, Debug}; @@ -23,6 +17,13 @@ use std::ops::Range; use std::path::PathBuf; use std::sync::Mutex; +use clap::{command, Parser}; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use libc::{ + ioctl, regcomp, regex_t, regexec, regmatch_t, winsize, REG_EXTENDED, STDERR_FILENO, + STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, +}; + static ERE: Mutex = Mutex::new(false); #[derive(Parser, Debug, Clone)] diff --git a/text/sort.rs b/text/sort.rs index b3320d116..1b5eeaf6b 100644 --- a/text/sort.rs +++ b/text/sort.rs @@ -8,7 +8,6 @@ // use std::cmp::Ordering; - use std::fs::File; use std::io::{self, BufRead, BufWriter, Error, ErrorKind, Read, Write}; use std::path::PathBuf; diff --git a/text/tests/comm/mod.rs b/text/tests/comm/mod.rs index b32773824..03d0cae55 100644 --- a/text/tests/comm/mod.rs +++ b/text/tests/comm/mod.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs; use std::path::PathBuf; +use plib::testing::{run_test, TestPlan}; + fn get_test_file_path(filename: &str) -> PathBuf { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests"); diff --git a/text/tests/diff-tests.rs b/text/tests/diff-tests.rs index 522b4785d..29686f3d9 100644 --- a/text/tests/diff-tests.rs +++ b/text/tests/diff-tests.rs @@ -11,13 +11,14 @@ #[path = "../diff_util/constants.rs"] mod constants; -use constants::{EXIT_STATUS_DIFFERENCE, EXIT_STATUS_NO_DIFFERENCE}; -use plib::testing::{run_test, TestPlan}; use std::collections::HashMap; use std::path::PathBuf; use std::process::Stdio; use std::sync::LazyLock; +use constants::{EXIT_STATUS_DIFFERENCE, EXIT_STATUS_NO_DIFFERENCE}; +use plib::testing::{run_test, TestPlan}; + fn diff_test(args: &[&str], expected_output: &str, expected_diff_exit_status: u8) { let str_args = args.iter().cloned().map(str::to_owned).collect(); diff --git a/text/tests/fold/mod.rs b/text/tests/fold/mod.rs index 537fd19a8..a4cc202ba 100644 --- a/text/tests/fold/mod.rs +++ b/text/tests/fold/mod.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs::File; use std::io::Read; use std::path::PathBuf; +use plib::testing::{run_test, TestPlan}; + fn get_test_file_path(filename: &str) -> PathBuf { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests/fold"); diff --git a/text/tests/head/mod.rs b/text/tests/head/mod.rs index 1c28d9327..fbdad575c 100644 --- a/text/tests/head/mod.rs +++ b/text/tests/head/mod.rs @@ -122,13 +122,14 @@ fn test_head_c() { /* #region Property-based tests */ mod property_tests { + use std::sync::mpsc::{self, RecvTimeoutError}; + use std::thread::{self}; + use std::time::Duration; + use plib::testing::run_test_base; use proptest::prelude::TestCaseError; use proptest::prop_assert; use proptest::test_runner::TestRunner; - use std::sync::mpsc::{self, RecvTimeoutError}; - use std::thread::{self}; - use std::time::Duration; fn get_test_runner(cases: u32) -> TestRunner { TestRunner::new(proptest::test_runner::Config { diff --git a/text/tests/paste/mod.rs b/text/tests/paste/mod.rs index b7883e833..ee6865420 100644 --- a/text/tests/paste/mod.rs +++ b/text/tests/paste/mod.rs @@ -8,10 +8,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, run_test_u8, TestPlan, TestPlanU8}; use std::fs; use std::path::PathBuf; +use plib::testing::{run_test, run_test_u8, TestPlan, TestPlanU8}; + fn get_test_file_path(filename: &str) -> PathBuf { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests/paste"); diff --git a/text/tests/pr/mod.rs b/text/tests/pr/mod.rs index 18ad60066..feee61bf7 100644 --- a/text/tests/pr/mod.rs +++ b/text/tests/pr/mod.rs @@ -8,11 +8,12 @@ // SPDX-License-Identifier: MIT // +use std::fs; +use std::io::Read; + use chrono::{DateTime, Local}; use plib::testing::{run_test, run_test_with_checker, TestPlan}; use regex::Regex; -use std::fs; -use std::io::Read; const PR_DATE_TIME_FORMAT: &str = "%b %d %H:%M %Y"; fn pr_test(args: &[&str], test_data: &str, expected_output: &str) { diff --git a/text/tr.rs b/text/tr.rs index 276b72d39..179f5a9d1 100644 --- a/text/tr.rs +++ b/text/tr.rs @@ -1,8 +1,9 @@ +use std::error::Error; +use std::process; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use setup::{ForRemoval, ForTranslation}; -use std::error::Error; -use std::process; use transformation::delete::DeleteTransformation; use transformation::delete_and_squeeze::{DeleteAndSqueezeState, DeleteAndSqueezeTransformation}; use transformation::squeeze::{SqueezeState, SqueezeTransformation}; @@ -994,9 +995,10 @@ mod parsing { } mod setup { - use crate::parsing::{CharOperand, CharRepetition, DataTypeWithData, EquivOperand, Operand}; use std::error::Error; + use crate::parsing::{CharOperand, CharRepetition, DataTypeWithData, EquivOperand, Operand}; + fn add_normal_char( data_type_with_data: DataTypeWithData, seven_bit: &mut [bool; 128_usize], diff --git a/text/unexpand.rs b/text/unexpand.rs index 76a930bae..926a66c2e 100644 --- a/text/unexpand.rs +++ b/text/unexpand.rs @@ -1,8 +1,9 @@ -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::io::{self, BufRead, Write}; use std::path::PathBuf; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + #[derive(Parser)] #[command(version, about)] struct Args { diff --git a/text/uniq.rs b/text/uniq.rs index 33d2575a2..4cf6b1093 100644 --- a/text/uniq.rs +++ b/text/uniq.rs @@ -1,9 +1,10 @@ -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::fs::File; use std::io::{self, BufRead, BufReader, Write}; use std::path::PathBuf; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// The uniq utility - filters out duplicate lines in a file #[derive(Parser)] #[command(version, about)] diff --git a/tree/chgrp.rs b/tree/chgrp.rs index df1570c2c..8ccdac95d 100644 --- a/tree/chgrp.rs +++ b/tree/chgrp.rs @@ -9,14 +9,16 @@ mod common; -use self::common::error_string; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::cell::RefCell; use std::ffi::CString; use std::io; use std::os::unix::fs::MetadataExt; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +use self::common::error_string; + /// chgrp - change file group ownership #[derive(Parser)] #[command(version, about, disable_help_flag = true)] diff --git a/tree/chmod.rs b/tree/chmod.rs index d0371b04e..88cb6e9a2 100644 --- a/tree/chmod.rs +++ b/tree/chmod.rs @@ -9,14 +9,16 @@ mod common; -use self::common::error_string; +use std::cell::RefCell; +use std::io; +use std::os::unix::fs::MetadataExt; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use modestr::ChmodMode; use plib::modestr; -use std::cell::RefCell; -use std::io; -use std::os::unix::fs::MetadataExt; + +use self::common::error_string; /// chmod - change the file modes #[derive(Parser)] diff --git a/tree/chown.rs b/tree/chown.rs index cf5e3e2c1..b16aceddf 100644 --- a/tree/chown.rs +++ b/tree/chown.rs @@ -10,13 +10,14 @@ // - implement -h, -H, -L, -P // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::ffi::CString; use std::os::unix::fs::MetadataExt; use std::path::Path; use std::{fs, io}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// chown - change the file ownership #[derive(Parser)] #[command(version, about)] diff --git a/tree/common/mod.rs b/tree/common/mod.rs index 64be53cd4..2fdc06ccf 100644 --- a/tree/common/mod.rs +++ b/tree/common/mod.rs @@ -4,8 +4,6 @@ // module (but is used in `cp` or `mv`). #![allow(unused)] -use ftw::{self, traverse_directory}; -use gettextrs::gettext; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::ffi::{CStr, CString, OsStr}; @@ -16,6 +14,9 @@ use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; use std::{fs, io}; +use ftw::{self, traverse_directory}; +use gettextrs::gettext; + pub type InodeMap = HashMap<(u64, u64), (ftw::FileDescriptor, CString)>; /// Return the error message. diff --git a/tree/cp.rs b/tree/cp.rs index 82abc6582..083f0ca1d 100644 --- a/tree/cp.rs +++ b/tree/cp.rs @@ -9,13 +9,15 @@ mod common; -use self::common::{copy_file, copy_files, error_string, CopyConfig}; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::collections::HashSet; use std::path::PathBuf; use std::{fs, io}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +use self::common::{copy_file, copy_files, error_string, CopyConfig}; + /// cp - copy files #[derive(Parser)] #[command(version, about)] diff --git a/tree/du.rs b/tree/du.rs index 5fe487b6f..da7a3d73a 100644 --- a/tree/du.rs +++ b/tree/du.rs @@ -10,12 +10,13 @@ // - implement -H, -L, -x // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::os::unix::fs::MetadataExt; use std::path::Path; use std::{fs, io}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// du - estimate file space usage #[derive(Parser)] #[command(version, about)] diff --git a/tree/link.rs b/tree/link.rs index b3ad4da6b..d8230e6ca 100644 --- a/tree/link.rs +++ b/tree/link.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // +use std::{fs, io}; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use std::{fs, io}; /// link - call link function #[derive(Parser)] diff --git a/tree/ln.rs b/tree/ln.rs index 33e2b6074..f5db2b72c 100644 --- a/tree/ln.rs +++ b/tree/ln.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::path::{Path, PathBuf}; use std::{fs, io}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + /// ln - link files #[derive(Parser)] #[command(version, about)] diff --git a/tree/ls.rs b/tree/ls.rs index 3363e91fb..1032d2e9a 100644 --- a/tree/ls.rs +++ b/tree/ls.rs @@ -9,10 +9,6 @@ mod ls_util; -use self::ls_util::{ls_from_utf8_lossy, Entry, LongFormatPadding, MultiColumnPadding}; -use clap::{CommandFactory, FromArgMatches, Parser}; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use plib::platform::P_WINSIZE_REQUEST_CODE; use std::collections::HashMap; use std::ffi::{CString, OsStr}; use std::io; @@ -23,6 +19,12 @@ use std::path::{Path, PathBuf}; use std::process::ExitCode; use std::sync::atomic::{AtomicU8, Ordering}; +use clap::{CommandFactory, FromArgMatches, Parser}; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use plib::platform::P_WINSIZE_REQUEST_CODE; + +use self::ls_util::{ls_from_utf8_lossy, Entry, LongFormatPadding, MultiColumnPadding}; + /// ls - list directory contents #[derive(Parser)] #[command(version, about)] diff --git a/tree/ls_util/entry.rs b/tree/ls_util/entry.rs index c014c357d..8cb5839c7 100644 --- a/tree/ls_util/entry.rs +++ b/tree/ls_util/entry.rs @@ -7,12 +7,6 @@ // SPDX-License-Identifier: MIT // -use super::ls_from_utf8_lossy; -use crate::{ - ClassifyFiles, Config, FileTimeOption, LongFormatOptions, OutputFormat, - DATE_TIME_FORMAT_OLD_OR_FUTURE, DATE_TIME_FORMAT_RECENT, -}; -use chrono::{DateTime, Local}; use std::cmp::Ordering; use std::ffi::{CStr, OsStr, OsString}; use std::io; @@ -20,6 +14,14 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::{FileTypeExt, MetadataExt}; use std::time::{Duration, SystemTime}; +use chrono::{DateTime, Local}; + +use super::ls_from_utf8_lossy; +use crate::{ + ClassifyFiles, Config, FileTimeOption, LongFormatOptions, OutputFormat, + DATE_TIME_FORMAT_OLD_OR_FUTURE, DATE_TIME_FORMAT_RECENT, +}; + enum FileInfo { Size(u64), DeviceInfo((u32, u32)), diff --git a/tree/mkdir.rs b/tree/mkdir.rs index 312069c5a..7fd5ef70b 100644 --- a/tree/mkdir.rs +++ b/tree/mkdir.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // +use std::ffi::CString; +use std::io; +use std::path::PathBuf; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use modestr::ChmodMode; use plib::modestr; -use std::ffi::CString; -use std::io; -use std::path::PathBuf; /// mkdir - make directories #[derive(Parser)] diff --git a/tree/mkfifo.rs b/tree/mkfifo.rs index 86bc7e89f..594fcb8fc 100644 --- a/tree/mkfifo.rs +++ b/tree/mkfifo.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // +use std::io; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use modestr::ChmodMode; use plib::modestr; -use std::io; /// mkfifo - make FIFO special files #[derive(Parser)] diff --git a/tree/mv.rs b/tree/mv.rs index 4fb598cce..6294e5324 100644 --- a/tree/mv.rs +++ b/tree/mv.rs @@ -10,10 +10,6 @@ mod common; -use self::common::{copy_file, error_string}; -use clap::Parser; -use common::CopyConfig; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::collections::{HashMap, HashSet}; use std::ffi::CString; use std::fs; @@ -22,6 +18,12 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; +use clap::Parser; +use common::CopyConfig; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +use self::common::{copy_file, error_string}; + /// mv - move files #[derive(Parser)] #[command(version, about)] diff --git a/tree/readlink.rs b/tree/readlink.rs index 36a82dac4..f903a9b2c 100644 --- a/tree/readlink.rs +++ b/tree/readlink.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::error::Error; use std::fs; use std::io::{stderr, stdout, ErrorKind, Write}; use std::path::{Component, Path, PathBuf}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + /// readlink — display the contents of a symbolic link #[derive(Parser)] #[command(version, about)] diff --git a/tree/rm.rs b/tree/rm.rs index 2e0bb74e7..6c1285b69 100644 --- a/tree/rm.rs +++ b/tree/rm.rs @@ -9,10 +9,6 @@ mod common; -use self::common::error_string; -use clap::Parser; -use ftw::{self, traverse_directory}; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::ffi::CString; use std::fs; use std::io::{self, IsTerminal}; @@ -20,6 +16,12 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; +use clap::Parser; +use ftw::{self, traverse_directory}; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + +use self::common::error_string; + /// rm - remove directory entries #[derive(Parser)] #[command(version, about)] diff --git a/tree/rmdir.rs b/tree/rmdir.rs index d4ba13c55..4c552465e 100644 --- a/tree/rmdir.rs +++ b/tree/rmdir.rs @@ -7,12 +7,13 @@ // SPDX-License-Identifier: MIT // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::fs; use std::io::{self, Error, ErrorKind}; use std::path::Path; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + /// rmdir - remove directories #[derive(Parser)] #[command(version, about)] diff --git a/tree/tests/chgrp/mod.rs b/tree/tests/chgrp/mod.rs index 2d0590958..ffe07c2f1 100644 --- a/tree/tests/chgrp/mod.rs +++ b/tree/tests/chgrp/mod.rs @@ -7,7 +7,6 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::ffi::{CStr, CString}; use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::os::unix::{self}; @@ -15,6 +14,8 @@ use std::sync::{Once, RwLock}; use std::time::Duration; use std::{fs, io, thread}; +use plib::testing::{run_test, TestPlan}; + fn chgrp_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/chmod/mod.rs b/tree/tests/chmod/mod.rs index 3caf38940..35cef2cdf 100644 --- a/tree/tests/chmod/mod.rs +++ b/tree/tests/chmod/mod.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs; use std::os::unix::fs::PermissionsExt; use std::os::unix::{self}; +use plib::testing::{run_test, TestPlan}; + fn chmod_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/cp/mod.rs b/tree/tests/cp/mod.rs index d9c62089c..d25962af2 100644 --- a/tree/tests/cp/mod.rs +++ b/tree/tests/cp/mod.rs @@ -7,7 +7,6 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::ffi::CString; use std::io::{Read, Write}; use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; @@ -16,6 +15,8 @@ use std::path::Path; use std::process::{Command, Stdio}; use std::{fs, io}; +use plib::testing::{run_test, TestPlan}; + fn cp_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/link/mod.rs b/tree/tests/link/mod.rs index 31e12ef90..002bb12b8 100644 --- a/tree/tests/link/mod.rs +++ b/tree/tests/link/mod.rs @@ -8,12 +8,13 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test_with_checker, TestPlan}; use std::fs; use std::io::Write; use std::path::PathBuf; use std::process::Output; +use plib::testing::{run_test_with_checker, TestPlan}; + fn get_test_file_path(filename: &str) -> PathBuf { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests"); diff --git a/tree/tests/ls/mod.rs b/tree/tests/ls/mod.rs index ff02d1115..1686dc9ab 100644 --- a/tree/tests/ls/mod.rs +++ b/tree/tests/ls/mod.rs @@ -7,8 +7,6 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, run_test_with_checker, TestPlan}; -use regex::Regex; use std::ffi::CString; use std::io::{self, Write}; use std::os::unix::fs::MetadataExt; @@ -16,6 +14,9 @@ use std::path::Path; use std::time::Duration; use std::{fs, thread}; +use plib::testing::{run_test, run_test_with_checker, TestPlan}; +use regex::Regex; + fn get_errno() -> i32 { io::Error::last_os_error().raw_os_error().unwrap() } diff --git a/tree/tests/mkdir/mod.rs b/tree/tests/mkdir/mod.rs index 50f964348..8fe8d6702 100644 --- a/tree/tests/mkdir/mod.rs +++ b/tree/tests/mkdir/mod.rs @@ -8,10 +8,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test_with_checker, TestPlan}; use std::fs; use std::path::Path; use std::process::Output; + +use plib::testing::{run_test_with_checker, TestPlan}; use tempfile::{tempdir, TempDir}; fn setup_test_env() -> (TempDir, String) { diff --git a/tree/tests/mv/mod.rs b/tree/tests/mv/mod.rs index 34d07a85a..1df58945d 100644 --- a/tree/tests/mv/mod.rs +++ b/tree/tests/mv/mod.rs @@ -7,7 +7,6 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::ffi::CString; use std::fs::{self, Permissions}; use std::io::{self, Read, Write}; @@ -16,6 +15,8 @@ use std::os::unix::{self}; use std::path::Path; use std::process::{Command, Stdio}; +use plib::testing::{run_test, TestPlan}; + fn mv_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/readlink/mod.rs b/tree/tests/readlink/mod.rs index 644b39e14..2379a4797 100644 --- a/tree/tests/readlink/mod.rs +++ b/tree/tests/readlink/mod.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs::File; use std::io::Write; use std::os::unix::fs::symlink; + +use plib::testing::{run_test, TestPlan}; use tempfile::tempdir; #[test] diff --git a/tree/tests/rm/mod.rs b/tree/tests/rm/mod.rs index aa6c99499..f2e7efd60 100644 --- a/tree/tests/rm/mod.rs +++ b/tree/tests/rm/mod.rs @@ -7,7 +7,6 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, run_test_with_checker, TestPlan}; use std::ffi::CString; use std::fs; use std::io::{self, Write}; @@ -16,6 +15,8 @@ use std::os::unix::{self}; use std::path::Path; use std::process::{Command, Stdio}; +use plib::testing::{run_test, run_test_with_checker, TestPlan}; + fn rm_test(args: &[&str], expected_output: &str, expected_error: &str, expected_exit_code: i32) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/tree/tests/rmdir/mod.rs b/tree/tests/rmdir/mod.rs index de82ac455..b91b78ca6 100644 --- a/tree/tests/rmdir/mod.rs +++ b/tree/tests/rmdir/mod.rs @@ -8,10 +8,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test_with_checker, TestPlan}; use std::fs; use std::path::Path; use std::process::Output; + +use plib::testing::{run_test_with_checker, TestPlan}; use tempfile::{tempdir, TempDir}; fn setup_test_env() -> (TempDir, String) { diff --git a/tree/tests/tree-tests-umask.rs b/tree/tests/tree-tests-umask.rs index 78c24de0f..ce187f6ff 100644 --- a/tree/tests/tree-tests-umask.rs +++ b/tree/tests/tree-tests-umask.rs @@ -11,12 +11,13 @@ //! in `tree-tests.rs`. They are located here in `tree-tests-umask.rs` so that they can have a //! different per-process umask than those in `tree-tests.rs`. -use plib::testing::{run_test, TestPlan}; use std::fs; use std::os::unix::fs::{DirBuilderExt, MetadataExt, PermissionsExt}; use std::path::Path; use std::sync::Mutex; +use plib::testing::{run_test, TestPlan}; + static UMASK_SETTER: Mutex = Mutex::new(UmaskSetter); // Used to serialize changes to the process' umask diff --git a/tree/tests/unlink/mod.rs b/tree/tests/unlink/mod.rs index c60c96c6c..c8bf324eb 100644 --- a/tree/tests/unlink/mod.rs +++ b/tree/tests/unlink/mod.rs @@ -8,8 +8,9 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, run_test_with_checker, TestPlan}; use std::fs; + +use plib::testing::{run_test, run_test_with_checker, TestPlan}; use tempfile::tempdir; #[test] diff --git a/tree/unlink.rs b/tree/unlink.rs index ab682b557..d38138a56 100644 --- a/tree/unlink.rs +++ b/tree/unlink.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // +use std::{fs, io}; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use std::{fs, io}; /// unlink - call the unlink function #[derive(Parser)] diff --git a/users/id.rs b/users/id.rs index da36d4fe2..f265b78fb 100644 --- a/users/id.rs +++ b/users/id.rs @@ -10,11 +10,12 @@ // - bug: only one group is returned, in group list (MacOS-only?) // +use std::collections::HashMap; +use std::io::Error; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use plib::group; -use std::collections::HashMap; -use std::io::Error; /// id - return user identity #[derive(Parser)] diff --git a/users/mesg.rs b/users/mesg.rs index aca96b812..312d88eb9 100644 --- a/users/mesg.rs +++ b/users/mesg.rs @@ -11,11 +11,12 @@ // - set process exit code according to spec // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::io::{self, Error, ErrorKind, IsTerminal}; use std::mem; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; + /// mesg - permit or deny messages #[derive(Parser)] #[command(version, about)] diff --git a/users/newgrp.rs b/users/newgrp.rs index 6b84e5fc1..ca99efad2 100644 --- a/users/newgrp.rs +++ b/users/newgrp.rs @@ -7,6 +7,16 @@ // SPDX-License-Identifier: MIT // +use std::ffi::{CStr, CString}; +use std::process::{self, Command}; +use std::{env, io}; +#[cfg(target_os = "linux")] +use std::{ + fs::File, + io::{BufRead, BufReader}, + os::unix::io::AsRawFd, +}; + use clap::error::ErrorKind; use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; @@ -14,24 +24,12 @@ use libc::{ getgid, getgrnam, getgroups, getlogin, getpwnam, getpwuid, getuid, gid_t, passwd, setegid, setgid, setgroups, setuid, uid_t, }; - #[cfg(target_os = "linux")] use libc::{ECHO, ECHONL, TCSANOW}; #[cfg(target_os = "linux")] use libcrypt_rs::Crypt; use plib::group::Group; -use std::ffi::{CStr, CString}; -use std::process::{self, Command}; -use std::{env, io}; - -#[cfg(target_os = "linux")] -use std::{ - fs::File, - io::{BufRead, BufReader}, - os::unix::io::AsRawFd, -}; - #[cfg(target_os = "linux")] const GROUPSHADOW_PATH: &str = "/etc/gshadow"; diff --git a/users/pwd.rs b/users/pwd.rs index 48fb74a4a..a66f740a1 100644 --- a/users/pwd.rs +++ b/users/pwd.rs @@ -10,11 +10,12 @@ // - compliance: for -L mode, Rust performs unwanted normalization for "." // -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::ffi::OsStr; use std::path::{Component, Path}; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + const PWD_ENV: &str = "PWD"; /// pwd - return working directory name diff --git a/users/talk.rs b/users/talk.rs index fe0c6d27f..e03d8ea3a 100644 --- a/users/talk.rs +++ b/users/talk.rs @@ -6,20 +6,6 @@ // SPDX-License-Identifier: MIT // -use clap::error::ErrorKind; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use thiserror::Error; - -use binrw::{binrw, BinReaderExt, BinWrite, Endian}; -#[cfg(target_os = "linux")] -use libc::sa_family_t; -use libc::{ - addrinfo, getaddrinfo, gethostname, getpid, getpwuid, getservbyname, getuid, ioctl, signal, - sockaddr_in, winsize, AF_INET, AI_CANONNAME, SIGINT, SIGPIPE, SIGQUIT, SOCK_DGRAM, - STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, -}; - use std::ffi::{CStr, CString}; use std::io::{self, Cursor, Error, IsTerminal, Write}; use std::mem::{size_of, zeroed}; @@ -32,6 +18,19 @@ use std::sync::{Arc, LazyLock, Mutex}; use std::time::{Duration, Instant}; use std::{char, process, ptr, thread}; +use binrw::{binrw, BinReaderExt, BinWrite, Endian}; +use clap::error::ErrorKind; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +#[cfg(target_os = "linux")] +use libc::sa_family_t; +use libc::{ + addrinfo, getaddrinfo, gethostname, getpid, getpwuid, getservbyname, getuid, ioctl, signal, + sockaddr_in, winsize, AF_INET, AI_CANONNAME, SIGINT, SIGPIPE, SIGQUIT, SOCK_DGRAM, + STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ, +}; +use thiserror::Error; + #[derive(Parser)] #[command(version, about=gettext("talk - talk to another user"))] struct Args { diff --git a/users/tty.rs b/users/tty.rs index 815c8bef0..e08bfcd38 100644 --- a/users/tty.rs +++ b/users/tty.rs @@ -7,9 +7,10 @@ // SPDX-License-Identifier: MIT // -use plib::curuser::tty; use std::io::{self, IsTerminal}; +use plib::curuser::tty; + fn main() { let is_tty = io::stdin().is_terminal(); if !is_tty { diff --git a/users/write.rs b/users/write.rs index 0a817ce63..5b3bf5dbe 100644 --- a/users/write.rs +++ b/users/write.rs @@ -7,15 +7,16 @@ // SPDX-License-Identifier: MIT // -use chrono::Local; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use plib::{curuser, platform, utmpx}; use std::fs::{self, OpenOptions}; use std::io::{self, BufRead, Write}; use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::process::exit; +use chrono::Local; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; +use plib::{curuser, platform, utmpx}; + const ALERT_CHAR: char = '\u{07}'; const INTR_CHAR: char = '\u{03}'; const EOF_CHAR: char = '\u{04}'; diff --git a/xform/cksum.rs b/xform/cksum.rs index f63306bdf..66d5136a3 100644 --- a/xform/cksum.rs +++ b/xform/cksum.rs @@ -17,12 +17,13 @@ mod crc32; +use std::io::{self, Read}; +use std::path::PathBuf; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use plib::io::input_stream; use plib::BUFSZ; -use std::io::{self, Read}; -use std::path::PathBuf; /// cksum - write file checksums and sizes #[derive(Parser)] diff --git a/xform/compress.rs b/xform/compress.rs index fd307e1e2..c25fb66c2 100644 --- a/xform/compress.rs +++ b/xform/compress.rs @@ -7,13 +7,14 @@ // SPDX-License-Identifier: MIT // +use std::fs::{self, File}; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use plib::io::input_stream; use plib::lzw::UnixLZWWriter; -use std::fs::{self, File}; -use std::io::{self, Write}; -use std::path::{Path, PathBuf}; const NAME_MAX: usize = 255; diff --git a/xform/tests/compress/mod.rs b/xform/tests/compress/mod.rs index 5e48b5f1d..f5278ee27 100644 --- a/xform/tests/compress/mod.rs +++ b/xform/tests/compress/mod.rs @@ -7,10 +7,11 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs::{remove_file, File}; use std::io::Read; +use plib::testing::{run_test, TestPlan}; + fn compress_test(args: &[&str], expected_output: &str, expected_error: &str) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/xform/tests/uue/mod.rs b/xform/tests/uue/mod.rs index cecb21de4..e4741361c 100644 --- a/xform/tests/uue/mod.rs +++ b/xform/tests/uue/mod.rs @@ -7,11 +7,12 @@ // SPDX-License-Identifier: MIT // -use plib::testing::{run_test, TestPlan}; use std::fs::{File, Permissions}; use std::io::Read; use std::os::unix::fs::PermissionsExt; +use plib::testing::{run_test, TestPlan}; + const RWX: u32 = 0o7; const UUCODE_PERMISSION_PLACEHOLDER: &str = "#PERM#"; diff --git a/xform/uncompress.rs b/xform/uncompress.rs index f438071c1..8131ef9a9 100644 --- a/xform/uncompress.rs +++ b/xform/uncompress.rs @@ -11,12 +11,13 @@ // - support options -f, -v // +use std::io::{self, Write}; +use std::path::PathBuf; + use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use plib::io::input_stream; use plib::lzw::UnixLZWReader; -use std::io::{self, Write}; -use std::path::PathBuf; /// uncompress - expand compressed data #[derive(Parser)] diff --git a/xform/uudecode.rs b/xform/uudecode.rs index 566d9bce0..77e7739db 100644 --- a/xform/uudecode.rs +++ b/xform/uudecode.rs @@ -7,14 +7,15 @@ // SPDX-License-Identifier: MIT // -use base64::prelude::*; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::fs::{remove_file, File}; use std::io::{self, Error, Read, Write}; use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; +use base64::prelude::*; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + macro_rules! reduce { ($e : expr) => { $e - 0x20 diff --git a/xform/uuencode.rs b/xform/uuencode.rs index b0a5e3984..84237f115 100644 --- a/xform/uuencode.rs +++ b/xform/uuencode.rs @@ -7,14 +7,15 @@ // SPDX-License-Identifier: MIT // -use base64::prelude::*; -use clap::Parser; -use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use std::fs::{File, Permissions}; use std::io::{self, Read, Write}; use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; +use base64::prelude::*; +use clap::Parser; +use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; + const PERMISSION_MASK: u32 = 0o7; const RW: u32 = 0o666;