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 90d89f6..97c7ed7 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 87d9134..b0318b8 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 07c70ee..a94be15 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 1b000ab..7b55a3d 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 f89452f724d20e9af7070788cc15e2d0e099d883 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 27 Sep 2024 10:56:46 -0500 Subject: [PATCH 5/5] style: Use inline format args --- examples/example_fixture.rs | 6 +++--- src/assert.rs | 8 ++++---- src/bin/bin_fixture.rs | 6 +++--- src/cargo.rs | 4 ++-- src/cmd.rs | 2 +- src/output.rs | 12 ++++++------ tests/cargo.rs | 8 ++++---- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/example_fixture.rs b/examples/example_fixture.rs index 0b22817..218cb44 100644 --- a/examples/example_fixture.rs +++ b/examples/example_fixture.rs @@ -8,10 +8,10 @@ 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}"); } let code = env::var("exit") @@ -27,7 +27,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/src/assert.rs b/src/assert.rs index 6c2e9c4..77723c9 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -64,7 +64,7 @@ impl<'c> OutputAssertExt for &'c mut process::Command { panic!("Failed to spawn {:?}: {}", self, err); } }; - Assert::new(output).append_context("command", format!("{:?}", self)) + Assert::new(output).append_context("command", format!("{self:?}")) } } @@ -1084,13 +1084,13 @@ impl fmt::Display for AssertError { writeln!(f, "Command interrupted") } AssertReason::UnexpectedReturnCode { case_tree } => { - writeln!(f, "Unexpected return code, failed {}", case_tree) + writeln!(f, "Unexpected return code, failed {case_tree}") } AssertReason::UnexpectedStdout { case_tree } => { - writeln!(f, "Unexpected stdout, failed {}", case_tree) + writeln!(f, "Unexpected stdout, failed {case_tree}") } AssertReason::UnexpectedStderr { case_tree } => { - writeln!(f, "Unexpected stderr, failed {}", case_tree) + writeln!(f, "Unexpected stderr, failed {case_tree}") } }?; write!(f, "{}", self.assert) diff --git a/src/bin/bin_fixture.rs b/src/bin/bin_fixture.rs index 882819d..0c30c7d 100644 --- a/src/bin/bin_fixture.rs +++ b/src/bin/bin_fixture.rs @@ -8,10 +8,10 @@ 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 let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) { @@ -31,7 +31,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/src/cargo.rs b/src/cargo.rs index 27da82e..2c1604d 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -181,7 +181,7 @@ impl Error for CargoError {} impl fmt::Display for CargoError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(ref cause) = self.cause { - writeln!(f, "Cause: {}", cause)?; + writeln!(f, "Cause: {cause}")?; } Ok(()) } @@ -222,7 +222,7 @@ pub fn cargo_bin>(name: S) -> path::PathBuf { } fn cargo_bin_str(name: &str) -> path::PathBuf { - let env_var = format!("CARGO_BIN_EXE_{}", name); + let env_var = format!("CARGO_BIN_EXE_{name}"); env::var_os(env_var) .map(|p| p.into()) .unwrap_or_else(|| target_dir().join(format!("{}{}", name, env::consts::EXE_SUFFIX))) diff --git a/src/cmd.rs b/src/cmd.rs index 654481c..22dcc3e 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -648,7 +648,7 @@ impl<'c> OutputAssertExt for &'c mut Command { let output = match self.output() { Ok(output) => output, Err(err) => { - panic!("Failed to spawn {:?}: {}", self, err); + panic!("Failed to spawn {self:?}: {err}"); } }; let assert = Assert::new(output).append_context("command", format!("{:?}", self.cmd)); diff --git a/src/output.rs b/src/output.rs index e072f19..8969b28 100644 --- a/src/output.rs +++ b/src/output.rs @@ -109,7 +109,7 @@ impl<'c> OutputOkExt for &'c mut process::Command { if output.status.success() { Ok(output) } else { - let error = OutputError::new(output).set_cmd(format!("{:?}", self)); + let error = OutputError::new(output).set_cmd(format!("{self:?}")); Err(error) } } @@ -266,8 +266,8 @@ enum OutputCause { impl fmt::Display for OutputCause { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - OutputCause::Expected(ref e) => write!(f, "{:#}", e), - OutputCause::Unexpected(ref e) => write!(f, "{:#}", e), + OutputCause::Expected(ref e) => write!(f, "{e:#}"), + OutputCause::Unexpected(ref e) => write!(f, "{e:#}"), } } } @@ -369,9 +369,9 @@ fn format_bytes(data: &[u8], f: &mut impl fmt::Write) -> fmt::Result { .as_bstr() .lines_with_terminator() .skip(LINES_MAX_START + lines_omitted); - writeln!(f, "<{} lines total>", lines_total)?; + writeln!(f, "<{lines_total} lines total>")?; write_debug_bstrs(f, true, start_lines)?; - writeln!(f, "<{} lines omitted>", lines_omitted)?; + writeln!(f, "<{lines_omitted} lines omitted>")?; write_debug_bstrs(f, true, end_lines) } else if BYTES_MIN_OVERFLOW <= data.len() { write!( @@ -434,7 +434,7 @@ mod test { fn format_bytes() { let mut s = String::new(); for i in 0..80 { - s.push_str(&format!("{}\n", i)); + s.push_str(&format!("{i}\n")); } let mut buf = String::new(); diff --git a/tests/cargo.rs b/tests/cargo.rs index 5f074a5..b7a244a 100644 --- a/tests/cargo.rs +++ b/tests/cargo.rs @@ -34,7 +34,7 @@ fn mod_example() { .unwrap(); let mut cmd = bin_under_test.command(); let output = cmd.unwrap(); - println!("{:?}", output); + println!("{output:?}"); } } @@ -43,7 +43,7 @@ fn mod_example() { fn trait_example() { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); let output = cmd.unwrap(); - println!("{:?}", output); + println!("{output:?}"); } #[test] @@ -51,12 +51,12 @@ fn trait_example() { fn cargo_bin_example_1() { let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); let output = cmd.unwrap(); - println!("{:?}", output); + println!("{output:?}"); } #[test] fn cargo_bin_example_2() { let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); let output = cmd.unwrap(); - println!("{:?}", output); + println!("{output:?}"); }