Skip to content

Fix K3WX.yaml (comments in map key) bug in yaml-test-suite#18324

Merged
fisker merged 9 commits intoprettier:mainfrom
kovsu:fix-K3WX
Nov 27, 2025
Merged

Fix K3WX.yaml (comments in map key) bug in yaml-test-suite#18324
fisker merged 9 commits intoprettier:mainfrom
kovsu:fix-K3WX

Conversation

@kovsu
Copy link
Copy Markdown
Contributor

@kovsu kovsu commented Nov 26, 2025

Description

Ref: #18302

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Nov 26, 2025

Open in StackBlitz

yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-hermes@18324.tgz
yarn add https://pkg.pr.new/prettier/prettier/@prettier/plugin-oxc@18324.tgz
yarn add https://pkg.pr.new/prettier/prettier@18324.tgz

commit: c4d4975

@netlify
Copy link
Copy Markdown

netlify bot commented Nov 26, 2025

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit c4d4975
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6927ebcc851dda00080c591e
😎 Deploy Preview https://deploy-preview-18324--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/language-yaml/printer-yaml.js Outdated
Comment thread src/language-yaml/print/flow-mapping-sequence.js
Comment thread src/language-yaml/print/mapping-item.js Outdated
@fisker
Copy link
Copy Markdown
Member

fisker commented Nov 26, 2025

Can you add a changelog, I'll take another look later.

@fisker
Copy link
Copy Markdown
Member

fisker commented Nov 26, 2025

@kovsu You know what? Turns out this is not expected output.

Prettier pr-18196
Playground link

--parser yaml

Input:

{["foo"] # comment
  :bar }

Output:

{ ? ["foo"] # comment
  : bar }

So the expected output should be

{ ? "foo" # comment
  : bar }

if (
isAbsolutelyPrintedAsSingleLineNode(key.content, options) &&
!hasLeadingComments(key.content) &&
!hasMiddleComments(key.content) &&
!hasEndComments(key)
) {
missing "TrailingComment" check.

Can you apply?

@fisker
Copy link
Copy Markdown
Member

fisker commented Nov 26, 2025

#10874

@fisker
Copy link
Copy Markdown
Member

fisker commented Nov 26, 2025

Maybe you'll be interested in fixing #10879 . Of course, in separate PR.

@kovsu
Copy link
Copy Markdown
Contributor Author

kovsu commented Nov 27, 2025

Can you apply?

Done

Maybe you'll be interested in fixing #10879 . Of course, in separate PR.

I will try it 😀

Comment thread changelog_unreleased/yaml/18324.md Outdated
```yaml
# Input
{"foo": #comment
bar}
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.

@kovsu The input is incorrect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah, I see it works in playground so I thought it is right. Sry, my bad.

CleanShot 2025-11-27 at 14 03 50@2x

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.

Ha, so we also fixed this case. Added to tests c4d4975 (#18324)

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.

Looks like it's a bug in parser... Shouldn't the comment belong to value?

@fisker fisker changed the title Fix K3WX.yaml bug in yaml-test-suite Fix K3WX.yaml (comments in map key) bug in yaml-test-suite Nov 27, 2025
@fisker fisker merged commit a14c44f into prettier:main Nov 27, 2025
35 checks passed
@kovsu kovsu deleted the fix-K3WX branch November 27, 2025 06:28
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.

2 participants