From d833d045bf54fcc392ee2342943ae027d99f0c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Insaurralde?= Date: Thu, 2 Jul 2026 23:58:04 -0300 Subject: [PATCH] perf(formatters): hoist SCP git URL regex to package level in IsValidGitURL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move regexp.MustCompile for SCP-style git URLs out of IsValidGitURL so the pattern is compiled once at init instead of on every call. Signed-off-by: Matías Insaurralde --- formatters/sarif/sarif.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/formatters/sarif/sarif.go b/formatters/sarif/sarif.go index a2a4369..ece7250 100644 --- a/formatters/sarif/sarif.go +++ b/formatters/sarif/sarif.go @@ -16,6 +16,8 @@ import ( "github.com/owenrumney/go-sarif/v2/sarif" ) +var sshPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9._-]+:[a-zA-Z0-9/._-]+$`) + func NewFormat(out io.Writer, version string) *Format { return &Format{ out: out, @@ -196,6 +198,5 @@ func IsValidGitURL(gitURL string) bool { return parsedURL.Host != "" && parsedURL.Path != "" } - sshPattern := regexp.MustCompile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9._-]+:[a-zA-Z0-9/._-]+$`) return sshPattern.MatchString(gitURL) }