Skip to main content

Module utils

Module utils 

Source

Functions§

capitalise
Capitalise the first letter and lowercase the rest. Used by CP01 and CP03 for the Capitalise policy.
check_capitalisation
Check capitalisation of a token and return a violation if it doesn’t match. Shared by CP01, CP04, CP05 to avoid duplicating violation creation.
collect_matching_tokens
Collect all leaf tokens from a CST that match a filter predicate. Used by CP rules in consistent mode to gather all tokens of a category.
determine_majority_case
Determine the majority case from a list of token texts. Returns "upper" or "lower". Mixed-case tokens are skipped (always violations). On tie, defaults to "upper".
extract_alias_name
Extract the alias name from an AliasExpression. The alias name is the last Identifier or QuotedIdentifier before any non-trivia, non-keyword segment (scanning from the end).
find_keyword_in_children
Find a keyword by case-insensitive name in children. Returns (index, segment).
first_non_trivia
Return the first non-trivia child segment.
has_as_keyword
Check if an AliasExpression’s children contain an explicit AS keyword.
has_trailing_newline
Check if a segment ends with a Newline (possibly preceded by Whitespace). Used by layout rules (LT07, LT14) to detect newlines absorbed into clause bodies.
insert_as_keyword_fix
Generate a fix that inserts “AS “ before the last non-trivia child (the alias name). Used by AL01 and AL02.
is_false_alias
Check if the “alias name” in an AliasExpression is actually a misidentified SQL keyword (e.g. OVER in window functions). Returns true if the alias looks like a false positive.
is_in_table_context
Check if the current rule context is a table alias (parent is FROM or JOIN clause).
last_non_trivia
Return the last non-trivia child segment.