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

@ -17,7 +17,7 @@ fn from_delimited_string_to_value(
let headers = if noheaders {
(1..=reader.headers()?.len())
.map(|i| format!("column{}", i))
.map(|i| format!("column{i}"))
.collect::<Vec<String>>()
} else {
reader.headers()?.iter().map(String::from).collect()

View File

@ -113,7 +113,7 @@ fn from_ics(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
Ok(c) => output.push(calendar_to_value(c, head)),
Err(e) => output.push(Value::Error {
error: ShellError::UnsupportedInput(
format!("input cannot be parsed as .ics ({})", e),
format!("input cannot be parsed as .ics ({e})"),
"value originates from here".into(),
head,
span,

View File

@ -77,7 +77,7 @@ pub fn from_ini_string_to_value(
Ok(Value::Record { cols, vals, span })
}
Err(err) => Err(ShellError::UnsupportedInput(
format!("Could not load ini: {}", err),
format!("Could not load ini: {err}"),
"value originates from here".into(),
span,
val_span,

View File

@ -183,7 +183,7 @@ fn convert_string_to_value(string_input: String, span: Span) -> Result<Value, Sh
))
}
x => Err(ShellError::CantConvert(
format!("structured json data ({})", x),
format!("structured json data ({x})"),
"string".into(),
span,
None,

View File

@ -149,7 +149,7 @@ fn from_ods(
_ => Value::nothing(head),
};
row_output.insert(format!("column{}", i), value);
row_output.insert(format!("column{i}"), value);
}
let (cols, vals) =

View File

@ -197,7 +197,7 @@ fn parse_separated_columns<'a>(
let num_columns = ls.iter().map(|r| r.len()).max().unwrap_or(0);
let headers = (1..=num_columns)
.map(|i| format!("column{}", i))
.map(|i| format!("column{i}"))
.collect::<Vec<String>>();
collect(headers, ls.into_iter(), separator)
};

View File

@ -123,7 +123,7 @@ fn from_vcf(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
Ok(c) => contact_to_value(c, head),
Err(e) => Value::Error {
error: ShellError::UnsupportedInput(
format!("input cannot be parsed as .vcf ({})", e),
format!("input cannot be parsed as .vcf ({e})"),
"value originates from here".into(),
head,
span,

View File

@ -148,7 +148,7 @@ fn from_xlsx(
_ => Value::nothing(head),
};
row_output.insert(format!("column{}", i), value);
row_output.insert(format!("column{i}"), value);
}
let (cols, vals) =

View File

@ -120,7 +120,7 @@ fn convert_yaml_value_to_nu_value(
for (k, v) in t {
// A ShellError that we re-use multiple times in the Mapping scenario
let err_unexpected_map = ShellError::UnsupportedInput(
format!("Unexpected YAML:\nKey: {:?}\nValue: {:?}", k, v),
format!("Unexpected YAML:\nKey: {k:?}\nValue: {v:?}"),
"value originates from here".into(),
span,
val_span,
@ -189,7 +189,7 @@ pub fn from_yaml_string_to_value(
for document in serde_yaml::Deserializer::from_str(&s) {
let v: serde_yaml::Value = serde_yaml::Value::deserialize(document).map_err(|x| {
ShellError::UnsupportedInput(
format!("Could not load YAML: {}", x),
format!("Could not load YAML: {x}"),
"value originates from here".into(),
span,
val_span,

View File

@ -55,7 +55,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
Value::Binary { val, .. } => {
let mut s = String::with_capacity(2 * val.len());
for byte in val {
if write!(s, "{:02X}", byte).is_err() {
if write!(s, "{byte:02X}").is_err() {
return Err(ShellError::UnsupportedInput(
"could not convert binary to string".into(),
"value originates from here".into(),
@ -64,7 +64,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
));
}
}
Ok(format!("0x[{}]", s))
Ok(format!("0x[{s}]"))
}
Value::Block { .. } => Err(ShellError::UnsupportedInput(
"blocks are currently not nuon-compatible".into(),
@ -125,7 +125,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
.iter()
.map(|string| {
if needs_quotes(string) {
format!("\"{}\"", string)
format!("\"{string}\"")
} else {
string.to_string()
}

View File

@ -143,13 +143,13 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
.join(separator),
Value::LazyRecord { val, .. } => match val.collect() {
Ok(val) => local_into_string(val, separator, config),
Err(error) => format!("{:?}", error),
Err(error) => format!("{error:?}"),
},
Value::Block { val, .. } => format!("<Block {}>", val),
Value::Closure { val, .. } => format!("<Closure {}>", val),
Value::Block { val, .. } => format!("<Block {val}>"),
Value::Closure { val, .. } => format!("<Closure {val}>"),
Value::Nothing { .. } => String::new(),
Value::Error { error } => format!("{:?}", error),
Value::Binary { val, .. } => format!("{:?}", val),
Value::Error { error } => format!("{error:?}"),
Value::Binary { val, .. } => format!("{val:?}"),
Value::CellPath { val, .. } => val.into_string(),
Value::CustomValue { val, .. } => val.value_string(),
}