@@ -15,6 +15,7 @@ enum Replacement {
15
15
None ,
16
16
Name ( & ' static str ) ,
17
17
Message ( & ' static str ) ,
18
+ ContextRemovalMessage ( & ' static str ) ,
18
19
}
19
20
20
21
/// ## What it does
@@ -44,7 +45,6 @@ enum Replacement {
44
45
pub ( crate ) struct Airflow3Removal {
45
46
deprecated : String ,
46
47
replacement : Replacement ,
47
- is_context_variable : bool ,
48
48
}
49
49
50
50
impl Violation for Airflow3Removal {
@@ -55,19 +55,17 @@ impl Violation for Airflow3Removal {
55
55
let Airflow3Removal {
56
56
deprecated,
57
57
replacement,
58
- is_context_variable,
59
58
} = self ;
60
59
match replacement {
61
60
Replacement :: None => format ! ( "`{deprecated}` is removed in Airflow 3.0" ) ,
62
61
Replacement :: Name ( _) => {
63
62
format ! ( "`{deprecated}` is removed in Airflow 3.0" )
64
63
}
65
64
Replacement :: Message ( message) => {
66
- if * is_context_variable {
67
- format ! ( "`{deprecated}` {message}" )
68
- } else {
69
- format ! ( "`{deprecated}` is removed in Airflow 3.0; {message}" )
70
- }
65
+ format ! ( "`{deprecated}` is removed in Airflow 3.0; {message}" )
66
+ }
67
+ Replacement :: ContextRemovalMessage ( message) => {
68
+ format ! ( "`{deprecated}` {message}" )
71
69
}
72
70
}
73
71
}
@@ -95,7 +93,6 @@ fn diagnostic_for_argument(
95
93
Some ( name) => Replacement :: Name ( name) ,
96
94
None => Replacement :: None ,
97
95
} ,
98
- is_context_variable : false ,
99
96
} ,
100
97
keyword
101
98
. arg
@@ -213,7 +210,6 @@ fn removed_method(checker: &mut Checker, expr: &Expr) {
213
210
Airflow3Removal {
214
211
deprecated : attr. to_string ( ) ,
215
212
replacement,
216
- is_context_variable : false ,
217
213
} ,
218
214
attr. range ( ) ,
219
215
) ) ;
@@ -651,7 +647,6 @@ fn removed_name(checker: &mut Checker, expr: &Expr, ranged: impl Ranged) {
651
647
Airflow3Removal {
652
648
deprecated,
653
649
replacement,
654
- is_context_variable : false ,
655
650
} ,
656
651
ranged. range ( ) ,
657
652
) ) ;
@@ -667,31 +662,32 @@ fn extract_name_from_slice(slice: &Expr) -> Option<String> {
667
662
}
668
663
669
664
pub ( crate ) fn removed_context_variable ( checker : & mut Checker , expr : & Expr ) {
665
+ const REMOVED_CONTEXT_KEYS : [ & str ; 12 ] = [
666
+ "conf" ,
667
+ "execution_date" ,
668
+ "next_ds" ,
669
+ "next_ds_nodash" ,
670
+ "next_execution_date" ,
671
+ "prev_ds" ,
672
+ "prev_ds_nodash" ,
673
+ "prev_execution_date" ,
674
+ "prev_execution_date_success" ,
675
+ "tomorrow_ds" ,
676
+ "yesterday_ds" ,
677
+ "yesterday_ds_nodash" ,
678
+ ] ;
679
+
670
680
if let Expr :: Subscript ( ExprSubscript { value, slice, .. } ) = expr {
671
681
if let Expr :: Name ( ExprName { id, .. } ) = & * * value {
672
682
if id. as_str ( ) == "context" {
673
683
if let Some ( key) = extract_name_from_slice ( slice) {
674
- const REMOVED_CONTEXT_KEYS : [ & str ; 11 ] = [
675
- "execution_date" ,
676
- "next_ds" ,
677
- "next_ds_nodash" ,
678
- "next_execution_date" ,
679
- "prev_ds" ,
680
- "prev_ds_nodash" ,
681
- "prev_execution_date" ,
682
- "prev_execution_date_success" ,
683
- "tomorrow_ds" ,
684
- "yesterday_ds" ,
685
- "yesterday_ds_nodash" ,
686
- ] ;
687
684
if REMOVED_CONTEXT_KEYS . contains ( & key. as_str ( ) ) {
688
685
checker. diagnostics . push ( Diagnostic :: new (
689
686
Airflow3Removal {
690
687
deprecated : key,
691
- replacement : Replacement :: Message (
692
- "is removed in the Airflow context in Airflow 3.0" ,
688
+ replacement : Replacement :: ContextRemovalMessage (
689
+ "is removed in Airflow 3.0. " ,
693
690
) ,
694
- is_context_variable : true ,
695
691
} ,
696
692
slice. range ( ) ,
697
693
) ) ;
@@ -700,6 +696,23 @@ pub(crate) fn removed_context_variable(checker: &mut Checker, expr: &Expr) {
700
696
}
701
697
}
702
698
}
699
+
700
+ if let Expr :: StringLiteral ( ExprStringLiteral { value, .. } ) = expr {
701
+ let value_str = value. to_string ( ) ;
702
+ for key in REMOVED_CONTEXT_KEYS {
703
+ if value_str. contains ( & format ! ( "{{{{ {key} }}}}" ) ) {
704
+ checker. diagnostics . push ( Diagnostic :: new (
705
+ Airflow3Removal {
706
+ deprecated : key. to_string ( ) ,
707
+ replacement : Replacement :: ContextRemovalMessage (
708
+ "is removed in Airflow 3.0." ,
709
+ ) ,
710
+ } ,
711
+ expr. range ( ) ,
712
+ ) ) ;
713
+ }
714
+ }
715
+ }
703
716
}
704
717
705
718
/// AIR302
0 commit comments