Use variable names directly in the format strings (#7906)

# Description

Lint: `clippy::uninlined_format_args`

More readable in most situations.
(May be slightly confusing for modifier format strings
https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters)

Alternative to #7865

# User-Facing Changes

None intended

# Tests + Formatting

(Ran `cargo +stable clippy --fix --workspace -- -A clippy::all -D
clippy::uninlined_format_args` to achieve this. Depends on Rust `1.67`)
This commit is contained in:
Stefan Holderbach
2023-01-30 02:37:54 +01:00
committed by GitHub
parent 6ae497eedc
commit ab480856a5
134 changed files with 386 additions and 431 deletions

View File

@ -45,7 +45,7 @@ fn compute_sum_of_individual_row() -> Result<(), String> {
for (column_name, expected_value) in answers_for_columns {
let actual = nu!(
cwd: "tests/fixtures/formats/",
format!("open sample-ps-output.json | select {} | math sum | get {}", column_name, column_name)
format!("open sample-ps-output.json | select {column_name} | math sum | get {column_name}")
);
let result =
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;
@ -66,7 +66,7 @@ fn compute_sum_of_table() -> Result<(), String> {
for (column_name, expected_value) in answers_for_columns {
let actual = nu!(
cwd: "tests/fixtures/formats/",
format!("open sample-ps-output.json | select cpu mem virtual | math sum | get {}", column_name)
format!("open sample-ps-output.json | select cpu mem virtual | math sum | get {column_name}")
);
let result =
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;

View File

@ -3,7 +3,7 @@ use nu_test_support::nu;
#[test]
fn test_kill_invalid_pid() {
let pid = i32::MAX;
let actual = nu!(format!("kill {}", pid));
let actual = nu!(format!("kill {pid}"));
assert!(actual.err.contains("process didn't terminate successfully"));
}

View File

@ -97,7 +97,7 @@ mod columns {
let actual = nu!(
cwd: ".",
format!("{} | roll right --by 3 --cells-only | columns | str join '-' ", four_bitstring)
format!("{four_bitstring} | roll right --by 3 --cells-only | columns | str join '-' ")
);
assert_eq!(actual.out, expected_value.1);
@ -142,12 +142,11 @@ mod columns {
"#,
);
println!(
"{} | roll left --by 3 | {}",
bitstring_as_nu_row_pipeline, nu_row_literal_bitstring_to_decimal_value_pipeline
"{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}"
);
nu!(
cwd: ".",
format!("{} | roll left --by 3 | {}", bitstring_as_nu_row_pipeline, nu_row_literal_bitstring_to_decimal_value_pipeline)
format!("{bitstring_as_nu_row_pipeline} | roll left --by 3 | {nu_row_literal_bitstring_to_decimal_value_pipeline}")
).out
}

View File

@ -16,7 +16,7 @@ fn writes_out_csv() {
);
let actual = file_contents(expected_file);
println!("{}", actual);
println!("{actual}");
assert!(actual.contains("nu,0.14,A new type of shell,MIT,2018"));
})
}
@ -52,7 +52,7 @@ fn save_append_will_create_file_if_not_exists() {
);
let actual = file_contents(expected_file);
println!("{}", actual);
println!("{actual}");
assert_eq!(actual, "hello");
})
}
@ -78,7 +78,7 @@ fn save_append_will_not_overwrite_content() {
);
let actual = file_contents(expected_file);
println!("{}", actual);
println!("{actual}");
assert_eq!(actual, "hello world");
})
}

View File

@ -16,10 +16,9 @@ fn sources_also_files_under_custom_lib_dirs_path() {
"config.toml",
&format!(
r#"
lib_dirs = ["{}"]
lib_dirs = ["{library_path}"]
skip_welcome_message = true
"#,
library_path
"#
),
)]);
@ -151,7 +150,7 @@ fn can_source_dynamic_path() {
sandbox.with_files(vec![FileWithContent(foo_file, "echo foo")]);
let cmd = format!("let file = `{}`; source-env $file", foo_file);
let cmd = format!("let file = `{foo_file}`; source-env $file");
let actual = nu!(cwd: dirs.test(), &cmd);
assert_eq!(actual.out, "foo");

View File

@ -19,7 +19,7 @@ fn zips_two_tables() {
Playground::setup("zip_test_1", |dirs, nu| {
nu.with_files(vec![FileWithContent(
"zip_test.nu",
&format!("{}\n", ZIP_POWERED_TEST_ASSERTION_SCRIPT),
&format!("{ZIP_POWERED_TEST_ASSERTION_SCRIPT}\n"),
)]);
let actual = nu!(