Skip to content

ST04: Flattening of CASE ... WHEN statements removes comments #4848

@dmohns

Description

@dmohns

Search before asking

  • I searched the issues and found no similar issues.

What Happened

When applying sqlfluff fix the auto fix for ST04 (flattening of CASE ... WHEN statements) removes all comments.

Expected Behaviour

Not 100% clear. Either

  • Comments should be preserved relative to the start of CASE
  • Auto fix should not be possible if comments are present (because the comments may not make complete sense at new location)

Observed Behaviour

SELECT
    CASE
        WHEN FALSE
            THEN "value1"
        WHEN TRUE
            THEN "value2"
    END
FROM table

How to reproduce

Run sqlfluff fix on

SELECT
  CASE
      WHEN FALSE
        THEN "value1"  -- a comment
      ELSE
        CASE
            -- another comment
          WHEN TRUE
            THEN "value2"
        END
    END
FROM table

Dialect

BigQuery (put probably applies to all)

Version

2.1.0

Configuration

default

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions