Skip to content

Commit

Permalink
refactor: add gendoc for IsEmptyYamlDocument
Browse files Browse the repository at this point in the history
Signed-off-by: ah8ad3 <ah8ad3@gmail.com>
  • Loading branch information
ah8ad3 committed Apr 18, 2024
1 parent d510680 commit e84d58c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ func SplitYamlDocuments(fileBytes Document) ([]Document, error) {
}

// IsEmptyYamlDocument checks if a yaml document is empty (contains only comments)
//
// This function validate emptiness of yaml if comment-only single documents,
// and strings with multiple documents where all docs are comment-only.
func IsEmptyYamlDocument(document Document) bool {
for _, line := range strings.Split(string(document), "\n") {
line := strings.TrimSpace(line)
if line != "" && !strings.HasPrefix(line, "#") && !strings.HasPrefix(line, "---") {
if line != "" && !strings.HasPrefix(line, "#") && line != "---" {
return false
}
}
Expand Down

0 comments on commit e84d58c

Please sign in to comment.