Don't report as redundant 1st semicolon in enum without entries
So #KT-12524 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
3a606d13f0
commit
3e29f9ed5a
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElementVisitor
|
|||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
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.getChildrenOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.nextLeaf
|
import org.jetbrains.kotlin.psi.psiUtil.nextLeaf
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
|
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
|
||||||
|
|
||||||
@@ -57,6 +58,16 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
|
|
||||||
if (semicolon.parent is KtEnumEntry) return false
|
if (semicolon.parent is KtEnumEntry) return false
|
||||||
|
|
||||||
|
(semicolon.parent.parent as? KtClass)?.let {
|
||||||
|
if (it.isEnum() && it.getChildrenOfType<KtEnumEntry>().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 {
|
(semicolon.prevLeaf()?.parent as? KtLoopExpression)?.let {
|
||||||
if (it !is KtDoWhileExpression && it.body == null)
|
if (it !is KtDoWhileExpression && it.body == null)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -36,4 +36,15 @@ fun baz(args: Array<String>) {
|
|||||||
while (args.size > 0);
|
while (args.size > 0);
|
||||||
// But here redundant!
|
// But here redundant!
|
||||||
do while (args.size > 0);
|
do while (args.size > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Foo {
|
||||||
|
; //not redundant
|
||||||
|
;
|
||||||
|
companion object;
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Bar {
|
||||||
|
; //redundant
|
||||||
}
|
}
|
||||||
@@ -78,4 +78,40 @@
|
|||||||
<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>
|
||||||
<description>Redundant semicolon</description>
|
<description>Redundant semicolon</description>
|
||||||
</problem>
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>Test.kt</file>
|
||||||
|
<line>43</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>44</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>45</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>49</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>
|
</problems>
|
||||||
|
|||||||
Reference in New Issue
Block a user