Skip to content

Commit

Permalink
style: inline variables into format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Oct 2, 2024
1 parent 8223ac7 commit e7f17c0
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ testutils = { path = "lib/testutils" }

[workspace.lints.clippy]
explicit_iter_loop = "deny"
uninlined_format_args = "deny"

# Insta suggests compiling these packages in opt mode for faster testing.
# See https://docs.rs/insta/latest/insta/#optional-faster-runs.
Expand Down
4 changes: 2 additions & 2 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn main() -> std::io::Result<()> {
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}");
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,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)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl From<SnapshotError> 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!(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")),
}
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/operation/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -422,7 +422,7 @@ fn write_ref_target_summary(
})?;
write!(formatter, " ")?;
if let Some(prefix) = prefix {
write!(formatter, "{} ", prefix)?;
write!(formatter, "{prefix} ")?;
}
Ok(())
};
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions cli/src/description_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ pub fn edit_description(
settings: &UserSettings,
) -> Result<String, CommandError> {
let description = format!(
r#"{}
r#"{description}
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#,
description
"#
);

let description = edit_temp_file(
Expand Down
6 changes: 3 additions & 3 deletions cli/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<W: Write> ColorFormatter<W> {
}
if let Some(d) = new_debug {
if !d.is_empty() {
write!(self.output, "<<{}::", d)?;
write!(self.output, "<<{d}::")?;
}
self.current_debug = Some(d);
}
Expand Down Expand Up @@ -471,7 +471,7 @@ fn color_for_name_or_hex(name_or_hex: &str) -> Result<Color, config::ConfigError
"bright cyan" => 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}"))),
}
}

Expand Down Expand Up @@ -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<u8> = vec![];
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down
6 changes: 3 additions & 3 deletions cli/testing/fake-formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_diff_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")"#),
],
)
};
Expand Down
3 changes: 1 addition & 2 deletions lib/src/default_index/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ impl IndexStore for DefaultIndexStore {
}
ReadonlyIndexLoadError::Other { name: _, error } => {
eprintln!(
"{err} (maybe the format has changed): {source}. Reindexing...",
source = error
"{err} (maybe the format has changed): {error}. Reindexing..."
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e7f17c0

Please sign in to comment.