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
.sqlfluffwithdialectand (for dbt)templater = dbt. - Run
sqlfluff lint models/on pull requests. - Optionally run
sqlfluff fixlocally to auto-correct.
.sqlfluff
.sqlfluff
[sqlfluff]
dialect = snowflake
templater = dbt
max_line_length = 120
[sqlfluff:indentation]
tab_space_size = 4Workflow
.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 snowflakeGotchas
- 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
How to Lint and Type-Check Python Data Code With ruff and mypy in CIRun ruff and mypy in CI over pipeline Python so lint errors and type mistakes in transformation and DAG code…
How to Test SQL Transformations With DuckDB in CIUnit-test SQL transformation logic in CI with an in-process DuckDB database, loading fixtures and asserting o…