ktlint
ktlint copied to clipboard
indentation for expressions on newline
Expected Behavior
This should not trigger any rules (and is correct in 0.39.0):
operator fun x(resources: Resources, entity: X):
ListItem<SomeClass> =
foo(
resources = resources,
...
)
Observed Behavior (in 0.41.0)
operator fun x(resources: Resources, entity: X):
ListItem<SomeClass> =
foo(
resources = resources,
...
)
Steps to Reproduce
the same can be observed for
foo()
List<Sth> = map {
when (it.a) {
a.b -> c
else -> it
}
}
bar()
foo()
positiveButtonText =
R.string.my_long_res_name_that_forces_a_linebreak_string
bar()
Your Environment
- Version of ktlint used: upgrade to 0.41.0 (used to work in 0.39.0)
- Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): plain ktlint on cmd
- Version of Gradle used (if applicable):
- Operating System and version: any
- Link to your project (if it's a public repository): sry
I confirm this incorrect behaviour in 0.41.0
This issue will be solved by https://github.com/pinterest/ktlint/issues/1341. Note that code sample given in this issue do not adhere to the coding guideline and should be rewritten as documented in previously mentioned issue.
operator fun x(resources: Resources, entity: X):
ListItem<SomeClass> =
foo(
resources = resources,
...
)
The experimental:function-signature
rules which was released in 0.46.x is able to rewrite the examples above in accordance to the Kotlin Coding conventions and Android Kotlin Style guide. The return type ListItem<SomeClass>
and the closing parenthesis on the function should be on the same line. Once that is fixed, it is clear that the identation should be 4 instead of 8 characters.
The second example is ambiguous. If I interpret it as:
fun foobar() {
foo()
val something: List<Sth> = map {
when (it.a) {
a.b -> c
else -> it
}
}
bar()
}
then its formatting is correct.
Same for third example:
fun foobar() {
foo()
positiveButtonText =
R.string.my_long_res_name_that_forces_a_linebreak_string
bar()
}
Please let me know if I misinterpreted the last two examples and provide some real working code snippets which demonstrate the problems.
Original problem is also mentioned in #1217. As that issue contains more context and discussion, this issue is closed in favour of #1217. For second and third problem no feedback has been received since July 6th, 2022.
And now actually closing the issue.