From bac44ab652648708aef7e88e8f8f900210095eec Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Sun, 28 Jun 2020 07:03:52 +0900 Subject: [PATCH] NoWildcardImportsRule: don't report it if asterisk with backticks (#800) --- .../ktlint/ruleset/standard/NoWildcardImportsRule.kt | 4 ++-- .../ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt index 42d7bc5331..0c40afa0ea 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt @@ -14,8 +14,8 @@ class NoWildcardImportsRule : Rule("no-wildcard-imports") { ) { if (node.elementType == IMPORT_DIRECTIVE) { val importDirective = node.psi as KtImportDirective - val path = importDirective.importPath?.pathStr - if (path != null && !path.startsWith("kotlinx.android.synthetic") && path.contains('*')) { + val path = importDirective.importPath + if (path != null && path.isAllUnder && !path.pathStr.startsWith("kotlinx.android.synthetic")) { emit(node.startOffset, "Wildcard import", false) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt index f810fe7189..d4e9ff9c9d 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt @@ -16,6 +16,7 @@ class NoWildcardImportsRuleTest { import a.b.c.* import a.b import kotlinx.android.synthetic.main.layout_name.* + import foo.bar.`**` """.trimIndent() ) ).isEqualTo(