Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping rule should not prevent comments for interfaces on separate lines #1457

Merged
merged 5 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ public class WrappingRule : Rule(
// put entries on separate lines
// TODO: group emit()s below with the one above into one (similar to ParameterListWrappingRule)
for (c in node.children()) {
if (c.elementType == COMMA && !c.treeNext.isWhiteSpaceWithNewline()) {
if (c.elementType == COMMA &&
!c.treeNext.isWhiteSpaceWithNewline() &&
!c.isFollowedByCommentOnSameLine()
) {
requireNewlineAfterLeaf(
nodeAfterWhichNewlineIsRequired = c,
autoCorrect = autoCorrect,
Expand All @@ -222,6 +225,10 @@ public class WrappingRule : Rule(
}
}

private fun ASTNode.isFollowedByCommentOnSameLine() =
nextLeaf { !it.isWhiteSpaceWithoutNewline() }
?.isPartOfComment() == true

private fun rearrangeValueList(
node: ASTNode,
autoCorrect: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,38 @@ internal class WrappingRuleTest {
).isEmpty()
}

@Test
fun `test wrapping rule allows line comment`() {
val code =
"""
interface Foo1 {}
interface Foo2 {}
interface Foo3 {}
class Bar :
Foo1, // this comment should be legal
Foo2,// this comment should be legal
Foo3 {
}
""".trimIndent()
wrappingRuleAssertThat(code).hasNoLintViolations()
}

paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
@Test
fun `test wrapping rule allows block comment`() {
val code =
"""
interface Foo1 {}
interface Foo2 {}
interface Foo3 {}
class Bar :
Foo1, /* this comment should be legal */
Foo2,/* this comment should be legal */
Foo3 {
}
""".trimIndent()
wrappingRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun testLintNewlineAfterEqAllowed() {
assertThat(
Expand Down