Skip to content
This repository has been archived by the owner. It is now read-only.

Use two spaces before inline comments #59

Open
patrick91 opened this issue Mar 3, 2018 · 3 comments
Open

Use two spaces before inline comments #59

patrick91 opened this issue Mar 3, 2018 · 3 comments

Comments

@patrick91
Copy link
Member

@patrick91 patrick91 commented Mar 3, 2018

@ryanashcraft
Copy link
Collaborator

@ryanashcraft ryanashcraft commented Mar 3, 2018

I'm using this bug to get familiar with the internals of prettier and this plugin. My naive approach to getting this done is by adding a new prettier printer option to specify a trailing comment prefix here. Something like options.printer.trailingCommentPrefix, with a default of a single space, but plugin-python would provide a two-space string.

This change yields the following output for yarn prettier tests/python_comments/comments.py:

$ prettier --plugin=. --parser=python tests/python_comments/comments.py
- if a: # a
+ if a:  # a
    # b
    c

    # c

    d

    # e

    call()
    # a

However, this seems like a pretty granular configuration option to me, compared to the existing printer options. And I doubt you all want to go down the path where plugin-python is doing all the comment printer handling with the willPrintOwnComments option. Interested in hearing alternative solutions.

@j-f1
Copy link
Member

@j-f1 j-f1 commented Mar 3, 2018

What about putting a leading line when printing the comment?

@ryanashcraft
Copy link
Collaborator

@ryanashcraft ryanashcraft commented Mar 3, 2018

@j-f1 Not sure if I'm understanding your suggestion, but here's what happens when I change plugin-python's printComment to return group(concat([line, comment.value])):

$ prettier --plugin=. --parser=python tests/python_comments/comments.py
if a:  # a
     # b
    c

     # c

    d

     # e

    call()
     # a

As you can see, it adds an extra space even to comments that aren't inline.

Note: I also had to modify the final case in prettier's printTrailingComment from " " + contents to concat([" ", contents]), otherwise it would print:

$ prettier --plugin=. --parser=python tests/python_comments/comments.py
if a: [object Object]
     # b
    c

     # c

    d

     # e

    call()
     # a
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.