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

UnusedPrivateProperty improvements and refactoring out new UnusedVariable rule #7089

Merged
merged 17 commits into from
Apr 14, 2024

Conversation

psuzn
Copy link
Contributor

@psuzn psuzn commented Mar 25, 2024

Fixes #6702 and refactors the unused variable rules into its own separate UnusedVariable rule.

@psuzn
Copy link
Contributor Author

psuzn commented Mar 25, 2024

This is more or less done, but this breaks the unused variable checks (i.e. failng tests). The previous version of UnusedPrivateProperty was also doing checks for the unused variables. I can add those checks but it would be better to put checks for unused variables in on the seperate rule and keep this UnusedPrivateProperty rule just for unused private properties and constructor parameters.

@BraisGabin @3flex

@BraisGabin
Copy link
Member

This is more or less done, but this breaks the unused variable checks (i.e. failng tests). The previous version of UnusedPrivateProperty was also doing checks for the unused variables. I can add those checks but it would be better to put checks for unused variables in on the seperate rule and keep this UnusedPrivateProperty rule just for unused private properties and constructor parameters.

@BraisGabin @3flex

I'm ok about splitting this rule in two.

And there is other thing here, we are moving another rule away from plain detekt. I'm ok with that in general. Correctness is better than speed. But I wanted just to make that clear for anyone looking at this PR.

@@ -56,103 +67,163 @@ class UnusedPrivateProperty(config: Config) : Rule(
setOf("UNUSED_VARIABLE", "UNUSED_PARAMETER", "unused", "UnusedPrivateMember")

@Configuration("unused property names matching this regex are ignored")
private val allowedNames: Regex by config("_|ignored|expected|serialVersionUID", String::toRegex)
private val allowedNames: Regex by config(
"_|ignored|expected|serialVersionUID",
Copy link
Member

Choose a reason for hiding this comment

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

If this rule only works with properties then _ should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@psuzn
Copy link
Contributor Author

psuzn commented Mar 25, 2024

@BraisGabin how should I go with the unused variable rule, I can add it to this PR or do that in a new PR (we can create a new 3rd PR as a base for both).

Also, what should be the name for the new rule UnusedVariable?

@cortinico
Copy link
Member

And there is other thing here, we are moving another rule away from plain detekt. I'm ok with that in general. Correctness is better than speed. But I wanted just to make that clear for anyone looking at this PR.

I'm also fine with it 👍
Thanks for taking a stab at this @psuzn

Also, what should be the name for the new rule UnusedVariable?

UnusedVariable sounds like a good one 👍

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 89.68254% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 84.71%. Comparing base (7b5d42d) to head (02175cb).

Files Patch % Lines
...rbosch/detekt/rules/style/UnusedPrivateProperty.kt 88.57% 0 Missing and 8 partials ⚠️
...ab/arturbosch/detekt/rules/style/UnusedVariable.kt 90.90% 0 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7089      +/-   ##
============================================
+ Coverage     84.67%   84.71%   +0.04%     
- Complexity     3970     3975       +5     
============================================
  Files           575      576       +1     
  Lines         12051    12139      +88     
  Branches       2476     2497      +21     
============================================
+ Hits          10204    10284      +80     
  Misses          621      621              
- Partials       1226     1234       +8     

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

@detekt-ci
Copy link
Collaborator

detekt-ci commented Mar 26, 2024

Warnings
⚠️ This PR is approved with no milestone set. If merged, it won't appear in the detekt release notes.
Messages
📖 Thanks for adding a new rule to detekt ❤️
We detekted that you added tests, to your rule, that's awesome!

We detekted that you updated the default-detekt-config.yml file, that's awesome!

Generated by 🚫 dangerJS against 02175cb

@psuzn psuzn force-pushed the false-negative-unused-private-property branch from 7cb02ac to 42b5e78 Compare March 26, 2024 14:53
@psuzn psuzn changed the title fix for unused private property in same file UnusedPrivateProperty improvements and refactoring out new UnusedVariable rule Mar 26, 2024
Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

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

Top level properties shouldn't be handled by UnusedVariables because they aren't variables, they are properties. That should remain on UnusedPrivateProperty.

Other than that the PR looks really good!


Off-topic: Do we have a rule to check that all the parameters of a lambda are used? 🤔 I thought we have but I can't find it.

psuzn and others added 4 commits March 27, 2024 19:12
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
…ate-property' into false-negative-unused-private-property
Co-authored-by: Brais Gabín <braisgabin@gmail.com>
Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

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

Add one test more and this is good to go for me :) really good job! Thank you!

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
@BraisGabin
Copy link
Member

@psuzn can you rebase/merge your pr with main? It has conflicts. After that this is ready to merge.

@psuzn
Copy link
Contributor Author

psuzn commented Apr 14, 2024

should be good to go.

@BraisGabin BraisGabin merged commit dfda4e0 into detekt:main Apr 14, 2024
21 checks passed
@cortinico cortinico added this to the 2.0.0 milestone Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False Negative: Unused private property not reported in a file if used in another class
4 participants