Fixed footer comment issue #1321

This commit is contained in:
Mike Farah 2022-08-30 11:24:26 +10:00
parent 3d11b0545d
commit bf6b4d3941
2 changed files with 31 additions and 0 deletions

View File

@ -63,8 +63,12 @@ func assignCommentsOperator(d *dataTreeNavigator, context Context, expressionNod
} }
if preferences.FootComment && candidate.Node.Kind == yaml.DocumentNode && comment != "" { if preferences.FootComment && candidate.Node.Kind == yaml.DocumentNode && comment != "" {
candidate.TrailingContent = "# " + comment candidate.TrailingContent = "# " + comment
} else if preferences.FootComment && candidate.Node.Kind == yaml.DocumentNode {
candidate.TrailingContent = comment
} else if preferences.FootComment && candidate.Node.Kind != yaml.DocumentNode { } else if preferences.FootComment && candidate.Node.Kind != yaml.DocumentNode {
candidate.Node.FootComment = comment candidate.Node.FootComment = comment
candidate.TrailingContent = ""
} }
} }

View File

@ -62,6 +62,15 @@ var commentOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::a: cat\n# cat\n", "D0, P[], (doc)::a: cat\n# cat\n",
}, },
}, },
{
skipDoc: true,
description: "Set foot comment, using an expression",
document: "a: cat\n\n# hi",
expression: `. foot_comment=""`,
expected: []string{
"D0, P[], (doc)::a: cat\n",
},
},
{ {
skipDoc: true, skipDoc: true,
document: `a: cat`, document: `a: cat`,
@ -112,6 +121,24 @@ var commentOperatorScenarios = []expressionScenario{
"D0, P[], (!!str)::welcome!\n", "D0, P[], (!!str)::welcome!\n",
}, },
}, },
{
skipDoc: true,
description: "strip trailing comment recurse all",
document: "a: cat\n\n# haha",
expression: `... comments= ""`,
expected: []string{
"D0, P[], (!!map)::a: cat\n",
},
},
{
skipDoc: true,
description: "strip trailing comment recurse values",
document: "a: cat\n\n# haha",
expression: `.. comments= ""`,
expected: []string{
"D0, P[], (!!map)::a: cat\n",
},
},
{ {
description: "Head comment with document split", description: "Head comment with document split",
dontFormatInputForDoc: true, dontFormatInputForDoc: true,