Don't report redundant semicolon for a call before lambda expression
So #KT-22719 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f9555f3f64
commit
059a797e10
@@ -34,17 +34,19 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
super.visitElement(element)
|
super.visitElement(element)
|
||||||
|
|
||||||
if (element.node.elementType == KtTokens.SEMICOLON && isRedundant(element)) {
|
if (element.node.elementType == KtTokens.SEMICOLON && isRedundant(element)) {
|
||||||
holder.registerProblem(element,
|
holder.registerProblem(
|
||||||
"Redundant semicolon",
|
element,
|
||||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
"Redundant semicolon",
|
||||||
Fix)
|
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||||
|
Fix
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isRedundant(semicolon: PsiElement): Boolean {
|
private fun isRedundant(semicolon: PsiElement): Boolean {
|
||||||
val nextLeaf = semicolon.nextLeaf { it !is PsiWhiteSpace && it !is PsiComment || it.isLineBreak() }
|
val nextLeaf = semicolon.nextLeaf { it !is PsiWhiteSpace && it !is PsiComment || it.isLineBreak() }
|
||||||
val isAtEndOfLine = nextLeaf == null || nextLeaf.isLineBreak()
|
val isAtEndOfLine = nextLeaf == null || nextLeaf.isLineBreak()
|
||||||
if (!isAtEndOfLine) {
|
if (!isAtEndOfLine) {
|
||||||
//when there is no imports parser generates empty import list with no spaces
|
//when there is no imports parser generates empty import list with no spaces
|
||||||
@@ -59,7 +61,8 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
(semicolon.parent.parent as? KtClass)?.let {
|
(semicolon.parent.parent as? KtClass)?.let {
|
||||||
if (it.isEnum() && it.getChildrenOfType<KtEnumEntry>().isEmpty()) {
|
if (it.isEnum() && it.getChildrenOfType<KtEnumEntry>().isEmpty()) {
|
||||||
if (semicolon.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment && !it.isLineBreak() }?.node?.elementType == KtTokens.LBRACE
|
if (semicolon.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment && !it.isLineBreak() }?.node?.elementType == KtTokens.LBRACE
|
||||||
&& it.declarations.isNotEmpty()) {
|
&& it.declarations.isNotEmpty()
|
||||||
|
) {
|
||||||
//first semicolon in enum with no entries, but with some declarations
|
//first semicolon in enum with no entries, but with some declarations
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,7 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextLeaf?.nextLeaf { it !is PsiComment }?.node?.elementType == KtTokens.LBRACE) {
|
if (nextLeaf?.nextLeaf { it !is PsiWhiteSpace && it !is PsiComment }?.node?.elementType == KtTokens.LBRACE) {
|
||||||
return false // case with statement starting with '{' and call on the previous line
|
return false // case with statement starting with '{' and call on the previous line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
fun test() {
|
||||||
|
foo()<caret>;
|
||||||
|
// comment
|
||||||
|
{ i: Int -> }.doIt()
|
||||||
|
}
|
||||||
|
fun foo() {}
|
||||||
|
fun ((Int) -> Unit).doIt() {}
|
||||||
+6
@@ -2823,6 +2823,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSemicolon"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSemicolon"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("beforeCommentAndLambda.kt")
|
||||||
|
public void testBeforeCommentAndLambda() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/beforeCommentAndLambda.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("companionBeforeFun.kt")
|
@TestMetadata("companionBeforeFun.kt")
|
||||||
public void testCompanionBeforeFun() throws Exception {
|
public void testCompanionBeforeFun() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user