Skip to content

Conversation

@octo
Copy link
Contributor

@octo octo commented Jun 23, 2025

PR #247 introduced a regression with YAML documents such as this:

config: &shared
  key: value

instance:
  <<: *shared

Due to the "correct alias keys" setting, a extra space was emitted after *shared. This created trailing whitespace which many tools (rightly) complain about.

This change adds an extra condition to only emit the space in the "simple key" context. I'm not enough of a YAML expert to be sure this is the right thing to do, but it fixes my problem without failing any of the existing tests.

octo added 2 commits June 23, 2025 15:35
PR google#247 introduced a regression with YAML documents such as this:

```yaml
config: &shared
  key: value

instance:
  <<: *shared
```

Due to the "correct alias keys" setting, a extra space was emitted after
`*shared`. This created trailing whitespace which many tools (rightly) complain
about.

This change adds an extra condition to only emit the space in the "simple key"
context. I'm not enough of a YAML expert to be sure this is the right thing to
do, but it fixes my problem without failing any of the existing tests.
Copy link
Collaborator

@braydonk braydonk left a comment

Choose a reason for hiding this comment

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

I'm pretty sure this is the correct fix (it is at worst more correct than what I originally did). Thank you for the patch!

@braydonk braydonk merged commit 398e72a into google:main Jun 23, 2025
5 checks passed
steeef pushed a commit to steeef/yamlfmt that referenced this pull request Sep 5, 2025
* fix(yaml): Remove trailing whitespace from merge aliases.

PR google#247 introduced a regression with YAML documents such as this:

```yaml
config: &shared
  key: value

instance:
  <<: *shared
```

Due to the "correct alias keys" setting, a extra space was emitted after
`*shared`. This created trailing whitespace which many tools (rightly) complain
about.

This change adds an extra condition to only emit the space in the "simple key"
context. I'm not enough of a YAML expert to be sure this is the right thing to
do, but it fixes my problem without failing any of the existing tests.

* test(formattest): Print a diff between the expected and actual result.
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