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

@ -69,7 +69,7 @@ fn get_documentation(
if !config.no_subcommands {
let signatures = engine_state.get_signatures(true);
for sig in signatures {
if sig.name.starts_with(&format!("{} ", cmd_name))
if sig.name.starts_with(&format!("{cmd_name} "))
// Don't display deprecated commands in the Subcommands list
&& !sig.usage.starts_with("Deprecated command")
{
@ -84,11 +84,11 @@ fn get_documentation(
sig.search_terms.join(", "),
RESET
);
let _ = write!(long_desc, "{}", text);
let _ = write!(long_desc, "{text}");
}
let text = format!("{}Usage{}:\n > {}\n", G, RESET, sig.call_signature());
let _ = write!(long_desc, "{}", text);
let _ = write!(long_desc, "{text}");
if !subcommands.is_empty() {
let _ = write!(long_desc, "\n{G}Subcommands{RESET}:\n");
@ -105,11 +105,10 @@ fn get_documentation(
if sig.operates_on_cell_paths() {
let _ = writeln!(
long_desc,
"\n{}Signatures(Cell paths are supported){}:\n{}",
G, RESET, sig
"\n{G}Signatures(Cell paths are supported){RESET}:\n{sig}"
);
} else {
let _ = writeln!(long_desc, "\n{}Signatures{}:\n{}", G, RESET, sig);
let _ = writeln!(long_desc, "\n{G}Signatures{RESET}:\n{sig}");
}
}
@ -137,7 +136,7 @@ fn get_documentation(
)
}
};
let _ = writeln!(long_desc, "{}", text);
let _ = writeln!(long_desc, "{text}");
}
for positional in &sig.optional_positional {
let text = match &positional.shape {
@ -158,7 +157,7 @@ fn get_documentation(
)
}
};
let _ = writeln!(long_desc, "{}", text);
let _ = writeln!(long_desc, "{text}");
}
if let Some(rest_positional) = &sig.rest_positional {
@ -168,12 +167,12 @@ fn get_documentation(
document_shape(rest_positional.shape.clone()),
rest_positional.desc
);
let _ = writeln!(long_desc, "{}", text);
let _ = writeln!(long_desc, "{text}");
}
}
if !examples.is_empty() {
let _ = write!(long_desc, "\n{}Examples{}:", G, RESET);
let _ = write!(long_desc, "\n{G}Examples{RESET}:");
}
for example in examples {
@ -196,7 +195,7 @@ fn get_documentation(
let result = output.into_value(Span::unknown());
match result.as_string() {
Ok(s) => {
let _ = write!(long_desc, "\n > {}\n", s);
let _ = write!(long_desc, "\n > {s}\n");
}
_ => {
let _ = write!(long_desc, "\n > {}\n", example.example);
@ -237,7 +236,7 @@ pub fn get_flags_section(signature: &Signature) -> String {
const D: &str = "\x1b[39m"; // default
let mut long_desc = String::new();
let _ = write!(long_desc, "\n{}Flags{}:\n", G, RESET);
let _ = write!(long_desc, "\n{G}Flags{RESET}:\n");
for flag in &signature.named {
let msg = if let Some(arg) = &flag.arg {
if let Some(short) = flag.short {

View File

@ -174,7 +174,7 @@ pub fn current_dir_str(engine_state: &EngineState, stack: &Stack) -> Result<Stri
} else {
Err(ShellError::GenericError(
"Invalid current directory".to_string(),
format!("The 'PWD' environment variable must be set to an absolute path. Found: '{}'", cwd),
format!("The 'PWD' environment variable must be set to an absolute path. Found: '{cwd}'"),
Some(pwd.span()?),
None,
Vec::new()
@ -255,7 +255,7 @@ pub fn find_in_dirs_env(
} else {
return Err(ShellError::GenericError(
"Invalid current directory".to_string(),
format!("The 'FILE_PWD' environment variable must be set to an absolute path. Found: '{}'", cwd),
format!("The 'FILE_PWD' environment variable must be set to an absolute path. Found: '{cwd}'"),
Some(pwd.span()?),
None,
Vec::new()
@ -395,8 +395,8 @@ fn ensure_path(scope: &mut HashMap<String, Value>, env_path_name: &str) -> Optio
if !vals.iter().all(|v| matches!(v, Value::String { .. })) {
error = error.or_else(|| {
Some(ShellError::GenericError(
format!("Wrong {} environment variable value", env_path_name),
format!("{} must be a list of strings", env_path_name),
format!("Wrong {env_path_name} environment variable value"),
format!("{env_path_name} must be a list of strings"),
Some(*span),
None,
Vec::new(),
@ -416,8 +416,8 @@ fn ensure_path(scope: &mut HashMap<String, Value>, env_path_name: &str) -> Optio
error = error.or_else(|| {
Some(ShellError::GenericError(
format!("Wrong {} environment variable value", env_path_name),
format!("{} must be a list of strings", env_path_name),
format!("Wrong {env_path_name} environment variable value"),
format!("{env_path_name} must be a list of strings"),
Some(span),
None,
Vec::new(),

View File

@ -19,7 +19,7 @@ pub fn eval_operator(op: &Expression) -> Result<Operator, ShellError> {
..
} => Ok(operator.clone()),
Expression { span, expr, .. } => {
Err(ShellError::UnknownOperator(format!("{:?}", expr), *span))
Err(ShellError::UnknownOperator(format!("{expr:?}"), *span))
}
}
}