Skip to content

Commit 4dd9db8

Browse files
a-orenclaude
andcommitted
refactor: extract ignore-format regexes into precompiled Pattern constants
Avoids recompiling regexes on every IgnoredLine call. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2fba57b commit 4dd9db8

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/providers/GoModulesProvider.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public final class GoModulesProvider extends Provider {
6262
"TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED";
6363
private static final Logger log = LoggersFactory.getLogger(GoModulesProvider.class.getName());
6464
public static final String DEFAULT_MAIN_VERSION = "v0.0.0";
65+
66+
private static final Pattern STANDALONE_IGNORE_PATTERN =
67+
Pattern.compile("(exhortignore|trustify-da-ignore)");
68+
private static final Pattern INDIRECT_IGNORE_PATTERN =
69+
Pattern.compile("indirect\\s*;\\s*(//)?\\s*(exhortignore|trustify-da-ignore)");
70+
private static final Pattern DEPENDENCY_LINE_PATTERN =
71+
Pattern.compile("^[a-z.0-9/-]+\\s{1,2}[vV][0-9]\\.[0-9](\\.[0-9]){0,2}.*");
72+
6573
private final String goExecutable;
6674

6775
public String getMainModuleVersion() {
@@ -569,8 +577,8 @@ public boolean IgnoredLine(String line) {
569577
// "// indirect; // exhortignore").
570578
// Does NOT match "// indirect //exhortignore" (no semicolon) or
571579
// "// indirect exhortignore" (space-separated) — these are incorrect formats.
572-
if (comment.matches("(exhortignore|trustify-da-ignore)")
573-
|| comment.matches("indirect\\s*;\\s*(//)?\\s*(exhortignore|trustify-da-ignore)")) {
580+
if (STANDALONE_IGNORE_PATTERN.matcher(comment).matches()
581+
|| INDIRECT_IGNORE_PATTERN.matcher(comment).matches()) {
574582
// filter out lines where exhortignore or trustify-da-ignore has no meaning
575583
if (!trimmedRow.startsWith("module ")
576584
&& !trimmedRow.startsWith("go ")
@@ -582,8 +590,7 @@ public boolean IgnoredLine(String line) {
582590
&& !trimmedRow.startsWith("use ")
583591
&& !trimmedRow.contains("=>")) {
584592
if (trimmedRow.startsWith("require ")
585-
|| Pattern.matches(
586-
"^[a-z.0-9/-]+\\s{1,2}[vV][0-9]\\.[0-9](\\.[0-9]){0,2}.*", trimmedRow)) {
593+
|| DEPENDENCY_LINE_PATTERN.matcher(trimmedRow).matches()) {
587594
result = true;
588595
}
589596
}

0 commit comments

Comments
 (0)