eslint/no-useless-return Pedantic
功能
禁止多余的 return 语句。
为什么这不好?
后面没有任何内容的 return; 语句是多余的,并且对函数的运行时行为没有任何影响。这可能会造成困惑,因此最好禁止这类多余语句。
示例
以下是此规则的错误代码示例:
js
function foo() {
return;
}
function bar() {
doSomething();
return;
}
function baz() {
if (condition) {
doSomething();
return;
}
}以下是此规则的正确代码示例:
js
function foo() {
return 5;
}
function bar() {
if (condition) {
return;
}
doSomething();
}
function baz() {
return doSomething();
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-useless-return": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-useless-return": "error",
},
});bash
oxlint --deny no-useless-return版本
此规则于 v1.32.0 中添加。
