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

# Introduction

> Overview of SQL Linting and Formatting

export const title_0 = 'The SDF Linter'

<Warning>
  {title_0} is currently only available in our preview release. Preview features are not recommended for production use. For more information on how to install or update to the Preview release channel, see [here](/introduction/install#release-tracks).
</Warning>

### Overview

SDF contains an integrated high performance SQL linter and formatter. Linting and formatting are core competencies
of code-hygiene designed ensure code is consistent across your organization, simplify readability, code reviews,
and promote standardization.

SDF's SQL Linter has 4 crucial characteristics.

1. It is incredibly high performance, outperforming SQLFluff by well over 100X in most scenarios.
2. It has a high degree of overlap with SQL Fluff to ensure easy migration for existing SQLFLuff users.
3. It is out-of-the-box compatible with all SDF Jinja and configuration

SDF's auto-formatter works in conjunction with the linter to empower teams to write more unified SQL code.

Using the linter is easy.

* Unless otherwise configured, every SDF workspace has *Default Rules*.
* All files listed in your `includes` paths will be linted.
* Run `sdf lint` to lint sql files
* Run `sdf lint path/to/file.sql` to lint a subset of SQL files
* Run `sdf lint --fix` to fix issues where possible
* Run `sdf format` to format sql files

To create a global linter configuration for your workspace, you can use the `sdf-args` block in your sdf workspace file. These
defaults are command line flags that are implicitly added to each invocation of `sdf lint`.

```yml workspace.sdf.yml  theme={null}
sdf-args
   lint: >
     -w <lint-rule>=<option>
     ...
```

#### Dialect Compatibility

SQL linting is dialect specific. Currently, SDF Lint is only available for the Snowflake and BigQuery SQL dialects. Other dialects are coming soon.

| Dialect   | Availability |
| --------- | ------------ |
| Snowflake | 🟢           |
| BigQuery  | 🟢           |
| Redshift  | 🟡           |
| Trino     | 🔴           |
| SparkSQL  | 🔴           |

#### Default Rules

SDF has a set of default lint rules. Default rules designed to provide a simple configuration for most data teams.
All defaults can be auto-fixed or overwritten through manual configuration.

SDF's lint defaults are equivalent to the following `sdf-args` configuration. If no overrides for `sdf-args` are specified,
any invocation of `sdf lint` will use the default lint defaults. These defaults are as below:

```yml workspace.sdf.yml  theme={null}
sdf-args
   lint: >
      -w capitalization-keywords=consistent 
      -w capitalization-literals=consistent 
      -w capitalization-types=consistent 
      -w capitalization-functions=consistent 
      -w refernces-quoting
      -w structure-else-null
      -w structure-unused-cte
      -w structure-distinct
      -w structure-column-order
      -w convention-terminator
```

<Note>
  All other rules are turned off by default.
</Note>

<Note>
  All default lint rules can be automatically fixed with `sdf lint --fix`
</Note>

### Automatically Fix Issues

* Use `sdf lint --fix` to automatically resolve linting issues where possible
* For issues that can't be automatically fixed, SDF will provide error reports

```sql fix.sql theme={null}
select * FROM test
```

### Ignore Warnings

If you would like to ignore a lint warning for whatever reason, add the
inline comment `-- noqa` to your query. This will prevent that line from being
evaluated by the linter, for all rules.

```sql nofix.sql theme={null}
SeLeCt * from test --noqa
```

### Customize and Configure

* By default, `sdf lint` uses SDF's recommended rules and configuration
* To customize linter rules according to your preferences, override the default settings with a `sdf-args` block in your `workspace.sdf.yml`

<Note>
  The `sdf-args:` config block in a workspace file will override the default configuration.
</Note>

#### Default Rules

Per default, every SDF project has the following linter configuration turned on implicitly.
If you specify your own YML linter configuration, you will **turn off** the default rules and need to specify *all linting rules* yourself.

### Rules Reference

For the full list of rules and configuration options, please visit our
[lint rules reference page](/reference/lint-rules)

| Type   | Configuration                    | SDF Err        | SQLFluff Err | Auto-Fix | Default      |
| ------ | -------------------------------- | -------------- | ------------ | -------- | ------------ |
| Syntax | `capitalization_keywords`        | SDF107         | L010         | ✅        | `consistent` |
| Syntax | `capitalization-literal`         | SDF108, SDF109 | L040         | ✅        | `consistent` |
| Syntax | `capitalization-type`            | SDF110         | L063         | ✅        | `consistent` |
| Syntax | `capitalization-function`        | SDF106         | L030         | ✅        | `consistent` |
| Syntax | `convention-blocked-words`       | SDF124         | L029         | ❌        | `[]`         |
| Syntax | `references-keywords`            | SDF125         | L029         | ❌        | `[]`         |
| Syntax | `references-special-chars`       | SDF117         | L057         | ❌        | `""`         |
| Syntax | `references-quoting`             | SDF118         | L059         | ✅        | `on`         |
| Syntax | `references-consistent`          | SDF112         | L028         | ❌        | `off`        |
| Syntax | `references-qualification`       | SDF116         | L027         | ❌        | `off`        |
| Syntax | `ambiguous-column-references`    | SDF105         | L054         | ❌        | `off`        |
| Syntax | `structure-else-null`            | SDF119         | L035         | ✅        | `on`         |
| Syntax | `structure-simple-case`          | SDF120         | L043         | ❌        | `off`        |
| Syntax | `structure-unused-cte`           | SDF121         | L045         | ✅        | `only`       |
| Syntax | `structure-nested-case`          | SDF122         | L058         | ❌        | `off`        |
| Syntax | `structure-distinct`             | SDF123         | L015         | ✅        | `on`         |
| Syntax | `structure-join-condition-order` | SDF114         | ST09         | ❌        | `off`        |
| Syntax | `structure-column-order`         | SDF115         | L034         | ✅        | `off`        |
| Syntax | `convention-terminator`          | SDF111         | L052         | ✅        | `on`         |
| Syntax | `convention-comma`               | SDF104         | N/A          | ✅        | `on`         |
