SQLFluff hooks
Last updated
Was this helpful?
Last updated
Was this helpful?
Using with SQLFluff is a good way to provide automated linting to SQL developers. With , you also get the benefit of only linting/fixing the files that changed.
SQLFluff comes with two hooks:
sqlfluff-lint
: returns linting errors.
sqlfluff-fix
: attempts to fix rule violations.
sqlfluff-lint
Arguments
--dialect
: SQL dialect to use (e.g., postgres, mysql, snowflake)
--exclude-rules
: Comma-separated list of rule codes to exclude
--rules
: Comma-separated list of rule codes to check (defaults to all)
--processes
: Number of parallel processes to use
--ignore
: Comma-separated list of paths to ignore
Example
Requirements
SQLFluff installed (pip install sqlfluff
)
.sqlfluff
config file (optional but recommended)
How it works
Hook identifies all changed SQL files in your commit
Each file is checked against enabled SQLFluff rules
Fails if any rule violations are found
Provides detailed output of rule violations and suggested fixes
sqlfluff-fix
Arguments
--dialect
: SQL dialect to use (e.g., postgres, mysql, snowflake)
--exclude-rules
: Comma-separated list of rule codes to exclude from fixing
--rules
: Comma-separated list of rule codes to fix (defaults to all fixable rules)
--processes
: Number of parallel processes to use
--ignore
: Comma-separated list of paths to ignore
Example
Configuration
Add the dbt templater as an additional dependency in your pre-commit config
Example
Then, configure the dbt templater in your .sqlfluff
To point pre-commit to use your custom .sqlfluff
rules file, you need to either:
Put the .sqlfluff
file in your repository root (default behavior), or
Specify a custom path in your pre-commit configuration
Example
The --config
argument tells SQLFluff where to find your rules configuration. The path should be relative to your repository root.
See also:
Create a .sqlfluff
config file for project-specific rules. See also SQLFluff configurations
Run fix before lint to automatically resolve simple issues
Use --exclude-rules
for exceptions rather than disabling rules globally
Set appropriate line length limits for your team
Document any rule exclusions in your config file
Use consistent SQL dialects across your project