Skip to content

Commit 90af759

Browse files
committed
refactor(AIR301): combine similar cases in message and fix
1 parent 0a5ac66 commit 90af759

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub(crate) enum Replacement {
1010
Name(&'static str),
1111
Message(&'static str),
1212
AutoImport {
13-
path: &'static str,
13+
module: &'static str,
1414
name: &'static str,
1515
},
1616
SourceModuleMoved {
17-
name: String,
1817
module: &'static str,
18+
name: String,
1919
},
2020
}
2121

@@ -59,10 +59,10 @@ pub(crate) fn is_guarded_by_try_except(
5959
/// contain any [`ast::StmtImportFrom`] nodes that indicate the numpy
6060
/// member is being imported from the non-deprecated location?
6161
fn try_block_contains_undeprecated_import(try_node: &StmtTry, replacement: &Replacement) -> bool {
62-
let Replacement::AutoImport { path, name } = replacement else {
62+
let Replacement::AutoImport { module, name } = replacement else {
6363
return false;
6464
};
65-
let mut import_searcher = ImportSearcher::new(path, name);
65+
let mut import_searcher = ImportSearcher::new(module, name);
6666
import_searcher.visit_body(&try_node.body);
6767
import_searcher.found_import
6868
}

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,26 @@ impl Violation for Airflow3Removal {
5454
replacement,
5555
} = self;
5656
match replacement {
57-
Replacement::None => format!("`{deprecated}` is removed in Airflow 3.0"),
58-
Replacement::Name(_) => {
57+
Replacement::None
58+
| Replacement::Name(_)
59+
| Replacement::AutoImport { module: _, name: _ }
60+
| Replacement::SourceModuleMoved { module: _, name: _ } => {
5961
format!("`{deprecated}` is removed in Airflow 3.0")
6062
}
6163
Replacement::Message(message) => {
6264
format!("`{deprecated}` is removed in Airflow 3.0; {message}")
6365
}
64-
Replacement::AutoImport { path: _, name: _ } => {
65-
format!("`{deprecated}` is removed in Airflow 3.0")
66-
}
67-
Replacement::SourceModuleMoved { name: _, module: _ } => {
68-
format!("`{deprecated}` is removed in Airflow 3.0")
69-
}
7066
}
7167
}
7268

7369
fn fix_title(&self) -> Option<String> {
7470
let Airflow3Removal { replacement, .. } = self;
7571
match replacement {
7672
Replacement::Name(name) => Some(format!("Use `{name}` instead")),
77-
Replacement::AutoImport { path, name } => Some(format!("Use `{path}.{name}` instead")),
78-
Replacement::SourceModuleMoved { name, module } => {
73+
Replacement::AutoImport { module, name } => {
74+
Some(format!("Use `{module}.{name}` instead"))
75+
}
76+
Replacement::SourceModuleMoved { module, name } => {
7977
Some(format!("Use `{module}.{name}` instead"))
8078
}
8179
_ => None,
@@ -581,7 +579,7 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
581579
}
582580
["airflow", "api_connexion", "security", "requires_access_dataset"] => {
583581
Replacement::AutoImport {
584-
path: "airflow.api_connexion.security",
582+
module: "airflow.api_connexion.security",
585583
name: "requires_access_asset",
586584
}
587585
}
@@ -601,8 +599,8 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
601599
// airflow.configuration
602600
["airflow", "configuration", rest @ ("as_dict" | "get" | "getboolean" | "getfloat" | "getint" | "has_option"
603601
| "remove_option" | "set")] => Replacement::SourceModuleMoved {
604-
name: (*rest).to_string(),
605602
module: "airflow.configuration.conf",
603+
name: (*rest).to_string(),
606604
},
607605

608606
// airflow.contrib.*
@@ -622,7 +620,7 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
622620
}
623621
// airflow.datasets
624622
["airflow", "Dataset"] | ["airflow", "datasets", "Dataset"] => Replacement::AutoImport {
625-
path: "airflow.sdk",
623+
module: "airflow.sdk",
626624
name: "Asset",
627625
},
628626
["airflow", "datasets", rest] => match *rest {
@@ -670,8 +668,8 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
670668
// airflow.models.baseoperator
671669
["airflow", "models", "baseoperator", rest] => match *rest {
672670
"chain" | "chain_linear" | "cross_downstream" => Replacement::SourceModuleMoved {
673-
name: (*rest).to_string(),
674671
module: "airflow.sdk",
672+
name: (*rest).to_string(),
675673
},
676674
"BaseOperatorLink" => {
677675
Replacement::Name("airflow.sdk.definitions.baseoperatorlink.BaseOperatorLink")
@@ -881,10 +879,10 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
881879
range,
882880
);
883881

884-
if let Replacement::AutoImport { path, name } = replacement {
882+
if let Replacement::AutoImport { module, name } = replacement {
885883
diagnostic.try_set_fix(|| {
886884
let (import_edit, binding) = checker.importer().get_or_import_symbol(
887-
&ImportRequest::import_from(path, name),
885+
&ImportRequest::import_from(module, name),
888886
expr.start(),
889887
checker.semantic(),
890888
)?;

0 commit comments

Comments
 (0)