You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If exclude_rules = L009 is included in the .sqlfluff config when using templater = dbt , then any trailing newlines that are found at the end of a source dbt SQL model should be left as is when running sqlfluff fix my_dbt_model.sql. If no trailing newline exists, do nothing.
Observed Behaviour
When exclude_rules = L009 is included it the .sqlfluff config and using templater = dbt, running sqlfluff fix my_dbt_model.sqlremoves any trailing newlines if they exist in the source dbt SQL models.
This is an undesirable outcome for the following reasons:
Setting exclude_rules = L009 in .sqlfluff should result in leaving any existing trailing newlines (if they exist) as is. Right now, it is actually enforcing the opposite of L009 (i.e., no trailing newlines allowed), not excluding the rule from consideration as the config option suggests.
Including a trailing newline at the end of files is best practice. Not including these will result in pesky No newline at end of file warnings in GitHub. I would guess most users want to keep these trailing newlines
Steps to Reproduce
Hard to share a minimal example since the dbt templater uses the dbt compiler under the covers, so any example will require a dbt_project.
But the gist of the problem would look like...
A .sqlfluff like (per the docs)
[sqlfluff]
templater = dbt
# dbt templating does not keep trailing new lines (L009)
exclude_rules = L009
A dbt model like my_dbt_model.sql (note the trailing newline at end of file)
select*from {{ ref('foo_bar_model') }}
Running sqlfluff fix my_dbt_model.sql will result in (note the trailing newline has been removed!)
select*from {{ ref('foo_bar_model') }}
Version
▶ python --version
Python 3.7.3
▶ sqlfluff --version
sqlfluff, version 0.4.1
Configuration
# For SQLFluff Rules reference, see:
# https://docs.sqlfluff.com/en/stable/rules.html#rules-reference
[sqlfluff]
verbose = 0
nocolor = False
dialect = postgres
templater = dbt
rules = None
exclude_rules = L034
recurse = 0
output_line_length = 80
runaway_limit = 10
ignore = parsing
ignore_templated_areas = True
[sqlfluff:indentation]
indented_joins = False
template_blocks_indent = True
# Some rules can be configured directly from the config common to other rules.
[sqlfluff:rules]
tab_space_size = 4
max_line_length = 80
indent_unit = space
comma_style = trailing
allow_scalar = True
single_table_references = consistent
only_aliases = True
# Some rules have their own specific config.
# All SQLFluff rules can be found at: https://docs.sqlfluff.com/en/stable/rules.html#rules-reference
# When a rule in not listed below, we inherit the default behavior from above.
[sqlfluff:rules:L003]
lint_templated_tokens = True
[sqlfluff:rules:L010] # Keywords
capitalisation_policy = lower
[sqlfluff:rules:L014] # Unquoted identifiers
capitalisation_policy = lower
[sqlfluff:rules:L016]
# Setting to True allows us to copy/paste long URLs as comments
ignore_comment_lines = True
[sqlfluff:rules:L030] # Function names
capitalisation_policy = lower
[sqlfluff:rules:L038]
select_clause_trailing_comma = forbid
[sqlfluff:rules:L040] # Null & Boolean Literals
capitalisation_policy = lower
[sqlfluff:rules:L042]
# By default, allow subqueries in from clauses, but not join clauses.
forbid_subquery_in = join
The text was updated successfully, but these errors were encountered:
GClunies
changed the title
dbt-templater doesn't respect trailing newline when exclude_rules = L009
dbt-templater doesn't respect trailing newline when L009 is NOT in exclude_rules
Apr 6, 2021
GClunies
changed the title
dbt-templater doesn't respect trailing newline when L009 is NOT in exclude_rules
dbt-templater doesn't respect trailing newline when exclude_rules = L009
Apr 6, 2021
Expected Behaviour
If
exclude_rules = L009
is included in the.sqlfluff
config when usingtemplater = dbt
, then any trailing newlines that are found at the end of a source dbt SQL model should be left as is when runningsqlfluff fix my_dbt_model.sql
. If no trailing newline exists, do nothing.Observed Behaviour
When
exclude_rules = L009
is included it the.sqlfluff
config and usingtemplater = dbt
, runningsqlfluff fix my_dbt_model.sql
removes any trailing newlines if they exist in the source dbt SQL models.This is an undesirable outcome for the following reasons:
exclude_rules = L009
in.sqlfluff
should result in leaving any existing trailing newlines (if they exist) as is. Right now, it is actually enforcing the opposite of L009 (i.e., no trailing newlines allowed), not excluding the rule from consideration as the config option suggests.No newline at end of file
warnings in GitHub. I would guess most users want to keep these trailing newlinesSteps to Reproduce
Hard to share a minimal example since the dbt templater uses the dbt compiler under the covers, so any example will require a dbt_project.
But the gist of the problem would look like...
A
.sqlfluff
like (per the docs)A dbt model like
my_dbt_model.sql
(note the trailing newline at end of file)Running
sqlfluff fix my_dbt_model.sql
will result in (note the trailing newline has been removed!)Version
Configuration
The text was updated successfully, but these errors were encountered: