Skip to main content

What it flags

Repeated work constructs a RegExp from a fixed string and optional fixed flags and immediately calls test() or exec(). Loadwise checks patterns up to 1,024 characters against the syntax supported by its Node.js runtime. The finding appears with --include-contextual.

How to review or fix

Measure the allocation cost before reusing the expression. Engines can cache compiled patterns. The rule skips global and sticky expressions because a fresh object resets their lastIndex.

Version compatibility

When rolling back to a Loadwise version released before this rule, remove js-fixed-regexp-in-loop from rules and overrides in loadwise.config.json first. Older versions reject rule IDs they do not recognize, including entries set to off.