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!lang:javascriptIssues affecting JSlang:markdownIssues affecting Markdownlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.
Two trailing whitespace in a JSDoc are used to indicate a line break. Prettier keeps deleting them for me. Is there a way to configure it to ignore trailing whitespaces in JSDoc, like in the tslint ("no-trailing-whitespace": [true, "ignore-jsdoc"])?
Reacted by Niklas Molnes Hole, Mikumo, Louis Haddrell, Lee JeongHo, Loris Bettazza, imekachi, Ankur Parihar, David Whynot, Agata Zurek, Merlin and 25 more
Edit 2025: For those not wanting to read the full thread, the thread makes it clear later that trailing whitespace in JSDoc is a thing. This is a bug in Prettier.
Hi!
Prettier currently removes trailing whitespace in all comments. Can you provide a link to documentation saying that two spaces becomes a line break in JSDoc?
I'm currently using VS Code with Typescript in this environment it defenitly works, but I am no longer sure if this is a general thing. I'll keep searching for a bit...
Good hint! 👍
Looking at this Stackoverflow question I assume that's the case.
Not quite sure what this means for my requirement right now.
I assume prettier doesn't interpret the JSDoc as markdown, so I can't configure this behavior?
Also thought about that, but I would prefer to keep it like it is 😏
Adding empty lines would result in paragraphs, which is close to, but not exactly what should be achieved.
Also I would have to refactor a lot of code 😏
Reacted by Qwerty (Vítězslav Ackermann Ferko) and Muhammad Afifudin
At least this part doesn't look like a problem. Replace <space><space>\n → \n*\n and then run the result through Prettier. Prettier doesn't parse JSDoc, but it aligns comment lines that start with an asterisk.
I stumbled accross the same issue, and having the option to ignore trailing whitespace (or all rules for that matter) in comments would solve the problem. Also, I cannot see why this should not be an option as comments for documentation often use Markdown (I could be wrong, though, but e.g. VSCode uses Markdown comments to generate the Monaco documentation). It may not be a big issue, but I think when it is possible that todays comments may require the correct formatting, opting out of forced formatted comments would be beneficial.
More information about the problem
According to the Markdown specs from Commonmark, Markdown supports two or more spaces to create a newline (or <br />-tag, try it out here). This means that this is a core feature in Markdown. With that out of the way, here is an example:
Small example (JSDoc comment, note the two spaces after Line1):
Is parsed into this after running Prettier:
And results in being rendered like this in Markdown:
With no Prettier (aka with trailing spaces), it looks like this (which is the desired rendering):
I have also tried singleline and multiline prettier-ignore comments, and they work, except they are included in the rendered version:
After some tries I found that it was possible for me to use <br /> for newlines which solved my issue, but I still wonder if this could be added as an option to Prettier. I would really prefer to use two trailing spaces instead of HTML-tags.
Also, if someone would help guide me into the right direction, I am more than willing to help solve this issue :)
Reacted by Loris Bettazza, Peter Nann, Diogo dos Santos, Omar Adobati, Rolf Brocke, ntamotsu and Laurens DC
I have run into this issue with TypeScript, which can show these comments when hovering on objects, functions, properties, etc. I would like an option to leave trailing whitespace alone.
Same problem here, swagger-jsdoc converts my comments into documentation. description field of yml are in markdown format, thus double trailing space means new line.
What's the current solution?
6 remaining items
sebastian-fredriksson-bernholtz commented on Oct 18, 2022
Potential solution: It seems like at least VSCode supports using \ instead of double trailing whitespace for line break.
I guess that won't work for anyone using other markdown processors that doesn't support \ on the jsdoc, but it has solved my problem.
I found this after installing prettier-plugin-jsdoc (mentioned in #5659 (comment)) and noticing that it replaced the double trailing whitespace with \.
Reacted by Diogo dos Santos, James Thomas, Tobias Bammert, Qwerty (Vítězslav Ackermann Ferko), Muhammad Afifudin, hoshima, Stillward, foobar8080, Joseph Pouradier Duteil, Nikola Grancharov and 5 more
Reacted by Muhammad Afifudin, Shani Kehati, Zak and Ngô Trọng Phúc
Reacted by Qwerty (Vítězslav Ackermann Ferko) and Ngô Trọng Phúc
(if not difficult to implement,) trim double trailing whitespace if the next line is end of jsdoc comment or is a blank line indicating a paragraph break
preserve double trailing whitespace if next line is not blank - because it would be interpreted as a \ or <br/> in markdown
trim triple and excessive trailing whitespaces because those are probably accidental.
This would be in the spirit of Markdown and of Prettier in my opinion.
Forcing people to use \ is certainly not the optimal solution, because it goes against the spirit of Markdown, which is for the result to look good both in plain text and formatted views.
But, it's helpful to know I can use this workaround until Prettier resolves this issue. :)
Reacted by jw-redpanda, Dmitry Paliy, Eric Morton, Shani Kehati and o-m12a
I strongly agree with @700software's comment here above #6793 (comment). Keeping two "trailiing" whitespaces after a line in jsdoc (when it's not the last line of the jsdoc) is very helpful for aligning with markdown and vscode's interpolation of them.
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!lang:javascriptIssues affecting JSlang:markdownIssues affecting Markdownlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.
Activity
lydell commentedon Nov 4, 2019
Edit 2025: For those not wanting to read the full thread, the thread makes it clear later that trailing whitespace in JSDoc is a thing. This is a bug in Prettier.
Hi!
Prettier currently removes trailing whitespace in all comments. Can you provide a link to documentation saying that two spaces becomes a line break in JSDoc?
Tucaen commentedon Nov 4, 2019
This is actually harder to find than I thought 😳
I'm currently using VS Code with Typescript in this environment it defenitly works, but I am no longer sure if this is a general thing. I'll keep searching for a bit...
thorn0 commentedon Nov 4, 2019
Is this a markdown thing probably? VS Code treats text in JSDoc as markdown.
Tucaen commentedon Nov 4, 2019
Good hint! 👍
Looking at this Stackoverflow question I assume that's the case.
Not quite sure what this means for my requirement right now.
I assume prettier doesn't interpret the JSDoc as markdown, so I can't configure this behavior?
thorn0 commentedon Nov 4, 2019
You can use empty lines to achieve the same effect and make the comments more human-readable at that.
Tucaen commentedon Nov 4, 2019
Also thought about that, but I would prefer to keep it like it is 😏
Adding empty lines would result in paragraphs, which is close to, but not exactly what should be achieved.
Also I would have to refactor a lot of code 😏
thorn0 commentedon Nov 4, 2019
At least this part doesn't look like a problem. Replace
<space><space>\n→\n*\nand then run the result through Prettier. Prettier doesn't parse JSDoc, but it aligns comment lines that start with an asterisk.niklasmh commentedon Oct 20, 2020
I stumbled accross the same issue, and having the option to ignore trailing whitespace (or all rules for that matter) in comments would solve the problem. Also, I cannot see why this should not be an option as comments for documentation often use Markdown (I could be wrong, though, but e.g. VSCode uses Markdown comments to generate the Monaco documentation). It may not be a big issue, but I think when it is possible that todays comments may require the correct formatting, opting out of forced formatted comments would be beneficial.
More information about the problem
According to the Markdown specs from Commonmark, Markdown supports two or more spaces to create a newline (or
<br />-tag, try it out here). This means that this is a core feature in Markdown. With that out of the way, here is an example:Small example (JSDoc comment, note the two spaces after Line1):

