tconbeer/sqlfmt

Unstable indentation in jinja `set` tag with triple-quoted, multiline strings

Closed this issue · 2 comments

sqlfmt keeps adding \tab before every line wrapped with triple quotes.

Reproduce steps.
One can define a macro, say, to select columns depending on key:

{% macro test(key) %}
   {% set columns_by_source = {
      "a": """
          column_a1,
          column_a2,
          column_a3,
      """,
      "b": """
          column_b1,
          column_b2,
      """,
    } %}
   ....
{% endmacro %}

Now every time, running sqlfmt -k -l 80 ., sqlfmt will add \tab before each line continuously moving rows right.
Locally you can skip -k flag, but then if you have .pre-commit hooks in GitHub, it might prevent from merging as sqlfmt check will always fail.

What is the output of sqlfmt --version?

rev: v0.21.3
hooks:
    - id: sqlfmt
      language_version: python
      additional_dependencies: ['.[jinjafmt]']

Thanks for the report, I can reproduce. I guess the saga with unstable jinja indentation continues. (Related to #138 #176 etc)

@tconbeer , thanks.

I also tried 2 more hacks, which do not work:

  1. wrap with (..)
"a": """(
   column_a1,
   column_a2,
   column_a3,
)""",
  1. use tuple strings
"a": (
   "column_a1,\n"
   "column_a2,\n"
   "column_a3,\n"
),