prettier-plugin-jsdoc icon indicating copy to clipboard operation
prettier-plugin-jsdoc copied to clipboard

Any idea for how to get a comment's indentation _after_ formatting?

Open egilll opened this issue 3 years ago • 2 comments

Running Prettier twice is supposed to give the same output. There does however not appear to be a good way to figure out what a comment's indentation will be after code formatting. We therefore wrap lines at a comment's current width, but not at the width it will have after the rest of the file has been formatted:

                                                          /**
                                                           * Example example example
                                                           */

will become:

/**
 * Example example 
 * example
 */

which will then become:

/**
 * Example example example
 */

I do run into this issue when reorganizing code.

There is a function in Prettier's API, printComment, but it is not nearly as pluggable and would require us to extend Prettier's non-exposed estree printer.

egilll avatar Aug 29 '22 13:08 egilll

printComment is so interested. These functions (printComment, canAttachComment, isBlockComment, handleComments, ownLine) are so useful for us, but I don't test these before.

hosseinmd avatar Aug 30 '22 07:08 hosseinmd

Documentation for printComment is not so clear I added it to parser object but never called I don't know why

hosseinmd avatar Oct 06 '23 13:10 hosseinmd