Closed vanniktech closed 11 months ago
This might be the same occurrence?
I don't why a new line was entered after the ->
Why though? My understanding is that the 1st code is correctly formatted.
Yes, it is correctly formatted depending on the chosen code style. Starting from ktlint 1.x
the default code style of ktlint is changed from intellij_idea
to ktlint_official
. So, if you have not set the code style explicitly in your .editorconfig
, the code sample above which was accepted by 0.x
is now not accepted anymore. The multiline-expression-wrapping
ensures a more consistent code style throughout a project as multiline expressions are wrapped all in the same way.
With other code styles, both samples below are accepted:
val yearsAgo = dailyQueryWrapper.dailyPictureQueries.yearsAgo(
monthDates = localDates
.filter { it.atTime(it.yearsAgoReminderTime()) >= localDateTime } // Only allow for the future!
.map { LocalDateAdapter.encode(it).toString().drop(4) },
year = currentYearString,
).executeAsList()
and
val yearsAgo =
dailyQueryWrapper.dailyPictureQueries.yearsAgo(
monthDates =
localDates
.filter { it.atTime(it.yearsAgoReminderTime()) >= localDateTime } // Only allow for the future!
.map { LocalDateAdapter.encode(it).toString().drop(4) },
year = currentYearString,
).executeAsList()
Advantage is that you can decide on a per-case base what style is more readable. Disadvantage it can result in different formatting for the same code block in the same code base.
Huh. Using ktlint_code_style=intellij_idea
helped me in that case. I would have expected the change of the default to be in the 1.0.0 release notes. Thanks for your immediate help!
Huh. Using
ktlint_code_style=intellij_idea
helped me in that case. I would have expected the change of the default to be in the 1.0.0 release notes. Thanks for your immediate help!
It was mentioned in the release notes. But it might got lost between all other changes.
The following code gets flagged:
And then reformatted to:
Why though? My understanding is that the 1st code is correctly formatted.