Skip to content
← Back to rules

unicorn/max-nested-calls Style

What it does

Limit the depth of nested calls.

This rule counts calls and constructor calls passed into other calls or constructors. Fluent receiver chains and JSX wrappers are ignored.

Why is this bad?

Deeply nested calls make code hard to read. Extracting intermediate results into named variables improves readability.

Examples

Examples of incorrect code for this rule:

js
foo(bar(baz(qux())));

Examples of correct code for this rule:

js
const value = baz(qux());
foo(bar(value));

// Fluent chains are ignored.
query().filter().map().toArray();

Configuration

This rule accepts a configuration object with the following properties:

max

type: integer

default: 3

The maximum allowed nested call depth.

How to use

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

Version

This rule was added in vnext.

References