Check that airflow module is seen for AIR001 (#14627)

This commit is contained in:
Dhruv Manilawala
2024-11-27 12:55:08 +05:30
committed by GitHub
parent 82c01aa662
commit 0d649f9afd

View File

@@ -2,6 +2,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast as ast;
use ruff_python_ast::Expr;
use ruff_python_semantic::Modules;
use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;
@@ -49,6 +50,10 @@ pub(crate) fn variable_name_task_id(
targets: &[Expr],
value: &Expr,
) -> Option<Diagnostic> {
if !checker.semantic().seen_module(Modules::AIRFLOW) {
return None;
}
// If we have more than one target, we can't do anything.
let [target] = targets else {
return None;
@@ -69,7 +74,7 @@ pub(crate) fn variable_name_task_id(
if !checker
.semantic()
.resolve_qualified_name(func)
.is_some_and(|qualified_name| matches!(qualified_name.segments()[0], "airflow"))
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["airflow", ..]))
{
return None;
}