mirror of https://github.com/astral-sh/ruff
Remove `Applicability::Unspecified` and associated helpers
This commit is contained in:
parent
ee903bf168
commit
6eeadba9f5
|
|
@ -9,7 +9,7 @@ use crate::edit::Edit;
|
|||
/// of enum values based on their order (see Rust's [enum
|
||||
/// documentation](https://doc.rust-lang.org/reference/items/enumerations.html)). This allows us to
|
||||
/// apply [`Fix`]es based on their [`Applicability`].
|
||||
#[derive(Default, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum Applicability {
|
||||
/// The fix has a good chance of being incorrect or the code be incomplete.
|
||||
|
|
@ -17,10 +17,6 @@ pub enum Applicability {
|
|||
/// The fix should only be manually applied by the user.
|
||||
Manual,
|
||||
|
||||
/// The applicability of the fix is unknown or not relevant.
|
||||
#[default]
|
||||
Unspecified,
|
||||
|
||||
/// The fix may be what the user intended, but it is uncertain.
|
||||
/// The fix should result in valid code if it is applied.
|
||||
/// The fix can be applied with user opt-in.
|
||||
|
|
@ -36,7 +32,7 @@ impl Applicability {
|
|||
match self {
|
||||
Self::Automatic => "*",
|
||||
Self::Suggested => "**",
|
||||
_ => "*",
|
||||
Self::Manual => "-",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,30 +61,6 @@ pub struct Fix {
|
|||
}
|
||||
|
||||
impl Fix {
|
||||
/// Create a new [`Fix`] with an unspecified applicability from an [`Edit`] element.
|
||||
#[deprecated(
|
||||
note = "Use `Fix::automatic`, `Fix::suggested`, or `Fix::manual` instead to specify an applicability."
|
||||
)]
|
||||
pub fn unspecified(edit: Edit) -> Self {
|
||||
Self {
|
||||
edits: vec![edit],
|
||||
applicability: Applicability::Unspecified,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with an unspecified applicability from multiple [`Edit`] elements.
|
||||
#[deprecated(
|
||||
note = "Use `Fix::automatic_edits`, `Fix::suggested_edits`, or `Fix::manual_edits` instead to specify an applicability."
|
||||
)]
|
||||
pub fn unspecified_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
Self {
|
||||
edits: std::iter::once(edit).chain(rest).collect(),
|
||||
applicability: Applicability::Unspecified,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from an [`Edit`] element.
|
||||
pub fn automatic(edit: Edit) -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -160,14 +160,13 @@ mod tests {
|
|||
use crate::fix::{apply_fixes, FixResult};
|
||||
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn create_diagnostics(edit: impl IntoIterator<Item = Edit>) -> Vec<Diagnostic> {
|
||||
edit.into_iter()
|
||||
.map(|edit| Diagnostic {
|
||||
// The choice of rule here is arbitrary.
|
||||
// The choice of rule and fix applicability here is arbitarary
|
||||
kind: MissingNewlineAtEndOfFile.into(),
|
||||
range: edit.range(),
|
||||
fix: Some(Fix::unspecified(edit)),
|
||||
fix: Some(Fix::automatic(edit)),
|
||||
parent: None,
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ impl Display for Diff<'_> {
|
|||
Applicability::Automatic => "Fix",
|
||||
Applicability::Suggested => "Suggested fix",
|
||||
Applicability::Manual => "Possible fix",
|
||||
Applicability::Unspecified => "Suggested fix", /* For backwards compatibility, unspecified fixes are 'suggested' */
|
||||
};
|
||||
writeln!(f, "ℹ {}", message.blue())?;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue