Skip to content

Commit

Permalink
Avoid intermediate vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Dec 2, 2024
1 parent 352feb4 commit 6baabb0
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 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,41 @@ impl Violation for Airflow3Removal {
}
}

struct DeprecatedArgument(Vec<&'static str>, Option<&'static str>);
fn diagnostic_for_argument(
arguments: &Arguments,
deprecated_names: &[&str],
replacement: Option<&str>,
) -> Option<Diagnostic> {
for deprecated in deprecated_names {
if let Some(keyword) = arguments.find_keyword(deprecated) {
return 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),
));
}
}
None
}

fn removed_argument(checker: &mut Checker, qualname: &QualifiedName, arguments: &Arguments) {
let deprecations = match qualname.segments() {
["airflow", .., "DAG" | "dag"] => vec![DeprecatedArgument(
vec!["timetable", "schedule_interval"],
let diagnostic = match qualname.segments() {
["airflow", .., "DAG" | "dag"] => diagnostic_for_argument(
arguments,
&["timetable", "schedule_interval"],
Some("schedule"),
)],
_ => {
return;
}
),
_ => None,
};
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),
));
};
}
}
checker.diagnostics.extend(diagnostic);
}

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

0 comments on commit 6baabb0

Please sign in to comment.