New J2K: Do not remove semicolon after if expression when then branch is empty in RedundantSemicolonInspection
This commit is contained in:
committed by
Ilya Kirillov
parent
b13f7431f2
commit
02c8e4cede
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
@@ -79,6 +80,11 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
semicolon.prevLeaf()?.parent?.safeAs<KtIfExpression>()?.also { ifExpression ->
|
||||||
|
if (ifExpression.then == null)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (nextLeaf?.nextLeaf {
|
if (nextLeaf?.nextLeaf {
|
||||||
it !is PsiWhiteSpace && it !is PsiComment && it.getStrictParentOfType<KDoc>() == null &&
|
it !is PsiWhiteSpace && it !is PsiComment && it.getStrictParentOfType<KDoc>() == null &&
|
||||||
it.getStrictParentOfType<KtAnnotationEntry>() == null
|
it.getStrictParentOfType<KtAnnotationEntry>() == null
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ fun bar() {
|
|||||||
fun baz(args: Array<String>) {
|
fun baz(args: Array<String>) {
|
||||||
for (arg in args);
|
for (arg in args);
|
||||||
while (args.size > 0);
|
while (args.size > 0);
|
||||||
|
if (args.size > 0);
|
||||||
// But here redundant!
|
// But here redundant!
|
||||||
do while (args.size > 0);
|
do while (args.size > 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,16 +72,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>Test.kt</file>
|
<file>Test.kt</file>
|
||||||
<line>38</line>
|
<line>39</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>
|
|
||||||
|
|
||||||
<problem>
|
|
||||||
<file>Test.kt</file>
|
|
||||||
<line>43</line>
|
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
|
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
|
||||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
|
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
|
||||||
@@ -108,7 +99,16 @@
|
|||||||
|
|
||||||
<problem>
|
<problem>
|
||||||
<file>Test.kt</file>
|
<file>Test.kt</file>
|
||||||
<line>49</line>
|
<line>46</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>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>Test.kt</file>
|
||||||
|
<line>50</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
|
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
|
||||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
|
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
|
||||||
|
|||||||
Reference in New Issue
Block a user