regexAllGlobalFlags
Reports
matchAll()andreplaceAll()calls with regex arguments missing the global flag.
✅ This rule is included in the ts logical presets.
When calling String.prototype.matchAll() or String.prototype.replaceAll() with a regular expression, the regex must have the global (g) flag.
Without it, JavaScript throws a TypeError at runtime.
This rule detects regex literals and RegExp constructor calls that are missing the global flag when passed to these methods.
Examples
Section titled “Examples”"hello world".matchAll(/o/);"hello world".replaceAll(/o/, "0");const text = "example";text.matchAll(new RegExp("e"));"hello world".matchAll(/o/g);"hello world".replaceAll(/o/g, "0");const text = "example";text.matchAll(new RegExp("e", "g"));"hello world".replaceAll("o", "0");Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you’re transpiling to an environment without matchAll() or replaceAll() support and have polyfills that don’t enforce the global flag requirement, you might want to disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
regexp/no-missing-g-flag - Oxlint:
oxc/bad-replace-all-arg
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.