From ca94e9aa26f0a06fd750281756eba180a4ff6167 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 28 Dec 2022 20:56:43 -0500 Subject: [PATCH] Warn the user when max iteration count is reached (#1433) --- Cargo.toml | 6 ++++++ src/linter.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67b58b9a90..9461ecf495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,14 @@ members = [ [package] name = "ruff" version = "0.0.198" +authors = ["Charlie Marsh "] edition = "2021" rust-version = "1.65.0" +documentation = "https://github.com/charliermarsh/ruff" +homepage = "https://github.com/charliermarsh/ruff" +repository = "https://github.com/charliermarsh/ruff" +readme = "README.md" +license = "MIT" [lib] name = "ruff" diff --git a/src/linter.rs b/src/linter.rs index 46bcc30c84..9867434969 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -5,6 +5,7 @@ use std::ops::AddAssign; use std::path::Path; use anyhow::Result; +use colored::Colorize; use log::debug; use rustpython_parser::lexer::LexResult; use similar::TextDiff; @@ -27,6 +28,9 @@ use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; use crate::{cache, directives, fs, rustpython_helpers}; +const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME"); +const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY"); + #[derive(Debug, Default)] pub struct Diagnostics { pub messages: Vec, @@ -462,8 +466,8 @@ fn lint_fix( )?; // Apply autofix. - if iterations < MAX_ITERATIONS { - if let Some((fixed_contents, applied)) = fix_file(&checks, &locator) { + if let Some((fixed_contents, applied)) = fix_file(&checks, &locator) { + if iterations < MAX_ITERATIONS { // Count the number of fixed errors. fixed += applied; @@ -476,6 +480,24 @@ fn lint_fix( // Re-run the linter pass (by avoiding the break). continue; } + + eprintln!( + " +{}: Failed to converge after {} iterations. + +This likely indicates a bug in `{}`. If you could open an issue at: + +{}/issues + +quoting the contents of `{}`, along with the `pyproject.toml` settings and executed command, we'd \ + be very appreciative! +", + "warning".yellow().bold(), + MAX_ITERATIONS, + CARGO_PKG_NAME, + CARGO_PKG_REPOSITORY, + fs::relativize_path(path), + ); } // Convert to messages.