'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { files } from '../../../base-repo/app-constants/project-paths.js';
import { eslintFixTypeNames } from '../../../base-repo/constants/internal-common-strings.js';
import { packageJsonSectionNames } from '../../../base-repo/constants/tools-constants.js';
import { ruleRecommendationLevels, ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x577758,_0x17e1c2)=>__defProp(_0x577758,'name',{'value':_0x17e1c2,'configurable':!![]});const ruleName='must-use-strict-dependency-version';const strictDependencyMessageId='mustUseStrictDependencyVersion',constants={'meta':{'type':ruleTypes['problem'],'docs':{'description':'Enforce\x20exact\x20dependency\x20versions\x20without\x20^\x20or\x20~\x20prefixes','recommended':ruleRecommendationLevels['error']},'messages':{[strictDependencyMessageId]:ruleName+'\x0a###\x20**Must**\x20use\x20exact\x20dependency\x20versions.\x0a\x0a####\x20Wrong\x0a\x0a```json\x0a{\x0a\x20\x20\x20\x20\x22dependencies\x22:\x20{\x0a\x20\x20\x20\x20\x20\x20\x22package-name\x22:\x20\x22^1.0.0\x22,\x0a\x20\x20\x20\x20\x20\x20\x22another-package\x22:\x20\x22~2.3.1\x22\x0a\x20\x20\x20\x20}\x0a}\x0a```\x0a\x0a####\x20Correct\x0a\x0a```json\x0a{\x0a\x20\x20\x20\x20\x22dependencies\x22:\x20{\x0a\x20\x20\x20\x20\x20\x20\x22package-name\x22:\x20\x221.0.0\x22,\x0a\x20\x20\x20\x20\x20\x20\x22another-package\x22:\x20\x222.3.1\x22\x0a\x20\x20\x20\x20}\x0a}\x0a```\x0a\x0a####\x20Why\x0a\x0aUsing\x20exact\x20dependency\x20versions\x20protects\x20against\x20supply\x20chain\x20attacks\x20and\x20ensures\x20build\x20stability.\x20This\x20practice\x20prevents\x20automatic\x20updates\x20that\x20could\x20introduce\x20vulnerabilities\x20or\x20breaking\x20changes,\x20maintaining\x20consistent\x20behavior\x20across\x20all\x20deployments.'},'schema':[],'fixable':eslintFixTypeNames['code']},'versionPrefixes':['^','~']},createRule=ESLintUtils['RuleCreator'](_0x1c9cdf=>''+url+_0x1c9cdf),mustUseStrictDependencyVersion=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x3b4f5f){return {'Program'(){if(!isPackageJsonFile(_0x3b4f5f['filename']))return;const _0x95ceff=_0x3b4f5f['sourceCode'],_0x51d40d=_0x95ceff['getText'](),_0x52a66b=JSON['parse'](_0x51d40d);checkDependencySections(_0x52a66b,_0x51d40d,_0x95ceff,_0x3b4f5f);}};}});function isPackageJsonFile(_0x2289fb){return _0x2289fb['endsWith'](files['packageJson']);}__name(isPackageJsonFile,'isPackageJsonFile');function checkDependencySections(_0x2a3a99,_0x307e06,_0x45d77f,_0x4b9129){const _0x261dea=[packageJsonSectionNames['dependencies'],packageJsonSectionNames['devDependencies']];for(const _0x1ff824 of _0x261dea){_0x2a3a99[_0x1ff824]&&typeof _0x2a3a99[_0x1ff824]==='object'&&checkSectionDependencies(_0x2a3a99[_0x1ff824],_0x307e06,_0x45d77f,_0x4b9129);}}__name(checkDependencySections,'checkDependencySections');function checkSectionDependencies(_0x52e8a4,_0x14333a,_0x10798d,_0x40c13f){for(const [_0x553567,_0x56f306]of Object['entries'](_0x52e8a4)){typeof _0x56f306==='string'&&hasVersionPrefix(_0x56f306)&&reportInvalidVersion(_0x553567,_0x56f306,_0x14333a,_0x10798d,_0x40c13f);}}__name(checkSectionDependencies,'checkSectionDependencies');function reportInvalidVersion(_0x3e5220,_0x3d0f05,_0x1318d9,_0x57fa03,_0x5da734){const _0x54cd49=findVersionLocation(_0x3e5220,_0x3d0f05,_0x1318d9);_0x54cd49&&_0x5da734['report']({'messageId':strictDependencyMessageId,'data':{'packageName':_0x3e5220,'version':_0x3d0f05},'loc':{'start':_0x57fa03['getLocFromIndex'](_0x54cd49['start']),'end':_0x57fa03['getLocFromIndex'](_0x54cd49['end'])},'fix'(_0x16212c){const _0x5b2fcb=removeVersionPrefix(_0x3d0f05);return _0x16212c['replaceTextRange']([_0x54cd49['start'],_0x54cd49['end']],'\x22'+_0x5b2fcb+'\x22');}});}__name(reportInvalidVersion,'reportInvalidVersion');function findVersionLocation(_0x3cdd70,_0x19a7ba,_0x3c8ddd){const _0x2d5aea='\x22'+_0x3cdd70+'\x22:\x5cs*\x22'+_0x19a7ba['replace'](/[.*+?^${}()|[\]\\]/g,'\x5c$&')+'\x22',_0x12426e=new RegExp(_0x2d5aea),_0x2816dc=_0x12426e['exec'](_0x3c8ddd);if(_0x2816dc?.['index']!==void(0x1*-0x1c3c+0x3bb*0x7+0x21f)){const _0x1dc4df=_0x2816dc['index']+first(_0x2816dc)['indexOf']('\x22'+_0x19a7ba+'\x22'),_0x38fc99=_0x1dc4df+_0x19a7ba['length']+(-0x116f+0x1d8+0xf99);return {'start':_0x1dc4df,'end':_0x38fc99};}return void(-0x2160+0x20b7+0xa9);}__name(findVersionLocation,'findVersionLocation');function hasVersionPrefix(_0x3cd8b8){return constants['versionPrefixes']['some'](_0x53d45a=>_0x3cd8b8['startsWith'](_0x53d45a));}__name(hasVersionPrefix,'hasVersionPrefix');function removeVersionPrefix(_0x85f4a7){for(const _0x387d79 of constants['versionPrefixes']){if(_0x85f4a7['startsWith'](_0x387d79))return _0x85f4a7['slice'](_0x387d79['length']);}return _0x85f4a7;}__name(removeVersionPrefix,'removeVersionPrefix');

export { mustUseStrictDependencyVersion as default, ruleName };
