fix(configuration): enabled rules calculation #2072
Merged
+273
−71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It turns out the existing function
as_enabled_rules
was calculating the enabled rules in a wrong way. The function is generated by codegen, so I fixed the logic inxtask/codegen/src/generate_configuration.rs
and regenerated that file. I summarize the correct logic as follows:For non-nursery groups
all
and group-levelrecommend
should take precedence over their top-level alternatives.all
or group-levelrecommend
is not present, it should fallback to check top-levelall
or top-levelrecommend
.all
or top-levelrecommend
.For nursery group
all
and group-levelrecommend
should take precedence over top-level alternatives. (same as non-nursery groups)all
or group-levelrecommend
is not present, it should fallback to check top-levelall
or top-levelrecommend
only in unstable releases.all
or top-levelrecommend
only in unstable releases.Fixes #2028.
Test Plan
Since the nursery group is unstable because the rules in it may be promoted in later releases, I didn't add test cases for the nursery group. But I tested it locally and it works as expected.
I added a test case called
top_level_all_down_level_empty
. It's to check whether the non-recommended rules belonging to a group will be enabled if we have a top-levelall
astrue
and an empty config of that group. The expected result is they should be kept enabled. In current release (v1.6.1
) they are wrongly disabled. I guess the reason why this issue isn't discovered earlier is because most rules under a group are recommended rules.