diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/gihub/shyiko/ktlint/ruleset/standard/NoWildcardImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/gihub/shyiko/ktlint/ruleset/standard/NoWildcardImportsRule.kt
index 02a9639207..eeebac3318 100644
--- a/ktlint-ruleset-standard/src/main/kotlin/com/gihub/shyiko/ktlint/ruleset/standard/NoWildcardImportsRule.kt
+++ b/ktlint-ruleset-standard/src/main/kotlin/com/gihub/shyiko/ktlint/ruleset/standard/NoWildcardImportsRule.kt
@@ -2,16 +2,19 @@ package com.gihub.shyiko.ktlint.ruleset.standard
import com.github.shyiko.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
-import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.psi.KtImportDirective
+import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
class NoWildcardImportsRule : Rule("no-wildcard-imports") {
override fun visit(node: ASTNode, autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) {
- if (node is LeafPsiElement && node.textMatches("*") && node.isPartOf(KtImportDirective::class)) {
- emit(node.startOffset, "Wildcard import", false)
+ if (node.elementType == KtStubElementTypes.IMPORT_DIRECTIVE) {
+ val importDirective = node.psi as KtImportDirective
+ val path = importDirective.importPath?.pathStr
+ if (path != null && !path.startsWith("kotlinx.android.synthetic") && path.contains('*')) {
+ emit(node.startOffset, "Wildcard import", false)
+ }
}
}
-
}
diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt
index dd0f589af8..0aff40ae3b 100644
--- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt
+++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt
@@ -15,10 +15,11 @@ class NoWildcardImportsRuleTest {
import a.*
import a.b.c.*
import a.b
+ import kotlinx.android.synthetic.main.layout_name.*
""".trimIndent()
)).isEqualTo(listOf(
- LintError(1, 10, "no-wildcard-imports", "Wildcard import"),
- LintError(2, 14, "no-wildcard-imports", "Wildcard import")
+ LintError(1, 1, "no-wildcard-imports", "Wildcard import"),
+ LintError(2, 1, "no-wildcard-imports", "Wildcard import")
))
}
diff --git a/pom.xml b/pom.xml
index dc8dee88bf..18fae5a9f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -129,7 +129,7 @@
1.0.0
- # build "./ktlitn/target/ktlint" (executable jar)
+ # build "./ktlint/target/ktlint" (executable jar)
./mvnw -Pcapsule clean package -Dmaven.test.skip=true
# test (& check code style)