mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
chore: use inline formatting
Minor cleanup using clippy autofix. This makes the code a bit more readable, and helps spot a few inefficiencies and possible bugs. ``` cargo clippy --fix --workspace -- -A clippy::all -W clippy::uninlined_format_args && cargo fmt ```
This commit is contained in:
parent
b7bf8c9467
commit
47b10539d0
17 changed files with 33 additions and 39 deletions
|
@ -839,8 +839,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
has_padding(&mut cursor).unwrap(),
|
||||
expected,
|
||||
"Failed for input: '{}'",
|
||||
input
|
||||
"Failed for input: '{input}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ fn parse_gid_from_str(group: &str) -> Result<u32, String> {
|
|||
// Handle :gid format
|
||||
gid_str
|
||||
.parse::<u32>()
|
||||
.map_err(|_| format!("invalid group id: '{}'", gid_str))
|
||||
.map_err(|_| format!("invalid group id: '{gid_str}'"))
|
||||
} else {
|
||||
// Try as group name first
|
||||
match entries::grp2gid(group) {
|
||||
|
@ -32,7 +32,7 @@ fn parse_gid_from_str(group: &str) -> Result<u32, String> {
|
|||
// If group name lookup fails, try parsing as raw number
|
||||
Err(_) => group
|
||||
.parse::<u32>()
|
||||
.map_err(|_| format!("invalid group: '{}'", group)),
|
||||
.map_err(|_| format!("invalid group: '{group}'")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<GidUidOwnerFilter> {
|
|||
Err(_) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format!("invalid user: '{}'", from_group),
|
||||
format!("invalid user: '{from_group}'"),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
10
src/uu/env/src/env.rs
vendored
10
src/uu/env/src/env.rs
vendored
|
@ -317,19 +317,19 @@ pub fn parse_args_from_str(text: &NativeIntStr) -> UResult<Vec<NativeIntString>>
|
|||
}
|
||||
EnvError::EnvMissingClosingQuote(_, _) => USimpleError::new(125, e.to_string()),
|
||||
EnvError::EnvParsingOfVariableMissingClosingBrace(pos) => {
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e))
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
|
||||
}
|
||||
EnvError::EnvParsingOfMissingVariable(pos) => {
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e))
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
|
||||
}
|
||||
EnvError::EnvParsingOfVariableMissingClosingBraceAfterValue(pos) => {
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e))
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
|
||||
}
|
||||
EnvError::EnvParsingOfVariableUnexpectedNumber(pos, _) => {
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e))
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
|
||||
}
|
||||
EnvError::EnvParsingOfVariableExceptedBraceOrColon(pos, _) => {
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e))
|
||||
USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
|
||||
}
|
||||
_ => USimpleError::new(125, format!("Error: {e:?}")),
|
||||
})
|
||||
|
|
|
@ -247,7 +247,7 @@ impl HeadOptions {
|
|||
fn wrap_in_stdout_error(err: io::Error) -> io::Error {
|
||||
io::Error::new(
|
||||
err.kind(),
|
||||
format!("error writing 'standard output': {}", err),
|
||||
format!("error writing 'standard output': {err}"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -734,10 +734,7 @@ fn parse_separator(value_os: &OsString) -> UResult<SepSetting> {
|
|||
match chars.next() {
|
||||
None => Ok(SepSetting::Char(value.into())),
|
||||
Some('0') if c == '\\' => Ok(SepSetting::Byte(0)),
|
||||
_ => Err(USimpleError::new(
|
||||
1,
|
||||
format!("multi-character tab {}", value),
|
||||
)),
|
||||
_ => Err(USimpleError::new(1, format!("multi-character tab {value}"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ enum LnError {
|
|||
MissingDestination(PathBuf),
|
||||
|
||||
#[error("extra operand {}\nTry '{} --help' for more information.",
|
||||
format!("{:?}", _0).trim_matches('"'), _1)]
|
||||
format!("{_0:?}").trim_matches('"'), _1)]
|
||||
ExtraOperand(OsString, String),
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ impl std::str::FromStr for QuotingStyle {
|
|||
"shell" => Ok(QuotingStyle::Shell),
|
||||
"shell-escape-always" => Ok(QuotingStyle::ShellEscapeAlways),
|
||||
// The others aren't exposed to the user
|
||||
_ => Err(format!("Invalid quoting style: {}", s)),
|
||||
_ => Err(format!("Invalid quoting style: {s}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,9 +335,9 @@ fn quote_file_name(file_name: &str, quoting_style: &QuotingStyle) -> String {
|
|||
match quoting_style {
|
||||
QuotingStyle::Locale | QuotingStyle::Shell => {
|
||||
let escaped = file_name.replace('\'', r"\'");
|
||||
format!("'{}'", escaped)
|
||||
format!("'{escaped}'")
|
||||
}
|
||||
QuotingStyle::ShellEscapeAlways => format!("\"{}\"", file_name),
|
||||
QuotingStyle::ShellEscapeAlways => format!("\"{file_name}\""),
|
||||
QuotingStyle::Quote => file_name.to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -450,7 +450,7 @@ fn print_integer(
|
|||
let extended = match precision {
|
||||
Precision::NotSpecified => format!("{prefix}{arg}"),
|
||||
Precision::NoNumber => format!("{prefix}{arg}"),
|
||||
Precision::Number(p) => format!("{prefix}{arg:0>precision$}", precision = p),
|
||||
Precision::Number(p) => format!("{prefix}{arg:0>p$}"),
|
||||
};
|
||||
pad_and_print(&extended, flags.left, width, padding_char);
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ fn print_unsigned(
|
|||
let s = match precision {
|
||||
Precision::NotSpecified => s,
|
||||
Precision::NoNumber => s,
|
||||
Precision::Number(p) => format!("{s:0>precision$}", precision = p).into(),
|
||||
Precision::Number(p) => format!("{s:0>p$}").into(),
|
||||
};
|
||||
pad_and_print(&s, flags.left, width, padding_char);
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ fn print_unsigned_oct(
|
|||
let s = match precision {
|
||||
Precision::NotSpecified => format!("{prefix}{num:o}"),
|
||||
Precision::NoNumber => format!("{prefix}{num:o}"),
|
||||
Precision::Number(p) => format!("{prefix}{num:0>precision$o}", precision = p),
|
||||
Precision::Number(p) => format!("{prefix}{num:0>p$o}"),
|
||||
};
|
||||
pad_and_print(&s, flags.left, width, padding_char);
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ fn print_unsigned_hex(
|
|||
let s = match precision {
|
||||
Precision::NotSpecified => format!("{prefix}{num:x}"),
|
||||
Precision::NoNumber => format!("{prefix}{num:x}"),
|
||||
Precision::Number(p) => format!("{prefix}{num:0>precision$x}", precision = p),
|
||||
Precision::Number(p) => format!("{prefix}{num:0>p$x}"),
|
||||
};
|
||||
pad_and_print(&s, flags.left, width, padding_char);
|
||||
}
|
||||
|
@ -994,7 +994,7 @@ impl Stater {
|
|||
'R' => {
|
||||
let major = meta.rdev() >> 8;
|
||||
let minor = meta.rdev() & 0xff;
|
||||
OutputType::Str(format!("{},{}", major, minor))
|
||||
OutputType::Str(format!("{major},{minor}"))
|
||||
}
|
||||
'r' => OutputType::Unsigned(meta.rdev()),
|
||||
'H' => OutputType::Unsigned(meta.rdev() >> 8), // Major in decimal
|
||||
|
|
|
@ -170,7 +170,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
127,
|
||||
format!("{EXEC_ERROR} No such file or directory"),
|
||||
)),
|
||||
_ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {}", e))),
|
||||
_ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {e}"))),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -236,7 +236,7 @@ fn default_uptime(matches: &ArgMatches) -> UResult<()> {
|
|||
fn print_loadavg() {
|
||||
match get_formatted_loadavg() {
|
||||
Err(_) => {}
|
||||
Ok(s) => println!("{}", s),
|
||||
Ok(s) => println!("{s}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -433,7 +433,7 @@ fn numbered_backup_path(path: &Path) -> PathBuf {
|
|||
let file_name = path.file_name().unwrap_or_default();
|
||||
for i in 1_u64.. {
|
||||
let mut numbered_file_name = file_name.to_os_string();
|
||||
numbered_file_name.push(format!(".~{}~", i));
|
||||
numbered_file_name.push(format!(".~{i}~"));
|
||||
let path = path.with_file_name(numbered_file_name);
|
||||
if !path.exists() {
|
||||
return path;
|
||||
|
|
|
@ -15,8 +15,8 @@ pub enum Error {
|
|||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::WriteError(msg) => write!(f, "splice() write error: {}", msg),
|
||||
Error::Io(err) => write!(f, "I/O error: {}", err),
|
||||
Error::WriteError(msg) => write!(f, "splice() write error: {msg}"),
|
||||
Error::Io(err) => write!(f, "I/O error: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -863,7 +863,7 @@ mod tests {
|
|||
("????????????????", "shell"),
|
||||
(test_str, "shell-show"),
|
||||
("'????????????????'", "shell-always"),
|
||||
(&format!("'{}'", test_str), "shell-always-show"),
|
||||
(&format!("'{test_str}'"), "shell-always-show"),
|
||||
(
|
||||
"''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'",
|
||||
"shell-escape",
|
||||
|
@ -893,7 +893,7 @@ mod tests {
|
|||
("????????????????", "shell"),
|
||||
(test_str, "shell-show"),
|
||||
("'????????????????'", "shell-always"),
|
||||
(&format!("'{}'", test_str), "shell-always-show"),
|
||||
(&format!("'{test_str}'"), "shell-always-show"),
|
||||
(
|
||||
"''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'",
|
||||
"shell-escape",
|
||||
|
|
|
@ -308,7 +308,7 @@ pub fn format_nusers(nusers: usize) -> String {
|
|||
match nusers {
|
||||
0 => "0 user".to_string(),
|
||||
1 => "1 user".to_string(),
|
||||
_ => format!("{} users", nusers),
|
||||
_ => format!("{nusers} users"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6093,9 +6093,7 @@ fn test_cp_preserve_xattr_readonly_source() {
|
|||
let stdout = String::from_utf8_lossy(&getfattr_output.stdout);
|
||||
assert!(
|
||||
stdout.contains(xattr_key),
|
||||
"Expected '{}' not found in getfattr output:\n{}",
|
||||
xattr_key,
|
||||
stdout
|
||||
"Expected '{xattr_key}' not found in getfattr output:\n{stdout}"
|
||||
);
|
||||
|
||||
at.set_readonly(source_file);
|
||||
|
|
|
@ -1457,7 +1457,7 @@ fn create_named_pipe_with_writer(path: &str, data: &str) -> std::process::Child
|
|||
nix::unistd::mkfifo(path, nix::sys::stat::Mode::S_IRWXU).unwrap();
|
||||
std::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!("printf '{}' > {path}", data))
|
||||
.arg(format!("printf '{data}' > {path}"))
|
||||
.spawn()
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -435,7 +435,7 @@ fn test_all_but_last_bytes_large_file_piped() {
|
|||
.len();
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-c", &format!("-{}", seq_19001_20000_file_length)])
|
||||
.args(&["-c", &format!("-{seq_19001_20000_file_length}")])
|
||||
.pipe_in_fixture(seq_20000_file_name)
|
||||
.succeeds()
|
||||
.stdout_only_fixture(seq_19000_file_name);
|
||||
|
@ -695,7 +695,7 @@ fn test_validate_stdin_offset_bytes() {
|
|||
.len();
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-c", &format!("-{}", seq_19001_20000_file_length)])
|
||||
.args(&["-c", &format!("-{seq_19001_20000_file_length}")])
|
||||
.set_stdin(file)
|
||||
.succeeds()
|
||||
.stdout_only_fixture(seq_19000_file_name);
|
||||
|
|
|
@ -20,7 +20,7 @@ fn init() {
|
|||
std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
|
||||
}
|
||||
// Print for debugging
|
||||
eprintln!("Setting UUTESTS_BINARY_PATH={}", TESTS_BINARY);
|
||||
eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue