Server IP : 150.95.80.236 / Your IP : 13.59.26.221 Web Server : Apache System : Linux host-150-95-80-236 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : social-telecare ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/pcu.in.th/api-uat.pcu.in.th/node_modules/eslint/lib/rules/ |
Upload File : |
/** * @fileoverview Rule to enforce a maximum number of nested callbacks. * @author Ian Christian Myers */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ /** @type {import('../shared/types').Rule} */ module.exports = { meta: { type: "suggestion", docs: { description: "Enforce a maximum depth that callbacks can be nested", recommended: false, url: "https://eslint.org/docs/latest/rules/max-nested-callbacks" }, schema: [ { oneOf: [ { type: "integer", minimum: 0 }, { type: "object", properties: { maximum: { type: "integer", minimum: 0 }, max: { type: "integer", minimum: 0 } }, additionalProperties: false } ] } ], messages: { exceed: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}." } }, create(context) { //-------------------------------------------------------------------------- // Constants //-------------------------------------------------------------------------- const option = context.options[0]; let THRESHOLD = 10; if ( typeof option === "object" && (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max")) ) { THRESHOLD = option.maximum || option.max; } else if (typeof option === "number") { THRESHOLD = option; } //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- const callbackStack = []; /** * Checks a given function node for too many callbacks. * @param {ASTNode} node The node to check. * @returns {void} * @private */ function checkFunction(node) { const parent = node.parent; if (parent.type === "CallExpression") { callbackStack.push(node); } if (callbackStack.length > THRESHOLD) { const opts = { num: callbackStack.length, max: THRESHOLD }; context.report({ node, messageId: "exceed", data: opts }); } } /** * Pops the call stack. * @returns {void} * @private */ function popStack() { callbackStack.pop(); } //-------------------------------------------------------------------------- // Public API //-------------------------------------------------------------------------- return { ArrowFunctionExpression: checkFunction, "ArrowFunctionExpression:exit": popStack, FunctionExpression: checkFunction, "FunctionExpression:exit": popStack }; } };