prettier / prettier/prettier

More consistent parentheses preservation in multiline expressions

Open
#9,619 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:arrow functions lang:javascript status:needs discussion
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 2.1.2
Playground link

--parser typescript
--trailing-comma none

Input:

ctx.renderPage = () => (
  originalRenderPage({
    enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
  })
);

Output:

ctx.renderPage = () =>
  originalRenderPage({
    enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />)
  });

Expected behavior:
For the parentheses around this multiline expression to be preserved (why is Prettier even removing my manually placed parens in the first place?). It greatly improves legibility, and it would be in line with JSX component expression formatting:

Playground link

const SomeComponent = () => (
  <div>
    <h1>Hello</h1>
    <p>World</p>
  </div>
);

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

Start with the linked Prettier Playground reproduction using the TypeScript parser and compare the shown input and output. The work is done when the parentheses around the multiline arrow-function expression are preserved consistently with the JSX example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.