Skip to content

Commit 5dfbd1f

Browse files
committed
refactor(AIR302): refactor autofix as suggested
1 parent 9f4d7da commit 5dfbd1f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Violation for Airflow3Removal {
7272
}
7373
}
7474

75-
#[derive(Debug, Clone, Eq, PartialEq)]
75+
#[derive(Debug, Eq, PartialEq)]
7676
enum Replacement {
7777
None,
7878
Name(&'static str),
@@ -289,20 +289,26 @@ fn check_class_attribute(checker: &Checker, attribute_expr: &ExprAttribute) {
289289
},
290290
_ => return,
291291
};
292+
293+
// Create the `Fix` first to avoid cloning `Replacement`.
294+
let fix = if let Replacement::Name(name) = replacement {
295+
Some(Fix::safe_edit(Edit::range_replacement(
296+
name.to_string(),
297+
attr.range(),
298+
)))
299+
} else {
300+
None
301+
};
292302
let mut diagnostic = Diagnostic::new(
293303
Airflow3Removal {
294304
deprecated: attr.to_string(),
295-
replacement: replacement.clone(),
305+
replacement,
296306
},
297307
attr.range(),
298308
);
299-
if let Replacement::Name(name) = replacement {
300-
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
301-
name.to_string(),
302-
attr.range(),
303-
)));
309+
if let Some(fix) = fix {
310+
diagnostic.set_fix(fix);
304311
}
305-
306312
checker.report_diagnostic(diagnostic);
307313
}
308314

0 commit comments

Comments
 (0)