From 33bd08f49b4231e376c681c1ab0b83d56fbf0252 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 2 Apr 2025 23:07:35 +0800 Subject: [PATCH] [`airflow`] Move `AIR301` to `AIR002` (#16978) ## Summary Unlike other AIR3XX rules, this best practice can be applied to Airflow 1 and Airflow 2 as well. Thus, we think it might make sense for use to move it to AIR002 so that the first number of the error align to Airflow version as possible to reduce confusion ## Test Plan the test fixture has been updated --- .../fixtures/airflow/{AIR301.py => AIR002.py} | 0 crates/ruff_linter/src/codes.rs | 2 +- crates/ruff_linter/src/rules/airflow/mod.rs | 2 +- .../airflow/rules/dag_schedule_argument.rs | 17 +++++++++-------- ...ules__airflow__tests__AIR002_AIR002.py.snap} | 9 +++++---- ruff.schema.json | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) rename crates/ruff_linter/resources/test/fixtures/airflow/{AIR301.py => AIR002.py} (100%) rename crates/ruff_linter/src/rules/airflow/snapshots/{ruff_linter__rules__airflow__tests__AIR301_AIR301.py.snap => ruff_linter__rules__airflow__tests__AIR002_AIR002.py.snap} (59%) diff --git a/crates/ruff_linter/resources/test/fixtures/airflow/AIR301.py b/crates/ruff_linter/resources/test/fixtures/airflow/AIR002.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/airflow/AIR301.py rename to crates/ruff_linter/resources/test/fixtures/airflow/AIR002.py diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 4a7e49b70d..762152bae5 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -1068,7 +1068,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { // airflow (Airflow, "001") => (RuleGroup::Stable, rules::airflow::rules::AirflowVariableNameTaskIdMismatch), - (Airflow, "301") => (RuleGroup::Preview, rules::airflow::rules::AirflowDagNoScheduleArgument), + (Airflow, "002") => (RuleGroup::Preview, rules::airflow::rules::AirflowDagNoScheduleArgument), (Airflow, "302") => (RuleGroup::Preview, rules::airflow::rules::Airflow3Removal), (Airflow, "303") => (RuleGroup::Preview, rules::airflow::rules::Airflow3MovedToProvider), diff --git a/crates/ruff_linter/src/rules/airflow/mod.rs b/crates/ruff_linter/src/rules/airflow/mod.rs index d702009786..be4a9fe87d 100644 --- a/crates/ruff_linter/src/rules/airflow/mod.rs +++ b/crates/ruff_linter/src/rules/airflow/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::{assert_messages, settings}; #[test_case(Rule::AirflowVariableNameTaskIdMismatch, Path::new("AIR001.py"))] - #[test_case(Rule::AirflowDagNoScheduleArgument, Path::new("AIR301.py"))] + #[test_case(Rule::AirflowDagNoScheduleArgument, Path::new("AIR002.py"))] #[test_case(Rule::Airflow3Removal, Path::new("AIR302_args.py"))] #[test_case(Rule::Airflow3Removal, Path::new("AIR302_names.py"))] #[test_case(Rule::Airflow3Removal, Path::new("AIR302_class_attribute.py"))] diff --git a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs index b0b7c9c3ad..73f48cfc3e 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/dag_schedule_argument.rs @@ -9,16 +9,17 @@ use crate::checkers::ast::Checker; /// ## What it does /// Checks for a `DAG()` class or `@dag()` decorator without an explicit -/// `schedule` parameter. +/// `schedule` (or `schedule_interval` for Airflow 1) parameter. /// /// ## Why is this bad? -/// The default `schedule` value on Airflow 2 is `timedelta(days=1)`, which is -/// almost never what a user is looking for. Airflow 3 changes this the default -/// to *None*, and would break existing DAGs using the implicit default. +/// The default value of the `schedule` parameter on Airflow 2 and +/// `schedule_interval` on Airflow 1 is `timedelta(days=1)`, which is almost +/// never what a user is looking for. Airflow 3 changed the default value to `None`, +/// and would break existing dags using the implicit default. /// -/// If your DAG does not have an explicit `schedule` argument, Airflow 2 -/// schedules a run for it every day (at the time determined by `start_date`). -/// Such a DAG will no longer be scheduled on Airflow 3 at all, without any +/// If your dag does not have an explicit `schedule` / `schedule_interval` argument, +/// Airflow 2 schedules a run for it every day (at the time determined by `start_date`). +/// Such a dag will no longer be scheduled on Airflow 3 at all, without any /// exceptions or other messages visible to the user. /// /// ## Example @@ -49,7 +50,7 @@ impl Violation for AirflowDagNoScheduleArgument { } } -/// AIR301 +/// AIR002 pub(crate) fn dag_no_schedule_argument(checker: &Checker, expr: &Expr) { if !checker.semantic().seen_module(Modules::AIRFLOW) { return; diff --git a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR301_AIR301.py.snap b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR002_AIR002.py.snap similarity index 59% rename from crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR301_AIR301.py.snap rename to crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR002_AIR002.py.snap index 6407aa9ab2..3d4ac0706c 100644 --- a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR301_AIR301.py.snap +++ b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR002_AIR002.py.snap @@ -1,20 +1,21 @@ --- source: crates/ruff_linter/src/rules/airflow/mod.rs +snapshot_kind: text --- -AIR301.py:4:1: AIR301 DAG should have an explicit `schedule` argument +AIR002.py:4:1: AIR002 DAG should have an explicit `schedule` argument | 2 | from airflow.timetables.simple import NullTimetable 3 | 4 | DAG(dag_id="class_default_schedule") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR301 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AIR002 5 | 6 | DAG(dag_id="class_schedule", schedule="@hourly") | -AIR301.py:13:2: AIR301 DAG should have an explicit `schedule` argument +AIR002.py:13:2: AIR002 DAG should have an explicit `schedule` argument | 13 | @dag() - | ^^^^^ AIR301 + | ^^^^^ AIR002 14 | def decorator_default_schedule(): 15 | pass | diff --git a/ruff.schema.json b/ruff.schema.json index 7b2a63cd96..3c8ec9614b 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -2943,9 +2943,9 @@ "AIR0", "AIR00", "AIR001", + "AIR002", "AIR3", "AIR30", - "AIR301", "AIR302", "AIR303", "ALL",