diff --git a/internal/formats/transform.go b/internal/formats/transform.go index e3d4158..eae2116 100644 --- a/internal/formats/transform.go +++ b/internal/formats/transform.go @@ -15,6 +15,9 @@ import ( // EmptyYAMLValue represents an empty YAML value that renders as just a space after the colon type EmptyYAMLValue struct{} +// Pre-compiled regex for extracting rule titles +var titleRegex = regexp.MustCompile(`(?m)^#\s+(.+)$`) + func (e EmptyYAMLValue) MarshalYAML() (interface{}, error) { var node yaml.Node node.Kind = yaml.ScalarNode @@ -373,8 +376,7 @@ func GetRuleName(filePath string, sourceDir string) (string, error) { // ExtractRuleTitle extracts the title from the content of a rule file func ExtractRuleTitle(content []byte) string { // Look for a markdown heading (# Title) - re := regexp.MustCompile(`(?m)^#\s+(.+)$`) - match := re.FindSubmatch(content) + match := titleRegex.FindSubmatch(content) if len(match) > 1 { return string(match[1])