Skip to content

Fix YAML comment after an anchor doesn't stay on a separate line#11395

Open
wafuwafu13 wants to merge 2 commits intoprettier:mainfrom
wafuwafu13:fix-10518
Open

Fix YAML comment after an anchor doesn't stay on a separate line#11395
wafuwafu13 wants to merge 2 commits intoprettier:mainfrom
wafuwafu13:fix-10518

Conversation

@wafuwafu13
Copy link
Copy Markdown
Contributor

@wafuwafu13 wafuwafu13 commented Aug 24, 2021

Description

Fixes #10518

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@wafuwafu13 wafuwafu13 marked this pull request as ready for review August 24, 2021 08:33
@jdelStrother
Copy link
Copy Markdown

I've tried this locally and it seems good! Anything we can do to get it merged?

@alexander-akait
Copy link
Copy Markdown
Member

/cc @thorn0 can you look?

parts.push([
node.middleComments.length === 1 ? "" : hardline,
!anchor ||
(node.middleComments.length === 1 &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait. This condition looks too specific. What if there are multiple comments?

Prettier pr-11395
Playground link

--parser yaml

Input:

key1: &default # comment1
  # This key ...
  subkey1: value1

key2:
  <<: *default
     
key3: # comment2
  # comment3
  subkey3: value

Output:

key1: &default
  # comment1
  # This key ...
  subkey1: value1

key2:
  <<: *default

key3: # comment2
  # comment3
  subkey3: value

---
!shape
# Use the ! handle for presenting
!shape # Use the ! handle for presenting
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes shouldn't happen. Comments that are on their own line should stay on their line, trailing comments should stay trailing.

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

Successfully merging this pull request may close these issues.

YAML: a comment after an anchor doesn't stay on a separate line

4 participants