As we began writing (and reading!) more dbt code, we struggled with the problem of ensuring our models, macros, and snapshots were being written in a consistent way. One solution we found was this dbt-formatter extension for vscode. However, this was difficult to implement team-wide, as not everyone uses vscode and the autosave feature disables the autoformatting of files. Therefore, we decided to make a command line interface for the dbt-formatter package. We've also added a Dockerfile and pre-commit-hooks.yaml for use with pre-commit.
- Clone this repo
- From root, run
npm install
to install dependencies, thennpm link
to connect cli - Format a file with
dbt-formatter <path/to/file.sql> <options>
-
Add this repo to your .pre-commit-config.yaml with the current version and
dbt-formatter
for id. Example below
file path
these are the mostly the same as found here, except allowCamelCase
has been changed to --forbid-camel-case
as the original has a default value of true
. We have changed this to aid in readability and consistency. Additionally, we've added a --check-only
argument that will not reformat the file, instead simply returning the path to improperly formatted dbt model with an error code of 1
arg | type | default value |
---|---|---|
--sql | String | 'default' |
--indent | Number | 2 |
--upper | Boolean | false |
--newline | Boolean | false |
--lower-words | Boolean | false |
--forbid-camel-case | Boolean | false |
--check-only | Boolean | false |