Skip to content

Commit cc5b974

Browse files
committed
feat(AIR302): add autofix to check_class_attribute
1 parent 6d1ad47 commit cc5b974

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Violation for Airflow3Removal {
7272
}
7373
}
7474

75-
#[derive(Debug, Eq, PartialEq)]
75+
#[derive(Debug, Clone, Eq, PartialEq)]
7676
enum Replacement {
7777
None,
7878
Name(&'static str),
@@ -289,14 +289,21 @@ fn check_class_attribute(checker: &Checker, attribute_expr: &ExprAttribute) {
289289
},
290290
_ => return,
291291
};
292-
293-
checker.report_diagnostic(Diagnostic::new(
292+
let mut diagnostic = Diagnostic::new(
294293
Airflow3Removal {
295294
deprecated: attr.to_string(),
296-
replacement,
295+
replacement: replacement.clone(),
297296
},
298297
attr.range(),
299-
));
298+
);
299+
if let Replacement::Name(name) = replacement {
300+
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
301+
name.to_string(),
302+
attr.range(),
303+
)));
304+
}
305+
306+
checker.report_diagnostic(diagnostic);
300307
}
301308

302309
/// Checks whether an Airflow 3.0–removed context key is used in a function decorated with `@task`.

crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR302_AIR302_class_attribute.py.snap

+56-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/ruff_linter/src/rules/airflow/mod.rs
3+
snapshot_kind: text
34
---
45
AIR302_class_attribute.py:24:21: AIR302 `airflow.Dataset` is removed in Airflow 3.0
56
|
@@ -188,7 +189,7 @@ AIR302_class_attribute.py:50:11: AIR302 `airflow.lineage.hook.DatasetLineageInfo
188189
|
189190
= help: Use `airflow.lineage.hook.AssetLineageInfo` instead
190191

191-
AIR302_class_attribute.py:51:9: AIR302 `dataset` is removed in Airflow 3.0
192+
AIR302_class_attribute.py:51:9: AIR302 [*] `dataset` is removed in Airflow 3.0
192193
|
193194
49 | # airflow.lineage.hook
194195
50 | dl_info = DatasetLineageInfo()
@@ -199,6 +200,16 @@ AIR302_class_attribute.py:51:9: AIR302 `dataset` is removed in Airflow 3.0
199200
|
200201
= help: Use `asset` instead
201202

203+
Safe fix
204+
48 48 |
205+
49 49 | # airflow.lineage.hook
206+
50 50 | dl_info = DatasetLineageInfo()
207+
51 |-dl_info.dataset
208+
51 |+dl_info.asset
209+
52 52 |
210+
53 53 | hlc = HookLineageCollector()
211+
54 54 | hlc.create_dataset()
212+
202213
AIR302_class_attribute.py:54:5: AIR302 `create_dataset` is removed in Airflow 3.0
203214
|
204215
53 | hlc = HookLineageCollector()
@@ -294,7 +305,7 @@ AIR302_class_attribute.py:79:15: AIR302 `get_connections` is removed in Airflow
294305
|
295306
= help: Use `get_connection` instead
296307

297-
AIR302_class_attribute.py:87:4: AIR302 `dataset_factories` is removed in Airflow 3.0
308+
AIR302_class_attribute.py:87:4: AIR302 [*] `dataset_factories` is removed in Airflow 3.0
298309
|
299310
85 | pm = ProvidersManager()
300311
86 | pm.initialize_providers_asset_uri_resources()
@@ -305,7 +316,17 @@ AIR302_class_attribute.py:87:4: AIR302 `dataset_factories` is removed in Airflow
305316
|
306317
= help: Use `asset_factories` instead
307318

308-
AIR302_class_attribute.py:88:4: AIR302 `dataset_factories` is removed in Airflow 3.0
319+
Safe fix
320+
84 84 | # airflow.providers_manager
321+
85 85 | pm = ProvidersManager()
322+
86 86 | pm.initialize_providers_asset_uri_resources()
323+
87 |-pm.dataset_factories
324+
87 |+pm.asset_factories
325+
88 88 | pm.dataset_factories
326+
89 89 | pm.dataset_uri_handlers
327+
90 90 | pm.dataset_to_openlineage_converters
328+
329+
AIR302_class_attribute.py:88:4: AIR302 [*] `dataset_factories` is removed in Airflow 3.0
309330
|
310331
86 | pm.initialize_providers_asset_uri_resources()
311332
87 | pm.dataset_factories
@@ -316,7 +337,17 @@ AIR302_class_attribute.py:88:4: AIR302 `dataset_factories` is removed in Airflow
316337
|
317338
= help: Use `asset_factories` instead
318339

319-
AIR302_class_attribute.py:89:4: AIR302 `dataset_uri_handlers` is removed in Airflow 3.0
340+
Safe fix
341+
85 85 | pm = ProvidersManager()
342+
86 86 | pm.initialize_providers_asset_uri_resources()
343+
87 87 | pm.dataset_factories
344+
88 |-pm.dataset_factories
345+
88 |+pm.asset_factories
346+
89 89 | pm.dataset_uri_handlers
347+
90 90 | pm.dataset_to_openlineage_converters
348+
91 91 |
349+
350+
AIR302_class_attribute.py:89:4: AIR302 [*] `dataset_uri_handlers` is removed in Airflow 3.0
320351
|
321352
87 | pm.dataset_factories
322353
88 | pm.dataset_factories
@@ -326,7 +357,17 @@ AIR302_class_attribute.py:89:4: AIR302 `dataset_uri_handlers` is removed in Airf
326357
|
327358
= help: Use `asset_uri_handlers` instead
328359

329-
AIR302_class_attribute.py:90:4: AIR302 `dataset_to_openlineage_converters` is removed in Airflow 3.0
360+
Safe fix
361+
86 86 | pm.initialize_providers_asset_uri_resources()
362+
87 87 | pm.dataset_factories
363+
88 88 | pm.dataset_factories
364+
89 |-pm.dataset_uri_handlers
365+
89 |+pm.asset_uri_handlers
366+
90 90 | pm.dataset_to_openlineage_converters
367+
91 91 |
368+
92 92 | # airflow.secrets.base_secrets
369+
370+
AIR302_class_attribute.py:90:4: AIR302 [*] `dataset_to_openlineage_converters` is removed in Airflow 3.0
330371
|
331372
88 | pm.dataset_factories
332373
89 | pm.dataset_uri_handlers
@@ -337,6 +378,16 @@ AIR302_class_attribute.py:90:4: AIR302 `dataset_to_openlineage_converters` is re
337378
|
338379
= help: Use `asset_to_openlineage_converters` instead
339380

381+
Safe fix
382+
87 87 | pm.dataset_factories
383+
88 88 | pm.dataset_factories
384+
89 89 | pm.dataset_uri_handlers
385+
90 |-pm.dataset_to_openlineage_converters
386+
90 |+pm.asset_to_openlineage_converters
387+
91 91 |
388+
92 92 | # airflow.secrets.base_secrets
389+
93 93 | base_secret_backend = BaseSecretsBackend()
390+
340391
AIR302_class_attribute.py:94:21: AIR302 `get_conn_uri` is removed in Airflow 3.0
341392
|
342393
92 | # airflow.secrets.base_secrets

0 commit comments

Comments
 (0)