Repository: astral-sh/ruff
File: crates/ruff_linter/src/rules/airflow/rules/function_signature_change_in_3.rs (Rust)

Code before:
                    },
                },
                attr.range(),
            );
        }
    }
}

fn check_constructor_arguments(
    checker: &Checker,
    qualified_name: &QualifiedName,
    arguments: &Arguments,
    func: &Expr,
) {
    if let ["airflow", "Dataset"]
    | ["airflow", "datasets", "Dataset"]
    | ["airflow", "sdk", "Asset"] = qualified_name.segments()
    {
        if let Some(second_arg) = arguments.find_positional(1) {
            if is_dict_expression(checker, second_arg) {
                let function_name = qualified_name.segments().last().unwrap_or(&"").to_string();
                checker.report_diagnostic(
                    Airflow3IncompatibleFunctionSignature {
                        function_name,
                        change_type: FunctionSignatureChangeType::PositionalArgumentChange {
                            message: "Use keyword argument `extra=` instead of passing a dict as the second positional argument (e.g., `Asset(name=..., uri=..., extra=...)`)",
                        },
                    },
                    func.range(),
                );
            }
        }
    }
}

/// Check if an expression is a dictionary (either a literal or a `dict()` call).
fn is_dict_expression(checker: &Checker, expr: &Expr) -> bool {
    // Check for dict literal: {} or {"key": "value"}
    if expr.is_dict_expr() {
        return true;
    }

    // Check for dict() call
    if let Expr::Call(call) = expr {
        if checker
            .semantic()
            .resolve_builtin_symbol(&call.func)
            .is_some_and(|name| name == "dict")
        {
            return true;
        }

Review comment (suggestion):
```suggestion
                            message: "Use keyword argument `extra` instead of passing a dict as the second positional argument (e.g., `Asset(name=..., uri=..., extra=...)`)",
```

Code after:
                    },
                },
                attr.range(),
            );
        }
    }
}

fn check_constructor_arguments(
    checker: &Checker,
    qualified_name: &QualifiedName,
    arguments: &Arguments,
    func: &Expr,
) {
    if let ["airflow", "Dataset"]
    | ["airflow", "datasets", "Dataset"]
    | ["airflow", "sdk", "Asset"] = qualified_name.segments()
    {
        if let Some(second_arg) = arguments.find_positional(1) {
            if is_dict_expression(checker, second_arg) {
                let function_name = qualified_name.segments().last().unwrap_or(&"").to_string();
                checker.report_diagnostic(
                    Airflow3IncompatibleFunctionSignature {
                        function_name,
                        change_type: FunctionSignatureChangeType::PositionalArgumentChange {
                            message: "Use keyword argument `extra` instead of passing a dict as the second positional argument (e.g., `Asset(name=..., uri=..., extra=...)`)",
                        },
                    },
                    func.range(),
                );
            }
        }
    }
}

/// Check if an expression is a dictionary.
fn is_dict_expression(checker: &Checker, expr: &Expr) -> bool {
    match expr {
        Expr::Dict(_) => true,
        Expr::DictComp(_) => true,
        Expr::Call(call) => checker
            .semantic()
            .resolve_builtin_symbol(&call.func)
            .is_some_and(|name| name == "dict"),
        Expr::Name(name) => checker
            .semantic()
            .resolve_name(name)
            .map(|id| checker.semantic().binding(id))
            .is_some_and(|binding| typing::is_dict(binding, checker.semantic())),
        _ => false,
    }