NormalizeCommentIndentation removes indentation from standalone YAML comment lines to keep them left aligned.
(data []byte)
| 1307 | |
| 1308 | // NormalizeCommentIndentation removes indentation from standalone YAML comment lines to keep them left aligned. |
| 1309 | func NormalizeCommentIndentation(data []byte) []byte { |
| 1310 | lines := bytes.Split(data, []byte("\n")) |
| 1311 | changed := false |
| 1312 | for i, line := range lines { |
| 1313 | trimmed := bytes.TrimLeft(line, " \t") |
| 1314 | if len(trimmed) == 0 || trimmed[0] != '#' { |
| 1315 | continue |
| 1316 | } |
| 1317 | if len(trimmed) == len(line) { |
| 1318 | continue |
| 1319 | } |
| 1320 | lines[i] = append([]byte(nil), trimmed...) |
| 1321 | changed = true |
| 1322 | } |
| 1323 | if !changed { |
| 1324 | return data |
| 1325 | } |
| 1326 | return bytes.Join(lines, []byte("\n")) |
| 1327 | } |
| 1328 | |
| 1329 | // getOrCreateMapValue finds the value node for a given key in a mapping node. |
| 1330 | // If not found, it appends a new key/value pair and returns the new value node. |
no outgoing calls
no test coverage detected