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

Move suppressions to core #7101

Merged
merged 3 commits into from May 8, 2024
Merged

Move suppressions to core #7101

merged 3 commits into from May 8, 2024

Conversation

BraisGabin
Copy link
Member

@BraisGabin BraisGabin commented Mar 27, 2024

All the suppression logic should be handled by the core. Rule shouldn't know about that. This PR moves that logic to core and also moves the functions that are no longer used in api to core to keep api as clean as possible.

@@ -25,12 +27,12 @@ fun Rule.compileAndLint(@Language("kotlin") content: String): List<Finding> {

fun Rule.lint(@Language("kotlin") content: String): List<Finding> {
val ktFile = compileContentForTest(content)
return visitFile(ktFile)
return visitFile(ktFile).filterSuppressed(this)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like to add this here too much but I think that for now it's the simpler solution.

Why do we need this? Right now we have some tests on the rules that check that when an annotation is set the finding is not raised. Those tests are testing two things. From one side they are testing that the suppression works, that's tested already somewhere else so it should not be tested. But they are also testing that the KtElement that they provide is correct or that the configured alias is correct. We could refactor those tests but the tests would be more difficult to follow (I tried). For that reason I decide to keep this here.

The good part is that, if we want, we could refactor those tests and remove this later.

Copy link
Member

Choose a reason for hiding this comment

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

Step-by.step is the way to go here. As you said, I don't think it's ideal approach, though sufficient for now.

@BraisGabin BraisGabin marked this pull request as ready for review April 12, 2024 09:29
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.75%. Comparing base (5fa82dc) to head (aee13be).
Report is 15 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7101      +/-   ##
============================================
- Coverage     84.77%   84.75%   -0.03%     
+ Complexity     3993     3992       -1     
============================================
  Files           578      578              
  Lines         12138    12027     -111     
  Branches       2484     2485       +1     
============================================
- Hits          10290    10193      -97     
+ Misses          624      606      -18     
- Partials       1224     1228       +4     

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

@BraisGabin
Copy link
Member Author

@detekt/maintainers could I get a review here?

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

👍
Good to go in my point of view.
Just the function comment needs to be adapted.

@@ -101,15 +98,9 @@ open class Rule(

/**
* Reports a single code smell finding.
Copy link
Member

Choose a reason for hiding this comment

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

At this point, detekt does not report, bur rather add it to the findings list.

@@ -25,12 +27,12 @@ fun Rule.compileAndLint(@Language("kotlin") content: String): List<Finding> {

fun Rule.lint(@Language("kotlin") content: String): List<Finding> {
val ktFile = compileContentForTest(content)
return visitFile(ktFile)
return visitFile(ktFile).filterSuppressed(this)
Copy link
Member

Choose a reason for hiding this comment

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

Step-by.step is the way to go here. As you said, I don't think it's ideal approach, though sufficient for now.

@BraisGabin BraisGabin enabled auto-merge (squash) May 8, 2024 07:04
@BraisGabin BraisGabin merged commit bf3fc6f into main May 8, 2024
21 checks passed
@BraisGabin BraisGabin deleted the suppression-to-core branch May 8, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants