Revert "TrailingCommaInspection: don't report Missing line break for when entry that has no trailing comma"

This reverts commit 25787eb8
This commit is contained in:
Yan Zhulanow
2020-06-02 00:16:45 +09:00
parent a421f74ef0
commit 4d859a7212
3 changed files with 73 additions and 4 deletions
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.idea.util.isComma
import org.jetbrains.kotlin.idea.util.isLineBreak import org.jetbrains.kotlin.idea.util.isLineBreak
import org.jetbrains.kotlin.idea.util.leafIgnoringWhitespaceAndComments import org.jetbrains.kotlin.idea.util.leafIgnoringWhitespaceAndComments
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtWhenEntry
import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.psi.psiUtil.*
import javax.swing.JComponent import javax.swing.JComponent
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -63,9 +62,7 @@ class TrailingCommaInspection(
} }
val last = TrailingCommaHelper.elementAfterLastElement(commaOwner) val last = TrailingCommaHelper.elementAfterLastElement(commaOwner)
val whenEntryWithoutTrailingComma = if (last?.prevLeaf(true)?.isLineBreak() == false) {
commaOwner is KtWhenEntry && TrailingCommaHelper.trailingCommaOrLastElement(commaOwner)?.isComma != true
if (last?.prevLeaf(true)?.isLineBreak() == false && !whenEntryWithoutTrailingComma) {
registerProblemForLineBreak( registerProblemForLineBreak(
commaOwner, commaOwner,
last, last,
@@ -5507,6 +5507,18 @@
<offset>8</offset> <offset>8</offset>
<length>1</length> <length>1</length>
</problem> </problem>
<problem>
<file>WhenEntry.kt</file>
<line>15</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>44</offset>
<length>1</length>
</problem>
<problem> <problem>
<file>WhenEntry.kt</file> <file>WhenEntry.kt</file>
<line>21</line> <line>21</line>
@@ -5543,4 +5555,28 @@
<offset>9</offset> <offset>9</offset>
<length>1</length> <length>1</length>
</problem> </problem>
<problem>
<file>WhenEntry.kt</file>
<line>54</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>15</offset>
<length>1</length>
</problem>
<problem>
<file>WhenEntry.kt</file>
<line>62</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>15</offset>
<length>1</length>
</problem>
</problems> </problems>
@@ -1907,6 +1907,18 @@
<offset>44</offset> <offset>44</offset>
<length>1</length> <length>1</length>
</problem> </problem>
<problem>
<file>WhenEntry.kt</file>
<line>15</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>44</offset>
<length>1</length>
</problem>
<problem> <problem>
<file>WhenEntry.kt</file> <file>WhenEntry.kt</file>
<line>15</line> <line>15</line>
@@ -1967,6 +1979,18 @@
<offset>8</offset> <offset>8</offset>
<length>1</length> <length>1</length>
</problem> </problem>
<problem>
<file>WhenEntry.kt</file>
<line>54</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>15</offset>
<length>1</length>
</problem>
<problem> <problem>
<file>WhenEntry.kt</file> <file>WhenEntry.kt</file>
<line>54</line> <line>54</line>
@@ -1979,6 +2003,18 @@
<offset>8</offset> <offset>8</offset>
<length>1</length> <length>1</length>
</problem> </problem>
<problem>
<file>WhenEntry.kt</file>
<line>62</line>
<module>testProject</module>
<package>light_idea_test_case</package>
<entry_point TYPE="file" FQNAME="WhenEntry.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">Trailing comma recommendations</problem_class>
<description>Missing line break</description>
<highlighted_element>-</highlighted_element>
<offset>15</offset>
<length>1</length>
</problem>
<problem> <problem>
<file>WhenEntry.kt</file> <file>WhenEntry.kt</file>
<line>62</line> <line>62</line>