Skip to content

Commit a14c44f

Browse files
kovsufisker
andauthored
Fix K3WX.yaml (comments in map key) bug in yaml-test-suite (#18324)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
1 parent fad27ab commit a14c44f

File tree

7 files changed

+108
-1
lines changed

7 files changed

+108
-1
lines changed

changelog_unreleased/yaml/18324.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#### Use explicit key style for flow-mapping keys with trailing comments (#18324 by @kovsu, @fisker)
2+
3+
<!-- prettier-ignore -->
4+
```yaml
5+
# Input
6+
{ "foo" # comment
7+
:bar }
8+
9+
# Prettier stable
10+
{ "foo": bar } # comment
11+
12+
# Prettier main
13+
{ ? "foo" # comment
14+
: bar }
15+
```

src/language-yaml/print/mapping-item.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function printMappingItem(path, options, print) {
135135
isAbsolutelyPrintedAsSingleLineNode(key.content, options) &&
136136
!hasLeadingComments(key.content) &&
137137
!hasMiddleComments(key.content) &&
138+
!hasTrailingComment(key.content) &&
138139
!hasEndComments(key)
139140
) {
140141
return conditionalGroup([[printedKey, implicitMappingValue]]);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`key.yml format 1`] = `
4+
====================================options=====================================
5+
parsers: ["yaml"]
6+
printWidth: 80
7+
| printWidth
8+
=====================================input======================================
9+
{"key" # 1
10+
:value}
11+
---
12+
{["key"] # 2
13+
:value}
14+
---
15+
{
16+
# 3
17+
"key"
18+
:value}
19+
---
20+
{
21+
&[
22+
"key",
23+
# 4
24+
""]
25+
:value}
26+
---
27+
{"key": # 1
28+
value}
29+
30+
=====================================output=====================================
31+
{ ? "key" # 1
32+
: value }
33+
---
34+
{ ? ["key"] # 2
35+
: value }
36+
---
37+
{
38+
# 3
39+
"key": value,
40+
}
41+
---
42+
{ ? & [
43+
"key",
44+
# 4
45+
"",
46+
]
47+
: value }
48+
---
49+
{ ? "key" # 1
50+
: value }
51+
52+
================================================================================
53+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runFormatTest(import.meta, ["yaml"]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{"key" # 1
2+
:value}
3+
---
4+
{["key"] # 2
5+
:value}
6+
---
7+
{
8+
# 3
9+
"key"
10+
:value}
11+
---
12+
{
13+
&[
14+
"key",
15+
# 4
16+
""]
17+
:value}
18+
---
19+
{"key": # 1
20+
value}

tests/format/yaml/yaml-test-suite/__snapshots__/format.test.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,24 @@ printWidth: 80
38473847
================================================================================
38483848
`;
38493849
3850+
exports[`snippet: K3WX.yaml - Colon and adjacent value after comment on next line format 1`] = `
3851+
====================================options=====================================
3852+
parsers: ["yaml"]
3853+
printWidth: 80
3854+
| printWidth
3855+
=====================================input======================================
3856+
---
3857+
{ "foo" # comment
3858+
:bar }
3859+
3860+
=====================================output=====================================
3861+
---
3862+
{ ? "foo" # comment
3863+
: bar }
3864+
3865+
================================================================================
3866+
`;
3867+
38503868
exports[`snippet: K4SU.yaml - Multiple Entry Block Sequence format 1`] = `
38513869
====================================options=====================================
38523870
parsers: ["yaml"]

tests/format/yaml/yaml-test-suite/format.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const BUGS = new Set([
2020
"DE56-4.yaml",
2121
"JEF9-2.yaml",
2222
"JEF9-3.yaml",
23-
"K3WX.yaml",
2423
"L24T-2.yaml",
2524
]);
2625

0 commit comments

Comments
 (0)