Skip to content

Commit

Permalink
Fixed #204 - Unused import false positive (x.y.zNNN import inside x.y…
Browse files Browse the repository at this point in the history
….z package)
  • Loading branch information
shyiko committed May 2, 2018
1 parent 4385ea5 commit c9181df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {
val name = importDirective.importPath?.importedName?.asString()
val importPath = importDirective.importPath?.pathStr!!
if (importDirective.aliasName == null &&
importPath.startsWith(packageName) &&
(packageName.isEmpty() || importPath.startsWith("$packageName.")) &&
importPath.substring(packageName.length + 1).indexOf('.') == -1) {
emit(importDirective.startOffset, "Unnecessary import", true)
if (autoCorrect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class NoUnusedImportsRuleTest {
)).isEmpty()
}

@Test
fun testLintIssue204() {
assertThat(NoUnusedImportsRule().lint(
"""
package com.example.another
import com.example.anotherThing
class Foo {
val bar = anotherThing
}
""".trimIndent()
)).isEmpty()
}

@Test
fun testLintDestructuringAssignment() {
assertThat(NoUnusedImportsRule().lint(
Expand Down

0 comments on commit c9181df

Please sign in to comment.