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)
|
||||
|
||||
if (element.node.elementType == KtTokens.SEMICOLON && isRedundant(element)) {
|
||||
holder.registerProblem(element,
|
||||
"Redundant semicolon",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
Fix)
|
||||
holder.registerProblem(
|
||||
element,
|
||||
"Redundant semicolon",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
Fix
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
if (!isAtEndOfLine) {
|
||||
//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 {
|
||||
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()) {
|
||||
&& it.declarations.isNotEmpty()
|
||||
) {
|
||||
//first semicolon in enum with no entries, but with some declarations
|
||||
return false
|
||||
}
|
||||
@@ -71,7 +74,7 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user