Skip to content

Commit

Permalink
Avoid intermediate vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored and MichaReiser committed Dec 2, 2024
1 parent f3f5612 commit 3f381e6
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,44 @@ impl Violation for Airflow3Removal {
}
}

struct DeprecatedArgument(Vec<&'static str>, Option<&'static str>);
fn diagnostic_for_argument(
arguments: &Arguments,
deprecated: &str,
replacement: Option<&str>,
) -> Option<Diagnostic> {
let keyword = arguments.find_keyword(deprecated)?;
Some(Diagnostic::new(
Airflow3Removal {
deprecated: (*deprecated).to_string(),
replacement: match replacement {
Some(name) => Replacement::Name(name.to_owned()),
None => Replacement::None,
},
},
keyword
.arg
.as_ref()
.map_or_else(|| keyword.range(), Ranged::range),
))
}

fn removed_argument(checker: &mut Checker, qualname: &QualifiedName, arguments: &Arguments) {
let deprecations = match qualname.segments() {
["airflow", .., "DAG" | "dag"] => vec![DeprecatedArgument(
vec!["timetable", "schedule_interval"],
Some("schedule"),
)],
_ => {
return;
#[allow(clippy::single_match)]
match qualname.segments() {
["airflow", .., "DAG" | "dag"] => {
checker.diagnostics.extend(diagnostic_for_argument(
arguments,
"schedule_interval",
Some("schedule"),
));
checker.diagnostics.extend(diagnostic_for_argument(
arguments,
"timetable",
Some("schedule"),
));
}
_ => {}
};
for deprecation in deprecations {
for arg in deprecation.0 {
if let Some(keyword) = arguments.find_keyword(arg) {
checker.diagnostics.push(Diagnostic::new(
Airflow3Removal {
deprecated: arg.to_string(),
replacement: match deprecation.1 {
Some(name) => Replacement::Name(name.to_owned()),
None => Replacement::None,
},
},
keyword
.arg
.as_ref()
.map_or_else(|| keyword.range(), Ranged::range),
));
};
}
}
}

fn removed_name(checker: &mut Checker, expr: &Expr, ranged: impl Ranged) {
Expand Down

0 comments on commit 3f381e6

Please sign in to comment.