Skip to content

Commit

Permalink
fix: Be sure to only start on valid yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Apr 18, 2024
1 parent ec7649f commit 6b558e0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func RemoveCommentsFromYaml(reader io.Reader) ([]byte, error) {
scanner := bufio.NewScanner(reader)

commentMatcher := regexp.MustCompile(`^\s*#\s*`)
commentYamlMapMatcher := regexp.MustCompile(`^(\s*#\s*)[^:]+:.*$`)
schemaMatcher := regexp.MustCompile(`^\s*#\s@schema\s*`)

var line string
Expand Down Expand Up @@ -75,8 +76,8 @@ func RemoveCommentsFromYaml(reader io.Reader) ([]byte, error) {

// Havent found a potential yaml block yet
if !inCode {
if match := commentMatcher.Find([]byte(line)); match != nil {
codeIndention = len(match)
if matches := commentYamlMapMatcher.FindStringSubmatch(line); matches != nil {
codeIndention = len(matches[1])
inCode = true
}
}
Expand Down

0 comments on commit 6b558e0

Please sign in to comment.