From 28d2eb2def244054dd7cf580152b6e8ebb42e0cc Mon Sep 17 00:00:00 2001 From: dstarcev Date: Fri, 5 Aug 2016 17:39:34 +0300 Subject: [PATCH] Fix NoUnusedImportsRule failing on escaped imports --- .../github/shyiko/ktlint/rule/NoUnusedImportsRule.kt | 2 +- .../shyiko/ktlint/rule/NoUnusedImportsRuleTest.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRule.kt b/src/main/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRule.kt index 74a54e3108..5969914c63 100644 --- a/src/main/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRule.kt +++ b/src/main/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRule.kt @@ -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('`')) } } } diff --git a/src/test/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRuleTest.kt b/src/test/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRuleTest.kt index b225a73e3b..61b44190bc 100644 --- a/src/test/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRuleTest.kt +++ b/src/test/kotlin/com/github/shyiko/ktlint/rule/NoUnusedImportsRuleTest.kt @@ -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") )) } @@ -41,11 +45,14 @@ 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( @@ -53,11 +60,13 @@ class NoUnusedImportsRuleTest { 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() )