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: Fix printing doubles a blank line before a comment #9143

Merged
merged 12 commits into from Sep 7, 2020
27 changes: 27 additions & 0 deletions changelog_unreleased/yaml/pr-9143.md
@@ -0,0 +1,27 @@
#### Fix printing doubles a blank line before a comment (#9143 by @sosukesuzuki)

<!-- prettier-ignore -->
```yaml
# Input
- foo: 0
bar: 1

# baz: 2
- quux: 3

# Prettier stable
- foo: 0
bar: 1


# baz: 2
- quux: 3

# Prettier master
- foo: 0
bar: 1

# baz: 2
- quux: 3

```
2 changes: 1 addition & 1 deletion src/language-yaml/printer-yaml.js
Expand Up @@ -142,7 +142,7 @@ function genericPrint(path, options, print) {
options.originalText,
path.getValue(),
options.locStart
)
) && node.type === "mappingValue"
? hardline
: "",
print(path),
Expand Down
38 changes: 38 additions & 0 deletions tests/yaml/comment/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -137,6 +137,44 @@ printWidth: 80
================================================================================
`;

exports[`issue-9130.yml format 1`] = `
====================================options=====================================
parsers: ["yaml"]
printWidth: 80
| printWidth
=====================================input======================================
- foo: 0
bar: 1

# baz: 2
- quux: 3

- foo: 0
bar: 1

# baz: 2

# baz: 3
- quux: 3

=====================================output=====================================
- foo: 0
bar: 1

# baz: 2
- quux: 3

- foo: 0
bar: 1

# baz: 2

# baz: 3
- quux: 3

================================================================================
`;

exports[`map.yml format 1`] = `
====================================options=====================================
parsers: ["yaml"]
Expand Down
13 changes: 13 additions & 0 deletions tests/yaml/comment/issue-9130.yml
@@ -0,0 +1,13 @@
- foo: 0
bar: 1

# baz: 2
- quux: 3

- foo: 0
bar: 1

# baz: 2

# baz: 3
- quux: 3