From fbd7317eba9b112356ce4b170e29bcf9072c01bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Insaurralde?= Date: Fri, 11 Jul 2025 03:08:07 -0300 Subject: [PATCH] nit: precompile rule title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matías Insaurralde --- internal/formats/transform.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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])