Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nenkie76 opened this issue Jun 5, 2024 · 2 comments · Fixed by #625
Closed

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

nenkie76 opened this issue Jun 5, 2024 · 2 comments · Fixed by #625
Labels
bug Something isn't working

Comments

@nenkie76
Copy link

nenkie76 commented Jun 5, 2024

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]']
@tconbeer
Copy link
Owner

tconbeer commented Jun 11, 2024

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

@tconbeer tconbeer added the bug Something isn't working label Jun 11, 2024
@tconbeer tconbeer changed the title sqlfmt keeps adding \tab before every line wrapped with triple quotes Unstable indentation in jinja set tag with triple-quoted, multiline strings Jun 11, 2024
@nenkie76
Copy link
Author

@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"
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants