Search before asking
What Happened
I am using pre-commit to format my project files. One of my hooks is sqlfluff-fix.
When running pre-commit run sqlfluff-fix --files <file_name>.sql the comments inside my nested CASE statement were removed. Here is bellow a screenshot of the issue.
In the lines concerned by this issue sqlfluff gives the following error:
"L: 221 | P: 1 | LT02 | Expected indent of 4 spaces. [layout.indent]"

Expected Behaviour
The nested case should have been flattened without removing the comments.
Observed Behaviour
The nested case has been flattened AND the comments inside the original nested case were removed.
How to reproduce
- Create a file called test.sql with the following lines:
SELECT
CASE WHEN SUBSTR(VAR1,10,5)='00' THEN NULL ELSE
CASE
--Comment 1
--Comment 2
WHEN (t2.VAR2 = 'TEST') AND (t2.VAR3 = 'TEST') AND (t2.VAR4 = 'TEST') THEN 1
--Comment 3
WHEN (t2.VAR2 = 'TEST') AND (t2.VAR3 = 'TEST2') AND (t2.VAR4 = 'TEST4') THEN VAR5
ELSE 0
END
END
AS DELTAYTDRATE
FROM
OUR_TABLE t2
- Run sqlfluff-fix on it with the config that is mentionned in this issue
Dialect
bigquery dialect
Version
2.1.2
Configuration
My .sqlfluff file:
[sqlfluff]
dialect = bigquery
# Comma separated list of rules to exclude, or None
# Exclude rule LT05: Line is too long
# Exclude rule CP02: Inconsistent capitalisation of unquoted identifiers
# Exclude rule CV02: Use COALESCE instead of IFNULL or NVL
# Exclude rule ST06: Select wildcards then simple targets before calculations and aggregates.
# Exclude rule ST04: Nested CASE statement in ELSE clause could be flattened (removes comments inside CASE).
exclude_rules = LT05,CP02,CV02,ST06
# Number of passes to run before admitting defeat (default 10)
runaway_limit = 5
# Warn only for rule codes (one of more rule codes, seperated by commas: e.g. LT01,LT02)
# Also works for templating and parsing errors by using TMP or PRS
warnings = LT05,ST04
# Max line length is set by default to be in line with the dbt style guide.
# https://github.com/dbt-labs/corp/blob/main/dbt_style_guide.md
# Set to zero or negative to disable checks.
max_line_length = 99
# CPU processes to use while linting.
# If positive, just implies number of processes.
# If negative or zero, implies number_of_cpus - specified_number.
# e.g. -1 means use all processors but one. 0 means all cpus.
processes = -1
[sqlfluff:indentation]
indented_using_on = False
# allow_implicit_indents = True # doc: https://docs.sqlfluff.com/en/stable/layout.html
[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]
extended_capitalisation_policy = upper
Are you willing to work on and submit a PR to address the issue?
Code of Conduct
Search before asking
What Happened
I am using pre-commit to format my project files. One of my hooks is sqlfluff-fix.

When running
pre-commit run sqlfluff-fix --files <file_name>.sqlthe comments inside my nested CASE statement were removed. Here is bellow a screenshot of the issue.In the lines concerned by this issue sqlfluff gives the following error:
"L: 221 | P: 1 | LT02 | Expected indent of 4 spaces. [layout.indent]"
Expected Behaviour
The nested case should have been flattened without removing the comments.
Observed Behaviour
The nested case has been flattened AND the comments inside the original nested case were removed.
How to reproduce
Dialect
bigquery dialect
Version
2.1.2
Configuration
My .sqlfluff file:
Are you willing to work on and submit a PR to address the issue?
Code of Conduct