Skip to content
Myr

Merge pull request #1627 from hamirmahal/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 Thayne McCombs · committed by GitHub · parents 3d0d186, 87f230a · Browse files · 9 files+30 added−42 removed
This commit

State

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

Trailers

  • style: simplify string formatting for readability

Diff stats

9 files+30 added−42 removed

  • tests:+11 added−14 removed
  • other:+19 added−28 removed

9 files+30 added−42 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+10 added-16 removed
146 unmodified lines
147 let t1m_ago = ref_time - Duration::from_secs(60);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))153 .unwrap()154 .applies_to(&t1m_ago)155 );156 assert!(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))163 .unwrap()164 .applies_to(&t1m_ago)165 );166 assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))151 assert!(TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))152 .unwrap()153 .applies_to(&t1m_ago));154 assert!(!TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))155 .unwrap()156 .applies_to(&t1s_later));157 assert!(!TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))158 .unwrap()159 .applies_to(&t1m_ago));160 assert!(TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))161 .unwrap()162 .applies_to(&t1s_later));163 }164}
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-6 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
115 unmodified lines
375 let result = builder.add_ignore(global_ignore_file);376 match result {377 Some(ignore::Error::Partial(_)) => (),378 Some(err) => {379 print_error(format!(380 "Malformed pattern in global ignore file. {}.",381 err382 ));379 print_error(format!("Malformed pattern in global ignore file. {err}."));380 }381 None => (),382 }383 }
4 unmodified lines
388 let result = builder.add_ignore(ignore_file);389 match result {390 Some(ignore::Error::Partial(_)) => (),391 Some(err) => {395 print_error(format!("Malformed pattern in custom ignore file. {}.", err));392 print_error(format!("Malformed pattern in custom ignore file. {err}."));393 }394 None => (),395 }396 }
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-10 removed
593 unmodified lines
594 let root = te.system_root();595 let prefix = escape(&root.to_string_lossy());596597 te.assert_output(598 &[599 "--full-path",600 &format!("^{prefix}.*three.*foo$", prefix = prefix),601 ],598 &["--full-path", &format!("^{prefix}.*three.*foo$")],599 "one/two/three/d.foo600 one/two/three/directory_foo/",601 );602}
911 unmodified lines
1514fn test_symlink_as_absolute_root() {1515 let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);15161517 te.assert_output(1521 &["", &format!("{abs_path}/symlink", abs_path = abs_path)],1518 &["", &format!("{abs_path}/symlink")],1519 &format!(1520 "{abs_path}/symlink/c.foo1521 {abs_path}/symlink/C.Foo21522 {abs_path}/symlink/three/
16 unmodified lines
1539 "symlink",1540 &[1541 "--absolute-path",1542 "--full-path",1546 &format!("^{prefix}.*three", prefix = prefix),1543 &format!("^{prefix}.*three"),1544 ],1545 &format!(1546 "{abs_path}/{expected_path}/three/1547 {abs_path}/{expected_path}/three/d.foo
11 unmodified lines
1559 let prefix = escape(&root.to_string_lossy());1560 te.assert_output(1561 &[1562 "--full-path",1566 &format!("^{prefix}.*symlink.*three", prefix = prefix),1567 &format!("{abs_path}/symlink", abs_path = abs_path),1563 &format!("^{prefix}.*symlink.*three"),1564 &format!("{abs_path}/symlink"),1565 ],1566 &format!(1567 "{abs_path}/symlink/three/1568 {abs_path}/symlink/three/d.foo
764 unmodified lines
2333#[test]2334fn test_owner_current_group() {2335 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);2336 let gid = Gid::current();2340 te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");2337 te.assert_output(&["--owner", &format!(":{gid}"), "a.foo"], "a.foo");2338 if let Ok(Some(group)) = Group::from_gid(gid) {2339 te.assert_output(&["--owner", &format!(":{}", group.name), "a.foo"], "a.foo");2340 }2341}
270 unmodified lines
2612 .output()2613 .unwrap();26142615 if !output.status.success() {2619 panic!("{:?}", output);2616 panic!("{output:?}");2617 }2618}26192620/// 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}