prettier / prettier/prettier

When an arrow function appears as a lone call expression arg, params hug when arrow function body is a block statement, but don't otherwise

Open
#3,465 6 comments 29 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prettier 1.9.1
Playground link

Input:

const superLongVariable = []

const test1 = [].filter(item => superLongVariable.includes(item.veryLongAttribute) && superLongVariable.includes(item.veryLongAttribute2))

const test2 = [].filter((item, index) => superLongVariable.includes(item.veryLongAttribute) && superLongVariable.includes(item.veryLongAttribute2))

const test3 = [].filter(item => { return superLongVariable.includes(item.veryLongAttribute) && superLongVariable.includes(item.veryLongAttribute2)})

Output:

const superLongVariable = [];

const test1 = [].filter(
  item =>
    superLongVariable.includes(item.veryLongAttribute) &&
    superLongVariable.includes(item.veryLongAttribute2)
);

const test2 = [].filter(
  (item, index) =>
    superLongVariable.includes(item.veryLongAttribute) &&
    superLongVariable.includes(item.veryLongAttribute2)
);

const test3 = [].filter(item => {
  return (
    superLongVariable.includes(item.veryLongAttribute) &&
    superLongVariable.includes(item.veryLongAttribute2)
  );
});

Expected behavior:

const superLongVariable = [];

const test1 = [].filter(item =>
  superLongVariable.includes(item.veryLongAttribute) &&
  superLongVariable.includes(item.veryLongAttribute2)
);

const test2 = [].filter((item, index) =>
  superLongVariable.includes(item.veryLongAttribute) &&
  superLongVariable.includes(item.veryLongAttribute2)
);

const test3 = [].filter(item => {
  return (
    superLongVariable.includes(item.veryLongAttribute) &&
    superLongVariable.includes(item.veryLongAttribute2)
  );
});

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

Reproduce the formatter behavior from the linked Prettier Playground using the three JSX inputs. Compare the current output with the expected output, then trace the relevant formatting behavior and verify that lone call-expression arguments format consistently for both arrow-function body forms.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.