From f52691a90a774775dc3bfeec0b1e19e02eef76dc Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 2 Jan 2023 18:12:04 +0100 Subject: [PATCH] Print warning when running debug builds without --no-cache (#1549) --- src/commands.rs | 12 ++++++------ src/main_native.rs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 91877c383a..545839485c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -46,8 +46,8 @@ pub fn run( if paths.is_empty() { one_time_warning!( - "{} {}", - "warning:".yellow().bold(), + "{}: {}", + "warning".yellow().bold(), "No Python files found under the given path(s)" ); return Ok(Diagnostics::default()); @@ -196,8 +196,8 @@ pub fn add_noqa( if paths.is_empty() { one_time_warning!( - "{} {}", - "warning:".yellow().bold(), + "{}: {}", + "warning".yellow().bold(), "No Python files found under the given path(s)" ); return Ok(0); @@ -270,8 +270,8 @@ pub fn show_files( if paths.is_empty() { one_time_warning!( - "{} {}", - "warning:".yellow().bold(), + "{}: {}", + "warning".yellow().bold(), "No Python files found under the given path(s)" ); return Ok(()); diff --git a/src/main_native.rs b/src/main_native.rs index 76126a619e..c7826dbab7 100644 --- a/src/main_native.rs +++ b/src/main_native.rs @@ -29,6 +29,7 @@ use ::ruff::settings::{pyproject, Settings}; use ::ruff::updates; use anyhow::Result; use clap::{CommandFactory, Parser}; +use colored::Colorize; use notify::{recommended_watcher, RecursiveMode, Watcher}; use path_absolutize::path_dedot; @@ -172,13 +173,29 @@ pub(crate) fn inner_main() -> Result { }; let cache = !cli.no_cache; + #[cfg(debug_assertions)] + if cache { + // `--no-cache` doesn't respect code changes, and so is often confusing during + // development. + eprintln!( + "{}: debug build without --no-cache.", + "warning".yellow().bold() + ); + } + let printer = Printer::new(&format, &log_level, &autofix, &violations); if cli.watch { if !matches!(autofix, fixer::Mode::None) { - eprintln!("Warning: --fix is not enabled in watch mode."); + eprintln!( + "{}: --fix is not enabled in watch mode.", + "warning".yellow().bold() + ); } if format != SerializationFormat::Text { - eprintln!("Warning: --format 'text' is used in watch mode."); + eprintln!( + "{}: --format 'text' is used in watch mode.", + "warning".yellow().bold() + ); } // Perform an initial run instantly.