mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 23:27:27 +00:00
Rename Autofix
to Fix
(#7657)
**Summary** Mostly mechanical symbol rename and search-and-replace, with small changes to the markdown docs to read better
This commit is contained in:
parent
8028de8956
commit
1e173f7909
231 changed files with 943 additions and 960 deletions
|
@ -2,7 +2,7 @@ pub use diagnostic::{Diagnostic, DiagnosticKind};
|
|||
pub use edit::Edit;
|
||||
pub use fix::{Applicability, Fix, IsolationLevel};
|
||||
pub use source_map::{SourceMap, SourceMarker};
|
||||
pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation};
|
||||
pub use violation::{AlwaysFixableViolation, FixKind, Violation};
|
||||
|
||||
mod diagnostic;
|
||||
mod edit;
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
use std::fmt::{Debug, Display};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AutofixKind {
|
||||
pub enum FixKind {
|
||||
Sometimes,
|
||||
Always,
|
||||
None,
|
||||
}
|
||||
|
||||
impl Display for AutofixKind {
|
||||
impl Display for FixKind {
|
||||
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."),
|
||||
FixKind::Sometimes => write!(f, "Fix is sometimes available."),
|
||||
FixKind::Always => write!(f, "Fix is always available."),
|
||||
FixKind::None => write!(f, "Fix 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: AutofixKind = AutofixKind::None;
|
||||
/// `None` in the case an fix is never available or otherwise Some
|
||||
/// [`FixKind`] describing the available fix.
|
||||
const FIX_KIND: FixKind = FixKind::None;
|
||||
|
||||
/// The message used to describe the violation.
|
||||
fn message(&self) -> String;
|
||||
|
@ -30,13 +30,13 @@ pub trait Violation: Debug + PartialEq + Eq {
|
|||
None
|
||||
}
|
||||
|
||||
// TODO(micha): Move `autofix_title` to `Fix`, add new `advice` method that is shown as an advice.
|
||||
// TODO(micha): Move `fix_title` to `Fix`, add new `advice` method that is shown as an advice.
|
||||
// Change the `Diagnostic` renderer to show the advice, and render the fix message after the `Suggested fix: <here>`
|
||||
|
||||
/// Returns the title for the autofix. The message is also shown as an advice as part of the diagnostics.
|
||||
/// Returns the title for the fix. The message is also shown as an advice as part of the diagnostics.
|
||||
///
|
||||
/// Required for rules that have autofixes.
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
/// Required for rules that have fixes.
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ pub trait Violation: Debug + PartialEq + Eq {
|
|||
}
|
||||
|
||||
/// This trait exists just to make implementing the [`Violation`] trait more
|
||||
/// convenient for violations that can always be autofixed.
|
||||
pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq {
|
||||
/// convenient for violations that can always be fixed.
|
||||
pub trait AlwaysFixableViolation: Debug + PartialEq + Eq {
|
||||
/// The message used to describe the violation.
|
||||
fn message(&self) -> String;
|
||||
|
||||
|
@ -55,31 +55,31 @@ pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq {
|
|||
None
|
||||
}
|
||||
|
||||
/// The title displayed for the available autofix.
|
||||
fn autofix_title(&self) -> String;
|
||||
/// The title displayed for the available fix.
|
||||
fn fix_title(&self) -> String;
|
||||
|
||||
/// Returns the format strings used by
|
||||
/// [`message`](AlwaysAutofixableViolation::message).
|
||||
/// [`message`](AlwaysFixableViolation::message).
|
||||
fn message_formats() -> &'static [&'static str];
|
||||
}
|
||||
|
||||
/// A blanket implementation.
|
||||
impl<VA: AlwaysAutofixableViolation> Violation for VA {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Always;
|
||||
impl<V: AlwaysFixableViolation> Violation for V {
|
||||
const FIX_KIND: FixKind = FixKind::Always;
|
||||
|
||||
fn message(&self) -> String {
|
||||
<Self as AlwaysAutofixableViolation>::message(self)
|
||||
<Self as AlwaysFixableViolation>::message(self)
|
||||
}
|
||||
|
||||
fn explanation() -> Option<&'static str> {
|
||||
<Self as AlwaysAutofixableViolation>::explanation()
|
||||
<Self as AlwaysFixableViolation>::explanation()
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
Some(<Self as AlwaysAutofixableViolation>::autofix_title(self))
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(<Self as AlwaysFixableViolation>::fix_title(self))
|
||||
}
|
||||
|
||||
fn message_formats() -> &'static [&'static str] {
|
||||
<Self as AlwaysAutofixableViolation>::message_formats()
|
||||
<Self as AlwaysFixableViolation>::message_formats()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue