Sqruff started its life aiming to be an exact replacement for sqlfluff, but it is slowly diverging. Key differences include:
Accurate dialect definitions: Unlike sqlfluff, sqruff aims for dialect definitions that accurately reflect the target SQL dialect. Sqruff only concerns itself with formatting valid SQL code rather than aiming to fix partially correct code.
Configuration: While sqruff's configuration format is similar to sqlfluff, it will slowly diverge over time as sqruff develops its own identity.
Dialects Supported
Sqruff currently supports the following SQL dialects:
ANSI SQL - Standard SQL syntax - This dialect is used by default
Either download the binary from the releases page with cargo binstall or compile it yourself with cargo:
cargo binstall sqruff
cargo install sqruff
GitHub Action
You can also use the GitHub Action to install and run sqruff in your CI/CD pipeline. Inside a GitHub Action, sqruff automatically outputs linting results in the GitHub format so they can be easily viewed in the PR tab.
To fix a single file or a set of files, run the following command:
sqruff fix <file/paths/directory>
Configuration
Settings for SQL dialect, indentation, capitalization, and other linting/style options are configured in a .sqruff file. This file should be located in the directory where Sqruff is being run.
The following example highlights a few configuration points: setting the dialect to sqlite, turning on all rules except AM01 and AM02, and configuring some indentation settings. For a comprehensive list of configuration options, see the default configuration file. You can also refer to the rules documentation for more information on configuring specific rules.
[sqruff]
dialect = sqlite
exclude_rules = AM01,AM02
rules = all
[sqruff:indentation]
indent_unit = space
tab_space_size = 4
indented_joins = True
Ignoring files
Like .ignore files, sqruff ignores files and folders specified in a .sqruffignore file placed in the root of where the command is run. For example, if placed in .sqruffignore, the following code will ignore .hql files and files in any directory named temp:
# ignore ALL .hql files
*.hql
# ignore ALL files in ANY directory named temp
temp/
Ignoring errors
The NoQA directive is a way to disable specific rules or all rules for a specific line or range of lines. Similar to flake8’s ignore, individual lines can be ignored by adding -- noqa to the end of the line.
Ignoring single-line errors
The following example will ignore all errors on the line where it is placed:
-- Ignore all errors
SeLeCt 1 from tBl ; -- noqa
-- Ignore rule CP02 & rule CP03
SeLeCt 1 from tBl ; -- noqa: CP02,CP03
Ignoring multiple line errors
Similar to pylint’s “pylint directive”, ranges of lines can be ignored by adding -- noqa:disable=<rule>[,...] | all to the line. Following this directive, specified rules (or all rules, if “all” was specified) will be ignored until a corresponding -– noqa:enable=<rule>[,…] | all.
For example:
-- Ignore rule AL02 from this line forward
SELECT col_a a FROM foo -- noqa: disable=AL02
-- Ignore all rules from this line forward
SELECT col_a a FROM foo -- noqa: disable=all
-- Enforce all rules from this line forward
SELECT col_a a FROM foo -- noqa: enable=all
Help
To get help on the available commands and options, run the following command:
sqruff --help
For all the details on the CLI commands and options, see the CLI documentation.
Docs
For more details, see the documents in the docs folder, which contains: