Skip to content

Commit

Permalink
Fixed unused infix function call import false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Jan 25, 2017
1 parent e30bdf5 commit d9cf92c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gihub.shyiko.ktlint.ruleset.standard

import com.github.shyiko.ktlint.core.Rule
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.KtImportDirective
import org.jetbrains.kotlin.psi.psiUtil.startOffset
Expand All @@ -17,8 +18,9 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) {
if (node.elementType == KtStubElementTypes.FILE) {
node.visit { node ->
if (node.elementType == KtStubElementTypes.REFERENCE_EXPRESSION &&
!node.psi.isPartOf(KtImportDirective::class)) {
val type = node.elementType
if ((type == KtNodeTypes.REFERENCE_EXPRESSION || type == KtNodeTypes.OPERATION_REFERENCE) &&
!node.psi.isPartOf(KtImportDirective::class)) {
ref.add(node.text.trim('`'))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class NoUnusedImportsRuleTest {
import p.a.*
import escaped.`when`
import escaped.`foo`
import infixfunc
fun main() {
println(a())
C.call(B())
1 infixfunc 2
`when`()
}
""".trimIndent()
Expand Down

0 comments on commit d9cf92c

Please sign in to comment.