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

Core handles active rules #6782

Merged
merged 5 commits into from
Jan 12, 2024
Merged

Core handles active rules #6782

merged 5 commits into from
Jan 12, 2024

Conversation

BraisGabin
Copy link
Member

@BraisGabin BraisGabin commented Dec 28, 2023

Until now core said to all the rules to execute, even if they were disabled, and then the rules decide if they should execute or not looking at their own configuration.

This PR changes that. Now the rule doesn't know if it is active or not. Now the core checks if a rule is active or not and decide what to do. This simplifies a bit more the Rule API. Also, this is not the final PR in this regard. The suppression is right now handled by the rule and I would like to move that to core too. But that will be done later.

This comes with a bonus: Config.empty is finally "empty". Until now it was empty except for the active parameter. That one always returned true instead of the expected null.

Also, I was looking how to test this and I found out that the tests were there already. That's the reason I created #6781 I was just looking how to test this and refactor those tests when I found out that this was already tested.

@BraisGabin BraisGabin added the breaking change Marker for breaking changes which should be highlighted in the changelog label Dec 28, 2023
@BraisGabin BraisGabin added this to the 2.0.0 milestone Dec 28, 2023
Copy link

codecov bot commented Dec 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d87918b) 84.94% compared to head (a9d6358) 84.95%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6782   +/-   ##
=========================================
  Coverage     84.94%   84.95%           
+ Complexity     3890     3887    -3     
=========================================
  Files           573      574    +1     
  Lines         12910    12913    +3     
  Branches       2445     2443    -2     
=========================================
+ Hits          10967    10970    +3     
  Misses          721      721           
  Partials       1222     1222           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BraisGabin BraisGabin marked this pull request as ready for review January 8, 2024 19:17
@@ -11,8 +11,7 @@ import io.gitlab.arturbosch.detekt.api.internal.createPathFilters
import io.gitlab.arturbosch.detekt.core.ProcessingSettings
import org.jetbrains.kotlin.psi.KtFile

fun Config.isActive(): Boolean =
valueOrDefault(Config.ACTIVE_KEY, true)
internal fun Config.isActive(default: Boolean): Boolean = valueOrDefault(Config.ACTIVE_KEY, default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename this to isActiveOrDefault?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the location of the method is a bit misleading. The file is RuleSets but it is an extension on Config that is used in the context of rules, rulesets and processors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right with both comments. I did the changes.

@BraisGabin BraisGabin enabled auto-merge (squash) January 12, 2024 18:41
@BraisGabin BraisGabin merged commit 430927c into main Jan 12, 2024
26 checks passed
@BraisGabin BraisGabin deleted the core-handles-active-rules branch January 12, 2024 18:56
mgroth0 pushed a commit to mgroth0/detekt that referenced this pull request Feb 11, 2024
* Rules doesn't handle if they are active or not

* rename isActive to isActiveOrDefault

---------

Co-authored-by: marschwar <marschwar@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api breaking change Marker for breaking changes which should be highlighted in the changelog cli core formatting reports rules suppressors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants