Redundant semicolon: fix false positive between modifier and declaration
#KT-25579 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1898df3fb7
commit
2bf3b435f2
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
@@ -86,6 +87,11 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
||||
return false
|
||||
}
|
||||
|
||||
val prevNameReference = semicolon.getPrevSiblingIgnoringWhitespaceAndComments() as? KtNameReferenceExpression
|
||||
if (prevNameReference != null && prevNameReference.text in softModifierKeywords
|
||||
&& semicolon.getNextSiblingIgnoringWhitespaceAndComments() is KtDeclaration
|
||||
) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -112,4 +118,6 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
||||
descriptor.psiElement.delete()
|
||||
}
|
||||
}
|
||||
|
||||
private val softModifierKeywords = KtTokens.SOFT_KEYWORDS.types.mapNotNull { (it as? KtModifierKeywordToken)?.toString() }
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun test(import: Int) {
|
||||
import<caret>;
|
||||
val a = 1
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
fun test(import: Int) {
|
||||
import
|
||||
val a = 1
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
fun test(data: Int) {
|
||||
data<caret>;
|
||||
val a = 1
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
fun test(inline: Int) {
|
||||
inline<caret>;
|
||||
fun a() {
|
||||
}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// PROBLEM: none
|
||||
fun test(public: Int) {
|
||||
public // comment1
|
||||
<caret>; // comment2
|
||||
class A
|
||||
}
|
||||
+20
@@ -3973,6 +3973,26 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("betweenSoftKeywordAndDeclaration.kt")
|
||||
public void testBetweenSoftKeywordAndDeclaration() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftKeywordAndDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("betweenSoftModifierKeywordAndDeclaration.kt")
|
||||
public void testBetweenSoftModifierKeywordAndDeclaration() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftModifierKeywordAndDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("betweenSoftModifierKeywordAndDeclaration2.kt")
|
||||
public void testBetweenSoftModifierKeywordAndDeclaration2() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftModifierKeywordAndDeclaration2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("betweenSoftModifierKeywordAndDeclaration3.kt")
|
||||
public void testBetweenSoftModifierKeywordAndDeclaration3() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftModifierKeywordAndDeclaration3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("companionBeforeFun.kt")
|
||||
public void testCompanionBeforeFun() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");
|
||||
|
||||
Reference in New Issue
Block a user