Rename Fix to Edit (#3702)

This commit is contained in:
Charlie Marsh 2023-03-24 19:29:14 -04:00 committed by GitHub
parent c721eedc37
commit 2083134a96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 394 additions and 404 deletions

View file

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use ruff_python_ast::types::Range;
use crate::fix::Fix;
use crate::edit::Edit;
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -27,7 +27,7 @@ pub struct Diagnostic {
pub kind: DiagnosticKind,
pub location: Location,
pub end_location: Location,
pub fix: Option<Fix>,
pub fix: Option<Edit>,
pub parent: Option<Location>,
}
@ -42,12 +42,12 @@ impl Diagnostic {
}
}
pub fn amend(&mut self, fix: Fix) -> &mut Self {
pub fn amend(&mut self, fix: Edit) -> &mut Self {
self.fix = Some(fix);
self
}
pub fn try_amend(&mut self, func: impl FnOnce() -> Result<Fix>) -> &mut Self {
pub fn try_amend(&mut self, func: impl FnOnce() -> Result<Edit>) -> &mut Self {
match func() {
Ok(fix) => self.fix = Some(fix),
Err(err) => error!("Failed to create fix: {}", err),

View file

@ -4,13 +4,16 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Fix {
pub struct Edit {
/// The replacement content to insert between the start and end locations.
pub content: String,
/// The start location of the edit.
pub location: Location,
/// The end location of the edit.
pub end_location: Location,
}
impl Fix {
impl Edit {
pub const fn deletion(start: Location, end: Location) -> Self {
Self {
content: String::new(),

View file

@ -1,7 +1,7 @@
pub use diagnostic::{Diagnostic, DiagnosticKind};
pub use fix::Fix;
pub use edit::Edit;
pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation};
mod diagnostic;
mod fix;
mod edit;
mod violation;