1 # enforce a maximum depth that callbacks can be nested (max-nested-callbacks)
3 Many JavaScript libraries use the callback pattern to manage asynchronous operations. A program of any complexity will most likely need to manage several asynchronous operations at various levels of concurrency. A common pitfall that is easy to fall into is nesting callbacks, which makes code more difficult to read the deeper the callbacks are nested.
19 This rule enforces a maximum depth that callbacks can be nested to increase code clarity.
23 This rule has a number or object option:
25 * `"max"` (default `10`) enforces a maximum depth that callbacks can be nested
27 **Deprecated:** The object property `maximum` is deprecated; please use the object property `max` instead.
31 Examples of **incorrect** code for this rule with the `{ "max": 3 }` option:
34 /*eslint max-nested-callbacks: ["error", 3]*/
47 Examples of **correct** code for this rule with the `{ "max": 3 }` option:
50 /*eslint max-nested-callbacks: ["error", 3]*/
54 function handleFoo1() {
58 function handleFoo2() {
62 function handleFoo3() {
66 function handleFoo4() {
73 * [Control flow in Node.js](http://book.mixu.net/node/ch7.html)
74 * [Control Flow in Node](https://howtonode.org/control-flow)
75 * [Control Flow in Node Part II](https://howtonode.org/control-flow-part-ii)
79 * [complexity](complexity.md)
80 * [max-depth](max-depth.md)
81 * [max-len](max-len.md)
82 * [max-lines](max-lines.md)
83 * [max-lines-per-function](max-lines-per-function.md)
84 * [max-params](max-params.md)
85 * [max-statements](max-statements.md)