Skip to content
Myr

style: simplify string formatting for readability

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Hamir Mahal · committed by Hamir Mahal · parent 3d0d186 · Browse files · 9 files+24 added−25 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+24 added−25 removed

  • tests:+11 added−11 removed
  • other:+13 added−14 removed

9 files+24 added−25 removed

modified:src/exec/command.rs+1 added-1 removed
101 unmodified lines
102 ));103 ExitCode::GeneralError104 }105 (_, err) => {106 print_error(format!("Problem while executing command: {}", err));106 print_error(format!("Problem while executing command: {err}"));107 ExitCode::GeneralError108 }109 }110}
modified:src/filter/time.rs+4 added-4 removed
147 unmodified lines
148 let t1s_later = ref_time + Duration::from_secs(1);149 // Timestamp only supported via '@' prefix150 assert!(TimeFilter::before(&ref_time, &ref_timestamp.to_string()).is_none());151 assert!(152 TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))152 TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))153 .unwrap()154 .applies_to(&t1m_ago)155 );156 assert!(157 !TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))157 !TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))158 .unwrap()159 .applies_to(&t1s_later)160 );161 assert!(162 !TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))162 !TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))163 .unwrap()164 .applies_to(&t1m_ago)165 );166 assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))166 assert!(TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))167 .unwrap()168 .applies_to(&t1s_later));169 }170}
modified:src/hyperlink.rs+1 added-1 removed
33 unmodified lines
34 }35 #[cfg(windows)]36 b'\\' => f.write_char('/'),37 _ => {38 write!(f, "%{:02X}", byte)38 write!(f, "%{byte:02X}")39 }40 }41}42
45 unmodified lines
modified:src/main.rs+1 added-1 removed
61 unmodified lines
62 Ok(exit_code) => {63 exit_code.exit();64 }65 Err(err) => {66 eprintln!("[fd error]: {:#}", err);66 eprintln!("[fd error]: {err:#}");67 ExitCode::GeneralError.exit();68 }69 }70}
420 unmodified lines
modified:src/output.rs+2 added-2 removed
15 unmodified lines
16pub fn print_entry<W: Write>(stdout: &mut W, entry: &DirEntry, config: &Config) -> io::Result<()> {17 let mut has_hyperlink = false;18 if config.hyperlink {19 if let Some(url) = PathUrl::new(entry.path()) {20 write!(stdout, "\x1B]8;;{}\x1B\\", url)?;20 write!(stdout, "\x1B]8;;{url}\x1B\\")?;21 has_hyperlink = true;22 }23 }24
117 unmodified lines
142 let mut path_string = path.to_string_lossy();143 if let Some(ref separator) = config.path_separator {144 *path_string.to_mut() = replace_path_separator(&path_string, separator);145 }146 write!(stdout, "{}", path_string)?;146 write!(stdout, "{path_string}")?;147 print_trailing_slash(stdout, entry, config, None)148}149150#[cfg(not(unix))]
25 unmodified lines
modified:src/walk.rs+3 added-4 removed
250 unmodified lines
251 /// Output a path.252 fn print(&mut self, entry: &DirEntry) -> Result<(), ExitCode> {253 if let Err(e) = output::print_entry(&mut self.stdout, entry, self.config) {254 if e.kind() != ::std::io::ErrorKind::BrokenPipe {255 print_error(format!("Could not write to output: {}", e));255 print_error(format!("Could not write to output: {e}"));256 return Err(ExitCode::GeneralError);257 }258 }259
116 unmodified lines
376 match result {377 Some(ignore::Error::Partial(_)) => (),378 Some(err) => {379 print_error(format!(380 "Malformed pattern in global ignore file. {}.",381 err380 "Malformed pattern in global ignore file. {err}."381 ));382 }383 None => (),384 }
5 unmodified lines
390 let result = builder.add_ignore(ignore_file);391 match result {392 Some(ignore::Error::Partial(_)) => (),393 Some(err) => {395 print_error(format!("Malformed pattern in custom ignore file. {}.", err));394 print_error(format!("Malformed pattern in custom ignore file. {err}."));395 }396 None => (),397 }398 }
274 unmodified lines
modified:tests/testenv/mod.rs+4 added-4 removed
102 unmodified lines
103 // Generate diff text.104 let diff_text = diff::lines(expected, actual)105 .into_iter()106 .map(|diff| match diff {107 diff::Result::Left(l) => format!("-{}", l),108 diff::Result::Both(l, _) => format!(" {}", l),109 diff::Result::Right(r) => format!("+{}", r),107 diff::Result::Left(l) => format!("-{l}"),108 diff::Result::Both(l, _) => format!(" {l}"),109 diff::Result::Right(r) => format!("+{r}"),110 })111 .collect::<Vec<_>>()112 .join("\n");113
175 unmodified lines
289 /// and does not succeed.290 pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {291 let status = self.assert_error_subdirectory(".", args, Some(expected));292 if status.success() {293 panic!("error '{}' did not occur.", expected);293 panic!("error '{expected}' did not occur.");294 }295 }296297 /// Assert that calling *fd* with the specified arguments does not succeed.
57 unmodified lines
modified:tests/tests.rs+7 added-7 removed
595 unmodified lines
596597 te.assert_output(598 &[599 "--full-path",600 &format!("^{prefix}.*three.*foo$", prefix = prefix),600 &format!("^{prefix}.*three.*foo$"),601 ],602 "one/two/three/d.foo603 one/two/three/directory_foo/",604 );
912 unmodified lines
1517fn test_symlink_as_absolute_root() {1518 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);15191520 te.assert_output(1521 &["", &format!("{abs_path}/symlink", abs_path = abs_path)],1521 &["", &format!("{abs_path}/symlink")],1522 &format!(1523 "{abs_path}/symlink/c.foo1524 {abs_path}/symlink/C.Foo21525 {abs_path}/symlink/three/
16 unmodified lines
1542 "symlink",1543 &[1544 "--absolute-path",1545 "--full-path",1546 &format!("^{prefix}.*three", prefix = prefix),1546 &format!("^{prefix}.*three"),1547 ],1548 &format!(1549 "{abs_path}/{expected_path}/three/1550 {abs_path}/{expected_path}/three/d.foo
11 unmodified lines
1562 let prefix = escape(&root.to_string_lossy());1563 te.assert_output(1564 &[1565 "--full-path",1566 &format!("^{prefix}.*symlink.*three", prefix = prefix),1567 &format!("{abs_path}/symlink", abs_path = abs_path),1566 &format!("^{prefix}.*symlink.*three"),1567 &format!("{abs_path}/symlink"),1568 ],1569 &format!(1570 "{abs_path}/symlink/three/1571 {abs_path}/symlink/three/d.foo
764 unmodified lines
2336#[test]2337fn test_owner_current_group() {2338 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);2339 let gid = Gid::current();2340 te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");2340 te.assert_output(&["--owner", &format!(":{gid}"), "a.foo"], "a.foo");2341 if let Ok(Some(group)) = Group::from_gid(gid) {2342 te.assert_output(&["--owner", &format!(":{}", group.name), "a.foo"], "a.foo");2343 }2344}
270 unmodified lines
2615 .output()2616 .unwrap();26172618 if !output.status.success() {2619 panic!("{:?}", output);2619 panic!("{output:?}");2620 }2621}26222623/// Test behavior of .git directory with various flags
70 unmodified lines
modified:build.rs+1 added-1 removed
3 unmodified lines
4 match version_check::is_min_version(min_version) {5 Some(true) => {}6 // rustc version too small or can't figure it out7 _ => {8 eprintln!("'fd' requires rustc >= {}", min_version);8 eprintln!("'fd' requires rustc >= {min_version}");9 std::process::exit(1);10 }11 }12}