prettier / prettier/prettier

Call Wrapping: Keep function name and arguments together

Open
#5,610 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Function call wrapping is not optimal for readability: Function names tend to get pushed to the right, whereas arguments end up on the left, creating a wide gap that the eyes have to cross in order to read the call.

It would be great if we could make this better, e.g. as suggested below. I will be happy to make the necessary code changes if there is consensus on this suggestion.

Prettier 1.15.3
Playground link

--parser babylon

Input:

const {qfwvfkwjdqgz, bctsyljqucgz, xuodxhmgwwpw} = 
  qbhtcuzxwedz(yrwimwkjeeiu, njwvozigdkfi, alvvjgkmnmhd);

Output:

const { qfwvfkwjdqgz, bctsyljqucgz, xuodxhmgwwpw } = qbhtcuzxwedz(
  yrwimwkjeeiu,
  njwvozigdkfi,
  alvvjgkmnmhd
);

Expected behavior:

const { qfwvfkwjdqgz, bctsyljqucgz, xuodxhmgwwpw } = 
  qbhtcuzxwedz(
    yrwimwkjeeiu,
    njwvozigdkfi,
    alvvjgkmnmhd
  );

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 Playground example and compare the current and expected JSX output for the call-wrapping case. Trace the formatter entry point responsible for this behavior, then identify the relevant existing tests before deciding how the expected output should be covered. Done means the example keeps the function name and arguments together as shown without regressing other wrapping cases.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.