Skip to content

Prettier introduces YAML styling choices which cause yamllint to complain #6780

Closed

Description

@ssokolow

Prettier 1.18.2
Playground link

--parser yaml

Input:

- hosts: localhost  # Hello

Output:

- hosts: localhost # Hello

Expected behavior:
Inline comments should have two spaces after the # to prevent yamllint from producing output like this:

  117:33    warning  too few spaces before comment  (comments)
  118:38    warning  too few spaces before comment  (comments)
  119:53    warning  too few spaces before comment  (comments)
  120:35    warning  too few spaces before comment  (comments)
  121:26    warning  too few spaces before comment  (comments)
  123:38    warning  too few spaces before comment  (comments)
  125:35    warning  too few spaces before comment  (comments)
  126:26    warning  too few spaces before comment  (comments)
  127:32    warning  too few spaces before comment  (comments)
  145:33    warning  too few spaces before comment  (comments)
  219:36    warning  too few spaces before comment  (comments)
  220:34    warning  too few spaces before comment  (comments)
  221:39    warning  too few spaces before comment  (comments)
  222:35    warning  too few spaces before comment  (comments)
  223:37    warning  too few spaces before comment  (comments)
  224:33    warning  too few spaces before comment  (comments)
  225:34    warning  too few spaces before comment  (comments)
  226:30    warning  too few spaces before comment  (comments)
  227:39    warning  too few spaces before comment  (comments)
  228:37    warning  too few spaces before comment  (comments)
  232:39    warning  too few spaces before comment  (comments)
  233:44    warning  too few spaces before comment  (comments)
  263:31    warning  too few spaces before comment  (comments)
  268:32    warning  too few spaces before comment  (comments)
  271:32    warning  too few spaces before comment  (comments)
  274:45    warning  too few spaces before comment  (comments)
  277:40    warning  too few spaces before comment  (comments)
  282:41    warning  too few spaces before comment  (comments)
  285:34    warning  too few spaces before comment  (comments)
  288:36    warning  too few spaces before comment  (comments)
  291:34    warning  too few spaces before comment  (comments)
  294:40    warning  too few spaces before comment  (comments)

Activity

  1. lydell commented on Nov 2, 2019

    @lydell
    Member
  2. added
    status:awaiting response
    on Nov 2, 2019
  3. ssokolow commented on Nov 2, 2019

    @ssokolow
    Author

    In that case, please change this to a request to amend https://prettier.io/docs/en/integrating-with-linters.html with instructions for adding the following to either the project linting config or ~/.config/yamllint/config:

    ---
    extends: default
    
    rules:
      comments:
        min-spaces-from-content: 1
    # vim: ft=yaml :

    Also, if it's Prettier policy that linters should leave the formatting up to Prettier, then should I open another issue for how yamllint wants #Foo to become # Foo (ie. comments should start with a space after the #) but Prettier ignores the problem?

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

    @lydell
    Member

    Thanks for the response!

    I don’t think we should add an incomplete config in the docs. Not a complete one either – that should be a separate package, just like eslint-config-prettier.

    About #Foo vs # Foo – we don’t enforce a space at the start of comments in any language. That’s because it can break tools that use comments in certain ways. So using a linter for that is encouraged if you want to enforce that space! For example, I use the spaced-comment ESLint rule to achieve that in JS:

    https://github.com/lydell/eslint-config-lydell/blob/3682d0e5abb11a36ad0cdecb0fae1ab8bdb16e25/index.js#L150-L159

    "spaced-comment": [
      "error",
      "always",
      {
        block: {
          markers: [":", "::"], // Support Flow type comments.
          balanced: true,
        },
      },
    ],
    

    As you can see, I had to add special config to the rule to still be able to support Flow comments that have to start with : or ::.

    Hope this answers your questions!

  6. added
    lang:yaml
    type:question
    on Nov 2, 2019
  7. ssokolow commented on Nov 2, 2019

    @ssokolow
    Author

    I don’t think we should add an incomplete config in the docs. Not a complete one either – that should be a separate package, just like eslint-config-prettier.

    Fair enough.

    Hope this answers your questions!

    It does. That necessity reminds me of an old, unmaintained Python documentation tool named ePyDoc which uses #{ and #} for section markers.

    That said, as someone who works primarily in Python, where all modern tools are built to play nicely with the #<space> rule in PEP8, it irks me to see a formatter not having an option I could set on a case-by-case basis. Oh well. C'est la vie.

    (Maybe I can hack together something in Vimscript as an ALEFixPost hook to automate adding whitespace on save.)

  8. added
    locked-due-to-inactivity
    on Jan 31, 2020
  9. locked as resolved and limited conversation to collaborators on Jan 31, 2020
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:yamllocked-due-to-inactivitytype:question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions