Skip to content

Commit

Permalink
Merge pull request #113 from ah8ad3/ignore-empty-documents
Browse files Browse the repository at this point in the history
Ignore empty documents.
  • Loading branch information
k8s-ci-robot committed Apr 23, 2024
2 parents 69421c1 + 7793113 commit 4ffbdb6
Show file tree
Hide file tree
Showing 3 changed files with 10 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)
//
// Returns true for 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, "#") {
if line != "" && !strings.HasPrefix(line, "#") && line != "---" {
return false
}
}
Expand Down
1 change: 1 addition & 0 deletions testcases/manifests/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
5 changes: 5 additions & 0 deletions testcases/manifests/empty_with_document.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Some document
# Some document
# Some document
# Some document
---

0 comments on commit 4ffbdb6

Please sign in to comment.