tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
373 stars 15 forks source link

formatting does not work in queries defined as variables #535

Closed mgsnuno closed 7 months ago

mgsnuno commented 7 months ago

Describe the bug formatting does not work in queries defined as variables

To Reproduce format the following:

{% set payment_methods_query %}
select payment_method, payment_amount, payment_currency, payment_date from app_data.payments where payment_date > '2023-03-03' 
{% endset %}

Expected behavior query should be formatted:

{% set payment_methods_query %}
select payment_method, payment_amount, payment_currency, payment_date
from app_data.payments
where payment_date > '2023-03-03'
{% endset %}

Actual behavior nothing is formatted:

{% set payment_methods_query %}
select payment_method, payment_amount, payment_currency, payment_date from app_data.payments where payment_date > '2023-03-03' 
{% endset %}

Additional context sqlfmt, version 0.21.0

tconbeer commented 7 months ago

This is expected behavior; {% set %} blocks contain arbitrary data -- we don't have any way to know that those blocks contain SQL that can be safely formatted.

mgsnuno commented 7 months ago

ok, thank you, would it be possible to tag the blocks we want to be formatted?

tconbeer commented 7 months ago

Feel free to propose a syntax for that as a new discussion; I'm going to close this issue for now.