Skip to content

Commit

Permalink
Add configuration documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jochemvandooren committed May 27, 2024
1 parent 7050680 commit 15f7502
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
66 changes: 66 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Configuration

`dbt-score` can be configured through a `pyproject.toml` file or via the command
line.

## pyproject.toml

It is recommended to place the file in the root of your dbt project. `dbt-score`
will look for `pyproject.toml` in the directory from which it is run and it's
parent directories.

An example of a `pyproject.toml` file to configure `dbt-score` can be found
below:

```toml
[tool.dbt-score]
rule_namespaces = ["dbt_score.rules", "custom_rules"]
disabled_rules = ["dbt_score.rules.generic.columns_have_description"]

[tool.dbt-score.rules."dbt_score.rules.generic.sql_has_reasonable_size"]
severity = 1
max_lines = 300
```

### Configuration options

The following options can be set in the `pyproject.toml` file:

#### Main configuration

```toml
[tool.dbt-score]
```

- `rule_namespaces`: A list of namespaces to search for rules. The default is
`["dbt_score.rules", "dbt_score_rules"]`. Be aware when overriding this
setting, that the default rules are in `dbt_score.rules` and are disabled if
not included here.
- `disabled_rules`: A list of rules to disable.

#### Rule configuration

```toml
[tool.dbt-score.rules."rule_namespace.rule_name"]
```

Every rule can be configured with the following option:

- `severity`: The severity of the rule. An integer with a minimum value of 1 and
a maximum value of 4.

Some rules have additional configuration options, e.g.
[sql_has_reasonable_size](/rules/generic/#sql_has_reasonable_size). Depending on
the rule, the options will have different names, types and default values. In
the case of the
[sql_has_reasonable_size](/rules/generic/#sql_has_reasonable_size), the
`max_lines` option can be configured.

## Command line

All configuration options can also be set via the command line. To understand
how to configure `dbt-score` from the command line:

```bash
dbt score lint --help
```
23 changes: 23 additions & 0 deletions docs/create_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,26 @@ rules defined in `.py` files will be automatically discovered.
If nested folders are used, e.g. `dbt_score_rules/generic_rules/rules.py`, an
`__init__.py` file needs to be present in the nested folder to make it
discoverable.

### Configurable rules

It's possible to create rules that can be
[configured](configuration.md/#tooldbt-scorerulesrule_namespacerule_name) with
additional options (apart from the `severity`). In order to create a
configurable rule, the evaluation function of the rule should have additional
input parameters with a default value defined. In the example below, the rule
has a `max_lines` parameter with a default value of 200, which can be configured
in the `pyproject.toml` file.

```python
from dbt_score import Model, rule, RuleViolation

@rule
def sql_has_reasonable_size(model: Model, max_lines: int = 200) -> RuleViolation | None:
"""The SQL query of a model should not be too long."""
count_lines = len(model.raw_code.split("\n"))
if count_lines > max_lines:
return RuleViolation(
message=f"SQL query too long: {count_lines} lines (> {max_lines})."
)
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nav:
- Home: index.md
- Get started: get_started.md
- Create rules: create_rules.md
- Configuration: configuration.md
- Rules:
- rules/generic.md
- Reference:
Expand Down

0 comments on commit 15f7502

Please sign in to comment.