Skip to content

Conversation

@braydonk
Copy link
Collaborator

@braydonk braydonk commented May 18, 2025

As outlined in #242, the yaml library did not initially handle this edge case of using an alias node as a key properly. This PR adds functionality to correct that. In case there is some other edge case where this breaks, the disable_alias_key_correction formatter config option was added.

braydonk added 3 commits May 18, 2025 10:33
As outlined in #247, the yaml library did not initially handle this edge
case of using an alias node as a key properly. This PR adds
functionality to correct that. In case there is some other edge case
where this breaks, the `disable_alias_key_correction` formatter config
option was added.
@braydonk braydonk merged commit bb1d122 into main May 18, 2025
8 checks passed
octo added a commit to octo/yamlfmt that referenced this pull request Jun 23, 2025
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.
braydonk pushed a commit that referenced this pull request Jun 23, 2025
* fix(yaml): Remove trailing whitespace from merge aliases.

PR #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.
steeef pushed a commit to steeef/yamlfmt that referenced this pull request Sep 5, 2025
* pkg/yaml: correct alias keys

As outlined in google#247, the yaml library did not initially handle this edge
case of using an alias node as a key properly. This PR adds
functionality to correct that. In case there is some other edge case
where this breaks, the `disable_alias_key_correction` formatter config
option was added.

* forgot to fix this comment

* forgot to enable the setting for this test
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.

1 participant