eslint/no-new Suspicious
它的作用
禁止在赋值或比较之外使用 new 运算符。
为什么这不好?
在不进行赋值或比较的情况下调用 new,会使其引用被丢弃,并且在许多 情况下构造函数可以被函数替代。
示例
以下是此规则的错误代码示例:
javascript
new Person();
() => {
new Date();
};以下是此规则的正确代码示例:
javascript
var a = new Date()(() => new Date());如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-new": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-new": "error",
},
});bash
oxlint --deny no-new版本
此规则已在 v0.4.0 中添加。
