eslint/no-setter-return Correctness
它的作用
setter 不能返回值。
对于 TypeScript 代码,可以禁用此规则,因为 TypeScript 编译器会强制执行此检查。
为什么这很糟糕?
虽然从 setter 返回值不会产生错误,但返回的值会被忽略。因此,从 setter 返回值要么是不必要的,要么可能是错误,因为返回的值无法被使用。
示例
以下是此规则的错误代码示例:
javascript
class URL {
set origin() {
return true;
}
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-setter-return": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-setter-return": "error",
},
});bash
oxlint --deny no-setter-return版本
此规则于 v0.0.3 中添加。
