Do not add trailing whitespace to new map keys (dart-lang/yaml_edit#16)
diff --git a/pkgs/yaml_edit/lib/src/map_mutations.dart b/pkgs/yaml_edit/lib/src/map_mutations.dart index 5e40db7..9906a65 100644 --- a/pkgs/yaml_edit/lib/src/map_mutations.dart +++ b/pkgs/yaml_edit/lib/src/map_mutations.dart
@@ -57,14 +57,7 @@ final keyString = yamlEncodeFlowString(wrapAsYamlNode(key)); final lineEnding = getLineEnding(yaml); - var valueString = yamlEncodeBlockString(newValue, newIndentation, lineEnding); - if (isCollection(newValue) && - !isFlowYamlCollectionNode(newValue) && - !isEmpty(newValue)) { - valueString = '$lineEnding$valueString'; - } - - var formattedValue = ' ' * getMapIndentation(yaml, map) + '$keyString: '; + var formattedValue = ' ' * getMapIndentation(yaml, map); var offset = map.span.end.offset; final insertionIndex = getMapInsertionIndex(map, keyString); @@ -90,7 +83,14 @@ } } - formattedValue += valueString + lineEnding; + var valueString = yamlEncodeBlockString(newValue, newIndentation, lineEnding); + if (isCollection(newValue) && + !isFlowYamlCollectionNode(newValue) && + !isEmpty(newValue)) { + formattedValue += '$keyString:' + lineEnding + valueString + lineEnding; + } else { + formattedValue += '$keyString: ' + valueString + lineEnding; + } return SourceEdit(offset, 0, formattedValue); }
diff --git a/pkgs/yaml_edit/test/update_test.dart b/pkgs/yaml_edit/test/update_test.dart index 9b4928b..3e392e0 100644 --- a/pkgs/yaml_edit/test/update_test.dart +++ b/pkgs/yaml_edit/test/update_test.dart
@@ -767,7 +767,7 @@ expect(doc.toString(), equals(''' a: aa: 1 - bb: + bb: aaa: dddd: c bbb: @@ -806,7 +806,7 @@ expect(doc.toString(), equals(''' a: aa: 1 - bb: + bb: - 0 - - 1 - 2