Jinja blocks should be indented #317
-
We calculate the (nesting) depth of jinja blocks, but we don't use this for indentation. I think this makes the most sense for simple use cases when you're actually templating SQL, since it makes the structure of the SQL more apparent, and the compiled code will be indented properly: {% set cols = ['a', 'b', 'c'] %}
select
{% for col in cols %}
nullif({{ col }}, "") as {{ col }}
{% endfor %}
from tbl But for crazy all-jinja models/macros, you lose a lot by not having any indentation. (e.g., the incremental materialization). Maybe the right answer is somewhere in between -- don't indent on the first open block, but do indent on any nested blocks? Or we could allow this to be configurable by model, based on the presence of a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
hey @tconbeer! I think I lean towards your middle ground there most of the time! I lean towards indenting every new block of a Jinja operator (except consecutive |
Beta Was this translation helpful? Give feedback.
-
💯 I personally find it more natural everything indented à la python (and have received feedback in that sense as well) I would expect the block in the top comment to be indented like this: {% set cols = ['a', 'b', 'c'] %}
select
{% for col in cols %}
nullif({{ col }}, "") as {{ col }}
{% endfor %}
from tbl Would that make sense to you? |
Beta Was this translation helpful? Give feedback.
💯
I personally find it more natural everything indented à la python (and have received feedback in that sense as well)
I would expect the block in the top comment to be indented like this:
Would that make sense to you?