Introduction
Overview of SQL Linting and Formatting
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.
- It is incredibly high performance, outperforming SQLFluff by well over 100X in most scenarios.
- It has a high degree of overlap with SQL Fluff to ensure easy migration for existing SQLFLuff users.
- 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
.
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:
All other rules are turned off by default.
All default lint rules can be automatically fixed with sdf lint --fix
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
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.
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 yourworkspace.sdf.yml
The sdf-args:
config block in a workspace file will override the default configuration.
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
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 |