unicorn/max-nested-calls Style
作用
限制嵌套调用的深度。
此规则会统计传入其他调用或构造函数中的调用和构造函数调用。 流式接收者链和 JSX 包装器会被忽略。
为什么这不好?
过深的嵌套调用会使代码难以阅读。将中间结果提取到具名变量中可以提高可读性。
示例
以下是此规则的错误代码示例:
js
foo(bar(baz(qux())));以下是此规则的正确代码示例:
js
const value = baz(qux());
foo(bar(value));
// 流式链会被忽略。
query().filter().map().toArray();配置
此规则接受一个配置对象,包含以下属性:
max
类型:integer
默认值:3
允许的最大嵌套调用深度。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/max-nested-calls": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/max-nested-calls": "error",
},
});bash
oxlint --deny unicorn/max-nested-calls版本
此规则已在 v1.71.0 中添加。
