mirror of https://github.com/astral-sh/ruff
Mark fixable issues in printer output (#2500)
This commit is contained in:
parent
b9c1a3c5c1
commit
b2be30cb07
|
|
@ -122,7 +122,7 @@ impl<'a> Printer<'a> {
|
|||
if num_fixable > 0 {
|
||||
writeln!(
|
||||
stdout,
|
||||
"{num_fixable} potentially fixable with the --fix option."
|
||||
"[*] {num_fixable} potentially fixable with the --fix option."
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
|
@ -475,7 +475,20 @@ fn num_digits(n: usize) -> usize {
|
|||
|
||||
/// Print a single `Message` with full details.
|
||||
fn print_message<T: Write>(stdout: &mut T, message: &Message) -> Result<()> {
|
||||
let label = format!(
|
||||
let label = if message.kind.fixable() {
|
||||
format!(
|
||||
"{}{}{}{}{}{} {} [*] {}",
|
||||
relativize_path(Path::new(&message.filename)).bold(),
|
||||
":".cyan(),
|
||||
message.location.row(),
|
||||
":".cyan(),
|
||||
message.location.column(),
|
||||
":".cyan(),
|
||||
message.kind.rule().code().red().bold(),
|
||||
message.kind.body(),
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{}{}{}{}{}{} {} {}",
|
||||
relativize_path(Path::new(&message.filename)).bold(),
|
||||
":".cyan(),
|
||||
|
|
@ -485,7 +498,8 @@ fn print_message<T: Write>(stdout: &mut T, message: &Message) -> Result<()> {
|
|||
":".cyan(),
|
||||
message.kind.rule().code().red().bold(),
|
||||
message.kind.body(),
|
||||
);
|
||||
)
|
||||
};
|
||||
writeln!(stdout, "{label}")?;
|
||||
if let Some(source) = &message.source {
|
||||
let commit = message.kind.commit();
|
||||
|
|
@ -540,7 +554,19 @@ fn print_grouped_message<T: Write>(
|
|||
row_length: usize,
|
||||
column_length: usize,
|
||||
) -> Result<()> {
|
||||
let label = format!(
|
||||
let label = if message.kind.fixable() {
|
||||
format!(
|
||||
" {}{}{}{}{} {} [*] {}",
|
||||
" ".repeat(row_length - num_digits(message.location.row())),
|
||||
message.location.row(),
|
||||
":".cyan(),
|
||||
message.location.column(),
|
||||
" ".repeat(column_length - num_digits(message.location.column())),
|
||||
message.kind.rule().code().red().bold(),
|
||||
message.kind.body(),
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
" {}{}{}{}{} {} {}",
|
||||
" ".repeat(row_length - num_digits(message.location.row())),
|
||||
message.location.row(),
|
||||
|
|
@ -549,7 +575,8 @@ fn print_grouped_message<T: Write>(
|
|||
" ".repeat(column_length - num_digits(message.location.column())),
|
||||
message.kind.rule().code().red().bold(),
|
||||
message.kind.body(),
|
||||
);
|
||||
)
|
||||
};
|
||||
writeln!(stdout, "{label}")?;
|
||||
if let Some(source) = &message.source {
|
||||
let commit = message.kind.commit();
|
||||
|
|
|
|||
|
|
@ -31,8 +31,10 @@ fn test_stdin_error() -> Result<()> {
|
|||
.failure();
|
||||
assert_eq!(
|
||||
str::from_utf8(&output.get_output().stdout)?,
|
||||
"-:1:8: F401 `os` imported but unused\nFound 1 error.\n1 potentially fixable with the \
|
||||
--fix option.\n"
|
||||
r#"-:1:8: F401 [*] `os` imported but unused
|
||||
Found 1 error.
|
||||
[*] 1 potentially fixable with the --fix option.
|
||||
"#
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -54,8 +56,10 @@ fn test_stdin_filename() -> Result<()> {
|
|||
.failure();
|
||||
assert_eq!(
|
||||
str::from_utf8(&output.get_output().stdout)?,
|
||||
"F401.py:1:8: F401 `os` imported but unused\nFound 1 error.\n1 potentially fixable with \
|
||||
the --fix option.\n"
|
||||
r#"F401.py:1:8: F401 [*] `os` imported but unused
|
||||
Found 1 error.
|
||||
[*] 1 potentially fixable with the --fix option.
|
||||
"#
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue