VS Code
You can use the Run on Save extension with sqlfmt to automatically format files when they are saved. After installing the extension:
- On the extension's page, click the gear icon to access the extension settings.
- Choose if you would like to create either a User or Workspace setting, and select the appropriate tab.
- Then select "Edit in
settings.json
", and add the following:
settings.json
{
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*\\.sql(\\.jinja)?",
"isAsync": true,
"cmd": "sqlfmt ${file}"
}
]
}
}
Configuring sqlfmt with Run on Save
You can either use a pyproject.toml
file in your project directory or add other options to the cmd
key in the settings above if you would like to change the default behavior of sqlfmt