-
-
Notifications
You must be signed in to change notification settings - Fork 798
Improve correctness of UnusedPrivateProperty #5935
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
Improve correctness of UnusedPrivateProperty #5935
Conversation
super.visitReferenceExpression(expression) | ||
} | ||
|
||
private fun skipNode(expression: KtReferenceExpression): Boolean { | ||
return when { |
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.
note: adding a bit of structure as we can followup with more exceptions and rules for other edge cases
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.
example of a followup: ignore import statements as well
c5983cb
to
4385b42
Compare
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.
detekt found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.
Codecov Report
@@ Coverage Diff @@
## main #5935 +/- ##
=========================================
Coverage 84.46% 84.46%
Complexity 3784 3784
=========================================
Files 546 546
Lines 12923 12928 +5
Branches 2268 2271 +3
=========================================
+ Hits 10915 10920 +5
Misses 877 877
Partials 1131 1131
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
4385b42
to
6d11524
Compare
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivatePropertySpec.kt
Fixed
Show fixed
Hide fixed
6d11524
to
3dba288
Compare
3dba288
to
b09a18d
Compare
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.
Thanks for the quick fix!
Besides the redundant two tests, this PR looks very good!
} | ||
|
||
@Test | ||
fun `package declarations are ignored`() { |
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 do think we only need this test to be added. The other cases are covered by the existing tests.
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.
good point! I had skimmed the file for these tests but initially failed to see them nested in the inner classes.
I removed the other two.
on that note though, lmk of including my 1 test under a new "irrelevant references are ignored" nested class (it seems all tests are nested somewhere)
I was planning on following this up with some other edge cases (eg import statements should be ignored as well)
but I am happy to put the test nested somewhere else if that makes sense, just lmk where it better fits
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.
Regarding test under new nested class 👍
Regarding follow up --> please submit a new PR, it's easier to review 👍
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.
yes, def meant followup PRs! thanks for reviewing so swiftly :)
Fixes #5934
Basically ignore package declarations when counting references for the purposes of identifying Unused Private Properties.
Followups
I believe there are many other edge cases that could be considered; for example, the right-hand side of a dot-expression is also being considered a use reference:
Should cause an error, but it doesn't. I'm not sure if there is a better solution here other than exploring each edge case individually, but I am happy to chip down on at least the more obvious ones on followup PRs.