Skip to content

Commit

Permalink
Fix NoUnusedImportsRule failing on escaped imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dstarcev committed Aug 5, 2016
1 parent 9efa4c9 commit 28d2eb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NoUnusedImportsRule : Rule {
node.visit { node ->
if (node.elementType == KtStubElementTypes.REFERENCE_EXPRESSION) {
if (node.psi.getNonStrictParentOfType(KtImportDirective::class.java) == null) {
ref.add(node.text)
ref.add(node.text.trim('`'))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ class NoUnusedImportsRuleTest {
import p2.B
import p.C
import p.a.*
import escaped.`when`
import escaped.`foo`
fun main() {
println(a())
C.call(B())
`when`()
}
""".trimIndent()
)).isEqualTo(listOf(
LintError(2, 1, "rule-id", "Unused import"),
LintError(3, 1, "rule-id", "Unused import"),
LintError(4, 1, "rule-id", "Unused import")
LintError(4, 1, "rule-id", "Unused import"),
LintError(9, 1, "rule-id", "Unused import")
))
}

Expand All @@ -41,23 +45,28 @@ class NoUnusedImportsRuleTest {
import p.B as B12
import p2.B as B2
import p.C
import escaped.`when`
import escaped.`foo`
fun main() {
println(a())
C.call()
fn(B2.NAME)
`when`()
}
""".trimIndent()
)).isEqualTo(
"""
import p.a
import p2.B as B2
import p.C
import escaped.`when`
fun main() {
println(a())
C.call()
fn(B2.NAME)
`when`()
}
""".trimIndent()
)
Expand Down

0 comments on commit 28d2eb2

Please # to comment.