'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import * as _0x1869d0 from 'path';
import * as _0x3881d1 from 'fs';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { folders, files } from '../../../base-repo/app-constants/project-paths.js';
import { fileExtensions } from '../../../base-repo/app-constants/internal-system-constants.js';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x833c3a,_0x34c751)=>__defProp(_0x833c3a,'name',{'value':_0x34c751,'configurable':!![]});const ruleName='must-have-both-rule-and-tests';const constants={'messageIds':{'missingFile':'missingFile'},'meta':{'type':ruleTypes['problem'],'docs':{'description':'Enforce\x201:1\x20mapping\x20between\x20rule\x20files\x20and\x20test\x20files.'},'messages':{'missingFile':'must-have-both-rule-and-tests\x0a###\x20**Must**\x20have\x20both\x20rule\x20and\x20test\x20files.\x0a\x0a{{errorMessage}}\x0a\x0a####\x20Wrong\x0a\x0aflint/rules/foo.ts\x0a(Missing\x20flint/tests/foo.spec.ts)\x0a\x0a####\x20Correct\x0a\x0aflint/rules/foo.ts\x0aflint/tests/foo.spec.ts\x0a\x0a####\x20Why\x0a\x0aEvery\x20rule\x20must\x20have\x20a\x20corresponding\x20test\x20to\x20ensure\x20reliability\x20and\x20prevent\x20regressions.\x20Test\x20files\x20should\x20not\x20exist\x20without\x20a\x20corresponding\x20rule\x20implementation.'},'schema':[{'type':'object','properties':{'mockFiles':{'type':jsBasicTypes['array'],'items':{'type':'string'}}},'additionalProperties':![]}]},'dirs':{'package':folders['flint'],'rules':folders['rules'],'tests':folders['tests']},'extensions':{'rule':fileExtensions['ts'],'test':fileExtensions['spec'],'definition':fileExtensions['dts']},'fileTypes':{'rule':'rule','test':folders['test']},'ignoredPaths':[folders['rules']+'/'+files['indexTs']]},createRule=ESLintUtils['RuleCreator'](_0x4c1471=>''+url+_0x4c1471),enforceRuleTestParity=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x4649a7){const _0x45c22e=_0x1869d0['posix']['normalize'](_0x4649a7['filename']),_0x393cff=isIgnoredFile(_0x45c22e),_0x5b9a64=getFileType(_0x45c22e);if(!_0x393cff&&_0x5b9a64){const _0x1d801f=getPairedPath(_0x45c22e,_0x5b9a64),_0x261c7a=checkFileExistence(_0x1d801f,firstOrUndefined(_0x4649a7['options']));if(!_0x261c7a){const _0xe495b5=_0x5b9a64===constants['fileTypes']['rule'],_0x369714=getDisplayPath(_0xe495b5?_0x45c22e:_0x1d801f),_0x3ace84=getDisplayPath(_0xe495b5?_0x1d801f:_0x45c22e),_0x34c6d0=getErrorMessage(_0xe495b5,_0x369714,_0x3ace84);_0x4649a7['report']({'loc':{'line':0x1,'column':0x0},'messageId':constants['messageIds']['missingFile'],'data':{'errorMessage':_0x34c6d0}});}}return {};}});function getFileType(_0x366eaf){let _0x2e8213;const _0x2b857c='/'+constants['dirs']['package']+'/'+constants['dirs']['rules']+'/',_0x5ce9b8='/'+constants['dirs']['package']+'/'+constants['dirs']['tests']+'/';if(_0x366eaf['includes'](_0x2b857c)&&_0x366eaf['endsWith'](constants['extensions']['rule'])&&!_0x366eaf['endsWith'](constants['extensions']['test'])&&!_0x366eaf['endsWith'](constants['extensions']['definition']))_0x2e8213=constants['fileTypes']['rule'];else _0x366eaf['includes'](_0x5ce9b8)&&_0x366eaf['endsWith'](constants['extensions']['test'])&&(_0x2e8213=constants['fileTypes']['test']);return _0x2e8213;}__name(getFileType,'getFileType');function getPairedPath(_0xf4160e,_0x3eb000){const _0x5df817=_0x3eb000===constants['fileTypes']['rule'],_0x523a87=_0x5df817?constants['dirs']['rules']:constants['dirs']['tests'],_0x56e1d8=_0x5df817?constants['dirs']['tests']:constants['dirs']['rules'],_0x4dec0e=_0x5df817?constants['extensions']['rule']:constants['extensions']['test'],_0x3ffc17=_0x5df817?constants['extensions']['test']:constants['extensions']['rule'],_0x50a6d4='/'+_0x523a87+'/',_0x5c5bac='/'+_0x56e1d8+'/',_0x1af0fa=_0xf4160e['lastIndexOf'](_0x50a6d4);if(_0x1af0fa===-(-0x6b6*-0x2+-0x1ed2+-0xa5*-0x1b))return _0xf4160e;const _0x2b1935=_0xf4160e['substring'](0x22fa+0x19dc+0x257*-0x1a,_0x1af0fa)+_0x5c5bac+_0xf4160e['substring'](_0x1af0fa+_0x50a6d4['length']);if(_0x2b1935['endsWith'](_0x4dec0e))return _0x2b1935['slice'](0x2*-0x2fc+0x419*-0x9+0x2ad9,-_0x4dec0e['length'])+_0x3ffc17;return _0x2b1935;}__name(getPairedPath,'getPairedPath');function getDisplayPath(_0x404817){const _0x5a19ca='/'+constants['dirs']['package']+'/',_0x46f311=_0x404817['lastIndexOf'](_0x5a19ca);let _0x48bdc7=_0x1869d0['basename'](_0x404817);return _0x46f311!==-(-0x23d5+-0x1cde+0x40b4)&&(_0x48bdc7=_0x404817['substring'](_0x46f311+(0x1*-0x283+0x600+0x4*-0xdf))),_0x48bdc7['split']('/')['join']('/');}__name(getDisplayPath,'getDisplayPath');function isIgnoredFile(_0x54c18c){const _0x30e519=constants['ignoredPaths']['some'](_0x148588=>{const _0x499dc6=constants['dirs']['package']+'/'+_0x148588;return _0x54c18c['endsWith'](_0x499dc6);});return _0x30e519;}__name(isIgnoredFile,'isIgnoredFile');function checkFileExistence(_0x3bada0,_0x2e8578){let _0xe86580=![];return _0x2e8578?.['mockFiles']?_0xe86580=_0x2e8578['mockFiles']['some'](_0x5d33fe=>_0x3bada0['endsWith'](_0x1869d0['posix']['normalize'](_0x5d33fe))):_0xe86580=_0x3881d1['existsSync'](_0x3bada0),_0xe86580;}__name(checkFileExistence,'checkFileExistence');function getErrorMessage(_0x3d2ef1,_0x2f7c0d,_0x3067e9){let _0x52c6dc;_0x3d2ef1?_0x52c6dc='Rule\x20file\x20found\x20at\x20`{{rulePath}}`,\x20but\x20no\x20corresponding\x20test\x20file\x20exists.\x0aExpected\x20location:\x20`{{testPath}}`':_0x52c6dc='Test\x20file\x20found\x20at\x20`{{testPath}}`,\x20but\x20no\x20corresponding\x20rule\x20file\x20exists.\x0aExpected\x20location:\x20`{{rulePath}}`';const _0x9bd8b7=_0x52c6dc['replace']('{{rulePath}}',_0x2f7c0d)['replace']('{{testPath}}',_0x3067e9);return _0x9bd8b7;}__name(getErrorMessage,'getErrorMessage');

export { enforceRuleTestParity as default, ruleName };
