Redundant semicolon: don't report when semicolon is between type and '!'
#KT-38240 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
8e8171547b
commit
4cf83d9526
@@ -90,9 +90,13 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
||||
return false
|
||||
}
|
||||
|
||||
val prevNameReference = semicolon.getPrevSiblingIgnoringWhitespaceAndComments() as? KtNameReferenceExpression
|
||||
if (prevNameReference != null && prevNameReference.text in softModifierKeywords
|
||||
&& semicolon.getNextSiblingIgnoringWhitespaceAndComments() is KtDeclaration
|
||||
val prevSibling = semicolon.getPrevSiblingIgnoringWhitespaceAndComments()
|
||||
val nextSibling = semicolon.getNextSiblingIgnoringWhitespaceAndComments()
|
||||
if (prevSibling.safeAs<KtNameReferenceExpression>()?.text in softModifierKeywords &&
|
||||
nextSibling is KtDeclaration
|
||||
) return false
|
||||
if (nextSibling.safeAs<KtPrefixExpression>()?.operationToken == KtTokens.EXCL &&
|
||||
semicolon.prevLeaf()?.getStrictParentOfType<KtTypeReference>() != null
|
||||
) return false
|
||||
|
||||
return true
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
fun test(a: Any) {
|
||||
foo {
|
||||
val b = a as Boolean;<caret>
|
||||
!b
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(f: () -> Boolean) {}
|
||||
+5
@@ -8416,6 +8416,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenSoftModifierKeywordAndDeclaration3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("betweenTypeAndNotOperator.kt")
|
||||
public void testBetweenTypeAndNotOperator() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/betweenTypeAndNotOperator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("companionBeforeFun.kt")
|
||||
public void testCompanionBeforeFun() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");
|
||||
|
||||
Reference in New Issue
Block a user