Skip to content

Commit

Permalink
ArgumentListWrappingRule: fix false positive when max_line_length in …
Browse files Browse the repository at this point in the history
…EditorConfig is set (pinterest#1010)
  • Loading branch information
t-kameyama authored and romtsn committed Mar 7, 2021
1 parent 316e407 commit b7cb8f8
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 @@ -69,7 +69,7 @@ class ArgumentListWrappingRule : Rule("argument-list-wrapping") {
val putArgumentsOnSeparateLines =
node.textContainsIgnoringLambda('\n') ||
// max_line_length exceeded
maxLineLength > -1 && (node.column - 1 + node.textLength) > maxLineLength
maxLineLength > -1 && (node.column - 1 + node.textLength) > maxLineLength && !node.textContains('\n')
if (putArgumentsOnSeparateLines) {
// IDEA quirk:
// generic<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,32 @@ class ArgumentListWrappingRuleTest {
).isEmpty()
}

@Test
fun testLambdaArgumentsAreIgnoredWithMaxLineLength() {
assertThat(
ArgumentListWrappingRule().lint(
"""
abstract class A(init: String.() -> Int)
class B : A({
toInt()
toInt()
toInt()
toInt()
toInt()
toInt()
})
fun test(a: Any, b: (Any) -> Any) {
test(a = "1", b = {
it.toString()
})
}
""".trimIndent(),
userData = mapOf("max_line_length" to "80")
)
).isEmpty()
}

@Test
fun testFormatWithLambdaArguments() {
assertThat(
Expand Down

0 comments on commit b7cb8f8

Please sign in to comment.