aboutsummaryrefslogtreecommitdiff
path: root/vendor/gopkg.in/yaml.v3/emitterc.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/yaml.v3/emitterc.go')
-rw-r--r--vendor/gopkg.in/yaml.v3/emitterc.go34
1 files changed, 16 insertions, 18 deletions
diff --git a/vendor/gopkg.in/yaml.v3/emitterc.go b/vendor/gopkg.in/yaml.v3/emitterc.go
index c29217ef5..0f47c9ca8 100644
--- a/vendor/gopkg.in/yaml.v3/emitterc.go
+++ b/vendor/gopkg.in/yaml.v3/emitterc.go
@@ -814,26 +814,24 @@ func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_
}
}
if len(emitter.key_line_comment) > 0 {
- // [Go] A line comment was previously provided for the key. Handle it before
- // the value so the inline comments are placed correctly.
- if yaml_emitter_silent_nil_event(emitter, event) && len(emitter.line_comment) == 0 {
- // Nothing other than the line comment will be written on the line.
- emitter.line_comment = emitter.key_line_comment
- emitter.key_line_comment = nil
- } else {
- // An actual value is coming, so emit the comment line.
+ // [Go] Line comments are generally associated with the value, but when there's
+ // no value on the same line as a mapping key they end up attached to the
+ // key itself.
+ if event.typ == yaml_SCALAR_EVENT {
+ if len(emitter.line_comment) == 0 {
+ // A scalar is coming and it has no line comments by itself yet,
+ // so just let it handle the line comment as usual. If it has a
+ // line comment, we can't have both so the one from the key is lost.
+ emitter.line_comment = emitter.key_line_comment
+ emitter.key_line_comment = nil
+ }
+ } else if event.sequence_style() != yaml_FLOW_SEQUENCE_STYLE && (event.typ == yaml_MAPPING_START_EVENT || event.typ == yaml_SEQUENCE_START_EVENT) {
+ // An indented block follows, so write the comment right now.
emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
if !yaml_emitter_process_line_comment(emitter) {
return false
}
emitter.line_comment, emitter.key_line_comment = emitter.key_line_comment, emitter.line_comment
- // Indent in unless it's a block that will reindent anyway.
- if event.sequence_style() == yaml_FLOW_SEQUENCE_STYLE || (event.typ != yaml_MAPPING_START_EVENT && event.typ != yaml_SEQUENCE_START_EVENT) {
- emitter.indent = emitter.best_indent*((emitter.indent+emitter.best_indent)/emitter.best_indent)
- if !yaml_emitter_write_indent(emitter) {
- return false
- }
- }
}
}
emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE)
@@ -1896,7 +1894,7 @@ func yaml_emitter_write_literal_scalar(emitter *yaml_emitter_t, value []byte) bo
if !yaml_emitter_write_block_scalar_hints(emitter, value) {
return false
}
- if !put_break(emitter) {
+ if !yaml_emitter_process_line_comment(emitter) {
return false
}
//emitter.indention = true
@@ -1933,10 +1931,10 @@ func yaml_emitter_write_folded_scalar(emitter *yaml_emitter_t, value []byte) boo
if !yaml_emitter_write_block_scalar_hints(emitter, value) {
return false
}
-
- if !put_break(emitter) {
+ if !yaml_emitter_process_line_comment(emitter) {
return false
}
+
//emitter.indention = true
emitter.whitespace = true