# oxc/bad-match-all-arg

> Require the `g` flag on a regular expression passed to `matchAll()`

`matchAll()` throws a `TypeError` when its regular expression doesn't have the `g` flag. The code parses and only fails when that line runs.

The rule checks a regular expression literal, `new RegExp()` and `RegExp()`, written in the call or kept in a variable. If the flags aren't a plain string, it can't tell and reports nothing. A string argument is fine, because `matchAll()` turns it into a global regular expression.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"oxc/bad-match-all-arg" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const words = [...text.matchAll(/\w+/)];

const tag = new RegExp("#\\w+", "i");
for (const match of text.matchAll(tag)) {
  tags.push(match[0]);
}
```

Not reported:

{/* good */}
```js
const words = [...text.matchAll(/\w+/g)];

const tag = new RegExp("#\\w+", "gi");
for (const match of text.matchAll(tag)) {
  tags.push(match[0]);
}

const commas = [...text.matchAll(",")];
```
