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
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
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
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