Skip to content

Commit

Permalink
Fixing #836 (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashachu authored Aug 20, 2020
1 parent c9d1db3 commit d9e6716
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {

// Contains list of all imports and checks if given import is present
private fun checkIfParentImportExists(text: String): Boolean {
// Only check static imports; identified if they start with a capital letter indicating a
// class name rather than a sub-package
if (text.isNotEmpty() && text[0] !in 'A'..'Z') {
return false
}

val staticImports = imports.filter { it.endsWith(text) }
staticImports.forEach { import ->
var count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,24 @@ class NoUnusedImportsRuleTest {
assertThat(actual).isEqualTo(expected)
}
}
""".trimIndent()
).isEmpty()
)
}

@Test
fun `only redundant static imports should be removed`() {
assertThat(
NoUnusedImportsRule().lint(
"""
import com.foo.psi.abc
import com.foo.psi.findAnnotation
fun main() {
val psi = getPsi()
psi.abc()
val bar = psi.findAnnotation(SOME_CONSTANT)
}
""".trimIndent()
)
Expand Down

0 comments on commit d9e6716

Please sign in to comment.