From 3152dd7a8e7f52b202ee3b64e5043d66c46c36cb Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 7 Dec 2022 19:07:51 -0500 Subject: [PATCH] Don't prompt users to --fix if they ran with --fix (#1133) --- src/main.rs | 2 +- src/printer.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index a5fee6b28f..a34084a3c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -392,7 +392,7 @@ fn inner_main() -> Result { // unless we're writing fixes via stdin (in which case, the transformed // source code goes to stdout). if !(is_stdin && matches!(autofix, fixer::Mode::Apply)) { - printer.write_once(&diagnostics)?; + printer.write_once(&diagnostics, &autofix)?; } // Check for updates if we're in a non-silent log level. diff --git a/src/printer.rs b/src/printer.rs index 8bf5bb5256..ce795653c1 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -9,7 +9,7 @@ use itertools::iterate; use rustpython_parser::ast::Location; use serde::Serialize; -use crate::autofix::Fix; +use crate::autofix::{fixer, Fix}; use crate::checks::CheckCode; use crate::fs::relativize_path; use crate::linter::Diagnostics; @@ -57,15 +57,15 @@ impl<'a> Printer<'a> { } } - fn post_text(&self, num_fixable: usize) { + fn post_text(&self, num_fixable: usize, autofix: &fixer::Mode) { if self.log_level >= &LogLevel::Default { - if num_fixable > 0 { + if num_fixable > 0 && !matches!(autofix, fixer::Mode::Apply) { println!("{num_fixable} potentially fixable with the --fix option."); } } } - pub fn write_once(&self, diagnostics: &Diagnostics) -> Result<()> { + pub fn write_once(&self, diagnostics: &Diagnostics, autofix: &fixer::Mode) -> Result<()> { if matches!(self.log_level, LogLevel::Silent) { return Ok(()); } @@ -147,7 +147,7 @@ impl<'a> Printer<'a> { print_message(message); } - self.post_text(num_fixable); + self.post_text(num_fixable, autofix); } SerializationFormat::Grouped => { self.pre_text(diagnostics); @@ -190,7 +190,7 @@ impl<'a> Printer<'a> { println!(); } - self.post_text(num_fixable); + self.post_text(num_fixable, autofix); } SerializationFormat::Github => { self.pre_text(diagnostics);