MCPcopy Create free account
hub / github.com/vale-cli/vale / applyCommentPatterns

Function applyCommentPatterns

internal/lint/html.go:128–148  ·  view source on GitHub ↗

applyCommentPatterns replaces any custom comment delimiters with HTML comment tags based on the user configuration. This makes it possible to apply comment-based controls using custom comment delimiters.

(c *core.Config, exts extensionConfig, content string)

Source from the content-addressed store, hash-verified

126// tags based on the user configuration. This makes it possible to apply
127// comment-based controls using custom comment delimiters.
128func applyCommentPatterns(c *core.Config, exts extensionConfig, content string) (string, error) {
129 for syntax, delims := range c.CommentDelimiters {
130 sec, err := glob.Compile(syntax)
131 if err != nil {
132 return content, err
133 } else if sec.Match(exts.Normed) || sec.Match(exts.Real) {
134 // This field was not assigned, so do nothing.
135 if delims[0] == "" && delims[1] == "" {
136 return content, nil
137 }
138 // Return an error if only one delimiter is configured
139 if (delims[0] == "" && delims[1] != "") || (delims[0] != "" && delims[1] == "") {
140 return content, fmt.Errorf("CommentDelimiters must be empty or have two values")
141 }
142
143 content = strings.ReplaceAll(content, delims[0], "<!--")
144 content = strings.ReplaceAll(content, delims[1], "-->")
145 }
146 }
147 return content, nil
148}
149
150func applyPatterns(c *core.Config, exts extensionConfig, content string) (string, error) {
151 s, err := applyBlockPatterns(c, exts, content)

Callers 1

applyPatternsFunction · 0.85

Calls 2

CompileFunction · 0.92
MatchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…