From 553258af51034bc84dc9f951201e7b8f2285b57e Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 25 Jul 2024 15:35:58 -0700 Subject: [PATCH 1/5] Have clippy warn about uninlined format arguments This makes clippy warn about `format!("{}", var)`, with a machine-applicable fix converting to `format!("{var}")`. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 90d89f6e..97c7ed79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,6 +80,7 @@ string_lit_as_bytes = "warn" string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" +uninlined_format_args = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" From 7a28f01acfe8eb95f4e54127e1b66aa31cf2aeed Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 23 Aug 2024 19:02:02 -0500 Subject: [PATCH 2/5] docs(contrib): Fix tpo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 87d9134e..b0318b82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp PRs should tell a cohesive story, with test and refactor commits that keep the fix or feature commits simple and clear. -Specifically, we would encouage +Specifically, we would encourage - File renames be isolated into their own commit - Add tests in a commit before their feature or fix, showing the current behavior. The diff for the feature/fix commit will then show how the behavior changed, From 37cf1085bc6aa53e18a37f0aa97be51afa6e7f14 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 01:02:47 +0000 Subject: [PATCH 3/5] chore(deps): Update EmbarkStudios/cargo-deny-action action to v2 --- .github/workflows/audit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 07c70eeb..a94be159 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -47,7 +47,7 @@ jobs: - bans licenses sources steps: - uses: actions/checkout@v4 - - uses: EmbarkStudios/cargo-deny-action@v1 + - uses: EmbarkStudios/cargo-deny-action@v2 with: command: check ${{ matrix.checks }} rust-version: stable From 6e193aa09aed80118df4e1317b8eed057bad6f0b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 26 Sep 2024 20:59:12 -0500 Subject: [PATCH 4/5] chore: Ensure pre-commit gets non-system Python This is needed with the ubuntu-24.04 images so that `setup-python` will install a version of Python that the pre-commit action can install into. See pre-commit/action#210 for more of an analysis of this. --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1b000abf..7b55a3d9 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -24,4 +24,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - uses: pre-commit/action@v3.0.1 From 3f8575fdd64dd6e7a117cdeac5964dac48c44a42 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 27 Sep 2024 13:23:50 -0500 Subject: [PATCH 5/5] style: Inline fmt args --- crates/snapbox/src/assert/error.rs | 2 +- crates/snapbox/src/assert/mod.rs | 6 +++--- crates/snapbox/src/bin/snap-fixture.rs | 10 +++++----- crates/snapbox/src/cmd.rs | 13 ++++++------- crates/snapbox/src/data/mod.rs | 2 +- crates/snapbox/src/filter/pattern.rs | 2 +- crates/snapbox/src/filter/redactions.rs | 6 +++--- crates/trycmd/src/bin/bin-fixture.rs | 10 +++++----- crates/trycmd/src/runner.rs | 6 +++--- crates/trycmd/src/schema.rs | 12 +++++------- 10 files changed, 33 insertions(+), 36 deletions(-) diff --git a/crates/snapbox/src/assert/error.rs b/crates/snapbox/src/assert/error.rs index 11b0a4ad..62fcfbed 100644 --- a/crates/snapbox/src/assert/error.rs +++ b/crates/snapbox/src/assert/error.rs @@ -38,7 +38,7 @@ impl std::fmt::Display for Error { if let Some(backtrace) = self.backtrace.as_ref() { writeln!(f)?; writeln!(f, "Backtrace:")?; - writeln!(f, "{}", backtrace)?; + writeln!(f, "{backtrace}")?; } Ok(()) } diff --git a/crates/snapbox/src/assert/mod.rs b/crates/snapbox/src/assert/mod.rs index 598ee29e..965b09c2 100644 --- a/crates/snapbox/src/assert/mod.rs +++ b/crates/snapbox/src/assert/mod.rs @@ -168,7 +168,7 @@ impl Assert { crate::report::Styled::new(String::new(), Default::default()) } else if let Some(action_var) = self.action_var.as_deref() { self.palette - .hint(format!("Update with {}=overwrite", action_var)) + .hint(format!("Update with {action_var}=overwrite")) } else { crate::report::Styled::new(String::new(), Default::default()) }; @@ -338,7 +338,7 @@ impl Assert { } if ok { use std::io::Write; - let _ = write!(stderr(), "{}", buffer); + let _ = write!(stderr(), "{buffer}"); match self.action { Action::Skip => unreachable!("Bailed out earlier"), Action::Ignore => { @@ -365,7 +365,7 @@ impl Assert { &mut buffer, "{}", self.palette - .hint(format_args!("Update with {}=overwrite", action_var)) + .hint(format_args!("Update with {action_var}=overwrite")) ) .unwrap(); } diff --git a/crates/snapbox/src/bin/snap-fixture.rs b/crates/snapbox/src/bin/snap-fixture.rs index 5f18378f..7cae86e5 100644 --- a/crates/snapbox/src/bin/snap-fixture.rs +++ b/crates/snapbox/src/bin/snap-fixture.rs @@ -8,15 +8,15 @@ use std::process; fn run() -> Result<(), Box> { if let Ok(text) = env::var("stdout") { - println!("{}", text); + println!("{text}"); } if let Ok(text) = env::var("stderr") { - eprintln!("{}", text); + eprintln!("{text}"); } if env::var("echo_large").as_deref() == Ok("1") { for i in 0..(128 * 1024) { - println!("{}", i); + println!("{i}"); } } @@ -33,7 +33,7 @@ fn run() -> Result<(), Box> { if let Ok(path) = env::var("cat") { let text = std::fs::read_to_string(path).unwrap(); - eprintln!("{}", text); + eprintln!("{text}"); } if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) { @@ -53,7 +53,7 @@ fn main() { let code = match run() { Ok(_) => 0, Err(ref e) => { - write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail"); + write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail"); 1 } }; diff --git a/crates/snapbox/src/cmd.rs b/crates/snapbox/src/cmd.rs index 7a9a811c..80e6a516 100644 --- a/crates/snapbox/src/cmd.rs +++ b/crates/snapbox/src/cmd.rs @@ -496,7 +496,7 @@ impl OutputAssert { use std::fmt::Write; let mut buf = String::new(); - writeln!(&mut buf, "{}", desc).unwrap(); + writeln!(&mut buf, "{desc}").unwrap(); self.write_stdout(&mut buf).unwrap(); self.write_stderr(&mut buf).unwrap(); panic!("{}", buf); @@ -526,7 +526,7 @@ impl OutputAssert { use std::fmt::Write; let mut buf = String::new(); - writeln!(&mut buf, "{}", desc).unwrap(); + writeln!(&mut buf, "{desc}").unwrap(); self.write_stdout(&mut buf).unwrap(); self.write_stderr(&mut buf).unwrap(); panic!("{}", buf); @@ -548,7 +548,7 @@ impl OutputAssert { use std::fmt::Write; let mut buf = String::new(); - writeln!(&mut buf, "{}", desc).unwrap(); + writeln!(&mut buf, "{desc}").unwrap(); self.write_stdout(&mut buf).unwrap(); self.write_stderr(&mut buf).unwrap(); panic!("{}", buf); @@ -580,7 +580,7 @@ impl OutputAssert { use std::fmt::Write; let mut buf = String::new(); - writeln!(&mut buf, "{}", desc).unwrap(); + writeln!(&mut buf, "{desc}").unwrap(); self.write_stdout(&mut buf).unwrap(); self.write_stderr(&mut buf).unwrap(); panic!("{}", buf); @@ -761,7 +761,7 @@ pub fn display_exit_status(status: std::process::ExitStatus) -> String { libc::SIGTRAP => ", SIGTRAP: trace/breakpoint trap", _ => "", }; - Some(format!("signal: {}{}", signal, name)) + Some(format!("signal: {signal}{name}")) } #[cfg(windows)] @@ -914,8 +914,7 @@ pub(crate) mod examples { } Err(crate::assert::Error::new(format!( - "Unknown error building example {}", - target_name + "Unknown error building example {target_name}" ))) } diff --git a/crates/snapbox/src/data/mod.rs b/crates/snapbox/src/data/mod.rs index 4704466a..df2512d0 100644 --- a/crates/snapbox/src/data/mod.rs +++ b/crates/snapbox/src/data/mod.rs @@ -38,7 +38,7 @@ pub trait ToDebug { impl ToDebug for D { fn to_debug(&self) -> Data { - Data::text(format!("{:#?}\n", self)) + Data::text(format!("{self:#?}\n")) } } diff --git a/crates/snapbox/src/filter/pattern.rs b/crates/snapbox/src/filter/pattern.rs index ead3b9e1..735e14b4 100644 --- a/crates/snapbox/src/filter/pattern.rs +++ b/crates/snapbox/src/filter/pattern.rs @@ -625,7 +625,7 @@ mod test { ]; for (line, pattern, expected) in cases { let actual = line_matches(line, pattern, &Redactions::new()); - assert_eq!(expected, actual, "line={:?} pattern={:?}", line, pattern); + assert_eq!(expected, actual, "line={line:?} pattern={pattern:?}"); } } } diff --git a/crates/snapbox/src/filter/redactions.rs b/crates/snapbox/src/filter/redactions.rs index e0f9227b..6585c4db 100644 --- a/crates/snapbox/src/filter/redactions.rs +++ b/crates/snapbox/src/filter/redactions.rs @@ -327,14 +327,14 @@ fn replace_many<'a>( fn validate_placeholder(placeholder: &'static str) -> crate::assert::Result<&'static str> { if !placeholder.starts_with('[') || !placeholder.ends_with(']') { - return Err(format!("Key `{}` is not enclosed in []", placeholder).into()); + return Err(format!("Key `{placeholder}` is not enclosed in []").into()); } if placeholder[1..(placeholder.len() - 1)] .find(|c: char| !c.is_ascii_uppercase() && c != '_') .is_some() { - return Err(format!("Key `{}` can only be A-Z but ", placeholder).into()); + return Err(format!("Key `{placeholder}` can only be A-Z but ").into()); } Ok(placeholder) @@ -356,7 +356,7 @@ mod test { ]; for (placeholder, expected) in cases { let actual = validate_placeholder(placeholder).is_ok(); - assert_eq!(expected, actual, "placeholder={:?}", placeholder); + assert_eq!(expected, actual, "placeholder={placeholder:?}"); } } } diff --git a/crates/trycmd/src/bin/bin-fixture.rs b/crates/trycmd/src/bin/bin-fixture.rs index 89a49f53..de18f0fd 100644 --- a/crates/trycmd/src/bin/bin-fixture.rs +++ b/crates/trycmd/src/bin/bin-fixture.rs @@ -6,15 +6,15 @@ use std::process; fn run() -> Result<(), Box> { if let Ok(text) = env::var("stdout") { - println!("{}", text); + println!("{text}"); } if let Ok(text) = env::var("stderr") { - eprintln!("{}", text); + eprintln!("{text}"); } if env::var("echo_large").as_deref() == Ok("1") { for i in 0..(128 * 1024) { - println!("{}", i); + println!("{i}"); } } @@ -31,7 +31,7 @@ fn run() -> Result<(), Box> { if let Ok(path) = env::var("cat") { let text = std::fs::read_to_string(path).unwrap(); - eprintln!("{}", text); + eprintln!("{text}"); } if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) { @@ -55,7 +55,7 @@ fn main() { let code = match run() { Ok(_) => 0, Err(ref e) => { - write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail"); + write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail"); 1 } }; diff --git a/crates/trycmd/src/runner.rs b/crates/trycmd/src/runner.rs index dfdfafcf..3f8f0eed 100644 --- a/crates/trycmd/src/runner.rs +++ b/crates/trycmd/src/runner.rs @@ -179,7 +179,7 @@ impl Case { Err(e) => { let output = Output::step(self.path.clone(), "setup".into()); return vec![Err( - output.error(format!("Failed to initialize sandbox: {}", e).into()) + output.error(format!("Failed to initialize sandbox: {e}").into()) )]; } }; @@ -283,7 +283,7 @@ impl Case { if let Err(err) = fs_context.close() { ok = false; output.fs.context.push(FileStatus::Failure( - format!("Failed to cleanup sandbox: {}", err).into(), + format!("Failed to cleanup sandbox: {err}").into(), )); } @@ -758,7 +758,7 @@ impl std::fmt::Display for Stream { f, "{} {}:", self.stream, - palette.error(format_args!("({})", msg)) + palette.error(format_args!("({msg})")) )?; writeln!(f, "{}", palette.info(&self.content))?; } diff --git a/crates/trycmd/src/schema.rs b/crates/trycmd/src/schema.rs index 2c17e533..944c439a 100644 --- a/crates/trycmd/src/schema.rs +++ b/crates/trycmd/src/schema.rs @@ -146,7 +146,7 @@ impl TryCmd { } } else if ext == std::ffi::OsStr::new("trycmd") || ext == std::ffi::OsStr::new("md") { if stderr.is_some() && stderr != Some(&crate::Data::new()) { - panic!("stderr should have been merged: {:?}", stderr); + panic!("stderr should have been merged: {stderr:?}"); } if let (Some(id), Some(stdout)) = (id, stdout) { let step = self @@ -245,9 +245,7 @@ impl TryCmd { cmd_start = line_num; stdout_start = line_num + 1; } else { - return Err( - format!("Expected `$` on line {}, got `{}`", line_num, line).into() - ); + return Err(format!("Expected `$` on line {line_num}, got `{line}`").into()); } } else { break 'outer; @@ -296,7 +294,7 @@ impl TryCmd { let bin = loop { if cmdline.is_empty() { - return Err(format!("No bin specified on line {}", cmd_start).into()); + return Err(format!("No bin specified on line {cmd_start}").into()); } let next = cmdline.remove(0); if let Some((key, value)) = next.split_once('=') { @@ -593,7 +591,7 @@ impl Step { ) -> Result { let bin = match &self.bin { Some(Bin::Path(path)) => Ok(path.clone()), - Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {}", name).into()), + Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {name}").into()), Some(Bin::Ignore) => Err("Internal error: tried to run an ignored bin".into()), Some(Bin::Error(err)) => Err(err.clone()), None => Err("No bin specified".into()), @@ -895,7 +893,7 @@ impl std::str::FromStr for CommandStatus { _ => s .parse::() .map(Self::Code) - .map_err(|_| crate::Error::new(format!("Expected an exit code, got {}", s))), + .map_err(|_| crate::Error::new(format!("Expected an exit code, got {s}"))), } } }