Skip to content

Configuration

Settings for SQL dialect, indentation, capitalization, and other linting and style options are configured in a .sqruff, .sqruff.ini, sqruff.toml, or pyproject.toml file. Sqruff loads configuration files from the user's home directory and each directory down to the directory where sqruff is run. When linting a file in a subdirectory, it then loads configuration from each directory down to the file. Settings found closer to the file override settings from outer directories.

The following example highlights a few configuration points: setting the dialect to sqlite, turning on all rules except AM01 and AM02, and configuring some indentation settings. For a comprehensive list of configuration options, see the default configuration file. You can also refer to the rules documentation for more information on configuring specific rules.

[sqruff]
dialect = sqlite
exclude_rules = AM01,AM02
rules = all

[sqruff:indentation]
indent_unit = space
tab_space_size = 4
indented_joins = True

The same configuration can be written in TOML:

[tool.sqlfluff.core]
dialect = "sqlite"
exclude_rules = ["AM01", "AM02"]
rules = "all"

[tool.sqlfluff.indentation]
indent_unit = "space"
tab_space_size = 4
indented_joins = true

See sample configurations for more examples.

The warnings setting makes selected violations visible without causing lint to fail. It accepts either rule codes or rule names, for example warnings = LT01,layout.end_of_file.

Keyword line position exclusions

LT14 supports keyword_line_position_exclusions, a comma-separated list of ancestor segment types whose keywords should be left in place. For example, keep ORDER BY inline inside window specifications and aggregate functions while requiring an outer ORDER BY to start a line:

[sqruff:layout:type:orderby_clause]
keyword_line_position = leading
keyword_line_position_exclusions = window_specification, aggregate_order_by

With this configuration, the following passes LT14:

SELECT
    ROW_NUMBER() OVER (PARTITION BY c ORDER BY d) AS e,
    STRING_AGG(a ORDER BY b, c)
FROM f
ORDER BY e

Writing FROM f ORDER BY e instead would fail LT14, which moves the outer ORDER BY onto a new line. The exclusions apply only inside the specified ancestor segments. Use keyword_line_position_exclusions = None to clear inherited exclusions and apply keyword positioning inside those segments too.