Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
egilll opened this issue Aug 29, 2022 · 2 comments
Open

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

egilll opened this issue Aug 29, 2022 · 2 comments

Comments

@egilll
Copy link

egilll commented Aug 29, 2022

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.

@hosseinmd
Copy link
Owner

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

@hosseinmd
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants