Remove `Applicability::Unspecified` and associated helpers

This commit is contained in:
Zanie 2023-10-03 14:26:51 -05:00
parent ee903bf168
commit 6eeadba9f5
3 changed files with 4 additions and 34 deletions

View File

@ -9,7 +9,7 @@ use crate::edit::Edit;
/// of enum values based on their order (see Rust's [enum /// 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 /// documentation](https://doc.rust-lang.org/reference/items/enumerations.html)). This allows us to
/// apply [`Fix`]es based on their [`Applicability`]. /// 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))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Applicability { pub enum Applicability {
/// The fix has a good chance of being incorrect or the code be incomplete. /// 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. /// The fix should only be manually applied by the user.
Manual, 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 may be what the user intended, but it is uncertain.
/// The fix should result in valid code if it is applied. /// The fix should result in valid code if it is applied.
/// The fix can be applied with user opt-in. /// The fix can be applied with user opt-in.
@ -36,7 +32,7 @@ impl Applicability {
match self { match self {
Self::Automatic => "*", Self::Automatic => "*",
Self::Suggested => "**", Self::Suggested => "**",
_ => "*", Self::Manual => "-",
} }
} }
} }
@ -65,30 +61,6 @@ pub struct Fix {
} }
impl 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. /// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from an [`Edit`] element.
pub fn automatic(edit: Edit) -> Self { pub fn automatic(edit: Edit) -> Self {
Self { Self {

View File

@ -160,14 +160,13 @@ mod tests {
use crate::fix::{apply_fixes, FixResult}; use crate::fix::{apply_fixes, FixResult};
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile; use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
#[allow(deprecated)]
fn create_diagnostics(edit: impl IntoIterator<Item = Edit>) -> Vec<Diagnostic> { fn create_diagnostics(edit: impl IntoIterator<Item = Edit>) -> Vec<Diagnostic> {
edit.into_iter() edit.into_iter()
.map(|edit| Diagnostic { .map(|edit| Diagnostic {
// The choice of rule here is arbitrary. // The choice of rule and fix applicability here is arbitarary
kind: MissingNewlineAtEndOfFile.into(), kind: MissingNewlineAtEndOfFile.into(),
range: edit.range(), range: edit.range(),
fix: Some(Fix::unspecified(edit)), fix: Some(Fix::automatic(edit)),
parent: None, parent: None,
}) })
.collect() .collect()

View File

@ -55,7 +55,6 @@ impl Display for Diff<'_> {
Applicability::Automatic => "Fix", Applicability::Automatic => "Fix",
Applicability::Suggested => "Suggested fix", Applicability::Suggested => "Suggested fix",
Applicability::Manual => "Possible fix", Applicability::Manual => "Possible fix",
Applicability::Unspecified => "Suggested fix", /* For backwards compatibility, unspecified fixes are 'suggested' */
}; };
writeln!(f, " {}", message.blue())?; writeln!(f, " {}", message.blue())?;