Skip to content

Commit

Permalink
fix: raw string for regexp.Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Feb 21, 2022
1 parent bc5e2db commit 69d0d77
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions xutil/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
indentation = 4
indentation = 2
)

func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag string, yamlKey func(string) string) (string, error) {
Expand All @@ -35,7 +35,7 @@ func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag s
} else {
result = fmt.Sprintf("%s %s\n", result, comment)
for i := 0; i < value.Len(); i++ {
result = fmt.Sprintf("%s%s -", result, indent)
result = fmt.Sprintf("%s%s-", result, indent)
nested, err := YAMLWithComments(value.Index(i).Interface(), atIndent+indentation, yamlTag, usageTag, yamlKey)
if err != nil {
return err
Expand Down Expand Up @@ -116,7 +116,7 @@ func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag s
}
}

reCompact, _ := regexp.Compile("(?m)\\n{2,}")
reCompact, _ := regexp.Compile(`(?m)\\n{2,}`)
result = reCompact.ReplaceAllString(result, "\n")
return result, nil
}
Expand Down

0 comments on commit 69d0d77

Please sign in to comment.