Skip to content

Commit

Permalink
fix: Adapt logic for formatting comments as plain text so hash symbol…
Browse files Browse the repository at this point in the history
…s are removed only at the beginning of the line
  • Loading branch information
erNail committed Jun 10, 2024
1 parent 9485e7b commit de50819
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/yamlutils/yaml_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ func RemoveYamlDocumentSeparators(yamlContent []byte) []byte {
// Returns:
// - string: The cleaned comment string.
func FormatCommentAsPlainText(comment string) string {
comment = strings.ReplaceAll(comment, "#", "")
lines := strings.Split(comment, "\n")

for i, line := range lines {
lines[i] = strings.TrimSpace(line)
lines[i] = strings.TrimSpace(strings.TrimPrefix(line, "#"))
}

cleanedComment := strings.Join(lines, "\n")
Expand Down
13 changes: 13 additions & 0 deletions internal/yamlutils/yaml_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func TestFormatCommentAsPlainTextFormatsMultiLineComment(t *testing.T) {
assert.Equal(t, expectedFormattedComment, actualFormattedComment)
}

func TestFormatCommentAsPlainTextOnlyRemovesHashSymbolInTheBeginning(t *testing.T) {
t.Parallel()

multilineComment := `# This is a comment with a # in it
# This is a comment with an [anchor link](#anchor) in it`

expectedFormattedComment := "This is a comment with a # in it\nThis is a comment with an [anchor link](#anchor) in it"

actualFormattedComment := FormatCommentAsPlainText(multilineComment)

assert.Equal(t, expectedFormattedComment, actualFormattedComment)
}

func TestReadYamlFilesFromDirectoryWithNoYamlFilesReturnsNoYamlFiles(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit de50819

Please sign in to comment.