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

`wrapAsYamlNode` should apply style recursively #24

Closed dcharkes closed 1 year ago

dcharkes commented 1 year ago

https://pub.dev/documentation/yaml_edit/latest/yaml_edit/wrapAsYamlNode.html

Should this wrap recursively?

input (lists, strings, maps):

[{name: bla, packaging: dynamic, path: {path_type: absolute, uri: path/with spaces/bla.dll}, target: windows_x64}]

output:

- name: bla
  packaging: dynamic
  path:
    path_type: absolute
    uri: path/with spaces/bla.dll
  target: windows_x64

conversion

String _toYamlString(Object yamlEncoding) => (YamlEditor('')
      ..update(
          [],
          wrapAsYamlNode(
            yamlEncoding,
            collectionStyle: CollectionStyle.BLOCK,
            scalarStyle: ScalarStyle.DOUBLE_QUOTED,
          )))
    .toString();

Asked for quotes, but didn't get any.

jonasfj commented 1 year ago

@dcharkes would https://github.com/dart-lang/yaml_edit/issues/26 solve this problem better?

dcharkes commented 1 year ago

Since wrapAsYamlNode already takes style arguments, why not add a recursive boolean or recursion depth to it instead rather than introducing a new method? It's unclear to me why wrapAsCustomStyledYamlNode should apply style why wrapAsYamlNode shouldn't.

jonasfj commented 1 year ago

I think wrapAsYamlNode probably could apply recursively, hmm, I guess that would solve most issues.

The wrapAsCustomStyledYamlNode is only really if you want to control styling even more.

jonasfj commented 1 year ago

Fixed