A `.sqlfluff` settings file I like

When using SQLfluff to format sql files it is possible to set certain formatting rules that should be followed when formatting the the files. These rules can be specified in a .sqlfluff file to be used by SQLfluff.

Below is a .sqlfluff file that I like to use to format dbt compatible SQL files that works in DataBricks:

[sqlfluff]
templater = jinja
dialect = databricks
rules = L001,L010,L011,L012,L014,L019,L020,L021,L022,L023,L030,L036,L050,L054,L002,L003,L004,L034,L013,L038
indent_unit = space
tab_space_size = 4
max_line_length = 120
exclude_rules = AM02
large_file_skip_byte_limit = 0
ignore = templating

# use dbt friendly templater
[sqlfluff:templater:jinja]
apply_dbt_builtins = True

[sqlfluff:rules]
capitalisation.policy = upper  # Or 'upper', 'lower', 'pascal'
comma_style.placement = leading  # Or 'trailing' for comma placement
indentation = true

[sqlfluff:rules:convention.select_trailing_comma]
select_clause_trailing_comma = forbid

[sqlfluff:layout:type:comma]
line_position = leading

[sqlfluff:rules:capitalisation.keywords]
# Keywords
capitalisation_policy = upper

[sqlfluff:layout:type:alias_expression]
# We want non-default spacing _before_ the alias expressions.
spacing_before = align
# We want to align them within the next outer select clause.
# This means for example that alias expressions within the FROM
# or JOIN clause would _not_ be aligned with them.
align_within = select_clause
# The point at which to stop searching outward for siblings, which
# in this example would likely be the boundary of a CTE. Stopping
# when we hit brackets is usually a good rule of thumb for this
# configuration.
align_scope = bracketed

Send a Comment

Your email address will not be published.