mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-16 17:08:27 +01:00
Merge pull request #1627 from hamirmahal/style/simplify-string-formatting-for-readability
style: simplify string formatting for readability
This commit is contained in:
commit
202e32953c
9 changed files with 30 additions and 42 deletions
2
build.rs
2
build.rs
|
@ -5,7 +5,7 @@ fn main() {
|
|||
Some(true) => {}
|
||||
// rustc version too small or can't figure it out
|
||||
_ => {
|
||||
eprintln!("'fd' requires rustc >= {}", min_version);
|
||||
eprintln!("'fd' requires rustc >= {min_version}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ pub fn handle_cmd_error(cmd: Option<&Command>, err: io::Error) -> ExitCode {
|
|||
ExitCode::GeneralError
|
||||
}
|
||||
(_, err) => {
|
||||
print_error(format!("Problem while executing command: {}", err));
|
||||
print_error(format!("Problem while executing command: {err}"));
|
||||
ExitCode::GeneralError
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,22 +148,16 @@ mod tests {
|
|||
let t1s_later = ref_time + Duration::from_secs(1);
|
||||
// Timestamp only supported via '@' prefix
|
||||
assert!(TimeFilter::before(&ref_time, &ref_timestamp.to_string()).is_none());
|
||||
assert!(
|
||||
TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
|
||||
assert!(TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))
|
||||
.unwrap()
|
||||
.applies_to(&t1m_ago)
|
||||
);
|
||||
assert!(
|
||||
!TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
|
||||
.applies_to(&t1m_ago));
|
||||
assert!(!TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))
|
||||
.unwrap()
|
||||
.applies_to(&t1s_later)
|
||||
);
|
||||
assert!(
|
||||
!TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
|
||||
.applies_to(&t1s_later));
|
||||
assert!(!TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))
|
||||
.unwrap()
|
||||
.applies_to(&t1m_ago)
|
||||
);
|
||||
assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
|
||||
.applies_to(&t1m_ago));
|
||||
assert!(TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))
|
||||
.unwrap()
|
||||
.applies_to(&t1s_later));
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ fn encode(f: &mut Formatter, byte: u8) -> fmt::Result {
|
|||
#[cfg(windows)]
|
||||
b'\\' => f.write_char('/'),
|
||||
_ => {
|
||||
write!(f, "%{:02X}", byte)
|
||||
write!(f, "%{byte:02X}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ fn main() {
|
|||
exit_code.exit();
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("[fd error]: {:#}", err);
|
||||
eprintln!("[fd error]: {err:#}");
|
||||
ExitCode::GeneralError.exit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ pub fn print_entry<W: Write>(stdout: &mut W, entry: &DirEntry, config: &Config)
|
|||
let mut has_hyperlink = false;
|
||||
if config.hyperlink {
|
||||
if let Some(url) = PathUrl::new(entry.path()) {
|
||||
write!(stdout, "\x1B]8;;{}\x1B\\", url)?;
|
||||
write!(stdout, "\x1B]8;;{url}\x1B\\")?;
|
||||
has_hyperlink = true;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ fn print_entry_uncolorized_base<W: Write>(
|
|||
if let Some(ref separator) = config.path_separator {
|
||||
*path_string.to_mut() = replace_path_separator(&path_string, separator);
|
||||
}
|
||||
write!(stdout, "{}", path_string)?;
|
||||
write!(stdout, "{path_string}")?;
|
||||
print_trailing_slash(stdout, entry, config, None)
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ impl<'a, W: Write> ReceiverBuffer<'a, W> {
|
|||
fn print(&mut self, entry: &DirEntry) -> Result<(), ExitCode> {
|
||||
if let Err(e) = output::print_entry(&mut self.stdout, entry, self.config) {
|
||||
if e.kind() != ::std::io::ErrorKind::BrokenPipe {
|
||||
print_error(format!("Could not write to output: {}", e));
|
||||
print_error(format!("Could not write to output: {e}"));
|
||||
return Err(ExitCode::GeneralError);
|
||||
}
|
||||
}
|
||||
|
@ -376,10 +376,7 @@ impl WorkerState {
|
|||
match result {
|
||||
Some(ignore::Error::Partial(_)) => (),
|
||||
Some(err) => {
|
||||
print_error(format!(
|
||||
"Malformed pattern in global ignore file. {}.",
|
||||
err
|
||||
));
|
||||
print_error(format!("Malformed pattern in global ignore file. {err}."));
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
|
@ -392,7 +389,7 @@ impl WorkerState {
|
|||
match result {
|
||||
Some(ignore::Error::Partial(_)) => (),
|
||||
Some(err) => {
|
||||
print_error(format!("Malformed pattern in custom ignore file. {}.", err));
|
||||
print_error(format!("Malformed pattern in custom ignore file. {err}."));
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
|
|
|
@ -104,9 +104,9 @@ fn format_output_error(args: &[&str], expected: &str, actual: &str) -> String {
|
|||
let diff_text = diff::lines(expected, actual)
|
||||
.into_iter()
|
||||
.map(|diff| match diff {
|
||||
diff::Result::Left(l) => format!("-{}", l),
|
||||
diff::Result::Both(l, _) => format!(" {}", l),
|
||||
diff::Result::Right(r) => format!("+{}", r),
|
||||
diff::Result::Left(l) => format!("-{l}"),
|
||||
diff::Result::Both(l, _) => format!(" {l}"),
|
||||
diff::Result::Right(r) => format!("+{r}"),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
@ -290,7 +290,7 @@ impl TestEnv {
|
|||
pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {
|
||||
let status = self.assert_error_subdirectory(".", args, Some(expected));
|
||||
if status.success() {
|
||||
panic!("error '{}' did not occur.", expected);
|
||||
panic!("error '{expected}' did not occur.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -595,10 +595,7 @@ fn test_full_path() {
|
|||
let prefix = escape(&root.to_string_lossy());
|
||||
|
||||
te.assert_output(
|
||||
&[
|
||||
"--full-path",
|
||||
&format!("^{prefix}.*three.*foo$", prefix = prefix),
|
||||
],
|
||||
&["--full-path", &format!("^{prefix}.*three.*foo$")],
|
||||
"one/two/three/d.foo
|
||||
one/two/three/directory_foo/",
|
||||
);
|
||||
|
@ -1518,7 +1515,7 @@ fn test_symlink_as_absolute_root() {
|
|||
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
|
||||
|
||||
te.assert_output(
|
||||
&["", &format!("{abs_path}/symlink", abs_path = abs_path)],
|
||||
&["", &format!("{abs_path}/symlink")],
|
||||
&format!(
|
||||
"{abs_path}/symlink/c.foo
|
||||
{abs_path}/symlink/C.Foo2
|
||||
|
@ -1543,7 +1540,7 @@ fn test_symlink_and_full_path() {
|
|||
&[
|
||||
"--absolute-path",
|
||||
"--full-path",
|
||||
&format!("^{prefix}.*three", prefix = prefix),
|
||||
&format!("^{prefix}.*three"),
|
||||
],
|
||||
&format!(
|
||||
"{abs_path}/{expected_path}/three/
|
||||
|
@ -1563,8 +1560,8 @@ fn test_symlink_and_full_path_abs_path() {
|
|||
te.assert_output(
|
||||
&[
|
||||
"--full-path",
|
||||
&format!("^{prefix}.*symlink.*three", prefix = prefix),
|
||||
&format!("{abs_path}/symlink", abs_path = abs_path),
|
||||
&format!("^{prefix}.*symlink.*three"),
|
||||
&format!("{abs_path}/symlink"),
|
||||
],
|
||||
&format!(
|
||||
"{abs_path}/symlink/three/
|
||||
|
@ -2337,7 +2334,7 @@ fn test_owner_current_user() {
|
|||
fn test_owner_current_group() {
|
||||
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||
let gid = Gid::current();
|
||||
te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");
|
||||
te.assert_output(&["--owner", &format!(":{gid}"), "a.foo"], "a.foo");
|
||||
if let Ok(Some(group)) = Group::from_gid(gid) {
|
||||
te.assert_output(&["--owner", &format!(":{}", group.name), "a.foo"], "a.foo");
|
||||
}
|
||||
|
@ -2616,7 +2613,7 @@ fn test_invalid_cwd() {
|
|||
.unwrap();
|
||||
|
||||
if !output.status.success() {
|
||||
panic!("{:?}", output);
|
||||
panic!("{output:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue