'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isNameMatch } from '@flint/infra/analysis';
import { url, eslintSchemaBasicTypes, ruleTypes } from '@flint/infra/constants/rules-meta';
import { collectionMethodNames } from '../../../base-repo/constants/internal-common-strings.js';
import { firstOrUndefined, first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x318b6d,_0x4df6fd)=>__defProp(_0x318b6d,'name',{'value':_0x4df6fd,'configurable':!![]});const ruleName='for-each-max-lines';const createRule=ESLintUtils['RuleCreator'](_0x4e4a1b=>''+url+_0x4e4a1b),defaultMaxStatements=0x273+0x2e*0xa6+0x19d*-0x14,forEachMethodName=collectionMethodNames['forEach'],forEachLinesMessageId='forEachMaxLines',forEachMaxLines=createRule({'name':ruleName,'meta':{'type':ruleTypes['problem'],'docs':{'description':'forEach\x20blocks\x20can\x20have\x20maximum\x203\x20lines'},'messages':{[forEachLinesMessageId]:ruleName+'\x0aForEach\x20callback\x20has\x20\x27{{callbackCount}}\x27\x20statements,\x20but\x20the\x20maximum\x20allowed\x20is\x20\x27{{maxStatements}}\x27.\x0a\x0a###\x20**Must**\x20limit\x20forEach\x20callback\x20to\x20a\x20maximum\x20number\x20of\x20lines.\x0a\x0a####\x20Wrong\x0a\x0aarray.forEach(foo\x20=>\x20{\x0a\x20\x20doA(foo);\x0a\x20\x20doB(foo);\x0a\x20\x20doC(foo);\x0a\x20\x20doD(foo);\x0a});\x0a\x0a####\x20Correct\x0a\x0aarray.forEach(foo\x20=>\x20{\x0a\x20\x20doA(foo);\x0a\x20\x20doB(foo);\x0a\x20\x20doC(foo);\x0a});\x0a\x0a####\x20Why\x0a\x0aLong\x20`forEach`\x20callbacks\x20can\x20make\x20code\x20harder\x20to\x20read\x20and\x20maintain.\x20Limiting\x20the\x20number\x20of\x20statements\x20encourages\x20cleaner,\x20more\x20modular\x20code,\x20often\x20prompting\x20extraction\x20into\x20separate\x20functions\x20if\x20the\x20logic\x20is\x20complex.'},'schema':[{'type':'object','properties':{'maxStatements':{'type':eslintSchemaBasicTypes['integer'],'minimum':0x1,'default':0x3}},'additionalProperties':![]}]},'create'(_0x1537f6){return {'CallExpression'(_0x58da61){_0x58da61['callee']['type']===nodeTypes['memberExpression']&&_0x58da61['callee']['property']['type']===nodeTypes['identifier']&&isNameMatch(_0x58da61['callee']['property'],forEachMethodName)&&checkForEach(_0x58da61,_0x1537f6);}};},'defaultOptions':[{'maxStatements':defaultMaxStatements}]});function checkForEach(_0x1eb813,_0xb9912c){const _0x377d3a=firstOrUndefined(_0xb9912c['options'])??{'maxStatements':defaultMaxStatements};if(_0x1eb813['arguments']['length']>-0x22a5+-0x2*0x767+0x3173){const _0x3f73b7=first(_0x1eb813['arguments']);if(_0x3f73b7?.['type']===nodeTypes['arrowFunctionExpression']||_0x3f73b7?.['type']===nodeTypes['functionExpression']){const _0x2a2dff=_0x3f73b7['body']['type']===nodeTypes['blockStatement']?_0x3f73b7['body']['body']:[_0x3f73b7['body']];_0x2a2dff['length']>_0x377d3a['maxStatements']&&_0xb9912c['report']({'node':_0x1eb813,'messageId':forEachLinesMessageId,'data':{'callbackCount':_0x2a2dff['length']['toString'](),'maxStatements':_0x377d3a['maxStatements']['toString']()}});}}}__name(checkForEach,'checkForEach');

export { forEachMaxLines as default, ruleName };
