From 46e27234640de619ee2ce74f425c02ed55261502 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 2 Oct 2024 21:48:42 +0200 Subject: [PATCH] style: inline variables into format strings --- Cargo.toml | 3 ++- cli/build.rs | 4 ++-- cli/src/cli_util.rs | 2 +- cli/src/command_error.rs | 2 +- cli/src/commands/git/push.rs | 2 +- cli/src/commands/operation/diff.rs | 8 ++++---- cli/src/commands/sparse.rs | 2 +- cli/src/description_util.rs | 5 ++--- cli/src/formatter.rs | 6 +++--- cli/src/ui.rs | 2 +- cli/testing/fake-formatter.rs | 6 +++--- cli/tests/test_diff_command.rs | 4 ++-- lib/src/default_index/store.rs | 5 +---- lib/src/repo.rs | 2 +- 14 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 691cf7271..7f4a09b35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -134,7 +134,8 @@ testutils = { path = "lib/testutils" } [workspace.lints.clippy] explicit_iter_loop = "warn" - +uninlined_format_args = "warn" + # Insta suggests compiling these packages in opt mode for faster testing. # See https://docs.rs/insta/latest/insta/#optional-faster-runs. [profile.dev.package] diff --git a/cli/build.rs b/cli/build.rs index 0986db748..993a0913e 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -33,9 +33,9 @@ fn main() { println!("cargo:rerun-if-env-changed=NIX_JJ_GIT_HASH"); if let Some(git_hash) = get_git_hash() { - println!("cargo:rustc-env=JJ_VERSION={}-{}", version, git_hash); + println!("cargo:rustc-env=JJ_VERSION={version}-{git_hash}"); } else { - println!("cargo:rustc-env=JJ_VERSION={}", version); + println!("cargo:rustc-env=JJ_VERSION={version}"); } } diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 1c80bd4a0..7183e9bb7 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -3314,7 +3314,7 @@ impl CliRunner { .flatten() .map(|path| format!("- {}", path.display())) .join("\n"); - e.hinted(format!("Check the following config files:\n{}", paths)) + e.hinted(format!("Check the following config files:\n{paths}")) })?; let string_args = expand_args(ui, &self.app, env::args_os(), &config)?; diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index d3ef9f445..03a0f13cb 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -352,7 +352,7 @@ impl From for CommandError { size_diff, max_size.0, max_size, ) } else { - format!("it is {}; the maximum size allowed is ~{}.", size, max_size,) + format!("it is {size}; the maximum size allowed is ~{max_size}.") }; user_error(format!( diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index bcfd04702..6b7d01903 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -123,7 +123,7 @@ pub struct GitPushArgs { fn make_bookmark_term(bookmark_names: &[impl fmt::Display]) -> String { match bookmark_names { - [bookmark_name] => format!("bookmark {}", bookmark_name), + [bookmark_name] => format!("bookmark {bookmark_name}"), bookmark_names => format!("bookmarks {}", bookmark_names.iter().join(", ")), } } diff --git a/cli/src/commands/operation/diff.rs b/cli/src/commands/operation/diff.rs index c2c0b3ee3..955647f34 100644 --- a/cli/src/commands/operation/diff.rs +++ b/cli/src/commands/operation/diff.rs @@ -282,7 +282,7 @@ pub fn show_op_diff( })?; for (name, (from_target, to_target)) in changed_local_bookmarks { with_content_format.write(formatter, |formatter| { - writeln!(formatter, "{}:", name)?; + writeln!(formatter, "{name}:")?; write_ref_target_summary( formatter, current_repo, @@ -310,7 +310,7 @@ pub fn show_op_diff( with_content_format.write(formatter, |formatter| writeln!(formatter, "Changed tags:"))?; for (name, (from_target, to_target)) in changed_tags { with_content_format.write(formatter, |formatter| { - writeln!(formatter, "{}:", name)?; + writeln!(formatter, "{name}:")?; write_ref_target_summary( formatter, current_repo, @@ -351,7 +351,7 @@ pub fn show_op_diff( }; for ((name, remote_name), (from_ref, to_ref)) in changed_remote_bookmarks { with_content_format.write(formatter, |formatter| { - writeln!(formatter, "{}@{}:", name, remote_name)?; + writeln!(formatter, "{name}@{remote_name}:")?; write_ref_target_summary( formatter, current_repo, @@ -422,7 +422,7 @@ fn write_ref_target_summary( })?; write!(formatter, " ")?; if let Some(prefix) = prefix { - write!(formatter, "{} ", prefix)?; + write!(formatter, "{prefix} ")?; } Ok(()) }; diff --git a/cli/src/commands/sparse.rs b/cli/src/commands/sparse.rs index 84c31d1a3..44c8282f6 100644 --- a/cli/src/commands/sparse.rs +++ b/cli/src/commands/sparse.rs @@ -177,7 +177,7 @@ fn edit_sparse( workspace_relative_sparse_path.display() )) })?; - writeln!(&mut content, "{}", path_string).unwrap(); + writeln!(&mut content, "{path_string}").unwrap(); } let content = edit_temp_file( diff --git a/cli/src/description_util.rs b/cli/src/description_util.rs index 317864627..e44fa542f 100644 --- a/cli/src/description_util.rs +++ b/cli/src/description_util.rs @@ -39,10 +39,9 @@ pub fn edit_description( settings: &UserSettings, ) -> Result { let description = format!( - r#"{} + r#"{description} JJ: Lines starting with "JJ: " (like this one) will be removed. -"#, - description +"# ); let description = edit_temp_file( diff --git a/cli/src/formatter.rs b/cli/src/formatter.rs index f487df84d..7df6915ae 100644 --- a/cli/src/formatter.rs +++ b/cli/src/formatter.rs @@ -395,7 +395,7 @@ impl ColorFormatter { } if let Some(d) = new_debug { if !d.is_empty() { - write!(self.output, "<<{}::", d)?; + write!(self.output, "<<{d}::")?; } self.current_debug = Some(d); } @@ -471,7 +471,7 @@ fn color_for_name_or_hex(name_or_hex: &str) -> Result Ok(Color::Cyan), "bright white" => Ok(Color::White), _ => color_for_hex(name_or_hex) - .ok_or_else(|| config::ConfigError::Message(format!("invalid color: {}", name_or_hex))), + .ok_or_else(|| config::ConfigError::Message(format!("invalid color: {name_or_hex}"))), } } @@ -786,7 +786,7 @@ mod tests { for [label, color] in labels_and_colors { // Use the color name as the label. config_builder = config_builder - .set_override(format!("colors.{}", label), color) + .set_override(format!("colors.{label}"), color) .unwrap(); } let mut output: Vec = vec![]; diff --git a/cli/src/ui.rs b/cli/src/ui.rs index be604b87d..5b5b85d87 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -632,7 +632,7 @@ impl Ui { let default_choice = default.map(|c| if c { "Y" } else { "N" }); let choice = self.prompt_choice( - &format!("{} {}", prompt, default_str), + &format!("{prompt} {default_str}"), &["y", "n", "yes", "no", "Yes", "No", "YES", "NO"], default_choice, )?; diff --git a/cli/testing/fake-formatter.rs b/cli/testing/fake-formatter.rs index f0fa6852c..952f87a3d 100644 --- a/cli/testing/fake-formatter.rs +++ b/cli/testing/fake-formatter.rs @@ -70,7 +70,7 @@ fn main() -> ExitCode { let args: Args = Args::parse(); // Code formatters tend to print errors before printing the result. if let Some(data) = args.stderr { - eprint!("{}", data); + eprint!("{data}"); } let stdout = if let Some(data) = args.stdout { // Other content-altering flags don't apply to --stdout. @@ -106,14 +106,14 @@ fn main() -> ExitCode { } stdout }; - print!("{}", stdout); + print!("{stdout}"); if let Some(path) = args.tee { let mut file = OpenOptions::new() .create(true) .append(true) .open(path) .unwrap(); - write!(file, "{}", stdout).unwrap(); + write!(file, "{stdout}").unwrap(); } if args.fail { ExitCode::FAILURE diff --git a/cli/tests/test_diff_command.rs b/cli/tests/test_diff_command.rs index 2c7ae86e0..f8311d4f2 100644 --- a/cli/tests/test_diff_command.rs +++ b/cli/tests/test_diff_command.rs @@ -433,8 +433,8 @@ fn test_diff_types() { &[ "diff", "--types", - &format!(r#"--from=description("{}")"#, from), - &format!(r#"--to=description("{}")"#, to), + &format!(r#"--from=description("{from}")"#), + &format!(r#"--to=description("{to}")"#), ], ) }; diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index df37d421a..28a50af5f 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -354,10 +354,7 @@ impl IndexStore for DefaultIndexStore { ); } ReadonlyIndexLoadError::Other { name: _, error } => { - eprintln!( - "{err} (maybe the format has changed): {source}. Reindexing...", - source = error - ); + eprintln!("{err} (maybe the format has changed): {error}. Reindexing..."); } } self.reinit().map_err(|err| IndexReadError(err.into()))?; diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 0e4220d62..1d89b600f 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -762,7 +762,7 @@ impl RepoLoader { tx.repo_mut().rebase_descendants(settings)?; } let tx_description = tx_description.map_or_else( - || format!("merge {} operations", num_operations), + || format!("merge {num_operations} operations"), |tx_description| tx_description.to_string(), ); let merged_repo = tx.write(tx_description).leave_unpublished();