SQLFluff is a dialect-flexible and configurable SQL linter it works with Jinja templating and dbt™️. SQLFluff will auto-fix most linting errors, allowing you to focus your time on what matters.
Paradime provides an integration out of the box for you to run SQLFluff in your dbt™️ project.
Configuration
Create the .sqlfluff configuration file
To get started simply you will need to create a file called .sqlfluff in your dbt™️ root directory (this is in the same directory where your dbt_project.yml lives.
Set your configuration file by adding supported rules
Now you will need to add your own configuration to decide which rules to enforce when running SQLFluff in the Paradime terminal.
You can copy and paste the below template to get started with some simple rules. Make sure to update line 4 with the appropriate sql dialect based on your data warehouse provider.
.sqlfluff
[sqlfluff]# Supported dialects https://docs.sqlfluff.com/en/stable/dialects.html# Or run 'sqlfluff dialects in the paradime terminal'dialect = snowflake#<--- update the dialect based on your connected data warehousetemplater = dbt[sqlfluff:templater:dbt]project_dir = ./# Comma separated list of rules to exclude, or None# See https://docs.sqlfluff.com/en/stable/configuration.html#enabling-and-disabling-rules# AM04 (ambiguous.column_count) and ST06 (structure.column_order) are# two of the more controversial rules included to illustrate usage.exclude_rules = ambiguous.column_count, structure.column_order# The standard max_line_length is 80 in line with the convention of# other tools and several style guides. Many projects however prefer# something a little longer.# Set to zero or negative to disable checks.max_line_length = 120# If using the dbt templater, we recommend setting the project dir.[sqlfluff:indentation]# While implicit indents are not enabled by default. Many of the# SQLFluff maintainers do use them in their projects.allow_implicit_indents = true# The default configuration for aliasing rules is "consistent"# which will auto-detect the setting from the rest of the file. This# is less desirable in a new project and you may find this (slightly# more strict) setting more useful.[sqlfluff:rules:aliasing.table]aliasing = explicit[sqlfluff:rules:aliasing.column]aliasing = explicit[sqlfluff:rules:aliasing.length]min_alias_length = 3# The default configuration for capitalization rules is "consistent"# which will auto-detect the setting from the rest of the file. This# is less desirable in a new project and you may find this (slightly# more strict) setting more useful.# Typically we find users rely on syntax highlighting rather than# capitalization to distinguish between keywords and identifiers.# Clearly, if your organization has already settled on uppercase# formatting for any of these syntax elements then set them to "upper".# See https://stackoverflow.com/questions/608196/why-should-i-capitalize-my-sql-keywords-is-there-a-good-reason[sqlfluff:rules:capitalisation.keywords]capitalisation_policy = lower[sqlfluff:rules:capitalisation.identifiers]capitalisation_policy = lower[sqlfluff:rules:capitalisation.functions]extended_capitalisation_policy = lower[sqlfluff:rules:capitalisation.literals]capitalisation_policy = lower[sqlfluff:rules:capitalisation.types]extended_capitalisation_policy = lower
You can check all the rules to help you manage code readability at the link below.
Running SQLFluff
SQLFluff provides a CLI to execute commands and lint your sql files in your dbt™️ project.
With Paradime you can execute SQLFluff with one click using the Prettify button in the terminal toolbar.
Simply open the file you want to lint and click on the Prettify button.