Skip to content

JSDoc trailing whitespaces are deleted #6793

Closed

Description

@Tucaen

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"])?

Activity

  1. lydell commented on Nov 4, 2019

    @lydell
    Member

    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?

  2. added
    status:awaiting response
    on Nov 4, 2019
  3. Tucaen commented on Nov 4, 2019

    @Tucaen
    Author

    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...

  4. removed
    status:awaiting response
    on Nov 4, 2019
  5. thorn0 commented on Nov 4, 2019

    @thorn0
    Member

    Is this a markdown thing probably? VS Code treats text in JSDoc as markdown.

  6. Tucaen commented on Nov 4, 2019

    @Tucaen
    Author

    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?

  7. thorn0 commented on Nov 4, 2019

    @thorn0
    Member

    You can use empty lines to achieve the same effect and make the comments more human-readable at that.

  8. Tucaen commented on Nov 4, 2019

    @Tucaen
    Author

    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 😏

  9. thorn0 commented on Nov 4, 2019

    @thorn0
    Member

    Also I would have to refactor a lot of code

    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.

  10. added
    area:comments
    lang:javascript
    on Nov 4, 2019
  11. added
    lang:markdown
    on May 27, 2020
  12. niklasmh commented on Oct 20, 2020

    @niklasmh

    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):
    image

    Is parsed into this after running Prettier:
    image

    And results in being rendered like this in Markdown:
    image

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

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

    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 :)

  13. chrbala commented on Dec 28, 2020

    @chrbala
  14. damianobarbati commented on Feb 17, 2021

    @damianobarbati

    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?

  15. 6 remaining items

  16. sebastian-fredriksson-bernholtz commented on Oct 18, 2022

    @sebastian-fredriksson-bernholtz

    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 \.

  17. jw-redpanda commented on Jun 17, 2023

    @jw-redpanda

    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.

  18. 700software commented on Nov 17, 2023

    @700software

    Ideally Prettier should, in jsdoc comments

    • trim single trailing whitespace to nothing
    • (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. :)

  19. minhxuvi commented on Feb 13, 2024

    @minhxuvi

    I have the same issue with markdown and mdx file. I have to disable prettier. But can't find any other good alternative.

  20. shanike commented on Dec 24, 2024

    @shanike

    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!

  21. added theissue type on Mar 3, 2025
  22. lake2 commented on Mar 10, 2025

    @lake2

    serveral years passed. The problem is still here

  23. rusproject commented on Apr 22, 2025

    @rusproject

    Problem is still relevant, guys. Please consider implementing a fix.

  24. added a commit that references this issue on Jan 9, 2026
  25. added
    locked-due-to-inactivity
    on Apr 13, 2026
  26. locked as resolved and limited conversation to collaborators on Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentshelp wantedlang:javascriptlang:markdownlocked-due-to-inactivity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions