'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { getTypeAnnotation, nodeTypes, getFunctionName } from '@flint/infra/analysis';
import { ruleRecommendationLevels, ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';

var __defProp=Object['defineProperty'],__name=(_0x567a84,_0x593d23)=>__defProp(_0x567a84,'name',{'value':_0x593d23,'configurable':!![]});const ruleName='must-not-use-po-in-assert-functions';const constants={'assertFunctionPrefix':flintRuleIdentifiers['assert'],'pageObjectPattern':/Po$|PageObject$/i,'messageIds':{'mustNotUsePoInAssertFunctions':'mustNotUsePoInAssertFunctions'},'meta':{'type':ruleTypes['problem'],'docs':{'description':'Assert\x20functions\x20must\x20not\x20accept\x20PageObject\x20parameters.\x20Use\x20`page`\x20instead.','recommended':ruleRecommendationLevels['error']},'messages':{'mustNotUsePoInAssertFunctions':'must-not-use-po-in-assert-functions\x0a###\x20**Must\x20not**\x20use\x20PageObject\x20parameters\x20in\x20assert\x20functions.\x0a\x0aAlways\x20pass\x20\x27page\x27\x20instead.\x0a\x0a####\x20Wrong\x0a\x0aexport\x20function\x20assertFoo(fooPo:\x20LoginPo)\x20{\x20…\x20}\x0a\x0a####\x20Correct\x0a\x0aexport\x20function\x20assertFoo(page)\x20{\x20…\x20}\x0a\x0a####\x20Why\x0a\x0aWe\x20standardize\x20on\x20using\x20page\x20as\x20a\x20parameter\x20in\x20assert\x20functions,\x20instead\x20of\x20passing\x20a\x20page\x20object\x20(po).\x20Assert\x20functions\x20should\x20stay\x20independent\x20from\x20page\x20object\x20implementations.'},'schema':[]}},createRule=ESLintUtils['RuleCreator'](_0x9320b5=>''+url+_0x9320b5),mustNotUsePoInAssertFunctions=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0xd7230f){return {'FunctionDeclaration'(_0x26b2c1){_0x26b2c1['id']?.['name']?.['startsWith'](constants['assertFunctionPrefix'])&&checkParams(_0x26b2c1['params'],_0xd7230f);},'FunctionExpression'(_0x35d214){checkAssertFunctionParams(_0x35d214,_0xd7230f);},'ArrowFunctionExpression'(_0x47328e){checkAssertFunctionParams(_0x47328e,_0xd7230f);}};}});function isPoParamName(_0xe6a8c){return constants['pageObjectPattern']['test'](_0xe6a8c);}__name(isPoParamName,'isPoParamName');function isPoParamType(_0x302dad){const _0x1802bd=getTypeAnnotation(_0x302dad);if(!_0x1802bd||_0x1802bd['type']!==nodeTypes['TSTypeAnnotation'])return ![];return checkType(_0x1802bd['typeAnnotation']);}__name(isPoParamType,'isPoParamType');function checkType(_0x5ed4bd){switch(_0x5ed4bd['type']){case nodeTypes['TSTypeReference']:if('typeName'in _0x5ed4bd&&_0x5ed4bd['typeName']['type']===nodeTypes['identifier'])return constants['pageObjectPattern']['test'](_0x5ed4bd['typeName']['name']);return ![];case nodeTypes['TSUnionType']:case nodeTypes['TSIntersectionType']:return _0x5ed4bd['types']['some'](checkType);case nodeTypes['TSArrayType']:return checkType(_0x5ed4bd['elementType']);default:return ![];}}__name(checkType,'checkType');function checkParam(_0x57d82f,_0x22abdb){if(!_0x22abdb)return;const _0x5d57a6=__name(_0x544787=>{(isPoParamName(_0x544787['name'])||isPoParamType(_0x544787))&&_0x57d82f['report']({'node':_0x544787,'messageId':constants['messageIds']['mustNotUsePoInAssertFunctions']});},'reportIfPo');switch(_0x22abdb['type']){case nodeTypes['identifier']:_0x5d57a6(_0x22abdb);break;case nodeTypes['assignmentPattern']:checkParam(_0x57d82f,_0x22abdb['left']);break;case nodeTypes['restElement']:checkParam(_0x57d82f,_0x22abdb['argument']);break;case nodeTypes['objectPattern']:if(_0x22abdb['typeAnnotation']){const _0x4319d5=_0x22abdb['typeAnnotation']['typeAnnotation'];checkType(_0x4319d5)&&_0x57d82f['report']({'node':_0x22abdb,'messageId':constants['messageIds']['mustNotUsePoInAssertFunctions']});}_0x22abdb['properties']['forEach'](_0x2c4f0a=>{if(_0x2c4f0a['type']===nodeTypes['property']&&_0x2c4f0a['value'])checkParam(_0x57d82f,_0x2c4f0a['value']);if(_0x2c4f0a['type']===nodeTypes['restElement'])checkParam(_0x57d82f,_0x2c4f0a['argument']);});break;case nodeTypes['arrayPattern']:_0x22abdb['elements']['forEach'](_0x32ec91=>{if(_0x32ec91)checkParam(_0x57d82f,_0x32ec91);});break;default:break;}}__name(checkParam,'checkParam');function checkParams(_0x43a123,_0x59c4c0){for(const _0x5e826c of _0x43a123){checkParam(_0x59c4c0,_0x5e826c);}}__name(checkParams,'checkParams');function checkAssertFunctionParams(_0x867a05,_0x2faecf){const _0x47ccdf=getFunctionName(_0x867a05);_0x47ccdf?.['startsWith'](constants['assertFunctionPrefix'])&&checkParams(_0x867a05['params'],_0x2faecf);}__name(checkAssertFunctionParams,'checkAssertFunctionParams');

export { mustNotUsePoInAssertFunctions as default, ruleName };
