Skip to content

Capitalisation Rules

This section contains 5 rule(s) related to capitalisation.

Rule Summary

CodeNameAliasesFix Compatible
CP01capitalisation.keywordsL010
CP02capitalisation.identifiersL014
CP03capitalisation.functionsL030
CP04capitalisation.literalsL040
CP05capitalisation.typesL063

CP01: capitalisation.keywords

Inconsistent capitalisation of keywords.

PropertyValue
Namecapitalisation.keywords
AliasesL010
Groupsall, core, capitalisation
Auto-fixableYes ✅

Anti-pattern

In this example, select is in lower-case whereas FROM is in upper-case.

sql
select
    a
FROM foo

Best practice

Make all keywords either in upper-case or in lower-case.

sql
SELECT
    a
FROM foo

-- Also good

select
    a
from foo

Configuration

OptionDescription
capitalisation_policyThe capitalisation policy to enforce. Must be one of ['consistent', 'upper', 'lower', 'capitalise'].
ignore_wordsComma separated list of words to ignore from rule.
ignore_words_regexWords to ignore from rule if they are a partial match for the regular expression. To ignore only full matches you can use ^ (beginning of text) and $ (end of text). Due to regular expression operator precedence, it is good practice to use parentheses around everything between ^ and $.

CP02: capitalisation.identifiers

Inconsistent capitalisation of unquoted identifiers.

PropertyValue
Namecapitalisation.identifiers
AliasesL014
Groupsall, core, capitalisation
Auto-fixableYes ✅

This rule applies to all unquoted identifiers, whether references or aliases, and whether they refer to columns or other objects (such as tables or schemas).

NOTE

In most dialects, unquoted identifiers are treated as case-insensitive and so the fixes proposed by this rule do not change the interpretation of the query. HOWEVER, some databases (notably bigquery_dialect_ref, trino_dialect_ref and clickhouse_dialect_ref) do take the casing of unquoted identifiers into account when determining the casing of the column heading in the result.

As this feature is only present in a few dialects, and not widely understood by users, we regard it as an antipattern. It is more widely understood that if the case of an identifier matters, then it should be quoted. If you, or your organisation, do wish to rely on this feature, we recommend that you disabled this rule (see ruleselection).

Anti-pattern

In this example, unquoted identifier a is in lower-case but B is in upper-case.

sql
select
    a,
    B
from foo

In this more complicated example, there are a mix of capitalisations in both reference and aliases of columns and tables. That inconsistency is acceptable when those identifiers are quoted, but not when unquoted.

sql
select
    col_1 + Col_2 as COL_3,
    "COL_4" as Col_5
from Foo as BAR

Best practice

Ensure all unquoted identifiers are either in upper-case or in lower-case.

sql
select
    a,
    b
from foo;

-- ...also good...

select
    A,
    B
from foo;

--- ...or for comparison with our more complex example, this too:

select
    col_1 + col_2 as col_3,
    "COL_4" as col_5
from foo as bar

Configuration

OptionDescription
extended_capitalisation_policyThe capitalisation policy to enforce, extended with PascalCase, snake_case, and camelCase. This is separate from capitalisation_policy as it should not be applied to keywords.Camel, Pascal, and Snake will never be inferred when the policy is set to consistent. This is because snake can cause destructive changes to the identifier, and unlinted code is too easily mistaken for camel and pascal. If, when set to consistent, no consistent case is found, it will default to upper. Must be one of ['consistent', 'upper', 'lower', 'pascal', 'capitalise', 'snake', 'camel'].
ignore_wordsComma separated list of words to ignore from rule.
ignore_words_regexWords to ignore from rule if they are a partial match for the regular expression. To ignore only full matches you can use ^ (beginning of text) and $ (end of text). Due to regular expression operator precedence, it is good practice to use parentheses around everything between ^ and $.
unquoted_identifiers_policyTypes of unquoted identifiers to flag violations for. Must be one of ['all', 'aliases', 'column_aliases', 'table_aliases'].

