dart-lang / yaml_edit

A library for YAML manipulation with comment and whitespace preservation.
https://pub.dev/packages/yaml_edit
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

Fix 55 #75

Closed jonasfj closed 6 months ago

jonasfj commented 6 months ago

please double check golden files during review


Fixes https://github.com/dart-lang/yaml_edit/issues/55.

When the value is empty the SourceSpan for the YamlNode representing the value in a map points to the colon.

Example:

foo:
  bar:

The YamlNode for foo.bar has a value of null and starts and ends at the colon : following bar. This means that removal might leave the colon behind, which causes invalid YAML.

We have the same issue when removing foo.bar from the following YAML document:

foo:
  baz: true
  bar:

However, in this case, we have a hack that ensures we always strip away the any comments that follows bar. We do this by deleting up-to the next newline. If we apply the same hack when removing foo.bar in the first example, then it works.

One could argue that it works by accident, but it's kind of desired that trailing comments are removed, when the value they are trailing is removed.

github-actions[bot] commented 6 months ago

Package publishing

Package Version Status Publish tag (post-merge)
package:yaml_edit 2.2.1 ready to publish v2.2.1

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.