# SQLFluff

Paradime provides native integration with SQLFluff, enabling automatic linting and formatting of SQL files in your dbt™ project directly from the IDE. This integration helps maintain consistent code style and catch potential SQL issues early, with built-in support for dbt™ and Jinja templating.

### Integration Features

* One-click SQL linting through the Lint button
* Built-in dbt™ templating support
* Native IDE integration
* Customizable linting rules
* Auto-fix capabilities for common issues

***

### Using the Integration

1. Open a `.sql` file in your editor
2. Click the **Lint** button in the [Command Panel](https://docs.paradime.io/app-help/documentation/code-ide/command-panel)
3. Review the changes made in [Git Lite](https://docs.paradime.io/app-help/documentation/code-ide/left-panel/git-lite)
   * Syntax errors
   * Style violations
   * Formatting suggestions
4. If satisfied with Lint updates, [Commit and Push](https://docs.paradime.io/app-help/code-ide/left-panel/git-lite#commit-and-push-your-changes) your changes to your remote branch.&#x20;

<figure><img src="https://2337193041-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHET0AD04uHMgdeLAjptq%2Fuploads%2FOv5V2apr4QnWmXiqvUHd%2Fimage.png?alt=media&#x26;token=dbe77506-5642-47f9-8ef1-b2964850c862" alt=""><figcaption><p>Using the Lint button for .sql file using SQLfluff</p></figcaption></figure>

### Configuration

Configure SQLFluff by creating a `.sqlfluff` file in your dbt™ project root directory:

1. Create a `.sqlfluff` file in your dbt™ project root directory (same location as your `dbt_project.yml`)
2. Add your configuration:

{% code title=".sqlfluff example file" %}

```yaml
[sqlfluff]
# Supported dialects https://docs.sqlfluff.com/en/stable/dialects.html
dialect = snowflake
templater = dbt

# 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:templater:dbt]
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 = upper

[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
```

{% endcode %}

{% hint style="info" %}
Visit [SQLfluff documentation](https://docs.sqlfluff.com/en/stable/configuration.html) for a complete list of configuration options.
{% endhint %}

{% @arcade/embed flowId="M3tkMiQ8rJHKsjustE4s" url="<https://app.arcade.software/share/M3tkMiQ8rJHKsjustE4s>" %}

{% hint style="info" %}
Want to automate SQLfluff linting? Learn how to set up [SQLfluff pre-commit hooks](https://docs.paradime.io/app-help/documentation/integrations/code-ide/pre-commit/sqlfluff-hooks) to automatically lint SQL files before each commit.
{% endhint %}

***

### Common Rules

SQLFluff enforces several key formatting rules:

* Consistent keyword capitalization
* Required table aliasing
* Maximum line length
* Proper indentation
* Column ordering

### dbt™ Support

The integration automatically handles dbt™-specific features:

* Jinja templating
* ref() and source() functions
* dbt™ macros
* Project configurations
