Make semicolon in loop with empty body not redundant

So #KT-12805 Fixed
This commit is contained in:
Dmitry Neverov
2017-05-14 20:44:26 +03:00
committed by Mikhail Glukhikh
parent e30b9758f4
commit bf4e69e17f
3 changed files with 22 additions and 3 deletions

View File

@@ -24,10 +24,9 @@ import com.intellij.psi.PsiElement
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.*
import org.jetbrains.kotlin.psi.psiUtil.nextLeaf
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
@@ -58,6 +57,11 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
if (semicolon.parent is KtEnumEntry) return false
(semicolon.prevLeaf()?.parent as? KtLoopExpression)?.let {
if (it !is KtDoWhileExpression && it.body == null)
return false
}
if (nextLeaf?.nextLeaf { it !is PsiComment }?.node?.elementType == KtTokens.LBRACE) {
return false // case with statement starting with '{' and call on the previous line
}

View File

@@ -29,4 +29,11 @@ fun ((Int) -> Unit).doIt() {
fun bar() {
a(); // redundant
b()
}
fun baz(args: Array<String>) {
for (arg in args);
while (args.size > 0);
// But here redundant!
do while (args.size > 0);
}

View File

@@ -70,4 +70,12 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
<problem>
<file>Test.kt</file>
<line>38</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
</problems>