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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 57e6ac53..5ac2c875 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, diff --git a/Cargo.toml b/Cargo.toml index 2e467652..a78c7a45 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" 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}"))), } } }