oxc/bad-replace-all-arg Correctness
它的作用
当 replaceAll 方法传入一个没有全局标志(g)的正则表达式时,此规则会发出警告。
为什么这不好?
当传入正则表达式时,replaceAll 方法要求设置全局标志(g)。 否则,它会在运行时抛出 TypeError,而不是执行替换。
示例
此规则的错误代码示例:
javascript
withSpaces.replaceAll(/\s+/, ",");此规则的正确代码示例:
javascript
withSpaces.replaceAll(/\s+/g, ",");如何使用
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-arg版本
此规则于 v0.0.22 中添加。
