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

YAML: Unstable array formatting #8377

Closed
fisker opened this issue May 21, 2020 · 0 comments · Fixed by #9669
Closed

YAML: Unstable array formatting #8377

fisker opened this issue May 21, 2020 · 0 comments · Fixed by #9669
Assignees
Labels
lang:yaml Issues affecting YAML locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@fisker
Copy link
Member

fisker commented May 21, 2020

Prettier 2.0.5
Playground link

--parser yaml

Input:

    needs:
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]

    steps:

Output:

needs: [check-format, check-lint, check-spelling]

# coverage,
# install-and-run-from-git,
steps:

Prettier 2.0.5
Playground link

--parser yaml

Input:

    needs:
      # prettier-ignore
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]

    steps:

Output:

needs:
  # prettier-ignore
  [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]

# coverage,
# install-and-run-from-git,
steps:

Second Output:

needs:
  # prettier-ignore
  [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]

# coverage,
# install-and-run-from-git,
# coverage,
# install-and-run-from-git,
steps:

original post by @cinderblock #6952 (comment)

Another manifestation of what I presume is the same bug. You can't even fix it with prettier-ignore.

Input

    needs:
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]

    steps:

Output

    needs: [check-format, check-lint, check-spelling]

    # coverage,
    # install-and-run-from-git,
    steps:

I expected no change. There seem to be two things happening here:

  1. Comments are being removed from the list. I don't think this is generally desirable. A common thing in JS for instance is to comment a single line from a list of things and that comment isn't taken out of the list.
  2. Comments are not allowed to be "after" a section and are forced to be used as comments that seem to describe the next section. Empty lines around comments should be preserved, imho.

If I try to "fix" this with # prettier-ignore, it breaks even worse:

Input

    needs:
      # prettier-ignore
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]
    steps:

Output

    needs:
      # prettier-ignore
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]
    # coverage,
    # install-and-run-from-git,
    steps:

This is also "unstable" as every time I autofix, Prettier replicates the comments. After "formatting" 5 times:

Output

    needs:
      # prettier-ignore
      [
        check-format,
        check-lint,
        check-spelling,
        # coverage,
        # install-and-run-from-git,
      ]
    # coverage,
    # install-and-run-from-git,
    # coverage,
    # install-and-run-from-git,
    # coverage,
    # install-and-run-from-git,
    # coverage,
    # install-and-run-from-git,
    # coverage,
    # install-and-run-from-git,
    steps:
@fisker fisker added lang:yaml Issues affecting YAML type:bug Issues identifying ugly output, or a defect in the program labels May 21, 2020
@fisker fisker self-assigned this May 25, 2020
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:yaml Issues affecting YAML locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant