Skip to content

Add support for formatting JSDoc comments #5659

Open

Description

@j-f1

It would be nice if Prettier formatted JSDoc comments, interpreting the text of the comment as markdown and properly handling tags.

There are two parsers we could use: comment-parser for the overall comment, and jsdoctypeparser for the types (in {}).

Activity

  1. ikatyang commented on Dec 19, 2018

    @ikatyang
    Member
  2. matchai commented on Dec 19, 2018

    @matchai

    tsdoc looks like an excellent solution. Full-featured, healthy project and well maintained. 👍

  3. j-f1 commented on Dec 19, 2018

    @j-f1
    MemberAuthor

    Unfortunately, TSDoc doesn’t support types :/

  4. matchai commented on Dec 19, 2018

    @matchai

    Strange... 🤔
    I was under the impression that tsdoc was fully responsible for JSDoc in TypeScript, but it seems not. In any case, TypeScript certainly supports types in JSDoc. We could use its compiler to produce an AST which can be used.

    Here's an example of the TypeScript AST with type data:
    https://astexplorer.net/#/gist/3315d0e2976252a97ca8325d4e70f84b/bfae7a580be265c412c895fb11f4d50821595646

    image

  5. balupton commented on Dec 6, 2019

    @balupton

    This issue was referred to #3094

    However, one does not need a comment parser to implement 3094.

    Can we track each specific feature being requests here? As the only one that I consider essential currently is 3094, as it missing is an annoyance when I convert jsdoc to typedoc, as often multiline jsdoc would become a singleline typedoc, which would be nice if prettier assisted me in converting

    /**
     * The Base Plugin class that {@link PluginLoader#PluginClass} must inherit from.
     */
    

    into

    /** The Base Plugin class that {@link PluginLoader#PluginClass} must inherit from. */
    
  6. paschalidi commented on Feb 7, 2020

    @paschalidi

    Hey @j-f1 can I take this over? Can you help me out how to start with this since its my first time contributing to this codebase?

  7. ir33k commented on Feb 22, 2020

    @ir33k

    Hi. I did create plugin for my team at work that extends "babel-flow" parser. It's not perfect and does not follow the plugin structure with parsing then printing. But it works.

    We use it for about month on few projects and it feels just great to have it finally automated. So I'd like to share it with you all. Repo: https://gitlab.com/gumen/prettier-plugin-jsdoc. Check unit tests to see what is supported and how.

  8. jasonwilliams commented on Dec 10, 2020

    @jasonwilliams

    I was wondering why double-space line breaks weren't working in comments and it seems Prettier doesn't parse comments as markdown.

    Would be nice to have support for this.

  9. fardad-dev commented on Dec 13, 2020

    @fardad-dev
    Contributor
  10. added
    lang:javascript
    on Sep 6, 2022
  11. added theissue type on Mar 3, 2025
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

    lang:javascript

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions