'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isEslintVisitorFunction, getFunctionName, isBinaryExpression, isObjectType, isPropertyAMethod } from '@flint/infra/analysis';
import _0x2de5a4__default from 'typescript';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { collectionMethodNames } from '../../../base-repo/constants/internal-common-strings.js';
import { anyFunction } from '@flint/infra/constants/ast-selectors';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';
import { firstOrUndefined, first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x3ecdb9,_0x251477)=>__defProp(_0x3ecdb9,'name',{'value':_0x251477,'configurable':!![]});const ruleName='must-not-pass-full-objects-into-functions-needlessly';const constants={'messageIds':{'unnecessaryObjectParam':'unnecessaryObjectParam'},'meta':{'type':ruleTypes['suggestion'],'docs':{'description':'Disallow\x20passing\x20full\x20objects\x20to\x20functions\x20when\x20only\x20a\x20single\x20data\x20property\x20is\x20used.'},'messages':{'unnecessaryObjectParam':'must-not-pass-full-objects-into-functions-needlessly\x0aParameter\x20\x27{{paramName}}\x27\x20of\x20function\x20\x27{{functionName}}\x27\x20is\x20only\x20used\x20to\x20access\x20the\x20property\x20\x27{{usedProperty}}\x27.\x20Consider\x20passing\x20\x27{{paramName}}.{{usedProperty}}\x27\x20directly\x20or\x20destructuring\x20the\x20parameter.\x0a\x0a###\x20**Must**\x20pass\x20only\x20what\x20is\x20required\x20into\x20functions.\x0a\x0a####\x20Wrong\x0a\x0afunction\x20getFoo(foo:\x20{\x20bar:\x20string;\x20baz:\x20string\x20})\x20{\x0a\x20\x20\x20\x20return\x20foo.bar;\x0a}\x0a\x0afunction\x20getFoo(foo:\x20{\x20bar:\x20number;\x20baz:\x20string\x20})\x20{\x0a\x20\x20\x20\x20const\x20{\x20baz\x20}\x20=\x20foo;\x0a\x20\x20\x20\x20return\x20baz;\x0a}\x0a\x0a####\x20Correct\x0a\x0afunction\x20getFoo(foo:\x20{\x20bar:\x20string;\x20baz:\x20boolean\x20})\x20{\x0a\x20\x20\x20\x20if\x20(foo.bar\x20===\x20\x27value\x27\x20&&\x20foo.baz)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20return\x20true;\x0a\x20\x20\x20\x20}\x0a\x20\x20\x20\x20return\x20false;\x0a}\x0a\x0afunction\x20getFoo({\x20bar,\x20baz\x20}:\x20{\x20bar:\x20string;\x20baz:\x20number\x20})\x20{\x0a\x20\x20\x20\x20console.log(bar,\x20baz);\x0a}\x0a\x0a####\x20Why\x0a\x0aThis\x20unwanted\x20behavior\x20tightly\x20couples\x20the\x20code.'},'schema':[{'type':'object','properties':{'excludeFunctions':{'type':jsBasicTypes['array'],'items':{'type':'string'},'description':'Array\x20of\x20function\x20names\x20to\x20exclude\x20from\x20this\x20rule'}},'additionalProperties':![]}]}},arrayMethods=[collectionMethodNames['map'],collectionMethodNames['filter'],collectionMethodNames['reduce'],collectionMethodNames['reduceRight'],collectionMethodNames['forEach'],flintRuleIdentifiers['find'],'findIndex','every','some',collectionMethodNames['sort'],collectionMethodNames['flatMap'],'findLast','findLastIndex','at',collectionMethodNames['concat'],collectionMethodNames['copyWithin'],'entries',flintRuleIdentifiers['keys'],collectionMethodNames['values'],collectionMethodNames['fill'],collectionMethodNames['includes'],'indexOf','lastIndexOf',collectionMethodNames['slice'],collectionMethodNames['join'],'toString','toLocaleString',collectionMethodNames['values'],collectionMethodNames['pop'],collectionMethodNames['push'],collectionMethodNames['shift'],collectionMethodNames['unshift'],collectionMethodNames['reverse'],collectionMethodNames['splice'],collectionMethodNames['toSorted'],collectionMethodNames['toReversed'],collectionMethodNames['toSpliced'],'with','groupBy'],createRule=ESLintUtils['RuleCreator'](_0x596ca3=>''+url+_0x596ca3),mustNotPassFullObjectsIntoFuncNeedlessly=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x5d7bc9){const _0x2c6001=ESLintUtils['getParserServices'](_0x5d7bc9),_0x3eeeb0=_0x2c6001['program']['getTypeChecker'](),_0x4519f3={'checker':_0x3eeeb0,'tsNodeMap':_0x2c6001['esTreeNodeToTSNodeMap']},_0x5e90eb=firstOrUndefined(_0x5d7bc9['options'])??{};return {[anyFunction](_0x50ef67){const _0x1312d3=_0x50ef67['parent']?.['type']===nodeTypes['methodDefinition']||_0x50ef67['parent']?.['type']===nodeTypes['TSMethodSignature'];if(_0x1312d3||isEslintVisitorFunction(_0x50ef67)||isCallbackFunction(_0x50ef67)||_0x50ef67['params']['length']<0x193+0x1db3+-0x1f45)return;const _0x19c5b6=_0x5d7bc9['sourceCode']['getScope'](_0x50ef67);if(_0x19c5b6){const _0x4deabe=getFunctionName(_0x50ef67)??'anonymous\x20function';if(shouldExcludeFunction(_0x4deabe,_0x5e90eb['excludeFunctions']??[]))return;for(const _0x589c7b of _0x50ef67['params']){!shouldSkipComplexUsage(_0x589c7b,_0x19c5b6)&&processFunctionParameter(_0x589c7b,_0x19c5b6,_0x4deabe,_0x5d7bc9,_0x4519f3);}}}};}});function isCallbackFunction(_0x5e35a0){const _0x481ef9=_0x5e35a0['parent'];if(_0x481ef9?.['type']===nodeTypes['callExpression']){const _0x368214=_0x481ef9;if(_0x368214['callee']['type']===nodeTypes['memberExpression']){const _0x177042=_0x368214['callee'];if(_0x177042['property']['type']===nodeTypes['identifier']){const _0x1b0103=_0x177042['property']['name'];return arrayMethods['includes'](_0x1b0103);}}}return ![];}__name(isCallbackFunction,'isCallbackFunction');function isComplexExpressionParent(_0x28a47e){if(!_0x28a47e)return ![];return _0x28a47e['type']===nodeTypes['conditionalExpression']||_0x28a47e['type']===nodeTypes['logicalExpression']||isBinaryExpression(_0x28a47e);}__name(isComplexExpressionParent,'isComplexExpressionParent');function isComplexStatementParent(_0x286ac9){if(!_0x286ac9)return ![];return _0x286ac9['type']===nodeTypes['ifStatement']||_0x286ac9['type']===nodeTypes['whileStatement']||_0x286ac9['type']===nodeTypes['forStatement']||_0x286ac9['type']===nodeTypes['conditionalExpression'];}__name(isComplexStatementParent,'isComplexStatementParent');function hasComplexUsageInParentChain(_0x1e7a74){let _0x253424=_0x1e7a74,_0x1f25e6=0x1*0x259f+0x1e7c+-0x441b;while(_0x253424&&_0x1f25e6<-0x25*-0x1b+-0x87b+-0x2f*-0x19){if(isComplexStatementParent(_0x253424))return !![];if(_0x253424['parent'])_0x253424=_0x253424['parent'],_0x1f25e6++;else break;}return ![];}__name(hasComplexUsageInParentChain,'hasComplexUsageInParentChain');function hasComplexUsage(_0x5de4c4,_0x1cce3e){const _0x4db3c2=_0x5de4c4['references']['filter'](_0x147986=>_0x147986['isRead']()&&_0x147986['identifier']!==_0x1cce3e);for(const _0xd1a8be of _0x4db3c2){const _0x9b8e4c=_0xd1a8be['identifier']['parent'];if(isComplexExpressionParent(_0x9b8e4c)||hasComplexUsageInParentChain(_0x9b8e4c))return !![];}return ![];}__name(hasComplexUsage,'hasComplexUsage');function shouldExcludeFunction(_0x26b6f9,_0x3d8da2){return _0x3d8da2['includes'](_0x26b6f9);}__name(shouldExcludeFunction,'shouldExcludeFunction');function isObjectParameter(_0x462b55,_0xb05f30){const _0x2a9a0d=_0xb05f30['tsNodeMap']['get'](_0x462b55),_0x4ecada=_0xb05f30['checker']['getTypeAtLocation'](_0x2a9a0d),_0x26eff0=(_0x4ecada['flags']&_0x2de5a4__default['TypeFlags']['Any'])!==0x196a+0x824*-0x2+-0x922*0x1||(_0x4ecada['flags']&_0x2de5a4__default['TypeFlags']['Unknown'])!==0x698+0x2501*0x1+-0x2b99,_0x3f98ab=(_0x4ecada['flags']&(_0x2de5a4__default['TypeFlags']['String']|_0x2de5a4__default['TypeFlags']['Number']|_0x2de5a4__default['TypeFlags']['Boolean']|_0x2de5a4__default['TypeFlags']['BigInt']|_0x2de5a4__default['TypeFlags']['StringLiteral']|_0x2de5a4__default['TypeFlags']['NumberLiteral']|_0x2de5a4__default['TypeFlags']['BooleanLiteral']|_0x2de5a4__default['TypeFlags']['Null']|_0x2de5a4__default['TypeFlags']['Undefined']|_0x2de5a4__default['TypeFlags']['Void']|_0x2de5a4__default['TypeFlags']['Never']))!==0x6b1*-0x3+0x7*-0x339+0x2aa2;if(_0x26eff0||_0x3f98ab||_0x4ecada['getCallSignatures']()['length']>0x1*-0x1ca1+-0xa*-0x266+0x4a5||_0xb05f30['checker']['isArrayType'](_0x4ecada)||_0xb05f30['checker']['isTupleType'](_0x4ecada))return ![];const _0x3df734=_0x4ecada['getSymbol']();let _0x257dca=![];if(_0x3df734){const _0x40a7e6=_0xb05f30['checker']['getPropertiesOfType'](_0x4ecada);if(_0x40a7e6['length']>0x691+0x1*0x1b6b+-0x21fc)return !![];}if(isObjectType(_0x4ecada)){const _0x356065=_0x4ecada;if(_0x356065['objectFlags']&(_0x2de5a4__default['ObjectFlags']['Class']|_0x2de5a4__default['ObjectFlags']['Interface']|_0x2de5a4__default['ObjectFlags']['Anonymous'])){const _0x19d494=_0xb05f30['checker']['getPropertiesOfType'](_0x4ecada);_0x257dca=_0x19d494['length']>-0x4*0x48f+-0x20*0xb+0x139c;}}return _0x257dca;}__name(isObjectParameter,'isObjectParameter');function getPropertyNameFromDestructuring(_0x39ed1d,_0x4052e4){let _0x422f68;if(_0x39ed1d['id']['type']===nodeTypes['objectPattern']&&_0x39ed1d['init']){const _0x455d23=_0x39ed1d['id']['properties']['filter'](_0x16eeea=>_0x16eeea['type']===nodeTypes['property']);if(_0x455d23['length']===0x8db+-0x1*0x22d0+0x19f6){const _0x4ee029=first(_0x455d23);if(_0x4ee029&&_0x4ee029['key']['type']===nodeTypes['identifier']){const _0x57d6f5=_0x4ee029['key']['name'],_0x9c768=isPropertyAMethod(_0x39ed1d['init'],_0x57d6f5,_0x4052e4);!_0x9c768&&(_0x422f68=_0x57d6f5);}}}return _0x422f68;}__name(getPropertyNameFromDestructuring,'getPropertyNameFromDestructuring');function getPropertyNameFromMemberAccess(_0x3fe8de,_0x140e47){let _0x4814cf;const _0x28bf78=_0x3fe8de['property'];if(_0x28bf78['type']===nodeTypes['identifier']){const _0x104363=_0x28bf78['name'],_0x3912eb=isPropertyAMethod(_0x3fe8de['object'],_0x104363,_0x140e47);!_0x3912eb&&(_0x4814cf=_0x104363);}return _0x4814cf;}__name(getPropertyNameFromMemberAccess,'getPropertyNameFromMemberAccess');function getSingleUsedProperty(_0x4ee4a8,_0x459eb4){let _0x307c7e;const _0x589375=_0x4ee4a8['identifier']['parent'];if(_0x589375?.['type']===nodeTypes['memberExpression']&&_0x589375['object']===_0x4ee4a8['identifier']&&!_0x589375['computed']){if(_0x589375['parent']?.['type']===nodeTypes['callExpression']&&_0x589375['parent']['callee']===_0x589375)return void(0x26e9+0x5*0x62f+0x22ea*-0x2);_0x307c7e=getPropertyNameFromMemberAccess(_0x589375,_0x459eb4);}else _0x589375?.['type']===nodeTypes['variableDeclarator']&&_0x589375['init']===_0x4ee4a8['identifier']&&(_0x307c7e=getPropertyNameFromDestructuring(_0x589375,_0x459eb4));return _0x307c7e;}__name(getSingleUsedProperty,'getSingleUsedProperty');function checkAndReport(_0x38e041,_0x3f9773,_0x33686e,_0x27ab87,_0x251760){const _0x431966=_0x3f9773['references']['filter'](_0x2e0c1b=>_0x2e0c1b['isRead']()&&_0x2e0c1b['identifier']!==_0x38e041);if(_0x431966['length']===-0x254+0x5e2+-0x38d){const _0x1e5a6b=first(_0x431966);if(_0x1e5a6b){const _0x312484=getSingleUsedProperty(_0x1e5a6b,_0x251760);_0x312484&&_0x27ab87['report']({'node':_0x38e041,'messageId':constants['messageIds']['unnecessaryObjectParam'],'data':{'paramName':_0x38e041['name'],'functionName':_0x33686e,'usedProperty':_0x312484}});}}}__name(checkAndReport,'checkAndReport');function processFunctionParameter(_0x5913b5,_0x372859,_0x24d22c,_0x288bc2,_0x9b0b14){if(_0x5913b5['type']===nodeTypes['identifier']&&isObjectParameter(_0x5913b5,_0x9b0b14)){const _0x47006a=_0x372859['set']['get'](_0x5913b5['name']);_0x47006a&&checkAndReport(_0x5913b5,_0x47006a,_0x24d22c,_0x288bc2,_0x9b0b14);}}__name(processFunctionParameter,'processFunctionParameter');function shouldSkipComplexUsage(_0x23ccdd,_0x3672c8){if(_0x23ccdd['type']===nodeTypes['identifier']){const _0x3600ca=_0x3672c8['set']['get'](_0x23ccdd['name']);if(_0x3600ca)return hasComplexUsage(_0x3600ca,_0x23ccdd);}return ![];}__name(shouldSkipComplexUsage,'shouldSkipComplexUsage');

export { mustNotPassFullObjectsIntoFuncNeedlessly as default, ruleName };
