]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/max-nested-callbacks.js
2 * @fileoverview Tests for max-nested-callbacks rule.
3 * @author Ian Christian Myers
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/max-nested-callbacks"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const OPENING
= "foo(function() {",
23 * Generates a code string with the specified number of nested callbacks.
24 * @param {int} times The number of times to nest the callbacks.
25 * @returns {string} Code with the specified number of nested callbacks
28 function nestFunctions(times
) {
32 for (let i
= 0; i
< times
; i
++) {
36 return openings
+ closings
;
39 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
42 const ruleTester
= new RuleTester();
44 ruleTester
.run("max-nested-callbacks", rule
, {
46 { code
: "foo(function() { bar(thing, function(data) {}); });", options
: [3] },
47 { code
: "var foo = function() {}; bar(function(){ baz(function() { qux(foo); }) });", options
: [2] },
48 { code
: "fn(function(){}, function(){}, function(){});", options
: [2] },
49 { code
: "fn(() => {}, function(){}, function(){});", options
: [2], parserOptions
: { ecmaVersion
: 6 } },
52 // object property options
53 { code
: "foo(function() { bar(thing, function(data) {}); });", options
: [{ max
: 3 }] }
57 code
: "foo(function() { bar(thing, function(data) { baz(function() {}); }); });",
59 errors
: [{ messageId
: "exceed", data
: { num
: 3, max
: 2 }, type
: "FunctionExpression" }]
62 code
: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });",
64 parserOptions
: { ecmaVersion
: 6 },
65 errors
: [{ messageId
: "exceed", data
: { num
: 3, max
: 2 }, type
: "FunctionExpression" }]
68 code
: "foo(() => { bar(thing, (data) => { baz( () => {}); }); });",
70 parserOptions
: { ecmaVersion
: 6 },
71 errors
: [{ messageId
: "exceed", data
: { num
: 3, max
: 2 }, type
: "ArrowFunctionExpression" }]
74 code
: "foo(function() { if (isTrue) { bar(function(data) { baz(function() {}); }); } });",
76 errors
: [{ messageId
: "exceed", data
: { num
: 3, max
: 2 }, type
: "FunctionExpression" }]
79 code
: nestFunctions(11),
80 errors
: [{ messageId
: "exceed", data
: { num
: 11, max
: 10 }, type
: "FunctionExpression" }]
83 code
: nestFunctions(11),
85 errors
: [{ messageId
: "exceed", data
: { num
: 11, max
: 10 }, type
: "FunctionExpression" }]
88 code
: "foo(function() {})",
89 options
: [{ max
: 0 }],
90 errors
: [{ messageId
: "exceed", data
: { num
: 1, max
: 0 } }]
93 // object property options
95 code
: "foo(function() { bar(thing, function(data) { baz(function() {}); }); });",
96 options
: [{ max
: 2 }],
97 errors
: [{ messageId
: "exceed", data
: { num
: 3, max
: 2 }, type
: "FunctionExpression" }]