Skip to content

Suggestion: Even more opinionated handling of whitespace around CTEs  #227

@nfcampos

Description

@nfcampos

Describe the bug
Currently whitespace around CTEs is preserved sometimes, which for me again isn't desired, but I understand if this is intended and not something you want to change

To Reproduce

with






    line_items as (





        select * from {{ ref("order_line_items__01_with_financials") }}
        
    ),









    gift_cards as (
        
        
        
        select * from {{ ref("gift_cards") }}
    
    
    
    ),







select *
from line_items





union all





select *
from gift_cards


Expected behavior
ie. when new lines exist around CTEs / other things (see the space before union all) then I expect it to be reduced to a single new line. (I personally would even go further and add those single new lines even if they weren't in the input, but I do understand that's probably a minority opinion)

with

    line_items as (

        select * from {{ ref("order_line_items__01_with_financials") }}

    ),

    gift_cards as (select * from {{ ref("gift_cards") }}),

select *
from line_items

union all

select *
from gift_cards

Actual behavior

with
    line_items as (





        select * from {{ ref("order_line_items__01_with_financials") }}

    ),









    gift_cards as (select * from {{ ref("gift_cards") }}),







select *
from line_items





union all
select *
from gift_cards

Additional context
What is the output of sqlfmt --version?
sqlfmt, version 0.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions