prettier / prettier/prettier

Prettier is moving comments to new line

Open
#15,546 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prettier 3.0.3
Playground link

--parser babel
--print-width 120
--tab-width 4
--single-quote
--trailing-comma none

Input:

CustomFramework.component.register('component-name', { //No I18N
    data: function () {
        return {
            message: CustomTypeDef.attr('object', { //No I18N
                default: {
                    foo: 'bar' //No I18N
                }
            })
        }
    }
}, {dependencies: ['CustomTypeDef']}); //No I18N

Output:

CustomFramework.component.register(
    'component-name',
    {
        //No I18N
        data: function () {
            return {
                message: CustomTypeDef.attr('object', {
                    //No I18N
                    default: {
                        foo: 'bar' //No I18N
                    }
                })
            };
        }
    },
    { dependencies: ['CustomTypeDef'] }
); //No I18N

Expected behavior:

I'm using a Proprietary JS Framework for work, Which's syntax looks something like this. And there is a Git-Hook that was added long time ago to check if all the string literals are having proper translations. If a string literal doesn't have translation then we have to append a comment string "//No I18N" to that line. Although at this point this check is not serving any purpose, I still have to add the comment and getting this removed is impossible as it is a org-wide standard.

I'm using Prettier in VSCode via extension version 10.1.0 and it is moving the comment to next line (only happening when comment is inside object literal "{"). Although there are some obvious work arounds for this, just looking for some alternate suggestions here.

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 reproduction using Prettier 3.0.3 and the shown parser and formatting options. Compare the JSX input and output, focusing on comments inside object literals and the trailing comment after the call. Done means the reproduction no longer moves the affected inline comments to a new line, with behavior verified against this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
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.