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

Fix chain method continuation containining higer order function call #2305

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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()
}
}