diff --git a/docs/create_rules.md b/docs/create_rules.md index e431239..2d6f871 100644 --- a/docs/create_rules.md +++ b/docs/create_rules.md @@ -39,11 +39,10 @@ from dbt_score import rule, Severity @rule(severity=Severity.HIGH) ``` -If a custom rule should be applied to only a subset of the models in the project, -a special value of type `SkipRule` can be returned. -Models that were skipped will be ignored in the final score. -More complex uses of skipping rules can use Model Filters (see below). - +If a custom rule should be applied to only a subset of the models in the +project, a special value of type `SkipRule` can be returned. Models that were +skipped will be ignored in the final score. More complex uses of skipping rules +can use Model Filters (see below). ```python from dbt_score import rule, Model, RuleViolation, SkipRule @@ -111,14 +110,13 @@ def sql_has_reasonable_number_of_lines(model: Model, max_lines: int = 200) -> Ru ### Filtering models -Custom and standard rules can be configured to have model filters. -Filters allows setting models of the project to be ignored by a given rule. +Custom and standard rules can be configured to have model filters. Filters +allows setting models of the project to be ignored by a given rule. -Filters are created using the same discovery mechanism and interface as custom rules, -except they do not accept parameters. -Similar to Python's built-in `filter` function, -when the filter evaluation returns `True` the model should be evaluated, -otherwise it should be skipped. +Filters are created using the same discovery mechanism and interface as custom +rules, except they do not accept parameters. Similar to Python's built-in +`filter` function, when the filter evaluation returns `True` the model should be +evaluated, otherwise it should be skipped. ```python from dbt_score import ModelFilter, model_filter @@ -134,8 +132,7 @@ class SkipSchemaY(ModelFilter): return model.schema.lower() != 'y' ``` -Similar to setting a rule severity, -standard rules can have filters set in the +Similar to setting a rule severity, standard rules can have filters set in the [configuration file](configuration.md/#tooldbt-scorerulesrule_namespacerule_name), while custom rules accept the configuration file or a decorator parameter. diff --git a/src/dbt_score/rule.py b/src/dbt_score/rule.py index 13bf18b..e82e459 100644 --- a/src/dbt_score/rule.py +++ b/src/dbt_score/rule.py @@ -42,9 +42,9 @@ def from_dict(rule_config: dict[str, Any]) -> "RuleConfig": else [] ) - return RuleConfig(severity=severity, - config=config, - model_filter_names=filter_names) + return RuleConfig( + severity=severity, config=config, model_filter_names=filter_names + ) @dataclass diff --git a/tests/test_config.py b/tests/test_config.py index 6d0a279..634e99a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -27,10 +27,9 @@ def test_load_valid_toml_file(valid_config_path): assert config.badge_config.first.icon == "1️⃣" assert config.fail_project_under == 7.5 assert config.fail_any_model_under == 6.9 - assert ( - config.rules_config["tests.rules.example.rule_test_example"].model_filter_names - == ["tests.rules.example.skip_model1"] - ) + assert config.rules_config[ + "tests.rules.example.rule_test_example" + ].model_filter_names == ["tests.rules.example.skip_model1"] def test_load_invalid_toml_file(caplog, invalid_config_path):