Capitalisation Rules
This section contains 5 rule(s) related to capitalisation.
Rule Summary
| Code | Name | Aliases | Fix Compatible |
|---|---|---|---|
| CP01 | capitalisation.keywords | L010 | ✅ |
| CP02 | capitalisation.identifiers | L014 | ✅ |
| CP03 | capitalisation.functions | L030 | ✅ |
| CP04 | capitalisation.literals | L040 | ✅ |
| CP05 | capitalisation.types | L063 | ✅ |
CP01: capitalisation.keywords
Inconsistent capitalisation of keywords.
| Property | Value |
|---|---|
| Name | capitalisation.keywords |
| Aliases | L010 |
| Groups | all, core, capitalisation |
| Auto-fixable | Yes ✅ |
Anti-pattern
In this example, select is in lower-case whereas FROM is in upper-case.
select
a
FROM fooBest practice
Make all keywords either in upper-case or in lower-case.
SELECT
a
FROM foo
-- Also good
select
a
from fooConfiguration
| Option | Description |
|---|---|
capitalisation_policy | The capitalisation policy to enforce. Must be one of ['consistent', 'upper', 'lower', 'capitalise']. |
ignore_words | Comma separated list of words to ignore from rule. |
ignore_words_regex | Words 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.
| Property | Value |
|---|---|
| Name | capitalisation.identifiers |
| Aliases | L014 |
| Groups | all, core, capitalisation |
| Auto-fixable | Yes ✅ |
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.
select
a,
B
from fooIn 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.
select
col_1 + Col_2 as COL_3,
"COL_4" as Col_5
from Foo as BARBest practice
Ensure all unquoted identifiers are either in upper-case or in lower-case.
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 barConfiguration
| Option | Description |
|---|---|
extended_capitalisation_policy | The 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_words | Comma separated list of words to ignore from rule. |
ignore_words_regex | Words 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_policy | Types 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.
| Property | Value |
|---|---|
| Name | capitalisation.functions |
| Aliases | L030 |
| Groups | all, core, capitalisation |
| Auto-fixable | Yes ✅ |
Anti-pattern
In this example, the two SUM functions don't have the same capitalisation.
SELECT
sum(a) AS aa,
SUM(b) AS bb
FROM fooBest practice
Make the case consistent.
SELECT
sum(a) AS aa,
sum(b) AS bb
FROM fooConfiguration
| Option | Description |
|---|---|
extended_capitalisation_policy | The 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_words | Comma separated list of words to ignore from rule. |
ignore_words_regex | Words 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.
| Property | Value |
|---|---|
| Name | capitalisation.literals |
| Aliases | L040 |
| Groups | all, core, capitalisation |
| Auto-fixable | Yes ✅ |
Anti-pattern
In this example, null and false are in lower-case whereas TRUE is in upper-case.
select
a,
null,
TRUE,
false
from fooBest practice
Ensure all literal null/true/false literals are consistently upper or lower case
select
a,
NULL,
TRUE,
FALSE
from foo
-- Also good
select
a,
null,
true,
false
from fooConfiguration
| Option | Description |
|---|---|
capitalisation_policy | The capitalisation policy to enforce. Must be one of ['consistent', 'upper', 'lower', 'capitalise']. |
ignore_words | Comma separated list of words to ignore from rule. |
ignore_words_regex | Words 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.
| Property | Value |
|---|---|
| Name | capitalisation.types |
| Aliases | L063 |
| Groups | all, core, capitalisation |
| Auto-fixable | Yes ✅ |
Anti-pattern
In this example, int and unsigned are in lower-case whereas VARCHAR is in upper-case.
CREATE TABLE t (
a int unsigned,
b VARCHAR(15)
);Best practice
Ensure all datatypes are consistently upper or lower case
CREATE TABLE t (
a INT UNSIGNED,
b VARCHAR(15)
);Configuration
| Option | Description |
|---|---|
extended_capitalisation_policy | The 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_words | Comma separated list of words to ignore from rule. |
ignore_words_regex | Words 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 $. |