oxc/bad-match-all-arg 正确性
功能
当使用不带全局标志(g)的正则表达式调用 matchAll 方法时,此规则会发出警告。
为什么这是个问题?
使用正则表达式调用时,matchAll 方法要求正则表达式带有全局标志(g)。 否则,它会在运行时抛出 TypeError,而不是返回一个迭代器。
示例
此规则的错误代码示例:
javascript
text.matchAll(/pattern/);此规则的正确代码示例:
javascript
text.matchAll(/pattern/g);使用方法
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版本
此规则在 v1.76.0 中添加。
