Basic config for sqlfluff linter. By default it uses postgres dialect.
-
Install python
-
Install sqlfluff
pip install sqlfluff
-
Install vs-code sqlfluff extension for VSCode
-
Open VSCode preferences
-
Search for
sqlfluff
-
Click on
Edit in settings.json
at one of the setting (should be in tabUser
) -
Save .sqlfluff file in somewhere in your computer (e.g.
C:/projects/config/.sqlfluff
) -
Add settings template from ./.vscode/settings.json and modify it to your needs (e.g. change
"sqlfluff.config": "C:/projects/config/.sqlfluff"
to the path where you saved the.sqlfluff
file) -
Save the file
-
Open a
.sql
file and you should see the linter working
- Do steps 1-5 from the installation section
- Save .sqlfluff file in your project (e.g.
${workspaceFolder}/.sqlfluff
) - Add settings template from ./.vscode/settings.json and change
sqlfluff.config
to the sqlfluff config file path in your project (e.g.${workspaceFolder}/.sqlfluff
)) - Save the file
- Open a
.sql
file and you should see the linter working
- You can use
Ctrl + Shift + P
to open the command palette and search forsqlfluff
to see all the available commands (vs-code default shortcut) - You can use
Ctrl + Alt + F
to format the current file (vs-code default shortcut) - Run
sqlfluff parse .\path\to\sql\code_file.sql --dialect postgres
to see the parsed code (you can change the dialect to any of the supported dialects). Replace.\path\to\sql\code_file.sql
with the path to your sql file. - Run
sqlfluff lint .\path\to\sql\code_file.sql --dialect postgres
to see the linting results (you can change the dialect to any of the supported dialects). Replace.\path\to\sql\code_file.sql
with the path to your sql file. - Run
sqlfluff fix .\path\to\sql\code_file.sql --dialect postgres
to fix the linting errors (you can change the dialect to any of the supported dialects). Replace.\path\to\sql\code_file.sql
with the path to your sql file.