You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
area:commentsIssues with how Prettier prints commentshelp wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!
Besides statements in code, I think it's also desirable when comments are formatted in a way that makes them easy to read. I once hacked together a small atom plugin, that worked for my usecase: format-javascript-comment.
Features that could be interesting for prettier are the following:
It wraps lines at a specific line length by taking minimum raggedness into account.
It wraps lines before JSDoc tags.
Leaves empty lines in multiline comments in place.
Here's a small demo:
It would of course be really cool if this was baked into prettier 🙂.
Reacted by Sindre Sorhus, Alexander D'Este, Nate Hunzaker, Georgii Dolzhykov, Daniel Steigerwald, Kristján Oddsson, Bryan Smith, David Philipson, Jason Kuhrt, Ivan Novikov and 310 more
Reacted by Philipp Rudloff
Reacted by Github's Fifn2, Jason Kuhrt, oleg koval, Marcin Dawid Nowaczyk, Bartosz Gościński, Thomas Willheim, wenchaoding, Leonardo Salazar, Luis Herranz, drummachineshavenosoul and 26 more
This is a neat idea, but we need to make comments fully robust first. Currently they are moved around incorrectly and I'm about to rehaul how comments work. Let's get that in first and then we can talk about it.
I'm a little hesitant to do this because users may put big diagrams or something in comments, and like string templates, it's kind of nice that we don't touch them. Also, users can combine your tool with ours to format both separately. We can keep this issue open for now though.
Tweaking the title to make it more clear.
Reacted by Alex Rattray, Daniel Yim, Lipis, Bryan Levay, avin-shum, Jason Gretz, Klaus Hott Vidal, Moritz Mahringer, Escape0707, James Jensen and 5 more
I personally would be very wary of reformatting within comments, as it tends to break a lot of things such as ascii diagrams, table-formatted text, and the like.
Reacted by Rohan Talip, James Jensen, tkontisdeus and Władysław Raczek
What about introducing a wrapComments option, defaulted to false? Although I can see how taking this approach in general could lead to an explosion of options...
Reacted by Lipis, Josh Froelich, Luis E. González, H, Eric Hebert, Mubaraq Wahab, Maksym Minenko, James Jensen, Albert Schilling, Gavin Golden and 6 more
Or just allow the same flag to skip a comment block from being formatted as other code (pending in #671)?
Reacted by Jason Kuhrt, Ivan Novikov, Ian Obermiller, Aaron Hardy, Alex Walter, Joe Alden, Jurosh, Mubaraq Wahab, James Jensen, Marvin Heilemann and 2 more
@rattrayalex What would you suggest how this could be integrated? With or without an option? Having it be skippable with prettier-ignore is probably pretty important.
Btw. I recently discovered something my atom plugin currently doesn't cover: Treating code blocks like {thisIsAProperty: true, hereIsAnotherProperty: false} in comments atomic, meaning they can't be split by white space. I usually mark these parts with back ticks, so they should easily be identifiable (the back ticks are removed from my snippet here in Github).
@amannn it would be great if this could be built well enough that it doesn't need to be an option. At a minimum, that means respecting prettier-ignore as you mentioned. It also means developing good heuristic around things like ascii-text, code examples (as you mentioned), etc.
Probably the best place to start would be gathering a bunch of examples of comment blocks from around github, and forming a test file with them.
It's also fantastic that you have an existing atom plugin; building on work & iteration from that would obviously be quite helpful.
Imagine if we could format JavaScript inside Markdown (#2444) inside JavaScript comments!
/** * ```js * if (hasScienceGoneTooFar()) { * throw new Issue("prettier/prettier", "wow"); * } * ``` */functionwow(){}
Reacted by Jan Amann, Thomas Waterfall, Daryl Roberts, Vaughan Rouesnel, Ian Copp, Anton Vynogradenko, Kim Joar Bekkelund, Artem Sapegin, Bazyli Brzóska, Lipis and 30 more
Reacted by Bazyli Brzóska, Pedro Moreira, Alex Burner, Bryan Swagerty, Marvin Heilemann, Shani Kehati, OD, Javier Lopez, Adam Verner and eugene-korial
An issue with making wrapped comments respect // prettier-ignore is if the programmer's intent is to ignore the statement following the API comments it's ignoring. Instead there could be prettier-ignore-comment?
Reacted by Anton Vynogradenko, Rohan Talip, Kyle Chilcutt and Marvin Heilemann
Yes, good idea to handle /** */ as Markdown and IMO it would be easy if we would ignore /**/ or //. That way ASCII arts would be safe since that should use the /**/ syntax anyway.
In the meantime I am using Rewrap, a VSCode extension.
Reacted by Joram van den Boezem, Felix Hungenberg, Sean Zhu, Lynn Romich, Cyrus, Carlo Patti, Matt Langston, Rafał Rzepecki, DerZyklop, Bernard and 2 more
Reacted by Gediminas Bivainis, Bernard and Karl Horky
It's F# and C# code - if anyone would be interested in starting to get involved in the Rewrap code, there's an initiative by the community to fork it here (original author is no longer around):
Hi! I'd like to work on this and want to agree on the design before writing code, since the main concerns here have been ASCII art, prettier-ignore fatigue and the no-new-options policy.
Proposal (phase 1, JS/TS only):
No new option. Reuse proseWrap. With the default ("preserve") nothing changes for anyone.
With proseWrap: "always"/"never", only /** ... */ doc comments are treated as Markdown paragraphs and rewrapped to printWidth (accounting for indentation and the * prefix), reusing the existing Markdown printer.
Never touched: // and plain /* */ comments, JSDoc tag lines (@param etc., left as-is in phase 1), fenced or 4-space-indented code, lists, tables, known directives, and anything under prettier-ignore.
Idempotent, with fixtures for each case above, and no existing snapshot changes.
Would the team accept a PR along these lines? Happy to adjust scope (e.g. keep it behind proseWrap: "always" only).
area:commentsIssues with how Prettier prints commentshelp wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!
Activity
jlongster commentedon Jan 17, 2017
This is a neat idea, but we need to make comments fully robust first. Currently they are moved around incorrectly and I'm about to rehaul how comments work. Let's get that in first and then we can talk about it.
I'm a little hesitant to do this because users may put big diagrams or something in comments, and like string templates, it's kind of nice that we don't touch them. Also, users can combine your tool with ours to format both separately. We can keep this issue open for now though.
Tweaking the title to make it more clear.
[-]Prettier comments[/-][+]Automatically wrap comments[/+]sophistifunk commentedon Jan 17, 2017
I personally would be very wary of reformatting within comments, as it tends to break a lot of things such as ascii diagrams, table-formatted text, and the like.
liddellj commentedon Feb 13, 2017
What about introducing a
wrapCommentsoption, defaulted tofalse? Although I can see how taking this approach in general could lead to an explosion of options...erbridge commentedon Feb 13, 2017
Or just allow the same flag to skip a comment block from being formatted as other code (pending in #671)?
[-]Automatically wrap comments[/-][+]Wrap comments[/+]rattrayalex commentedon Jul 14, 2017
There was a PR adding this functionality to JSX not too long ago. Comments have also largely had the overhaul mentioned, but still need some work.
If anyone is looking for a fun challenge, this may be a prime candidate!
amannn commentedon Jul 14, 2017
Great to see some people interested in this idea!
@rattrayalex What would you suggest how this could be integrated? With or without an option? Having it be skippable with
prettier-ignoreis probably pretty important.Btw. I recently discovered something my atom plugin currently doesn't cover: Treating code blocks like
{thisIsAProperty: true, hereIsAnotherProperty: false}in comments atomic, meaning they can't be split by white space. I usually mark these parts with back ticks, so they should easily be identifiable (the back ticks are removed from my snippet here in Github).rattrayalex commentedon Jul 14, 2017
@amannn it would be great if this could be built well enough that it doesn't need to be an option. At a minimum, that means respecting
prettier-ignoreas you mentioned. It also means developing good heuristic around things like ascii-text, code examples (as you mentioned), etc.Probably the best place to start would be gathering a bunch of examples of comment blocks from around github, and forming a test file with them.
It's also fantastic that you have an existing atom plugin; building on work & iteration from that would obviously be quite helpful.
azz commentedon Jul 15, 2017
Imagine if we could format JavaScript inside Markdown (#2444) inside JavaScript comments!
samhunta commentedon Aug 17, 2017
An issue with making wrapped comments respect
// prettier-ignoreis if the programmer's intent is to ignore the statement following the API comments it's ignoring. Instead there could be prettier-ignore-comment?22 remaining items
fardad-dev commentedon Dec 17, 2020
https://github.com/hosseinmd/prettier-plugin-jsdoc is a plugin for format Jsdoc. Extended @gum3n worked project.
muuvmuuv commentedon Feb 3, 2021
Yes, good idea to handle
/** */as Markdown and IMO it would be easy if we would ignore/**/or//. That way ASCII arts would be safe since that should use the/**/syntax anyway.Additionally, separating blocks for easier reading should be considered as well: fardad-dev/prettier-plugin-jsdoc#33
docs: ignore prettier
cupidchan commentedon Sep 27, 2022
Is there any update on this wrap comments request?
Sanaruca commentedon Sep 30, 2023
In the meantime I am using Rewrap, a VSCode extension.
lkraav commentedon Mar 20, 2024
TIL YAML (or I guess any) comments are not wrapped yet.
muuvmuuv commentedon Oct 15, 2024
Could that not be ported to an prettier plugin? Guess that would be a good thing for the time being.
karlhorky commentedon Oct 15, 2024
It's F# and C# code - if anyone would be interested in starting to get involved in the Rewrap code, there's an initiative by the community to fork it here (original author is no longer around):
Eg. to polish it up a bit and potentially port it to TypeScript, before any integration into Prettier is considered.
An alternative would be to try to adapt that code to Prettier as is, but that seems like multiple steps at once - feels riskier to do it all at once.
muuvmuuv commentedon Oct 15, 2024
Porting to TS; Sounds like a job for ChatGPT 😅
prettierx: option to import on one line in JS&TS (prettier#265)
Add prettier rule to fix on format
vhbui02 commentedon Mar 23, 2025
Are there any progress regarding this feature?
AndersonVitaease commentedon Nov 26, 2026
Hi! I'd like to work on this and want to agree on the design before writing code, since the main concerns here have been ASCII art,
prettier-ignorefatigue and the no-new-options policy.Proposal (phase 1, JS/TS only):
proseWrap. With the default ("preserve") nothing changes for anyone.proseWrap: "always"/"never", only/** ... */doc comments are treated as Markdown paragraphs and rewrapped toprintWidth(accounting for indentation and the*prefix), reusing the existing Markdown printer.//and plain/* */comments, JSDoc tag lines (@parametc., left as-is in phase 1), fenced or 4-space-indented code, lists, tables, known directives, and anything underprettier-ignore.Would the team accept a PR along these lines? Happy to adjust scope (e.g. keep it behind
proseWrap: "always"only).