Will It Vibe logoWill It Vibe?
PERF-009Low severity-4 points

RegExp constructed inside a loop body

Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.

What it detects

new RegExp(...) is called inside a loop body, recompiling the same pattern on every iteration instead of once. Heuristic: if the pattern text is actually built from the loop variable (a genuinely different regex per iteration) this is unavoidable; hoist the RegExp above the loop whenever the pattern is constant.

Why it matters

new RegExp(...) compiles the pattern text into a regular expression object; doing that inside a loop body recompiles the same pattern on every iteration instead of once, which is wasted work whenever the pattern text is actually constant. On a large loop this adds up, and it is one of the easiest "hoist the invariant out of the loop" wins available.

How to fix it

If the pattern string does not depend on the loop variable, move the new RegExp(...) call above the loop and reuse the compiled regex inside it. If the pattern is genuinely built from the loop variable (a different regex per iteration), this cannot be hoisted; leave it as-is.

The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing

Does your repo trip this check?

Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.

Scan your repo

Related Code Quality & Syntax checks