sqruff_lib/utils/
identifers.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use sqruff_lib_core::dialects::syntax::SyntaxKind;
use sqruff_lib_core::parser::segments::base::ErasedSegment;

pub fn identifiers_policy_applicable(policy: &str, parent_stack: &[ErasedSegment]) -> bool {
    match policy {
        "all" => true,
        "none" => false,
        _ => {
            let is_alias = parent_stack.last().map_or(false, |last| {
                [
                    SyntaxKind::AliasExpression,
                    SyntaxKind::ColumnDefinition,
                    SyntaxKind::WithCompoundStatement,
                ]
                .into_iter()
                .any(|it| last.is_type(it))
            });

            match policy {
                "aliases" if is_alias => true,
                "column_aliases" if is_alias => !parent_stack
                    .iter()
                    .any(|p| p.is_type(SyntaxKind::FromClause)),
                _ => false,
            }
        }
    }
}