Prettier is moving comments to new line
Nobody has claimed this yet.
- 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
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
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