mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Add space when joining rule codes for debug messages (#4225)
This commit is contained in:
parent
6db1a32eb9
commit
494e807315
1 changed files with 18 additions and 26 deletions
|
@ -4,6 +4,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use itertools::Itertools;
|
||||||
use log::error;
|
use log::error;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use rustpython_parser::lexer::LexResult;
|
use rustpython_parser::lexer::LexResult;
|
||||||
|
@ -457,7 +458,7 @@ pub fn lint_fix<'a>(
|
||||||
path,
|
path,
|
||||||
&transformed,
|
&transformed,
|
||||||
&result.error.unwrap(),
|
&result.error.unwrap(),
|
||||||
fixed.keys(),
|
fixed.keys().copied(),
|
||||||
);
|
);
|
||||||
return Err(anyhow!("Autofix introduced a syntax error"));
|
return Err(anyhow!("Autofix introduced a syntax error"));
|
||||||
}
|
}
|
||||||
|
@ -497,23 +498,21 @@ pub fn lint_fix<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_rule_codes(diagnostics: &[Diagnostic]) -> String {
|
fn collect_rule_codes(rules: impl IntoIterator<Item = Rule>) -> String {
|
||||||
let mut codes: Vec<String> = diagnostics
|
rules
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|diagnostic| diagnostic.kind.rule().noqa_code().to_string())
|
.map(|rule| rule.noqa_code().to_string())
|
||||||
.collect();
|
.sorted_unstable()
|
||||||
codes.sort();
|
.dedup()
|
||||||
codes.dedup();
|
.join(", ")
|
||||||
codes.join(",")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::print_stderr)]
|
#[allow(clippy::print_stderr)]
|
||||||
fn report_failed_to_converge_error(path: &Path, transformed: &str, diagnostics: &[Diagnostic]) {
|
fn report_failed_to_converge_error(path: &Path, transformed: &str, diagnostics: &[Diagnostic]) {
|
||||||
let codes = collect_rule_codes(diagnostics);
|
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
|
let codes = collect_rule_codes(diagnostics.iter().map(|diagnostic| diagnostic.kind.rule()));
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}: Failed to converge after {} iterations in `{}`, rule codes {}:---\n{}\n---",
|
"{}: Failed to converge after {} iterations in `{}` with rule codes {}:---\n{}\n---",
|
||||||
"debug error".red().bold(),
|
"debug error".red().bold(),
|
||||||
MAX_ITERATIONS,
|
MAX_ITERATIONS,
|
||||||
fs::relativize_path(path),
|
fs::relativize_path(path),
|
||||||
|
@ -529,37 +528,31 @@ This indicates a bug in `{}`. If you could open an issue at:
|
||||||
|
|
||||||
{}/issues/new?title=%5BInfinite%20loop%5D
|
{}/issues/new?title=%5BInfinite%20loop%5D
|
||||||
|
|
||||||
...quoting the contents of `{}`, the rule codes {}, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
|
...quoting the contents of `{}`, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
|
||||||
"#,
|
"#,
|
||||||
"error".red().bold(),
|
"error".red().bold(),
|
||||||
MAX_ITERATIONS,
|
MAX_ITERATIONS,
|
||||||
CARGO_PKG_NAME,
|
CARGO_PKG_NAME,
|
||||||
CARGO_PKG_REPOSITORY,
|
CARGO_PKG_REPOSITORY,
|
||||||
fs::relativize_path(path),
|
fs::relativize_path(path),
|
||||||
codes
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::print_stderr)]
|
#[allow(clippy::print_stderr)]
|
||||||
fn report_autofix_syntax_error<'a>(
|
fn report_autofix_syntax_error(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
transformed: &str,
|
transformed: &str,
|
||||||
error: &ParseError,
|
error: &ParseError,
|
||||||
rules: impl IntoIterator<Item = &'a Rule>,
|
rules: impl IntoIterator<Item = Rule>,
|
||||||
) {
|
) {
|
||||||
let mut codes: Vec<String> = rules
|
|
||||||
.into_iter()
|
|
||||||
.map(|rule| rule.noqa_code().to_string())
|
|
||||||
.collect();
|
|
||||||
codes.sort();
|
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
|
let codes = collect_rule_codes(rules);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}: Autofix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---",
|
"{}: Autofix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---",
|
||||||
"debug error".red().bold(),
|
"error".red().bold(),
|
||||||
fs::relativize_path(path),
|
fs::relativize_path(path),
|
||||||
codes.join(","),
|
codes,
|
||||||
error,
|
error,
|
||||||
transformed,
|
transformed,
|
||||||
);
|
);
|
||||||
|
@ -572,13 +565,12 @@ This indicates a bug in `{}`. If you could open an issue at:
|
||||||
|
|
||||||
{}/issues/new?title=%5BAutofix%20error%5D
|
{}/issues/new?title=%5BAutofix%20error%5D
|
||||||
|
|
||||||
...quoting the contents of `{}`, the rule codes {}, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
|
...quoting the contents of `{}`, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
|
||||||
"#,
|
"#,
|
||||||
"error".red().bold(),
|
"error".red().bold(),
|
||||||
CARGO_PKG_NAME,
|
CARGO_PKG_NAME,
|
||||||
CARGO_PKG_REPOSITORY,
|
CARGO_PKG_REPOSITORY,
|
||||||
fs::relativize_path(path),
|
fs::relativize_path(path),
|
||||||
codes.join(","),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue