mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Merge Availability and AutofixKind (#3629)
This commit is contained in:
parent
7c0f17279c
commit
fd39ec4bdd
26 changed files with 70 additions and 72 deletions
|
@ -1,6 +1,6 @@
|
|||
pub use diagnostic::{Diagnostic, DiagnosticKind};
|
||||
pub use fix::Fix;
|
||||
pub use violation::{AlwaysAutofixableViolation, AutofixKind, Availability, Violation};
|
||||
pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation};
|
||||
|
||||
mod diagnostic;
|
||||
mod fix;
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
use std::fmt::Debug;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
pub enum Availability {
|
||||
pub enum AutofixKind {
|
||||
Sometimes,
|
||||
Always,
|
||||
None,
|
||||
}
|
||||
|
||||
pub struct AutofixKind {
|
||||
pub available: Availability,
|
||||
}
|
||||
|
||||
impl AutofixKind {
|
||||
pub const fn new(available: Availability) -> Self {
|
||||
Self { available }
|
||||
impl Display for AutofixKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AutofixKind::Sometimes => write!(f, "Autofix is sometimes available."),
|
||||
AutofixKind::Always => write!(f, "Autofix is always available."),
|
||||
AutofixKind::None => write!(f, "Autofix is not available."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Violation: Debug + PartialEq + Eq {
|
||||
/// `None` in the case an autofix is never available or otherwise Some
|
||||
/// [`AutofixKind`] describing the available autofix.
|
||||
const AUTOFIX: Option<AutofixKind> = None;
|
||||
const AUTOFIX: AutofixKind = AutofixKind::None;
|
||||
|
||||
/// The message used to describe the violation.
|
||||
fn message(&self) -> String;
|
||||
|
@ -60,7 +61,7 @@ pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq {
|
|||
|
||||
/// A blanket implementation.
|
||||
impl<VA: AlwaysAutofixableViolation> Violation for VA {
|
||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Always));
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Always;
|
||||
|
||||
fn message(&self) -> String {
|
||||
<Self as AlwaysAutofixableViolation>::message(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue