Skip to content

Commit

Permalink
Make sequence indentation more usual
Browse files Browse the repository at this point in the history
Sequences used to be slightly different, and v3 made it slightly
different in a slightly different way, and that's all slightly bad.
All gone now. Sequences indent just like everything else.
  • Loading branch information
niemeyer committed May 4, 2020
1 parent 9f266ea commit ae27a74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_e
// Expect a block item node.
func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool {
if first {
// [Go] The original logic here would not indent the sequence when inside a mapping.
// In Go we always indent it, but take the sequence indicator out of the indentation.
indentless := emitter.best_indent == 2 && emitter.mapping_context && (emitter.column == 0 || !emitter.indention)
// [Go] The original logic here would not indent the sequence when
// inside a mapping. In Go we always indent it.
indentless := false
original := emitter.indent
if !yaml_emitter_increase_indent(emitter, false, indentless) {
return false
Expand Down
40 changes: 20 additions & 20 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ var nodeTests = []struct {
}},
},
}, {
"a:\n- b: c\n d: e\n",
"a:\n - b: c\n d: e\n",
yaml.Node{
Kind: yaml.DocumentNode,
Line: 1,
Expand All @@ -459,43 +459,43 @@ var nodeTests = []struct {
Kind: yaml.SequenceNode,
Tag: "!!seq",
Line: 2,
Column: 1,
Column: 3,
Content: []*yaml.Node{{
Kind: yaml.MappingNode,
Tag: "!!map",
Line: 2,
Column: 3,
Column: 5,
Content: []*yaml.Node{{
Kind: yaml.ScalarNode,
Value: "b",
Tag: "!!str",
Line: 2,
Column: 3,
Column: 5,
}, {
Kind: yaml.ScalarNode,
Value: "c",
Tag: "!!str",
Line: 2,
Column: 6,
Column: 8,
}, {
Kind: yaml.ScalarNode,
Value: "d",
Tag: "!!str",
Line: 3,
Column: 3,
Column: 5,
}, {
Kind: yaml.ScalarNode,
Value: "e",
Tag: "!!str",
Line: 3,
Column: 6,
Column: 8,
}},
}},
}},
}},
},
}, {
"a: # AI\n- b\nc:\n- d\n",
"a: # AI\n - b\nc:\n - d\n",
yaml.Node{
Kind: yaml.DocumentNode,
Line: 1,
Expand All @@ -520,10 +520,10 @@ var nodeTests = []struct {
Tag: "!!str",
Value: "b",
Line: 2,
Column: 3,
Column: 5,
}},
Line: 2,
Column: 1,
Column: 3,
}, {
Kind: yaml.ScalarNode,
Tag: "!!str",
Expand All @@ -538,10 +538,10 @@ var nodeTests = []struct {
Tag: "!!str",
Value: "d",
Line: 4,
Column: 3,
Column: 5,
}},
Line: 4,
Column: 1,
Column: 3,
}},
}},
},
Expand Down Expand Up @@ -1089,7 +1089,7 @@ var nodeTests = []struct {
}},
},
}, {
"# DH1\n\n# HA1\nka:\n # HB1\n kb:\n # HC1\n # HC2\n - lc # IC\n # FC1\n # FC2\n\n # HD1\n - ld # ID\n # FD1\n\n# DF1\n",
"# DH1\n\n# HA1\nka:\n # HB1\n kb:\n # HC1\n # HC2\n - lc # IC\n # FC1\n # FC2\n\n # HD1\n - ld # ID\n # FD1\n\n# DF1\n",
yaml.Node{
Kind: yaml.DocumentNode,
Line: 4,
Expand Down Expand Up @@ -1123,13 +1123,13 @@ var nodeTests = []struct {
}, {
Kind: yaml.SequenceNode,
Line: 9,
Column: 3,
Column: 5,
Tag: "!!seq",
Content: []*yaml.Node{{
Kind: yaml.ScalarNode,
Tag: "!!str",
Line: 9,
Column: 5,
Column: 7,
Value: "lc",
HeadComment: "# HC1\n# HC2",
LineComment: "# IC",
Expand All @@ -1138,7 +1138,7 @@ var nodeTests = []struct {
Kind: yaml.ScalarNode,
Tag: "!!str",
Line: 14,
Column: 5,
Column: 7,
Value: "ld",
HeadComment: "# HD1",

Expand All @@ -1150,7 +1150,7 @@ var nodeTests = []struct {
}},
},
}, {
"# DH1\n\n# HA1\nka:\n # HB1\n kb:\n # HC1\n # HC2\n - lc # IC\n # FC1\n # FC2\n\n # HD1\n - ld # ID\n # FD1\nke: ve\n\n# DF1\n",
"# DH1\n\n# HA1\nka:\n # HB1\n kb:\n # HC1\n # HC2\n - lc # IC\n # FC1\n # FC2\n\n # HD1\n - ld # ID\n # FD1\nke: ve\n\n# DF1\n",
yaml.Node{
Kind: yaml.DocumentNode,
Line: 4,
Expand Down Expand Up @@ -1184,13 +1184,13 @@ var nodeTests = []struct {
}, {
Kind: yaml.SequenceNode,
Line: 9,
Column: 3,
Column: 5,
Tag: "!!seq",
Content: []*yaml.Node{{
Kind: yaml.ScalarNode,
Tag: "!!str",
Line: 9,
Column: 5,
Column: 7,
Value: "lc",
HeadComment: "# HC1\n# HC2",
LineComment: "# IC",
Expand All @@ -1199,7 +1199,7 @@ var nodeTests = []struct {
Kind: yaml.ScalarNode,
Tag: "!!str",
Line: 14,
Column: 5,
Column: 7,
Value: "ld",
HeadComment: "# HD1",
LineComment: "# ID",
Expand Down

0 comments on commit ae27a74

Please sign in to comment.