mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:04:51 +00:00
add show_fix_status and fix_applicability getters on config
since these names were already taken, I moved the setters to `with_*` this allows fetching the values when setting up the GroupedEmitter even though it doesn't use the rest of the rendering infrastructure
This commit is contained in:
parent
2ea823e999
commit
6eeaffd324
4 changed files with 22 additions and 14 deletions
|
@ -229,8 +229,8 @@ impl Printer {
|
|||
.preview(preview)
|
||||
.hide_severity(true)
|
||||
.color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize())
|
||||
.show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||
.fix_applicability(self.unsafe_fixes.required_applicability())
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||
.with_fix_applicability(self.unsafe_fixes.required_applicability())
|
||||
.show_fix_diff(preview);
|
||||
|
||||
match DiagnosticFormat::try_from(self.format) {
|
||||
|
@ -246,8 +246,8 @@ impl Printer {
|
|||
}
|
||||
Err(RuffOutputFormat::Grouped) => {
|
||||
GroupedEmitter::default()
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||
.with_applicability(self.unsafe_fixes.required_applicability())
|
||||
.with_show_fix_status(config.show_fix_status())
|
||||
.with_applicability(config.fix_applicability())
|
||||
.emit(writer, &diagnostics.inner, &context)?;
|
||||
}
|
||||
Err(RuffOutputFormat::Sarif) => {
|
||||
|
@ -418,9 +418,9 @@ impl Printer {
|
|||
let config = DisplayDiagnosticConfig::default()
|
||||
.hide_severity(true)
|
||||
.color(!cfg!(test) && colored::control::SHOULD_COLORIZE.should_colorize())
|
||||
.show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref()))
|
||||
.format(format)
|
||||
.fix_applicability(self.unsafe_fixes.required_applicability());
|
||||
.with_fix_applicability(self.unsafe_fixes.required_applicability());
|
||||
write!(
|
||||
writer,
|
||||
"{}",
|
||||
|
|
|
@ -1353,7 +1353,7 @@ impl DisplayDiagnosticConfig {
|
|||
}
|
||||
|
||||
/// Whether to show a fix's availability or not.
|
||||
pub fn show_fix_status(self, yes: bool) -> DisplayDiagnosticConfig {
|
||||
pub fn with_show_fix_status(self, yes: bool) -> DisplayDiagnosticConfig {
|
||||
DisplayDiagnosticConfig {
|
||||
show_fix_status: yes,
|
||||
..self
|
||||
|
@ -1374,12 +1374,20 @@ impl DisplayDiagnosticConfig {
|
|||
/// availability for unsafe or display-only fixes.
|
||||
///
|
||||
/// Note that this option is currently ignored when `hide_severity` is false.
|
||||
pub fn fix_applicability(self, applicability: Applicability) -> DisplayDiagnosticConfig {
|
||||
pub fn with_fix_applicability(self, applicability: Applicability) -> DisplayDiagnosticConfig {
|
||||
DisplayDiagnosticConfig {
|
||||
fix_applicability: applicability,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_fix_status(&self) -> bool {
|
||||
self.show_fix_status
|
||||
}
|
||||
|
||||
pub fn fix_applicability(&self) -> Applicability {
|
||||
self.fix_applicability
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DisplayDiagnosticConfig {
|
||||
|
|
|
@ -2618,7 +2618,7 @@ watermelon
|
|||
/// Show fix availability when rendering.
|
||||
pub(super) fn show_fix_status(&mut self, yes: bool) {
|
||||
let mut config = std::mem::take(&mut self.config);
|
||||
config = config.show_fix_status(yes);
|
||||
config = config.with_show_fix_status(yes);
|
||||
self.config = config;
|
||||
}
|
||||
|
||||
|
@ -2632,7 +2632,7 @@ watermelon
|
|||
/// The lowest fix applicability to show when rendering.
|
||||
pub(super) fn fix_applicability(&mut self, applicability: Applicability) {
|
||||
let mut config = std::mem::take(&mut self.config);
|
||||
config = config.fix_applicability(applicability);
|
||||
config = config.with_fix_applicability(applicability);
|
||||
self.config = config;
|
||||
}
|
||||
|
||||
|
|
|
@ -449,9 +449,9 @@ pub(crate) fn print_jupyter_messages(
|
|||
let config = DisplayDiagnosticConfig::default()
|
||||
.format(DiagnosticFormat::Full)
|
||||
.hide_severity(true)
|
||||
.show_fix_status(true)
|
||||
.with_show_fix_status(true)
|
||||
.show_fix_diff(true)
|
||||
.fix_applicability(Applicability::DisplayOnly);
|
||||
.with_fix_applicability(Applicability::DisplayOnly);
|
||||
|
||||
DisplayDiagnostics::new(
|
||||
&EmitterContext::new(&FxHashMap::from_iter([(
|
||||
|
@ -468,9 +468,9 @@ pub(crate) fn print_messages(diagnostics: &[Diagnostic]) -> String {
|
|||
let config = DisplayDiagnosticConfig::default()
|
||||
.format(DiagnosticFormat::Full)
|
||||
.hide_severity(true)
|
||||
.show_fix_status(true)
|
||||
.with_show_fix_status(true)
|
||||
.show_fix_diff(true)
|
||||
.fix_applicability(Applicability::DisplayOnly);
|
||||
.with_fix_applicability(Applicability::DisplayOnly);
|
||||
|
||||
DisplayDiagnostics::new(
|
||||
&EmitterContext::new(&FxHashMap::default()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue