-
-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Hi,
**sqlfluff version: 3.1.1
python version: 3.12.3
dialect: snowflake
OS version: Microsoft Windows 11 Enterprise
Version: 10.0.22631 Build 22631
**
I want all of my column names uppercased in my code once the linter runs. However this happens successfully when I run sqlfluff fix on the command line however it doesn't work using the extension.
I have installed the sqlfluff extension into my VSCode IDE using the following customized .sqlfluff file:
[sqlfluff]
verbose = 0
nocolor = False
dialect = snowflake
templater = jinja
exclude_rules = ambiguous.column_count, structure.column_order, structure.subquery
ignore_templated_areas = True
ignore = templating
max_line_length = 120
large_file_skip_char_limit = 0
large_file_skip_byte_limit = 20000
processes = 0
[sqlfluff:rules:references.qualification]
qualification = 'always'
[sqlfluff:layout:type:comma]
line_position = leading
[sqlfluff:templater:dbt]
project_dir = ./
[sqlfluff:indentation]
indent_unit = space
tab_space_size = 4
indented_joins = False
indented_ctes = False
indented_using_on = True
indented_on_contents = True
indented_then = True
indented_then_contents = True
allow_implicit_indents = False
template_blocks_indent = True
trailing_comments = after
[sqlfluff:rules:aliasing.length]
min_alias_length = 1
[sqlfluff:rules:capitalisation.identifiers]
capitalisation_policy = upper
extended_capitalisation_policy = upper
unquoted_identifiers_policy = all
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper
[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.types]
capitalisation_policy = upper
extended_capitalisation_policy = upper
[sqlfluff:rules:aliasing.table]
aliasing.table = explicit
[sqlfluff:rules:aliasing.column]
aliasing.column = explicit
[sqlfluff:rules:aliasing.expression]
allow_scalar = true
[sqlfluff:rules:layout.spacing]
no_trailing_whitespace = true
extra_whitespace = false
[sqlfluff:rules:convention.not_equal]
preferred_not_equal_style = c_style
I created the below test code (test.sql) and tried to lint it using the extension :

The sqfluff extensions shows the following problems that it had found with the code:

As you can see, the rule CP02 hasn't been identified as a problem in the code although it's defined in the [sqlfluff:rules:capitalisation.identifiers] section and isn't excluded.
When I run the code,
sqlfluff lint test.sql
I get the following report:
$ sqlfluff lint test.sql
== [test.sql] FAIL
L: 1 | P: 1 | CP01 | Keywords must be upper case.
| [capitalisation.keywords]
L: 1 | P: 7 | LT01 | Unnecessary trailing whitespace.
| [layout.spacing]
L: 2 | P: 1 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces. [layout.indent]
L: 2 | P: 2 | LT04 | Found trailing comma ','. Expected only leading near
| line breaks. [layout.commas]
L: 3 | P: 1 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 3 | P: 1 | LT02 | Expected indent of 4 spaces. [layo | [capitalisation.keywords]
L: 4 | P: 6 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 4 | P: 9 | LT12 | Files must end with a single trailing newline.
| [layout.end_of_file]
All Finished π π!
You can see from the report that the lowercase column names have been correctly flagged as a problem (using rule CP02)
and when I then run
$ sqlfluff fix test.sql
==== finding fixable violations ====
== [test.sql] FAIL
L: 1 | P: 1 | CP01 | Keywords must be upper case.
| [capitalisation.keywords]
L: 1 | P: 7 | LT01 | Unnecessary trailing whitespace.
| [layout.spacing]
L: 2 | P: 1 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces. [layout.indent]
L: 2 | P: 2 | LT04 | Found trailing comma ','. Expected only leading near
| line breaks. [layout.commas]
L: 3 | P: 1 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 3 | P: 1 | LT02 | Expected indent of 4 spaces. [layout.indent]
L: 4 | P: 1 | CP01 | Keywords must be upper case.
| [capitalisation.keywords]
L: 4 | P: 6 | CP02 | Unquoted identifiers must be upper case.
| [capitalisation.identifiers]
L: 4 | P: 9 | LT12 | Files must end with a single trailing newline.
| [layout.end_of_file]
== [test.sql] FIXED
10 fixable linting violations found
the problems are fixed and the test code now looks like this which is the expected result:

Does rule CP02 work when using the extension to uppercase column names ?
Thanks