SQLFluff and Linting
Lint SQL with SQLFluff, enforce a house style, and auto-fix common formatting issues.
Why Lint SQL?
SQL is hand-written, easy to format inconsistently. Linting enforces a house style automatically:
- Lower vs UPPER keywords
- Comma at end vs start of line
- Naming conventions for tables, columns
- Indentation
- Anti-patterns (SELECT *, ambiguous joins, etc.)
SQLFluff: The De Facto Linter
Open source, dialect-aware, supports many SQL flavors and works great with dbt:
pip install sqlfluff
sqlfluff lint models/
sqlfluff fix models/ # auto-fix where safe