diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index d751d12e4a1..4b4d56cc96c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -25,6 +25,8 @@ import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtEnumEntry +import org.jetbrains.kotlin.psi.KtImportList +import org.jetbrains.kotlin.psi.KtPackageDirective import org.jetbrains.kotlin.psi.psiUtil.nextLeaf class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool { @@ -46,7 +48,13 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns private fun isRedundant(semicolon: PsiElement): Boolean { val nextLeaf = semicolon.nextLeaf { it !is PsiWhiteSpace && it !is PsiComment || it.isLineBreak() } val isAtEndOfLine = nextLeaf == null || nextLeaf.isLineBreak() - if (!isAtEndOfLine) return false + if (!isAtEndOfLine) { + //when there is no imports parser generates empty import list with no spaces + if (semicolon.parent is KtPackageDirective && (nextLeaf as? KtImportList)?.imports?.isEmpty() ?: false) { + return true + } + return false + } if (semicolon.parent is KtEnumEntry) return false diff --git a/idea/testData/inspections/redundantSemicolon/BeforeEmptyImports.kt b/idea/testData/inspections/redundantSemicolon/BeforeEmptyImports.kt new file mode 100644 index 00000000000..a02f99890e7 --- /dev/null +++ b/idea/testData/inspections/redundantSemicolon/BeforeEmptyImports.kt @@ -0,0 +1,3 @@ +package foo; // redundant + +class A \ No newline at end of file diff --git a/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml b/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml index 27fbe1a90b9..c2a30f94b7c 100644 --- a/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml +++ b/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml @@ -61,4 +61,13 @@ Redundant semicolon Redundant semicolon + + + BeforeEmptyImports.kt + 1 + light_idea_test_case + + Redundant semicolon + Redundant semicolon +