-
-
Notifications
You must be signed in to change notification settings - Fork 793
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
UnusedPrivateClass: don't report imported classes #2812
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2812 +/- ##
=========================================
Coverage 80.52% 80.52%
- Complexity 2323 2335 +12
=========================================
Files 386 387 +1
Lines 6957 6993 +36
Branches 1262 1269 +7
=========================================
+ Hits 5602 5631 +29
Misses 726 726
- Partials 629 636 +7
Continue to review full report at Codecov.
|
6d7d35e
to
bd3561b
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!
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 fix! Looks good!
detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateClassSpec.kt
Show resolved
Hide resolved
private fun KtNamedDeclaration.isUsed(): Boolean { | ||
if (nameAsSafeName.identifier in namedClasses) return true | ||
val fqName = fqName?.asString() | ||
return fqName != null && importDirectives.any { it.startsWith(fqName) } |
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.
@t-kameyama @arturbosch @schalkms isn't this a counter-example for startsWith
?
import foo.bar.Baz
import foo.bar.Bazinga
fun f() {
Baz()
}
IRL Bazinga
could be generated Baz_Factory
for example.
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.
oh, it's only about private classes..., but there must be a similar example for that too.
e.g. a private class was renamed, but the original import not removed, but detekt wouldn't find it?
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.
Hm, the import must start with the fully qualified name of the private class not the other way. So this should be okay?
I'm not sure if I understand your example.
package foo.bar
import foo.bar.Baz
import foo.bar.Bazinga
private class BazFactory
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.
False negative:
package com.example
import com.example.C.EFG.EFG1
class C {
fun test() {
println(EFG1)
}
private enum class E { // false negative
E1
}
private enum class EFG {
EFG1
}
}
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.
Yep, that's what I meant.
Also be careful with nested classes inside nested classes, they might be broken now or after a fix of the false negative too.
Fixes #2809