oxc/bad-replace-all-arg Correctness
What it does
This rule warns when the replaceAll 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 replaceAll method requires the global flag (g). Otherwise, it throws a TypeError at runtime instead of performing a replacement.
Examples
Examples of incorrect code for this rule:
javascript
withSpaces.replaceAll(/\s+/, ",");Examples of correct code for this rule:
javascript
withSpaces.replaceAll(/\s+/g, ",");How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"oxc/bad-replace-all-arg": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"oxc/bad-replace-all-arg": "error",
},
});bash
oxlint --deny oxc/bad-replace-all-argVersion
This rule was added in v0.0.22.
