Skip to content

Update dependency yaml to v2 - #301

Merged
fisker merged 11 commits into
prettier:mainfrom
ota-meshi:yaml-v2
Dec 3, 2025
Merged

Update dependency yaml to v2#301
fisker merged 11 commits into
prettier:mainfrom
ota-meshi:yaml-v2

Conversation

@ota-meshi

@ota-meshi ota-meshi commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

This PR upgrades the yaml package to v2.

I think most of the issues are with node locations, but there seem to be some differences in scalar values ​​such as block literals. Also, I'm not sure how to handle the new options yet.


close #279

6 | ¶
| ^
<blockFolded chomping="keep" indent=1 value=" 123\\n 456\\n\\n\\n" />
<blockFolded chomping="keep" indent=1 value=" 123\\n 456\\n\\n\\n" />

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.

The new value looks correct to me. What was the original value intended?

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.

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.

I tried changing it to String(blockValue.value), but it doesn't seem to make any difference to blockValue.source 🤔

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.

Also, String(blockValue.value) seems to break if there is a rather !!binary tag.

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.

I think we can trust .value in this case.

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.

Some expected values in the yaml-test-suite can be found in the test,

eg: JEF9-2.yaml
https://github.com/yaml/yaml-test-suite/blob/ccfa74e56afb53da960847ff6e6976c0a0825709/src/JEF9.yaml#L40

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.

As far as I can see, the new values ​​are the same as the yaml tests.

@fisker

fisker commented Dec 3, 2025

Copy link
Copy Markdown
Member

Can you try to fix the build script first? So we can have a test in Prettier, see how many tests would fail.

@ota-meshi

Copy link
Copy Markdown
Contributor Author

I've reviewed the last few remaining diffs, and the new values ​​seem reasonable to me.
They relate to the document scope, including comments, and the scope of block literals.
bb33fae

Could you please check these diffs? Please let me know if there are any issues.

@ota-meshi

Copy link
Copy Markdown
Contributor Author

Can you try to fix the build script first? So we can have a test in Prettier, see how many tests would fail.

What kind of script is that? Can you tell me more about it?

@ota-meshi

Copy link
Copy Markdown
Contributor Author

Oh, I hadn't checked the coverage yet.

@fisker

fisker commented Dec 3, 2025

Copy link
Copy Markdown
Member

All diff looks good to me! Thank you very much!

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2025

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/yaml-unist-parser@301.tgz

commit: 2c885f8

@fisker fisker mentioned this pull request Dec 3, 2025
4 tasks
@fisker

This comment was marked as outdated.

@fisker

This comment was marked as outdated.

@fisker
fisker marked this pull request as ready for review December 3, 2025 13:30
Comment thread src/transforms/document.ts
Comment thread src/transforms/context.ts Outdated
getOrderedComments(): Comment[] {
return this.#comments.sort(
(a, b) => a.position.start.offset - b.position.start.offset,
);

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.

Tests still passing without .sort(), can you confirm if it is still needed, or find a way to test if it does.

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.

Ah, there is another sort in comment attach.

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.

That's interesting.
Maybe we already sorted it somewhere else. I'll look into it.

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.

I removed the unnecessary sorting.
We were already sorting somewhere else.

.sort((a, b) => a.position.start.offset - b.position.end.offset)

}
}
// istanbul ignore next
// istanbul ignore next -- @preserve

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.

It seems that @preserve is needed to make this comment visible in the transpiled code by vitest.

https://vitest.dev/guide/coverage.html#ignoring-code

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.

Don't worry about the coverage. You can ignore.

@fisker
fisker merged commit 1e51228 into prettier:main Dec 3, 2025
@fisker

fisker commented Dec 3, 2025

Copy link
Copy Markdown
Member

Thanks again! ❤️

@fisker

fisker commented Dec 3, 2025

Copy link
Copy Markdown
Member

@ota-meshi Do you think we can build something that can be used in both this package and yaml-eslint-parser? Of course, without a major break change for users.

@ota-meshi

Copy link
Copy Markdown
Contributor Author

Thank you for the review and the refactoring after the merge!
Please feel free to let me know if any issues remain.

Do you think we can build something that can be used in both this package and yaml-eslint-parser? Of course, without a major break change for users.

I'm not sure yet 😅 If we need it, I'd love to share it with you.

@ota-meshi
ota-meshi deleted the yaml-v2 branch December 3, 2025 23:44
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.

Update yaml to v2

2 participants