mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
feat(cli): let --statistics show fixable codes (#2659)
This commit is contained in:
parent
fc628de667
commit
a129181407
2 changed files with 23 additions and 4 deletions
|
@ -48,6 +48,7 @@ struct ExpandedStatistics<'a> {
|
|||
count: usize,
|
||||
code: &'a str,
|
||||
message: String,
|
||||
fixable: bool,
|
||||
}
|
||||
|
||||
struct SerializeRuleAsCode<'a>(&'a Rule);
|
||||
|
@ -371,6 +372,12 @@ impl<'a> Printer<'a> {
|
|||
.find(|message| message.kind.rule() == *rule)
|
||||
.map(|message| message.kind.body())
|
||||
.unwrap(),
|
||||
fixable: diagnostics
|
||||
.messages
|
||||
.iter()
|
||||
.find(|message| message.kind.rule() == *rule)
|
||||
.iter()
|
||||
.any(|message| message.kind.fixable()),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -391,13 +398,25 @@ impl<'a> Printer<'a> {
|
|||
.map(|statistic| statistic.code.len())
|
||||
.max()
|
||||
.unwrap();
|
||||
let any_fixable = statistics.iter().any(|statistic| statistic.fixable);
|
||||
|
||||
// By default, we mimic Flake8's `--statistics` format.
|
||||
for msg in statistics {
|
||||
for statistic in statistics {
|
||||
writeln!(
|
||||
stdout,
|
||||
"{:>count_width$}\t{:<code_width$}\t{}",
|
||||
msg.count, msg.code, msg.message
|
||||
"{:>count_width$}\t{:<code_width$}\t{}{}",
|
||||
statistic.count,
|
||||
statistic.code,
|
||||
if any_fixable {
|
||||
if statistic.fixable {
|
||||
"[*] "
|
||||
} else {
|
||||
"[ ] "
|
||||
}
|
||||
} else {
|
||||
""
|
||||
},
|
||||
statistic.message,
|
||||
)?;
|
||||
}
|
||||
return Ok(());
|
||||
|
|
|
@ -200,7 +200,7 @@ fn show_statistics() -> Result<()> {
|
|||
.lines()
|
||||
.last()
|
||||
.unwrap(),
|
||||
"1\tF401\t`sys` imported but unused"
|
||||
"1\tF401\t[*] `sys` imported but unused"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue