TrailingComma: fix case of when without expression or property
#KT-34744 #KT-36393 Fixed
This commit is contained in:
@@ -22,8 +22,10 @@ import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings
|
||||
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.KtWhenEntry
|
||||
import org.jetbrains.kotlin.psi.KtWhenExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
/*
|
||||
* ASTBlock.node is nullable, this extension was introduced to minimize changes
|
||||
@@ -64,7 +66,7 @@ fun KtFunctionLiteral.needTrailingComma(settings: CodeStyleSettings?, checkExist
|
||||
fun KtWhenEntry.needTrailingComma(settings: CodeStyleSettings?, checkExistingTrailingComma: Boolean = true): Boolean = needTrailingComma(
|
||||
settings = settings,
|
||||
trailingComma = { if (checkExistingTrailingComma) trailingComma else null },
|
||||
additionalCheck = { !isElse },
|
||||
additionalCheck = { !isElse && parent.cast<KtWhenExpression>().leftParenthesis != null },
|
||||
globalEndOffset = { arrow?.endOffset },
|
||||
)
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ fun foo(x: Any) {
|
||||
}
|
||||
|
||||
when {
|
||||
x in coll,
|
||||
x in coll
|
||||
-> {
|
||||
|
||||
}
|
||||
|
||||
-12
@@ -3443,16 +3443,4 @@
|
||||
<offset>8</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>WhenEntry.kt</file>
|
||||
<line>69</line>
|
||||
<module>testProject</module>
|
||||
<package>light_idea_test_case</package>
|
||||
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
|
||||
<description>Missing trailing comma</description>
|
||||
<highlighted_element>l</highlighted_element>
|
||||
<offset>16</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
</problems>
|
||||
Vendored
-12
@@ -2027,18 +2027,6 @@
|
||||
<offset>8</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>WhenEntry.kt</file>
|
||||
<line>69</line>
|
||||
<module>testProject</module>
|
||||
<package>light_idea_test_case</package>
|
||||
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
|
||||
<description>Missing trailing comma</description>
|
||||
<highlighted_element>l</highlighted_element>
|
||||
<offset>16</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>LambdaValueParameters.kt</file>
|
||||
<line>4</line>
|
||||
|
||||
-12
@@ -3443,16 +3443,4 @@
|
||||
<offset>8</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>WhenEntry.kt</file>
|
||||
<line>69</line>
|
||||
<module>testProject</module>
|
||||
<package>light_idea_test_case</package>
|
||||
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
|
||||
<description>Missing trailing comma</description>
|
||||
<highlighted_element>l</highlighted_element>
|
||||
<offset>16</offset>
|
||||
<length>1</length>
|
||||
</problem>
|
||||
</problems>
|
||||
Reference in New Issue
Block a user