Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linter docs for dbt Cloud CLI #5753

Merged
merged 13 commits into from
Jul 16, 2024
45 changes: 41 additions & 4 deletions website/docs/docs/cloud/configure-cloud-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,50 @@ As a tip, most command-line tools have a `--help` flag to show available command
- `dbt run --help`: Lists the flags available for the `run` command
:::

### SQLFluff integration
The dbt Cloud CLI supports [SQLFluff](https://sqlfluff.com/), a modular and configuration SQL linter, which warns you of complex functions, syntax, formatting, and compilation errors.
### Lint SQL files

To get started, run `dbt sqlfluff -h` to see the list of supported commands and flags, such as `dbt sqlfluff lint` to lint SQL files.
From the dbt Cloud CLI, you can invoke [SQLFluff](https://sqlfluff.com/) which is a modular and configurable SQL linter that warns you of complex functions, syntax, formatting, and compilation errors. The available SQLFluff commands are: `fix`, `format`, and `lint`. To show detailed information about these commands and the available flags, run the `dbt sqlfluff -h` command.

The `lint` command in dbt supports many of the same flags that you can pass to SQLFluff, except for those that might pose a security risk. To lint SQL files, run the command as follows:
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

```shell
dbt sqlfluff lint [PATHS]... [flags]
```

When no path is set, dbt lints all SQL files in the project. To lint a specific SQL file or a directory of SQL files, set `PATHS` to the path of the SQL file or the directory path, respectively.
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

To show a list of all the dbt supported flags, run the `dbt sqlfluff lint -h` command. For example:

```shell
dbt sqlfluff lint -h
Lint SQL files via passing a list of files or using stdin.

PATH is the path to a sql file or directory to lint. This can be either a file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-') character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will be interpreted like passing the current working directory as a path argument.

Usage:
dbt sqlfluff lint [PATHS]... [flags]

Flags:
-d, --dialect string The dialect of SQL to lint.
--encoding string Specify encoding to use when reading and writing files. Defaults to autodetect.
-e, --exclude-rules string Exclude specific rules. For example specifying -–exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –-exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.
-f, --format SqlfluffOutputFormat What format to return the lint result in, one of "human", "json", "yaml", "github-annotation", "github-annotation-native", "none". (default human)
-h, --help help for lint
-i, --ignore string Ignore particular families of errors so that they don't cause a failed run. For example –-ignore parsing would mean that any parsing errors are ignored and don't influence the success or fail of a run. –-ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.
--ignore-local-config Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.
--rules string Narrow the search to only specific rules. For example specifying –-rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –-rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.
-t, --templater SqlfluffTemplater The templater to use, one of "raw", "jinja", "python", "placeholder", "dbt". (default jinja)
-v, --verbose count Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

Global Flags:
--log-format LogFormat The log format, either json or plain. (default plain)
--log-level LogLevel The log level, one of debug, info, warning, error or fatal. (default info)
--no-color Disables colorization of the output.
-q, --quiet Suppress all non-error logging to stdout.
```
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved

#### Considerations
Keep the following points in mind when using SQLFluff with the dbt Cloud:
Keep the following points in mind when using SQLFluff with dbt Cloud:

- When you run `dbt sqlfluff`, it picks up changes to your local .sqlfluff config.
- To use SQLFluff in continuous integration/continuous development, you need to have a `dbt_cloud.yml` file in your project and run commands from a valid dbt project.
nghi-ly marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading