> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coderabbit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SQLFluff

> How CodeRabbit runs SQLFluff to lint SQL files in pull requests.

[SQLFluff](https://github.com/sqlfluff/sqlfluff) is a dialect-flexible SQL linter for standardizing SQL code. CodeRabbit runs SQLFluff version 4.2.2 in a secure sandbox and reports lint findings on changed SQL files.

## Files

SQLFluff runs on files with the `.sql` extension.

## Configuration

To enable or disable SQLFluff, use your `.coderabbit.yaml` file or the CodeRabbit web UI:

<Tabs>
  <Tab title=".coderabbit.yaml">
    ```yaml .coderabbit.yaml theme={null}
    reviews:
      tools:
        sqlfluff:
          enabled: true
          config_file: "custom/.sqlfluff"
    ```
  </Tab>

  <Tab title="Web UI">
    Go to **Reviews > Tools > SQLFluff** in your organization or repository settings and toggle SQLFluff `on` or `off`.
  </Tab>
</Tabs>

SQLFluff supports the following configuration option:

* `config_file` (default: unset): Optional path to a SQLFluff configuration file relative to the repository. Use this when the config file is not named one of SQLFluff's default filenames.

When `config_file` is not set, CodeRabbit looks for these SQLFluff config files:

* `setup.cfg`
* `tox.ini`
* `pep8.ini`
* `.sqlfluff`
* `pyproject.toml`

CodeRabbit uses a SQLFluff config file only when it contains a `[sqlfluff]` or `[tool.sqlfluff]` section. If no valid SQLFluff config file is found, CodeRabbit writes a temporary config based on the selected review profile and detected SQL dialect.

## Profile behavior

When no valid SQLFluff config file is found, CodeRabbit generates a temporary config whose rule set depends on the active review profile:

* **Chill** uses a narrow default rule set focused on SQL issues that can cause incorrect results or runtime failures, including bare `UNION`, mismatched set-operation column counts, implicit cross joins, duplicate table aliases, and `NULL` comparisons with `=` or `!=`.
* **Assertive** uses a broader semantic and structural rule set, including checks for unused aliases or CTEs, duplicate aliases, identifier portability, unnecessary `CASE` expressions, misleading `DISTINCT` syntax, unreferenced joined tables, and T-SQL procedure issues. Layout, capitalization, style-preference, and high-noise reference rules remain excluded.

## dbt templater support

CodeRabbit includes `sqlfluff-templater-dbt` 4.2.2, `dbt-core` 1.10.22, and `dbt-duckdb` 1.10.1 with its SQLFluff installation. When your SQLFluff config sets `templater = dbt`, CodeRabbit can compile dbt-templated SQL for linting without requiring your repository to provide the Python templater package.

Before running the dbt templater, CodeRabbit runs a bounded `dbt deps` preflight when the project contains `packages.yml` or `dependencies.yml`. This installs dbt packages into the sandbox for the lint run only. Preflight failures are non-blocking: CodeRabbit still runs SQLFluff when possible, then cleans up `dbt_packages/` and any package lock file that CodeRabbit created.

CodeRabbit resolves dbt projects in repository subdirectories by passing the project directory through `DBT_PROJECT_DIR`. For profile selection, CodeRabbit uses the first available value in this order: the `profile` value in your SQLFluff configuration, the `DBT_PROFILE` environment variable, then the `profile` field in `dbt_project.yml`. Templated profile values in `dbt_project.yml` are ignored.

If the configured dbt profiles directory does not already contain a DuckDB profile, CodeRabbit writes a temporary `profiles.yml` that uses an in-memory DuckDB target for the lint run, then restores the previous profile file after SQLFluff finishes. The generated profile uses the resolved profile name and the `target` value from your SQLFluff config when present; otherwise it defaults to `dev`.

## Security policy and restrictions

SQLFluff runs in a secure sandbox using CodeRabbit's installed SQLFluff, dbt templater, and DuckDB adapter packages. CodeRabbit does not install repository-provided Python packages, custom SQLFluff plugins, third-party dbt adapters, or custom templaters for this integration.

<Info>
  Custom plugins, third-party dbt adapters, and custom templaters that require repository-provided Python packages are not supported.
</Info>

## When CodeRabbit skips SQLFluff

CodeRabbit skips SQLFluff when:

* SQLFluff is disabled in CodeRabbit settings.
* The pull request does not include changed `.sql` files.
* SQLFluff is already running in GitHub workflows.

## Ignored codes

The following SQLFluff codes are automatically ignored:

| Code   | Description                  |
| ------ | ---------------------------- |
| `LT01` | Trailing whitespace          |
| `LT02` | Indentation                  |
| `CP01` | Keyword capitalization       |
| `CP02` | Identifier capitalization    |
| `CP03` | Function name capitalization |
| `CV06` | Convention style checks      |
| `RF02` | Qualified reference style    |
| `RF06` | Reference style checks       |
| `LXR`  | Lexing stage failures        |
| `PRS`  | Parsing stage failures       |
| `TMP`  | Templating stage failures    |

## What's next

<CardGroup cols={1}>
  <Card title="All supported tools" href="/tools/list" icon="list" horizontal>
    Browse the complete list of linters, security analyzers, and CI/CD integrations available in CodeRabbit.
  </Card>

  <Card title="Tools reference" href="/reference/tools-reference" icon="wrench" horizontal>
    Explore detailed specifications and capabilities of all available CodeRabbit tools.
  </Card>

  <Card title="Configuration reference" href="/reference/configuration" icon="settings" horizontal>
    Full reference for all available options, including how to enable, disable, and tune individual tools.
  </Card>
</CardGroup>
