prettier / prettier/prettier

End-of-line comment inside object literal moved to next line

Open
#7,155 12 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prettier 1.19.1
Playground link

--parser babel

Input:

const x = {
  c: { // Very important key.
      a: 123
  }
};

Output:

const x = {
  c: {
    // Very important key.
    a: 123
  }
};

Expected behavior:

The comment should not be moved down.

Also affects TypeScript.

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 by reproducing the Playground example with the Babel parser and the JSX object literal shown in the issue; compare the behavior for JavaScript and TypeScript. Trace the formatter's comment-placement path for end-of-line comments, and consider the issue done when the comment remains on the same line as the object property in both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.