-
Notifications
You must be signed in to change notification settings - Fork 15
adding --selected-rule
#120
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,13 @@ def _add_rule(self, rule: Type[Rule]) -> None: | |
rule_name = rule.source() | ||
if rule_name in self._rules: | ||
raise DuplicatedRuleException(rule_name) | ||
if rule_name not in self.config.disabled_rules: | ||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a small comment that explains this? Our future selves will be grateful 😂 |
||
len(self.config.selected_rules) > 0 | ||
and rule_name in self.config.selected_rules | ||
) or ( | ||
len(self.config.selected_rules) == 0 | ||
and rule_name not in self.config.disabled_rules | ||
): | ||
rule_config = self.config.rules_config.get(rule_name, RuleConfig()) | ||
self._rules[rule_name] = rule(rule_config=rule_config) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,33 @@ def test_disabled_rule_registry_discovery(): | |
] | ||
|
||
|
||
def test_selected_rule_registry_discovery(): | ||
"""Ensure only selected rules are discovered.""" | ||
config = Config() | ||
config.selected_rules = ["tests.rules.nested.example.rule_test_nested_example"] | ||
r = RuleRegistry(config) | ||
r._load("tests.rules") | ||
assert sorted(r._rules.keys()) == [ | ||
"tests.rules.nested.example.rule_test_nested_example" | ||
] | ||
|
||
|
||
def test_selected_and_disabled_rule_registry_discovery(): | ||
"""Ensure selected rules are run even if otherwise disabled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice I see it does work as expected, still I think my comment makes sense; shouldn't we warn the user about this invalid config? It will be less magical to the users I think |
||
|
||
This is prevented by the CLI, but want to confirm selected rules | ||
are run even if disabled via pyproject.toml. | ||
""" | ||
config = Config() | ||
config.selected_rules = ["tests.rules.nested.example.rule_test_nested_example"] | ||
config.disabled_rules = ["tests.rules.nested.example.rule_test_nested_example"] | ||
r = RuleRegistry(config) | ||
r._load("tests.rules") | ||
assert sorted(r._rules.keys()) == [ | ||
"tests.rules.nested.example.rule_test_nested_example" | ||
] | ||
|
||
|
||
def test_configured_rule_registry_discovery(valid_config_path): | ||
"""Ensure rules are discovered and configured correctly.""" | ||
config = Config() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👌
We also need to take into account
pyproject.toml
configuration I think.Theoretically I could...
OR
dbt-score lint --selected-rule dbt_score.rules.generic.model_has_description
Which should not be possible IMO. So maybe we should add more validation to
Config.validate()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just catching up, it's been busy and lost track of this! I think your second example in particular feels like something I'd like to consider further. I could see utility in being able to say, effectively,
dbt_score.rules.generic.columns_have_description
is never run by default but there may be a certain scenario in which I explicitly want to run it, and it'd be beneficial to be able to do so at runtime.Is it possible to override the TOML-level configs for
disabled_rules
from the command line? Ifdbt_score.rules.generic.columns_have_description
is disabled per the TOML, can I un-disable it via the CLI in some way? It looks like I can potentially replace the list of rules that is disabled at runtime, but can I remove it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that disabling 1 or more rule via the CLI (
--disabled-rule foo --disabled-rule bar
) will effectively replace the set of rules disabled via the toml config file.Meaning you can remove at runtime the disabled rules from the config file, but only if you disable at least another rule 😅 Which is of course not great.
Not sure what the best approach is there. An example could be changing the CLI parameter to accept lists, including empty lists, e.g.
--disabled-rules foo bar
or--disabled-rules
(no value = empty list).