# unicorn/max-nested-calls

> Enforce a maximum depth of calls nested in the arguments of other calls

Nested calls run from the inside out, so you read `save(normalize(parse(read(file))))` backwards, counting parentheses on the way. Past a few levels, the code is easier to follow if you put a step in the middle into a well-named variable.

A call counts as nested when it's in an argument of another call or of a `new` expression. By default up to 3 levels are allowed, and each deeper call is reported.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/max-nested-calls" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"unicorn/max-nested-calls" = ["error", {
  max = 3,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 1} */}
```js
save(normalize(parse(read(file))));
```

Not reported:

{/* good */}
```js
const config = parse(read(file));
save(normalize(config));
```

A method chain isn't nesting:

{/* good */}
```js
const total = text.trim().split(",").map(Number).filter(Boolean).reduce(add);
```

The count starts again inside a function, a class or JSX:

{/* good */}
```js
schedule(retry(withTimeout(() => save(normalize(config)))));
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `max` | `3` | The deepest nesting that's allowed. |

{/* bad {"options": [{"max": 2}]} */}
```js
save(normalize(parse(text)));
```

{/* good {"options": [{"max": 4}]} */}
```js
save(normalize(parse(read(file))));
```
