mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:05:47 +02:00
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:
committed by
GitHub
parent
6ae497eedc
commit
ab480856a5
@ -34,7 +34,7 @@ impl CellPath {
|
||||
}
|
||||
match elem {
|
||||
PathMember::Int { val, .. } => {
|
||||
let _ = write!(output, "{}", val);
|
||||
let _ = write!(output, "{val}");
|
||||
}
|
||||
PathMember::String { val, .. } => output.push_str(val),
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ impl EngineState {
|
||||
|| file_name.contains('"')
|
||||
|| file_name.contains(' ')
|
||||
{
|
||||
file_name = format!("`{}`", file_name);
|
||||
file_name = format!("`{file_name}`");
|
||||
}
|
||||
|
||||
serde_json::to_string_pretty(&decl.signature())
|
||||
@ -499,7 +499,7 @@ impl EngineState {
|
||||
// Each signature is stored in the plugin file with the shell and signature
|
||||
// This information will be used when loading the plugin
|
||||
// information when nushell starts
|
||||
format!("register {} {} {}\n\n", file_name, shell_str, signature)
|
||||
format!("register {file_name} {shell_str} {signature}\n\n")
|
||||
})
|
||||
.map_err(|err| ShellError::PluginFailedToLoad(err.to_string()))
|
||||
.and_then(|line| {
|
||||
@ -511,7 +511,7 @@ impl EngineState {
|
||||
plugin_file.flush().map_err(|err| {
|
||||
ShellError::GenericError(
|
||||
"Error flushing plugin file".to_string(),
|
||||
format! {"{}", err},
|
||||
format! {"{err}"},
|
||||
None,
|
||||
None,
|
||||
Vec::new(),
|
||||
@ -567,7 +567,7 @@ impl EngineState {
|
||||
pub fn print_contents(&self) {
|
||||
for (contents, _, _) in self.file_contents.iter() {
|
||||
let string = String::from_utf8_lossy(contents);
|
||||
println!("{}", string);
|
||||
println!("{string}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -944,7 +944,7 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
|
||||
impl From<std::io::Error> for ShellError {
|
||||
fn from(input: std::io::Error) -> ShellError {
|
||||
ShellError::IOError(format!("{:?}", input))
|
||||
ShellError::IOError(format!("{input:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -956,7 +956,7 @@ impl std::convert::From<Box<dyn std::error::Error>> for ShellError {
|
||||
|
||||
impl From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
||||
fn from(input: Box<dyn std::error::Error + Send + Sync>) -> ShellError {
|
||||
ShellError::IOError(format!("{:?}", input))
|
||||
ShellError::IOError(format!("{input:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1046,8 +1046,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
suggestion.as_deref(),
|
||||
expected_suggestion,
|
||||
"Expected the following reasoning to hold but it did not: '{}'",
|
||||
discussion
|
||||
"Expected the following reasoning to hold but it did not: '{discussion}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl std::fmt::Display for Category {
|
||||
Category::Bits => "bits",
|
||||
};
|
||||
|
||||
write!(f, "{}", msg)
|
||||
write!(f, "{msg}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,7 @@ impl Span {
|
||||
pub fn new(start: usize, end: usize) -> Span {
|
||||
debug_assert!(
|
||||
end >= start,
|
||||
"Can't create a Span whose end < start, start={}, end={}",
|
||||
start,
|
||||
end
|
||||
"Can't create a Span whose end < start, start={start}, end={end}"
|
||||
);
|
||||
|
||||
Span { start, end }
|
||||
|
@ -178,14 +178,14 @@ impl Display for SyntaxShape {
|
||||
if let Some(args) = args {
|
||||
let arg_vec: Vec<_> = args.iter().map(|x| x.to_string()).collect();
|
||||
let arg_string = arg_vec.join(", ");
|
||||
write!(f, "closure({})", arg_string)
|
||||
write!(f, "closure({arg_string})")
|
||||
} else {
|
||||
write!(f, "closure()")
|
||||
}
|
||||
}
|
||||
SyntaxShape::Binary => write!(f, "binary"),
|
||||
SyntaxShape::Table => write!(f, "table"),
|
||||
SyntaxShape::List(x) => write!(f, "list<{}>", x),
|
||||
SyntaxShape::List(x) => write!(f, "list<{x}>"),
|
||||
SyntaxShape::Record => write!(f, "record"),
|
||||
SyntaxShape::Filesize => write!(f, "filesize"),
|
||||
SyntaxShape::Duration => write!(f, "duration"),
|
||||
@ -199,11 +199,11 @@ impl Display for SyntaxShape {
|
||||
SyntaxShape::Expression => write!(f, "expression"),
|
||||
SyntaxShape::Boolean => write!(f, "bool"),
|
||||
SyntaxShape::Error => write!(f, "error"),
|
||||
SyntaxShape::Custom(x, _) => write!(f, "custom<{}>", x),
|
||||
SyntaxShape::Custom(x, _) => write!(f, "custom<{x}>"),
|
||||
SyntaxShape::OneOf(list) => {
|
||||
let arg_vec: Vec<_> = list.iter().map(|x| x.to_string()).collect();
|
||||
let arg_string = arg_vec.join(", ");
|
||||
write!(f, "one_of({})", arg_string)
|
||||
write!(f, "one_of({arg_string})")
|
||||
}
|
||||
SyntaxShape::Nothing => write!(f, "nothing"),
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ impl Display for Type {
|
||||
"record<{}>",
|
||||
fields
|
||||
.iter()
|
||||
.map(|(x, y)| format!("{}: {}", x, y))
|
||||
.map(|(x, y)| format!("{x}: {y}"))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", "),
|
||||
)
|
||||
@ -131,13 +131,13 @@ impl Display for Type {
|
||||
"table<{}>",
|
||||
columns
|
||||
.iter()
|
||||
.map(|(x, y)| format!("{}: {}", x, y))
|
||||
.map(|(x, y)| format!("{x}: {y}"))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
}
|
||||
Type::List(l) => write!(f, "list<{}>", l),
|
||||
Type::List(l) => write!(f, "list<{l}>"),
|
||||
Type::Nothing => write!(f, "nothing"),
|
||||
Type::Number => write!(f, "number"),
|
||||
Type::String => write!(f, "string"),
|
||||
@ -145,7 +145,7 @@ impl Display for Type {
|
||||
Type::Any => write!(f, "any"),
|
||||
Type::Error => write!(f, "error"),
|
||||
Type::Binary => write!(f, "binary"),
|
||||
Type::Custom(custom) => write!(f, "{}", custom),
|
||||
Type::Custom(custom) => write!(f, "{custom}"),
|
||||
Type::Signature => write!(f, "signature"),
|
||||
}
|
||||
}
|
||||
|
@ -538,11 +538,11 @@ impl Value {
|
||||
};
|
||||
collected.into_string(separator, config)
|
||||
}
|
||||
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(),
|
||||
}
|
||||
@ -584,13 +584,13 @@ impl Value {
|
||||
),
|
||||
Value::LazyRecord { val, .. } => match val.collect() {
|
||||
Ok(val) => val.into_abbreviated_string(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(),
|
||||
}
|
||||
@ -598,7 +598,7 @@ impl Value {
|
||||
|
||||
/// Convert Value into a debug string
|
||||
pub fn debug_value(&self) -> String {
|
||||
format!("{:#?}", self)
|
||||
format!("{self:#?}")
|
||||
}
|
||||
|
||||
/// Convert Value into string. Note that Streams will be consumed.
|
||||
@ -609,7 +609,7 @@ impl Value {
|
||||
Value::Float { val, .. } => val.to_string(),
|
||||
Value::Filesize { val, .. } => format_filesize_from_conf(*val, config),
|
||||
Value::Duration { val, .. } => format_duration(*val),
|
||||
Value::Date { val, .. } => format!("{:?}", val),
|
||||
Value::Date { val, .. } => format!("{val:?}"),
|
||||
Value::Range { val, .. } => {
|
||||
format!(
|
||||
"{}..{}",
|
||||
@ -635,13 +635,13 @@ impl Value {
|
||||
),
|
||||
Value::LazyRecord { val, .. } => match val.collect() {
|
||||
Ok(val) => val.debug_string(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(),
|
||||
}
|
||||
@ -3266,16 +3266,16 @@ pub enum TimePeriod {
|
||||
impl TimePeriod {
|
||||
pub fn to_text(self) -> Cow<'static, str> {
|
||||
match self {
|
||||
Self::Nanos(n) => format!("{} ns", n).into(),
|
||||
Self::Micros(n) => format!("{} µs", n).into(),
|
||||
Self::Millis(n) => format!("{} ms", n).into(),
|
||||
Self::Seconds(n) => format!("{} sec", n).into(),
|
||||
Self::Minutes(n) => format!("{} min", n).into(),
|
||||
Self::Hours(n) => format!("{} hr", n).into(),
|
||||
Self::Days(n) => format!("{} day", n).into(),
|
||||
Self::Weeks(n) => format!("{} wk", n).into(),
|
||||
Self::Months(n) => format!("{} month", n).into(),
|
||||
Self::Years(n) => format!("{} yr", n).into(),
|
||||
Self::Nanos(n) => format!("{n} ns").into(),
|
||||
Self::Micros(n) => format!("{n} µs").into(),
|
||||
Self::Millis(n) => format!("{n} ms").into(),
|
||||
Self::Seconds(n) => format!("{n} sec").into(),
|
||||
Self::Minutes(n) => format!("{n} min").into(),
|
||||
Self::Hours(n) => format!("{n} hr").into(),
|
||||
Self::Days(n) => format!("{n} day").into(),
|
||||
Self::Weeks(n) => format!("{n} wk").into(),
|
||||
Self::Months(n) => format!("{n} month").into(),
|
||||
Self::Years(n) => format!("{n} yr").into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3489,13 +3489,13 @@ pub fn format_filesize(
|
||||
let locale_byte = adj_byte.get_value() as u64;
|
||||
let locale_byte_string = locale_byte.to_formatted_string(&locale);
|
||||
let locale_signed_byte_string = if num_bytes.is_negative() {
|
||||
format!("-{}", locale_byte_string)
|
||||
format!("-{locale_byte_string}")
|
||||
} else {
|
||||
locale_byte_string
|
||||
};
|
||||
|
||||
if filesize_format_var.1 == "auto" {
|
||||
format!("{} B", locale_signed_byte_string)
|
||||
format!("{locale_signed_byte_string} B")
|
||||
} else {
|
||||
locale_signed_byte_string
|
||||
}
|
||||
|
Reference in New Issue
Block a user