prettier / prettier/prettier

Improve readability for logical expression with long chain

Open
#11,244 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.