CP03: capitalisation.functions

Inconsistent capitalisation of function names.

PropertyValue
Namecapitalisation.functions
AliasesL030
Groupsall, core, capitalisation
Auto-fixableYes ✅

Anti-pattern

In this example, the two SUM functions don't have the same capitalisation.

sql
SELECT
    sum(a) AS aa,
    SUM(b) AS bb
FROM foo

Best practice

Make the case consistent.

sql
SELECT
    sum(a) AS aa,
    sum(b) AS bb
FROM foo

Configuration

OptionDescription
extended_capitalisation_policyThe capitalisation policy to enforce, extended with PascalCase, snake_case, and camelCase. This is separate from capitalisation_policy as it should not be applied to keywords.Camel, Pascal, and Snake will never be inferred when the policy is set to consistent. This is because snake can cause destructive changes to the identifier, and unlinted code is too easily mistaken for camel and pascal. If, when set to consistent, no consistent case is found, it will default to upper. Must be one of ['consistent', 'upper', 'lower', 'pascal', 'capitalise', 'snake', 'camel'].
ignore_wordsComma separated list of words to ignore from rule.
ignore_words_regexWords to ignore from rule if they are a partial match for the regular expression. To ignore only full matches you can use ^ (beginning of text) and $ (end of text). Due to regular expression operator precedence, it is good practice to use parentheses around everything between ^ and $.

CP04: capitalisation.literals

Inconsistent capitalisation of boolean/null literal.

PropertyValue
Namecapitalisation.literals
AliasesL040
Groupsall, core, capitalisation
Auto-fixableYes ✅

Anti-pattern

In this example, null and false are in lower-case whereas TRUE is in upper-case.

sql
select
    a,
    null,
    TRUE,
    false
from foo

Best practice

Ensure all literal null/true/false literals are consistently upper or lower case

sql
select
    a,
    NULL,
    TRUE,
    FALSE
from foo

-- Also good

select
    a,
    null,
    true,
    false
from foo

Configuration

OptionDescription
capitalisation_policyThe capitalisation policy to enforce. Must be one of ['consistent', 'upper', 'lower', 'capitalise'].
ignore_wordsComma separated list of words to ignore from rule.
ignore_words_regexWords to ignore from rule if they are a partial match for the regular expression. To ignore only full matches you can use ^ (beginning of text) and $ (end of text). Due to regular expression operator precedence, it is good practice to use parentheses around everything between ^ and $.

CP05: capitalisation.types

Inconsistent capitalisation of datatypes.

PropertyValue
Namecapitalisation.types
AliasesL063
Groupsall, core, capitalisation
Auto-fixableYes ✅

Anti-pattern

In this example, int and unsigned are in lower-case whereas VARCHAR is in upper-case.

sql
CREATE TABLE t (
    a int unsigned,
    b VARCHAR(15)
);

Best practice

Ensure all datatypes are consistently upper or lower case

sql
CREATE TABLE t (
    a INT UNSIGNED,
    b VARCHAR(15)
);

Configuration

OptionDescription
extended_capitalisation_policyThe capitalisation policy to enforce, extended with PascalCase, snake_case, and camelCase. This is separate from capitalisation_policy as it should not be applied to keywords.Camel, Pascal, and Snake will never be inferred when the policy is set to consistent. This is because snake can cause destructive changes to the identifier, and unlinted code is too easily mistaken for camel and pascal. If, when set to consistent, no consistent case is found, it will default to upper. Must be one of ['consistent', 'upper', 'lower', 'pascal', 'capitalise', 'snake', 'camel'].
ignore_wordsComma separated list of words to ignore from rule.
ignore_words_regexWords to ignore from rule if they are a partial match for the regular expression. To ignore only full matches you can use ^ (beginning of text) and $ (end of text). Due to regular expression operator precedence, it is good practice to use parentheses around everything between ^ and $.

Released under the MIT License.