Skip to content

Commit

Permalink
Issue #628 do not split comments with jinja tags (#642)
Browse files Browse the repository at this point in the history
* fix sqlfmt breaks up depends_on statements across multiple lines, causing an error in parsing #628

* add test to not split comments with jinja tags
  • Loading branch information
ryantimjohn authored Nov 12, 2024
1 parent e9205a9 commit 8c297f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sqlfmt/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def _split_before(cls, text: str, max_length: int) -> Iterator[str]:
"""
if len(text) < max_length:
yield text.rstrip()
elif re.match(r".*({{.*?}}|{%.*?%}).*", text):
# jinja comments are not split
yield text.rstrip()
else:
for idx, char in enumerate(reversed(text[:max_length])):
if char.isspace():
Expand Down
4 changes: 4 additions & 0 deletions tests/data/unformatted/127_more_comments.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- source: https://github.com/tconbeer/sqlfmt/issues/348
-- source: https://github.com/tconbeer/sqlfmt/issues/628
-- depends_on: {{ ref('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') }}
with table_a as (
select
/* Notice that this select statement can fit on a single line without comments */
Expand Down Expand Up @@ -26,6 +28,8 @@ select 1
, 4 -- four inline
)))))__SQLFMT_OUTPUT__(((((
-- source: https://github.com/tconbeer/sqlfmt/issues/348
-- source: https://github.com/tconbeer/sqlfmt/issues/628
-- depends_on: {{ ref('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') }}
with
table_a as (
select
Expand Down

0 comments on commit 8c297f8

Please sign in to comment.