Skip to content

Add a KotlinLang formatter for when expressions - #687

Open
AbdullinAM wants to merge 7 commits into
mainfrom
abdullin/when-conditions
Open

Add a KotlinLang formatter for when expressions#687
AbdullinAM wants to merge 7 commits into
mainfrom
abdullin/when-conditions

Conversation

@AbdullinAM

@AbdullinAM AbdullinAM commented Aug 31, 2026

Copy link
Copy Markdown
Member
  • Don't force break after comma in multiple-condition entries
  • Don't allow break before -> in any cases

@AbdullinAM
AbdullinAM force-pushed the abdullin/when-conditions branch 2 times, most recently from d6c240b to 5606559 Compare August 31, 2026 15:43
@AbdullinAM
AbdullinAM force-pushed the abdullin/rewrite-to-contexts branch 3 times, most recently from 03f232d to 6a69f86 Compare September 2, 2026 08:29
Base automatically changed from abdullin/rewrite-to-contexts to main September 2, 2026 08:43
@AbdullinAM
AbdullinAM force-pushed the abdullin/when-conditions branch from 5606559 to 24107ee Compare September 2, 2026 09:33
@kunyavskiy

Copy link
Copy Markdown
Collaborator

What do you think about breaking before if, instead of breaking after if in when guard?

Comment thread core/src/test/resources/cases/new_codestyle/when/guardComments.new.output Outdated
@AbdullinAM
AbdullinAM force-pushed the abdullin/when-conditions branch 5 times, most recently from 6dcd9f7 to 3e519c6 Compare September 4, 2026 12:35
@AbdullinAM
AbdullinAM force-pushed the abdullin/when-conditions branch from 3e519c6 to 7b1d636 Compare September 4, 2026 14:53
} else {
val conditions = whenEntry.conditions
val lastIndex = conditions.lastIndex
val lastCommaIndex = if (forceMultiline) lastIndex + 1 else lastIndex

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: probably checking on trailing lambda explicitly is better, in case we would have other reasons to make multiline later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants