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 {
|
if num_fixable > 0 {
|
||||||
writeln!(
|
writeln!(
|
||||||
stdout,
|
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.
|
/// 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 = 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(),
|
relativize_path(Path::new(&message.filename)).bold(),
|
||||||
":".cyan(),
|
":".cyan(),
|
||||||
|
|
@ -485,7 +498,8 @@ fn print_message<T: Write>(stdout: &mut T, message: &Message) -> Result<()> {
|
||||||
":".cyan(),
|
":".cyan(),
|
||||||
message.kind.rule().code().red().bold(),
|
message.kind.rule().code().red().bold(),
|
||||||
message.kind.body(),
|
message.kind.body(),
|
||||||
);
|
)
|
||||||
|
};
|
||||||
writeln!(stdout, "{label}")?;
|
writeln!(stdout, "{label}")?;
|
||||||
if let Some(source) = &message.source {
|
if let Some(source) = &message.source {
|
||||||
let commit = message.kind.commit();
|
let commit = message.kind.commit();
|
||||||
|
|
@ -540,7 +554,19 @@ fn print_grouped_message<T: Write>(
|
||||||
row_length: usize,
|
row_length: usize,
|
||||||
column_length: usize,
|
column_length: usize,
|
||||||
) -> Result<()> {
|
) -> 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())),
|
" ".repeat(row_length - num_digits(message.location.row())),
|
||||||
message.location.row(),
|
message.location.row(),
|
||||||
|
|
@ -549,7 +575,8 @@ fn print_grouped_message<T: Write>(
|
||||||
" ".repeat(column_length - num_digits(message.location.column())),
|
" ".repeat(column_length - num_digits(message.location.column())),
|
||||||
message.kind.rule().code().red().bold(),
|
message.kind.rule().code().red().bold(),
|
||||||
message.kind.body(),
|
message.kind.body(),
|
||||||
);
|
)
|
||||||
|
};
|
||||||
writeln!(stdout, "{label}")?;
|
writeln!(stdout, "{label}")?;
|
||||||
if let Some(source) = &message.source {
|
if let Some(source) = &message.source {
|
||||||
let commit = message.kind.commit();
|
let commit = message.kind.commit();
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,10 @@ fn test_stdin_error() -> Result<()> {
|
||||||
.failure();
|
.failure();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
str::from_utf8(&output.get_output().stdout)?,
|
str::from_utf8(&output.get_output().stdout)?,
|
||||||
"-:1:8: F401 `os` imported but unused\nFound 1 error.\n1 potentially fixable with the \
|
r#"-:1:8: F401 [*] `os` imported but unused
|
||||||
--fix option.\n"
|
Found 1 error.
|
||||||
|
[*] 1 potentially fixable with the --fix option.
|
||||||
|
"#
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -54,8 +56,10 @@ fn test_stdin_filename() -> Result<()> {
|
||||||
.failure();
|
.failure();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
str::from_utf8(&output.get_output().stdout)?,
|
str::from_utf8(&output.get_output().stdout)?,
|
||||||
"F401.py:1:8: F401 `os` imported but unused\nFound 1 error.\n1 potentially fixable with \
|
r#"F401.py:1:8: F401 [*] `os` imported but unused
|
||||||
the --fix option.\n"
|
Found 1 error.
|
||||||
|
[*] 1 potentially fixable with the --fix option.
|
||||||
|
"#
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue