diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index e9e9d767d54..c79f45ed671 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -25,6 +25,7 @@ import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType import org.jetbrains.kotlin.psi.psiUtil.nextLeaf import org.jetbrains.kotlin.psi.psiUtil.prevLeaf @@ -57,6 +58,16 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns if (semicolon.parent is KtEnumEntry) return false + (semicolon.parent.parent as? KtClass)?.let { + if (it.isEnum() && it.getChildrenOfType().isEmpty()) { + if (semicolon.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment && !it.isLineBreak() }?.node?.elementType == KtTokens.LBRACE + && it.declarations.isNotEmpty()) { + //first semicolon in enum with no entries, but with some declarations + return false + } + } + } + (semicolon.prevLeaf()?.parent as? KtLoopExpression)?.let { if (it !is KtDoWhileExpression && it.body == null) return false diff --git a/idea/testData/inspections/redundantSemicolon/Test.kt b/idea/testData/inspections/redundantSemicolon/Test.kt index b09d9ec92b5..6ba26d1f1ce 100644 --- a/idea/testData/inspections/redundantSemicolon/Test.kt +++ b/idea/testData/inspections/redundantSemicolon/Test.kt @@ -36,4 +36,15 @@ fun baz(args: Array) { while (args.size > 0); // But here redundant! do while (args.size > 0); +} + +enum class Foo { + ; //not redundant + ; + companion object; + ; +} + +enum class Bar { + ; //redundant } \ 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 6508265824c..f5ac0d931d8 100644 --- a/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml +++ b/idea/testData/inspections/redundantSemicolon/inspectionData/expected.xml @@ -78,4 +78,40 @@ Redundant semicolon Redundant semicolon + + + Test.kt + 43 + light_idea_test_case + + Redundant semicolon + Redundant semicolon + + + + Test.kt + 44 + light_idea_test_case + + Redundant semicolon + Redundant semicolon + + + + Test.kt + 45 + light_idea_test_case + + Redundant semicolon + Redundant semicolon + + + + Test.kt + 49 + light_idea_test_case + + Redundant semicolon + Redundant semicolon +