Skip to content
Latchkey

How to Lint SQL With sqlfluff in CI

sqlfluff lint parses SQL for a given dialect and returns non-zero on violations, so it gates style in CI.

Configure the dialect and templater in .sqlfluff, then run sqlfluff lint over your models directory in the pull request.

Steps

  • Add a .sqlfluff with dialect and (for dbt) templater = dbt.
  • Run sqlfluff lint models/ on pull requests.
  • Optionally run sqlfluff fix locally to auto-correct.

.sqlfluff

.sqlfluff
[sqlfluff]
dialect = snowflake
templater = dbt
max_line_length = 120

[sqlfluff:indentation]
tab_space_size = 4

Workflow

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - run: pip install sqlfluff==3.1.0 sqlfluff-templater-dbt dbt-snowflake
  - run: sqlfluff lint models/ --dialect snowflake

Gotchas

  • The dbt templater needs your adapter installed to compile models before linting.
  • Set the dialect explicitly; the wrong dialect produces spurious parse errors.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →