Skip to content

Commit 5d57788

Browse files
authored
[airflow] Add autofix for AIR302 method checks (#16976)
## Summary Add autofix logic to `AIR302` method checks ## Test Plan Test fixtures have been updated accordingly
1 parent 718b0ca commit 5d57788

File tree

2 files changed

+288
-27
lines changed

2 files changed

+288
-27
lines changed

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,27 @@ fn check_method(checker: &Checker, call_expr: &ExprCall) {
504504
}
505505
}
506506
};
507-
checker.report_diagnostic(Diagnostic::new(
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+
};
516+
517+
let mut diagnostic = Diagnostic::new(
508518
Airflow3Removal {
509519
deprecated: attr.to_string(),
510520
replacement,
511521
},
512522
attr.range(),
513-
));
523+
);
524+
if let Some(fix) = fix {
525+
diagnostic.set_fix(fix);
526+
}
527+
checker.report_diagnostic(diagnostic);
514528
}
515529

516530
/// Check whether a removed Airflow name is used.

0 commit comments

Comments
 (0)