Is parsed into this after running Prettier:

And results in being rendered like this in Markdown:

With no Prettier (aka with trailing spaces), it looks like this (which is the desired rendering):

I have also tried singleline and multiline prettier-ignore comments, and they work, except they are included in the rendered version:

After some tries I found that it was possible for me to use
<br />for newlines which solved my issue, but I still wonder if this could be added as an option to Prettier. I would really prefer to use two trailing spaces instead of HTML-tags.Also, if someone would help guide me into the right direction, I am more than willing to help solve this issue :)
chrbala commentedon Dec 28, 2020
I have run into this issue with TypeScript, which can show these comments when hovering on objects, functions, properties, etc. I would like an option to leave trailing whitespace alone.
Repro:
https://www.typescriptlang.org/play?#code/PTAEAkHsDcFMCdQwaAsgTwGIFcB2BjAFwEtJdQBDXAE1HUm1HytAGdZZRCALCwr7p2qxW+eMQAOJMqF6tQAG2K5OAI3iwKAa1YAoXcABUh3aEOgAKt2LyblUADNsRUuR58AXKFCnz3gIIAdKAahNjwuPI8nLjYALaqKA7EcN6+3qAAQsEAcrBwiKHhkZS46DzKAOagsArsaWbAuvhkrPwYOATS5AC8oAAUAJSgPQB8oACsANz6IGhYeC5kAEyg1JAioLiQ-LypSiqg6po6s8bpVnZ2FI7O3QKe6QHBRRFRglvxiYjJcE9ZuXyKFeJSo5WsuGqtXYviaLUi7QWXVcqz6QxG42muiAA
damianobarbati commentedon Feb 17, 2021
Same problem here, swagger-jsdoc converts my comments into documentation.
descriptionfield of yml are in markdown format, thus double trailing space means new line.What's the current solution?
6 remaining items
sebastian-fredriksson-bernholtz commentedon Oct 18, 2022
Potential solution: It seems like at least VSCode supports using
\instead of double trailing whitespace for line break.I guess that won't work for anyone using other markdown processors that doesn't support
\on the jsdoc, but it has solved my problem.I found this after installing prettier-plugin-jsdoc (mentioned in #5659 (comment)) and noticing that it replaced the double trailing whitespace with
\.jw-redpanda commentedon Jun 17, 2023
Same issue here.
Hope that it is able to treat JsDoc/hints with double trailing space as a special case that it will not be trimmed.
Although trailing \ or adding an extra line can perform a line break but the jsdoc/hint looks not natural.
700software commentedon Nov 17, 2023
Ideally Prettier should, in jsdoc comments
\or<br/>in markdownThis would be in the spirit of Markdown and of Prettier in my opinion.
Forcing people to use
\is certainly not the optimal solution, because it goes against the spirit of Markdown, which is for the result to look good both in plain text and formatted views.But, it's helpful to know I can use this workaround until Prettier resolves this issue. :)
minhxuvi commentedon Feb 13, 2024
I have the same issue with markdown and mdx file. I have to disable prettier. But can't find any other good alternative.
shanike commentedon Dec 24, 2024
Any update?
I strongly agree with @700software's comment here above #6793 (comment). Keeping two "trailiing" whitespaces after a line in jsdoc (when it's not the last line of the jsdoc) is very helpful for aligning with markdown and vscode's interpolation of them.
In the markdown guide they mention double trailing whitespaces.
THANKS!
lake2 commentedon Mar 10, 2025
serveral years passed. The problem is still here
rusproject commentedon Apr 22, 2025
Problem is still relevant, guys. Please consider implementing a fix.
support trailing double spaces in JSDoc