Skip to content

Commit

Permalink
Fix chain method continuation for dot qualifying expression containin…
Browse files Browse the repository at this point in the history
…g a call expression returning a (higher order) function `chain-method-continuation` (#2305)

Closes #2304
  • Loading branch information
paul-dingemans authored Oct 13, 2023
1 parent 2acdeeb commit 2b25d78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Force blank line before object declaration if preceded by another declaration `blank-line-before-declaration` [#2284](https://github.com/pinterest/ktlint/issues/2284)
* Fix malformed AST when `&&` or `||` is at start of line `chain-wrapping` [#2297](https://github.com/pinterest/ktlint/issues/2297)
* Do not report false positives `type-argument-list-spacing` and `type-parameter-list-spacing` [#2299](https://github.com/pinterest/ktlint/issues/2299)
* Fix chain method continuation for dot qualifying expression containing a call expression returning a (higher order) function `chain-method-continuation` [#2304](https://github.com/pinterest/ktlint/issues/2304)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public class ChainMethodContinuationRule :
}
}

ARRAY_ACCESS_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION -> {
CALL_EXPRESSION, ARRAY_ACCESS_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION -> {
children()
.mapNotNull { it.toChainedExpression() }
.singleOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,25 @@ class ChainMethodContinuationRuleTest {
.setMaxLineLength()
.hasNoLintViolations()
}

@Test
fun `Issue 2304 - Given a dot qualified expression in which the call expression returns a function which is called with value argument`() {
val code =
"""
fun foo(baz: Baz) = bar.get()(baz)
""".trimIndent()
chainMethodContinuationRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2304 - Given a dot qualified expression in which the call expression returns a function which is called with value argument ans has a trailing lambda`() {
val code =
"""
fun foo(baz: Baz) =
bar.get()(baz) {
// do something
}
""".trimIndent()
chainMethodContinuationRuleAssertThat(code).hasNoLintViolations()
}
}

0 comments on commit 2b25d78

Please sign in to comment.