refactor: Use format! keyword arguments

This commit is contained in:
Martin Fischer 2023-02-10 09:45:01 +01:00 committed by Charlie Marsh
parent 6f16f1c39b
commit c32441e4ab

View file

@ -499,20 +499,18 @@ fn num_digits(n: usize) -> usize {
/// Print a single `Message` with full details. /// Print a single `Message` with full details.
fn print_message<T: Write>(stdout: &mut T, message: &Message) -> Result<()> { fn print_message<T: Write>(stdout: &mut T, message: &Message) -> Result<()> {
let label = format!( let label = format!(
"{}{}{}{}{}{} {} {}{}", "{path}{sep}{row}{sep}{col}{sep} {code} {autofix}{body}",
relativize_path(Path::new(&message.filename)).bold(), path = relativize_path(Path::new(&message.filename)).bold(),
":".cyan(), sep = ":".cyan(),
message.location.row(), row = message.location.row(),
":".cyan(), col = message.location.column(),
message.location.column(), code = message.kind.rule().code().red().bold(),
":".cyan(), autofix = message
message.kind.rule().code().red().bold(),
message
.kind .kind
.fixable() .fixable()
.then_some(format_args!("[{}] ", "*".cyan())) .then_some(format_args!("[{}] ", "*".cyan()))
.unwrap_or(format_args!("")), .unwrap_or(format_args!("")),
message.kind.body(), body = message.kind.body(),
); );
writeln!(stdout, "{label}")?; writeln!(stdout, "{label}")?;
if let Some(source) = &message.source { if let Some(source) = &message.source {
@ -569,19 +567,19 @@ fn print_grouped_message<T: Write>(
column_length: usize, column_length: usize,
) -> Result<()> { ) -> Result<()> {
let label = format!( let label = format!(
" {}{}{}{}{} {} {}{}", " {row_padding}{row}{sep}{col}{col_padding} {code} {autofix}{body}",
" ".repeat(row_length - num_digits(message.location.row())), row_padding = " ".repeat(row_length - num_digits(message.location.row())),
message.location.row(), row = message.location.row(),
":".cyan(), sep = ":".cyan(),
message.location.column(), col = message.location.column(),
" ".repeat(column_length - num_digits(message.location.column())), col_padding = " ".repeat(column_length - num_digits(message.location.column())),
message.kind.rule().code().red().bold(), code = message.kind.rule().code().red().bold(),
message autofix = message
.kind .kind
.fixable() .fixable()
.then_some(format_args!("[{}] ", "*".cyan())) .then_some(format_args!("[{}] ", "*".cyan()))
.unwrap_or(format_args!("")), .unwrap_or(format_args!("")),
message.kind.body(), body = message.kind.body(),
); );
writeln!(stdout, "{label}")?; writeln!(stdout, "{label}")?;
if let Some(source) = &message.source { if let Some(source) = &message.source {