'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { nodeTypes, isArrayLikeTypeNode } from '@flint/infra/analysis';
import { collectionMethodNames } from '../../../base-repo/constants/internal-common-strings.js';

var __defProp=Object['defineProperty'],__name=(_0x58cd6f,_0xc1347b)=>__defProp(_0x58cd6f,'name',{'value':_0xc1347b,'configurable':!![]});const ruleName='no-inplace-array-mutation';const mutatingMethods={'sort':{'immutable':collectionMethodNames['toSorted']},'reverse':{'immutable':collectionMethodNames['toReversed']},'splice':{'immutable':collectionMethodNames['toSpliced']}},ruleContent='\x0a###\x20**Must\x20not**\x20use\x20mutating\x20array\x20methods.\x20Use\x20immutable\x20alternatives\x20instead.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20sortedItems\x20=\x20items.sort((a,\x20b)\x20=>\x20a\x20-\x20b);\x0aconst\x20reversedItems\x20=\x20items.reverse();\x0aconst\x20newItems\x20=\x20items.splice(0,\x201);\x0aitems[index]\x20=\x20value;\x0a\x0a####\x20Correct\x0a\x0aconst\x20sortedItems\x20=\x20items.toSorted((a,\x20b)\x20=>\x20a\x20-\x20b);\x0aconst\x20reversedItems\x20=\x20items.toReversed();\x0aconst\x20newItems\x20=\x20items.toSpliced(0,\x201);\x0aconst\x20nextItems\x20=\x20items.with(index,\x20value);\x0a\x0a####\x20Why\x0a\x0aMutating\x20arrays\x20in\x20place\x20causes\x20side\x20effects\x20and\x20makes\x20code\x20harder\x20to\x20reason\x20about.';var noInplaceArrayMutation = createEslintRule(ruleName,ruleContent,_0x13fb36=>{const _0x5c105c=_0x13fb36['sourceCode']['parserServices'],_0x1a5f33=isParserServicesWithTypeInformation(_0x5c105c);return {'CallExpression'({callee:_0x70740d}){const _0x3b8ddd=getMutationMethodReportData(_0x70740d);_0x3b8ddd&&_0x13fb36['report']({'node':_0x3b8ddd['node'],'messageId':ruleName,'data':{'methodName':_0x3b8ddd['methodName'],'suggestion':_0x3b8ddd['suggestion']}});},'AssignmentExpression'({left:_0x59da45,operator:_0x21448b}){let _0x2b57fb;_0x1a5f33&&(_0x2b57fb=getAssignmentReportData(_0x59da45,_0x21448b,_0x5c105c)),_0x2b57fb&&_0x13fb36['report']({'node':_0x2b57fb['node'],'messageId':ruleName,'data':{'methodName':_0x2b57fb['methodName'],'suggestion':_0x2b57fb['suggestion']}});}};},{'dynamicMessage':'\x27{{methodName}}\x27\x20mutates\x20the\x20array\x20in\x20place.\x20Use\x20\x27{{suggestion}}\x27\x20instead.'});function getMutationMethodReportData(_0x439d40){let _0x25fd3a;if(_0x439d40['type']===nodeTypes['memberExpression']){const _0x3a00d8=_0x439d40['property'];if(_0x3a00d8['type']===nodeTypes['identifier']&&Object['hasOwn'](mutatingMethods,_0x3a00d8['name'])){const _0x74adb3=_0x3a00d8['name'],_0x1b997f=mutatingMethods[_0x74adb3],_0x192161=_0x1b997f['immutable']??_0x1b997f['suggestion']??'an\x20immutable\x20alternative';_0x25fd3a={'node':_0x3a00d8,'methodName':_0x74adb3,'suggestion':_0x192161};}}return _0x25fd3a;}__name(getMutationMethodReportData,'getMutationMethodReportData');function getAssignmentReportData(_0x341bfe,_0x1c921d,_0x2dead2){let _0x562d3e;return _0x1c921d==='='&&_0x341bfe['type']===nodeTypes['memberExpression']&&_0x341bfe['computed']&&isArrayLikeTypeNode(_0x341bfe['object'],_0x2dead2)&&(_0x562d3e={'node':_0x341bfe,'methodName':'index\x20assignment','suggestion':'with(index,\x20value)'}),_0x562d3e;}__name(getAssignmentReportData,'getAssignmentReportData');function isParserServicesWithTypeInformation(_0x1cfb0b){return !!_0x1cfb0b?.['program']&&!!_0x1cfb0b['esTreeNodeToTSNodeMap'];}__name(isParserServicesWithTypeInformation,'isParserServicesWithTypeInformation');

export { noInplaceArrayMutation as default, ruleName };
