mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:48:22 +00:00
Improve --explain output
Previous output for `ruff --explain E711`: E711 (pycodestyle): Comparison to `None` should be `cond is None` New output: none-comparison Code: E711 (pycodestyle) Autofix is always available. Message formats: * Comparison to `None` should be `cond is None` * Comparison to `None` should be `cond is not None`
This commit is contained in:
parent
ec0c7647ab
commit
6acf2accc6
1 changed files with 17 additions and 7 deletions
|
@ -19,7 +19,7 @@ use ruff::registry::Rule;
|
|||
use ruff::resolver::{FileDiscovery, PyprojectDiscovery};
|
||||
use ruff::settings::flags;
|
||||
use ruff::settings::types::SerializationFormat;
|
||||
use ruff::{fix, fs, packaging, resolver, warn_user_once, IOError};
|
||||
use ruff::{fix, fs, packaging, resolver, warn_user_once, AutofixAvailability, IOError};
|
||||
use serde::Serialize;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
|
@ -293,12 +293,22 @@ struct Explanation<'a> {
|
|||
pub fn explain(rule: &Rule, format: SerializationFormat) -> Result<()> {
|
||||
match format {
|
||||
SerializationFormat::Text | SerializationFormat::Grouped => {
|
||||
println!(
|
||||
"{} ({}): {}",
|
||||
rule.code(),
|
||||
rule.origin().name(),
|
||||
rule.message_formats()[0]
|
||||
);
|
||||
println!("{}\n", rule.as_ref());
|
||||
println!("Code: {} ({})\n", rule.code(), rule.origin().name());
|
||||
|
||||
if let Some(autofix) = rule.autofixable() {
|
||||
println!(
|
||||
"{}",
|
||||
match autofix.available {
|
||||
AutofixAvailability::Sometimes => "Autofix is sometimes available.\n",
|
||||
AutofixAvailability::Always => "Autofix is always available.\n",
|
||||
}
|
||||
);
|
||||
}
|
||||
println!("Message formats:\n");
|
||||
for format in rule.message_formats() {
|
||||
println!("* {format}");
|
||||
}
|
||||
}
|
||||
SerializationFormat::Json => {
|
||||
println!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue