-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
Check for static imports in unused imports rule #3188
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3188 +/- ##
============================================
+ Coverage 79.55% 79.57% +0.01%
Complexity 2631 2631
============================================
Files 440 440
Lines 7964 7969 +5
Branches 1521 1522 +1
============================================
+ Hits 6336 6341 +5
Misses 818 818
Partials 810 810
Continue to review full report at Codecov.
|
594ef8b
to
9737886
Compare
9737886
to
d6ef885
Compare
When I run the task |
Use Compile all the snippets each time that we run the tests slow down the test and is kind of meta testing (testing the tests). For that reason we have the compilation disabled by default and we just compile them in CI.
|
val mainFile = """ | ||
import x.y.z.Foo | ||
|
||
val x = Foo.LAZY | ||
""" | ||
val additionalFile = """ | ||
package x.y.z | ||
|
||
enum class FetchType { | ||
LAZY | ||
} |
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.
Why does this compile? the enum is called FetchType
but the import is for Foo
🤔
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 wrote the tests with Foo and later renamed them before committing to mimic the issue reported. However, your point of compilation seems to be valid 😮
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.
@schalkms do you have any idea about why does this happen? This doesn't stop the PR but I will like to know why does this happen
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.
@BraisGabin Yes, I do. Please take a look at the following lines and closely check line number 68.
detekt/detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/RuleExtensions.kt
Lines 63 to 72 in da6259a
fun BaseRule.compileAndLintWithContext( | |
environment: KotlinCoreEnvironment, | |
@Language("kotlin") content: String, | |
@Language("kotlin") vararg additionalContents: String, | |
): List<Finding> { | |
if (shouldCompileTestSnippets && additionalContents.isEmpty()) { | |
KotlinScriptEngine.compile(content) | |
} | |
return lintWithContext(environment, content, *additionalContents) | |
} |
* Check for static imports in unused imports rule * Fix test compilation * Fix test variable names
* Check for static imports in unused imports rule * Fix test compilation * Fix test variable names
* Check for static imports in unused imports rule * Fix test compilation * Fix test variable names
Fixes #3131