Skip to content
← Back to rules

oxc/bad-match-all-arg Correctness

This rule is turned on by default.

What it does

This rule warns when the matchAll method is called with a regular expression that does not have the global flag (g).

Why is this bad?

When called with a regular expression, the matchAll method requires the global flag (g). Otherwise, it throws a TypeError at runtime instead of returning an iterator.

Examples

Examples of incorrect code for this rule:

javascript
text.matchAll(/pattern/);

Examples of correct code for this rule:

javascript
text.matchAll(/pattern/g);

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "oxc/bad-match-all-arg": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/bad-match-all-arg": "error",
  },
});
bash
oxlint --deny oxc/bad-match-all-arg

Version

This rule was added in vnext.

References