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

@ -104,7 +104,7 @@ impl NuCompleter {
return Some(result);
}
}
Err(err) => println!("failed to eval completer block: {}", err),
Err(err) => println!("failed to eval completer block: {err}"),
}
None

View File

@ -119,7 +119,7 @@ pub fn directory_completion(
let mut file_name = entry.file_name().to_string_lossy().into_owned();
if matches(&partial, &file_name, options) {
let mut path = if prepend_base_dir(original_input, &base_dir_name) {
format!("{}{}", base_dir_name, file_name)
format!("{base_dir_name}{file_name}")
} else {
file_name.to_string()
};
@ -135,7 +135,7 @@ pub fn directory_completion(
|| path.contains(' ')
|| path.contains('#')
{
path = format!("`{}`", path);
path = format!("`{path}`");
}
Some((span, path))

View File

@ -58,7 +58,7 @@ impl Completer for DotNuCompletion {
};
// Check if the base_dir is a folder
if base_dir != format!(".{}", SEP) {
if base_dir != format!(".{SEP}") {
// Add the base dir into the directories to be searched
search_dirs.push(base_dir.clone());

View File

@ -124,7 +124,7 @@ pub fn file_path_completion(
let mut file_name = entry.file_name().to_string_lossy().into_owned();
if matches(&partial, &file_name, options) {
let mut path = if prepend_base_dir(original_input, &base_dir_name) {
format!("{}{}", base_dir_name, file_name)
format!("{base_dir_name}{file_name}")
} else {
file_name.to_string()
};
@ -142,7 +142,7 @@ pub fn file_path_completion(
|| path.contains('(')
|| path.contains(')')
{
path = format!("`{}`", path);
path = format!("`{path}`");
}
Some((span, path))
@ -170,7 +170,7 @@ pub fn matches(partial: &str, from: &str, options: &CompletionOptions) -> bool {
/// Returns whether the base_dir should be prepended to the file path
pub fn prepend_base_dir(input: &str, base_dir: &str) -> bool {
if base_dir == format!(".{}", SEP) {
if base_dir == format!(".{SEP}") {
// if the current base_dir path is the local folder we only add a "./" prefix if the user
// input already includes a local folder prefix.
let manually_entered = {

View File

@ -81,7 +81,7 @@ pub fn evaluate_file(
report_error(
&working_set,
&ShellError::FileNotFoundCustom(
format!("The file path '{}' does not have a parent", file_path_str),
format!("The file path '{file_path_str}' does not have a parent"),
Span::unknown(),
),
);
@ -193,6 +193,6 @@ fn print_or_exit(pipeline_data: PipelineData, engine_state: &mut EngineState, co
}
let out = item.into_string("\n", config) + "\n";
let _ = stdout_write_all_and_flush(out).map_err(|err| eprintln!("{}", err));
let _ = stdout_write_all_and_flush(out).map_err(|err| eprintln!("{err}"));
}
}

View File

@ -411,10 +411,10 @@ impl DescriptionMenu {
RESET
)
} else {
format!(" {}\r\n", example)
format!(" {example}\r\n")
}
} else {
format!(" {}\r\n", example)
format!(" {example}\r\n")
}
})
.collect();
@ -429,7 +429,7 @@ impl DescriptionMenu {
examples,
)
} else {
format!("\r\n\r\nExamples:\r\n{}", examples,)
format!("\r\n\r\nExamples:\r\n{examples}",)
}
}
}

View File

@ -154,7 +154,7 @@ fn convert_to_suggestions(
.flat_map(|val| convert_to_suggestions(val, line, pos, only_buffer_difference))
.collect(),
_ => vec![Suggestion {
value: format!("Not a record: {:?}", value),
value: format!("Not a record: {value:?}"),
description: None,
extra: None,
span: reedline::Span {

View File

@ -91,7 +91,7 @@ impl NushellPrompt {
}
fn default_wrapped_custom_string(&self, str: String) -> String {
format!("({})", str)
format!("({str})")
}
}

View File

@ -106,8 +106,7 @@ pub(crate) fn update_prompt<'prompt>(
let left_prompt_string = if config.shell_integration {
if let Some(prompt_string) = left_prompt_string {
Some(format!(
"{}{}{}",
PRE_PROMPT_MARKER, prompt_string, POST_PROMPT_MARKER
"{PRE_PROMPT_MARKER}{prompt_string}{POST_PROMPT_MARKER}"
))
} else {
left_prompt_string

View File

@ -683,7 +683,7 @@ fn add_parsed_keybinding(
.filter(|num| matches!(num, 1..=20))
.ok_or(ShellError::UnsupportedConfigValue(
"(f1|f2|...|f20)".to_string(),
format!("unknown function key: {}", c),
format!("unknown function key: {c}"),
keybinding.keycode.span()?,
))?;
KeyCode::F(fn_num)

View File

@ -125,7 +125,7 @@ pub fn evaluate_repl(
if show_banner {
let banner = get_banner(engine_state, stack);
if use_ansi {
println!("{}", banner);
println!("{banner}");
} else {
println!("{}", nu_utils::strip_ansi_string_likely(banner));
}
@ -143,7 +143,7 @@ pub fn evaluate_repl(
engine_state,
stack,
s.item.as_bytes(),
&format!("entry #{}", entry_num),
&format!("entry #{entry_num}"),
PipelineData::empty(),
);
engine_state.merge_env(stack, get_guaranteed_cwd(engine_state, stack))?;
@ -470,7 +470,7 @@ pub fn evaluate_repl(
engine_state,
stack,
s.as_bytes(),
&format!("entry #{}", entry_num),
&format!("entry #{entry_num}"),
PipelineData::empty(),
);
}
@ -528,7 +528,7 @@ pub fn evaluate_repl(
// ESC]0;stringBEL -- Set icon name and window title to string
// ESC]1;stringBEL -- Set icon name to string
// ESC]2;stringBEL -- Set window title to string
run_ansi_sequence(&format!("\x1b]2;{}\x07", maybe_abbrev_path))?;
run_ansi_sequence(&format!("\x1b]2;{maybe_abbrev_path}\x07"))?;
}
run_ansi_sequence(RESET_APPLICATION_MODE)?;
}
@ -568,7 +568,7 @@ pub fn evaluate_repl(
Err(err) => {
let message = err.to_string();
if !message.contains("duration") {
eprintln!("Error: {:?}", err);
eprintln!("Error: {err:?}");
// TODO: Identify possible error cases where a hard failure is preferable
// Ignoring and reporting could hide bigger problems
// e.g. https://github.com/nushell/nushell/issues/6452

View File

@ -44,7 +44,7 @@ fn gather_env_vars(
report_error(
&working_set,
&ShellError::GenericError(
format!("Environment variable was not captured: {}", env_str),
format!("Environment variable was not captured: {env_str}"),
"".to_string(),
None,
Some(msg.into()),
@ -80,8 +80,7 @@ fn gather_env_vars(
"".to_string(),
None,
Some(format!(
"Retrieving current directory failed: {:?} not a valid utf-8 path",
init_cwd
"Retrieving current directory failed: {init_cwd:?} not a valid utf-8 path"
)),
Vec::new(),
),