You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For curly braces, put the opening brace in the end of the line where the construct begins, and the closing brace on a separate line aligned horizontally with the opening construct.
I expect braces to be aligned with their opening construct, taking into account continuation indentation.
Observed Behavior
The opening construct seems to be evaluated as the imageUrls declaration, but the brace belongs with the map function call. This issue only seems to happen with this particular indentation in tandem with safe-call operators.
A case can be made that the ?.map call should be wrapped to the next line, and that's fine, but this indentation seems clearly awkward to me. If the wrapping of the map method is the rub, then ktlint should auto format that as well.
Steps to Reproduce
Run ktlint on the following code. Observe the awkward indentation and the different in output bar is made non-nullable.
val bar:List<Integer>?=listOf(1, 2, 3, 4)
val foo = bar
?.filter { number ->
number %2==0
}?.map { evenNumber ->
evenNumber * evenNumber
}
Your Environment
Version of ktlint used: 0.37.1
Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
val commonArgs = arrayOf(
"--android",
"--reporter=plain?group_by_file",
"src/**/*.kt",
"**/*.gradle.kts"
)
val ktlint by registering(JavaExec::class) {
group = "verification"
description = "Check Kotlin code style."
classpath = configurations.getByName("ktlint")
main = "com.pinterest.ktlint.Main"
args(*commonArgs)
}
val ktlintFormat by registering(JavaExec::class) {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = configurations.getByName("ktlint")
main = "com.pinterest.ktlint.Main"
args("--format", *commonArgs)
}
Version of Gradle used (if applicable): 6.4.1
Operating System and version: macOS 10.15.5
Link to your project (if it's a public repository): It's a commercial, closed-source project.
The text was updated successfully, but these errors were encountered:
Expected Behavior
https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
I expect braces to be aligned with their opening construct, taking into account continuation indentation.
Observed Behavior
The opening construct seems to be evaluated as the
imageUrls
declaration, but the brace belongs with the map function call. This issue only seems to happen with this particular indentation in tandem with safe-call operators.A case can be made that the
?.map
call should be wrapped to the next line, and that's fine, but this indentation seems clearly awkward to me. If the wrapping of the map method is the rub, then ktlint should auto format that as well.Steps to Reproduce
Run ktlint on the following code. Observe the awkward indentation and the different in output bar is made non-nullable.
Your Environment
The text was updated successfully, but these errors were encountered: