Improve readability for logical expression with long chain
Open
Nobody has claimed this yet.
lang:javascript
status:needs discussion
- Dominant language
- JavaScript
- Stars
- 52.3k
- Forks
- 5k
- Avg merge
- 19h 2m
- Merged PRs (30d)
- 117
Description
Prettier 2.3.2
Playground link
--parser babel
Input:
a = fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups.groupId ?? b
a = fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups.groupId || b
a = fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups.groupId ? b : c
Output:
a =
fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups
.groupId ?? b;
a =
fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups
.groupId || b;
a = fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups
.groupId
? b
: c;
Expected behavior:
Expect break before or after ?? and ||, maybe
a = fooBarFooBarFooBar.match(/^foo-bar\/foo-bar\/(?<groupId>.*)$/)?.groups
.groupId ??
b;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the linked Playground reproduction as the entry point, comparing the provided input and current output for the ??, ||, and conditional expressions. The work is done when the logical-expression formatting breaks before or after ?? and || as described, while preserving the expected conditional-expression formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100