Skip to content

Commit d362b7b

Browse files
committed
refactor(AIR302): refactor fix as suggested
1 parent 71a63d2 commit d362b7b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

+13-7
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),
@@ -504,19 +504,25 @@ fn check_method(checker: &Checker, call_expr: &ExprCall) {
504504
}
505505
}
506506
};
507+
// Create the `Fix` first to avoid cloning `Replacement`.
508+
let fix = if let Replacement::Name(name) = replacement {
509+
Some(Fix::safe_edit(Edit::range_replacement(
510+
name.to_string(),
511+
attr.range(),
512+
)))
513+
} else {
514+
None
515+
};
507516

508517
let mut diagnostic = Diagnostic::new(
509518
Airflow3Removal {
510519
deprecated: attr.to_string(),
511-
replacement: replacement.clone(),
520+
replacement,
512521
},
513522
attr.range(),
514523
);
515-
if let Replacement::Name(name) = replacement {
516-
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
517-
name.to_string(),
518-
attr.range(),
519-
)));
524+
if let Some(fix) = fix {
525+
diagnostic.set_fix(fix);
520526
}
521527
checker.report_diagnostic(diagnostic);
522528
}

0 commit comments

Comments
 (0)