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

@ -682,13 +682,13 @@ Format: #
}
let output = if escape && param_is_valid_string {
format!("\x1b[{}", code_string)
format!("\x1b[{code_string}")
} else if osc && param_is_valid_string {
// Operating system command aka osc ESC ] <- note the right brace, not left brace for osc
// OCS's need to end with either:
// bel '\x07' char
// string terminator aka st '\\' char
format!("\x1b]{}", code_string)
format!("\x1b]{code_string}")
} else if param_is_valid_string {
// parse hex colors like #00FF00
if code_string.starts_with('#') {
@ -700,7 +700,7 @@ Format: #
Err(err) => {
return Err(ShellError::GenericError(
"error parsing hex color".to_string(),
format!("{}", err),
format!("{err}"),
Some(code.span()?),
None,
Vec::new(),
@ -738,7 +738,7 @@ Format: #
"attr" => nu_style.attr = Some(v.as_string()?),
_ => {
return Err(ShellError::IncompatibleParametersSingle(
format!("problem with key: {}", k),
format!("problem with key: {k}"),
code.expect_span(),
))
}

View File

@ -146,7 +146,7 @@ fn process_value(value: &Value, text: &Option<String>, command_span: &Span) -> V
}
fn add_osc_link(text: &str, link: &str) -> String {
format!("\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\", link, text)
format!("\u{1b}]8;;{link}\u{1b}\\{text}\u{1b}]8;;\u{1b}\\")
}
#[cfg(test)]

View File

@ -57,7 +57,7 @@ impl Command for Input {
let _ = crossterm::terminal::enable_raw_mode();
if let Some(prompt) = prompt {
print!("{}", prompt);
print!("{prompt}");
let _ = std::io::stdout().flush();
}
if let Some(c) = bytes_until.bytes().next() {
@ -92,7 +92,7 @@ impl Command for Input {
}
} else {
if let Some(prompt) = prompt {
print!("{}", prompt);
print!("{prompt}");
let _ = std::io::stdout().flush();
}

View File

@ -113,10 +113,10 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
"flags".into(),
],
vals: vec![
Value::string(format!("{}", c), Span::unknown()),
Value::string(format!("{c}"), Span::unknown()),
Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()),
Value::string(format!("{:?}", modifiers), Span::unknown()),
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
Value::string(format!("{modifiers:?}"), Span::unknown()),
Value::string(format!("{modifiers:#08b}"), Span::unknown()),
],
span: Span::unknown(),
};
@ -126,9 +126,9 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
let record = Value::Record {
cols: vec!["code".into(), "modifier".into(), "flags".into()],
vals: vec![
Value::string(format!("{:?}", code), Span::unknown()),
Value::string(format!("{:?}", modifiers), Span::unknown()),
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
Value::string(format!("{code:?}"), Span::unknown()),
Value::string(format!("{modifiers:?}"), Span::unknown()),
Value::string(format!("{modifiers:#08b}"), Span::unknown()),
],
span: Span::unknown(),
};
@ -138,7 +138,7 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
} else {
let record = Value::Record {
cols: vec!["event".into()],
vals: vec![Value::string(format!("{:?}", event), Span::unknown())],
vals: vec![Value::string(format!("{event:?}"), Span::unknown())],
span: Span::unknown(),
};
Ok(record)