From a129181407bfc7fa82ea4c212ce83c623a912d95 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Fri, 10 Feb 2023 01:36:31 +0100 Subject: [PATCH] feat(cli): let --statistics show fixable codes (#2659) --- crates/ruff_cli/src/printer.rs | 25 ++++++++++++++++++++--- crates/ruff_cli/tests/integration_test.rs | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/ruff_cli/src/printer.rs b/crates/ruff_cli/src/printer.rs index b6841b239e..eb36850463 100644 --- a/crates/ruff_cli/src/printer.rs +++ b/crates/ruff_cli/src/printer.rs @@ -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::>(); @@ -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{:count_width$}\t{: Result<()> { .lines() .last() .unwrap(), - "1\tF401\t`sys` imported but unused" + "1\tF401\t[*] `sys` imported but unused" ); Ok(()) }