sqlfluff-lint: returns linting errors.sqlfluff-fix: attempts to fix rule violations.
sqlfluff-lint
What it does
Checks SQL files against SQLFluff rules to enforce consistent formatting and catch potential SQL anti-patterns.When to use it
Use this hook when you want to enforce consistent SQL style across your project. It’s particularly useful for teams working on shared SQL codebases where maintaining consistent style is important.
Checks SQL files against SQLFluff rules to enforce consistent formatting and catch potential SQL anti-patterns.When to use it
Use this hook when you want to enforce consistent SQL style across your project. It’s particularly useful for teams working on shared SQL codebases where maintaining consistent style is important.
--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
- SQLFluff installed (
pip install sqlfluff) .sqlfluffconfig file (optional but recommended)
- 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
What it does
Automatically fixes SQL files to conform to SQLFluff rules and formatting standards.When to use it
Use this hook when you want to automatically format SQL files according to your team’s standards. It saves time by fixing common formatting issues before they’re committed.
Automatically fixes SQL files to conform to SQLFluff rules and formatting standards.When to use it
Use this hook when you want to automatically format SQL files according to your team’s standards. It saves time by fixing common formatting issues before they’re committed.
--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
Using SQLFluff with dbt
What it does
Enables SQLFluff to understand and lint dbt-specific SQL syntax, including dbt macros, ref/source functions, and Jinja templating.When to use it
Use this configuration when you’re using SQLFluff in a dbt project. It allows SQLFluff to properly parse and lint SQL files that contain dbt-specific syntax and templating.
Enables SQLFluff to understand and lint dbt-specific SQL syntax, including dbt macros, ref/source functions, and Jinja templating.When to use it
Use this configuration when you’re using SQLFluff in a dbt project. It allows SQLFluff to properly parse and lint SQL files that contain dbt-specific syntax and templating.
.sqlfluff
Using rules in your .sqlfluff file
To point pre-commit to use your custom.sqlfluff rules file, you need to either:
- Put the
.sqlflufffile in your repository root (default behavior), or - Specify a custom path in your pre-commit configuration
--config argument tells SQLFluff where to find your rules configuration. The path should be relative to your repository root.
See also:
Sql Fluff
Best Practices
- Create a
.sqlfluffconfig file for project-specific rules. See also sql-fluff.md configurations - Run fix before lint to automatically resolve simple issues
- Use
--exclude-rulesfor 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