Skip to content

Commit

Permalink
Fixing issue where ktlint would erroneously want to insert a newline …
Browse files Browse the repository at this point in the history
…if parameter comments were used (#434)

* Fixing issue where ktlint would erroneously want to insert a newline if parameter comments were used

Fixes pinterest/ktlint#433
  • Loading branch information
shashachu authored May 22, 2019
1 parent df55f84 commit b61e827
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast {
) {
return
}
if (!node.nextCodeLeaf()?.prevLeaf().isWhiteSpaceWithNewline() &&
if (!node.nextCodeLeaf()?.prevLeaf {
// Skip comments, whitespace, and empty nodes
!it.isPartOfComment() &&
!it.isWhiteSpaceWithoutNewline() &&
it.textLength > 0
}.isWhiteSpaceWithNewline() &&
// IDEA quirk:
// if (true &&
// true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,27 @@ class IndentationRuleTest {
).isEmpty()
}

@Test(description = "https://github.com/pinterest/ktlint/issues/433")
fun testLintParameterListWithComments() {
assertThat(
IndentationRule().lint(
"""
fun main() {
foo(
/*param1=*/param1,
/*param2=*/param2
)
foo(
/*param1=*/ param1,
/*param2=*/ param2
)
}
""".trimIndent()
)
).isEmpty()
}

@Test
fun testUnexpectedTabCharacter() {
val ktScript = "fun main() {\n\t\treturn 0\n\t}"
Expand Down

0 comments on commit b61e827

Please sign in to comment.