'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import _0x1869d0__default from 'path';
import _0x3881d1__default from 'fs';
import { fileBaseNames } from '../../../base-repo/constants/internal-common-strings.js';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { getFileName } from '@flint/infra/analysis';
import { customEslintRules } from '@flint/test-infra/test-constants';
import { eslintLoggerLogError } from '@flint/test-infra/logger';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { createConfigFilesKey } from '@flint/infra/config-edited-checker';
import { readGitHead } from '@flint/infra/git-readers';
import { flintConfigFileNames } from '@flint/infra/constants/rule-strings';
import { eslintRuleSyntax } from '@flint/infra/constants/eslint-rule-syntax';
import { nonRootProjectPaths, folders } from '../../../base-repo/app-constants/project-paths.js';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x3c7c84,_0x2aef14)=>__defProp(_0x3c7c84,'name',{'value':_0x2aef14,'configurable':!![]});const ruleName='must-add-custom-rule-in-config';const constants={'configFileNames':new Set([flintConfigFileNames['projectSpecific'],flintConfigFileNames['eslintBase'],flintConfigFileNames['nonLevelTwo']]),'pluginName':customEslintRules+'/','meta':{'type':ruleTypes['problem'],'docs':{'description':'checks\x20for\x20the\x20existence\x20of\x20the\x20rule\x20in\x20the\x20configs'},'messages':{'mustAddCustomRuleInConfig':'must-add-custom-rule-in-config\x0a###\x20**Must**\x20add\x20{{fullRuleName}}\x20custom\x20rule\x20in\x20at\x20least\x20one\x20config:\x20project-specific-eslint-configs.js,\x20eslint-base.config.js\x20or\x20non-level-two-eslint-config.js.\x0a\x0a####\x20Wrong\x0a\x0arules/filename-kebab-case.ts\x0a\x0aconst\x20flintSpecificConfig={\x0a\x20\x20\x20\x20rules:{\x0a\x20\x20\x20\x20\x22custom-eslint-rules/for-each-max-lines\x22:\x20\x22error\x22,\x0a\x20\x20\x20\x20}\x0a}\x0a\x0a####\x20Correct\x0a\x0arules/filename-kebab-case.ts\x0a\x0aconst\x20flintSpecificConfig={\x0a\x20\x20\x20\x20rules:{\x0a\x20\x20\x20\x20\x22custom-eslint-rules/filename-kebab-case.ts\x22:\x20\x22error\x22,\x0a\x20\x20\x20\x20}\x0a}\x0a\x0a####\x20Why\x0a\x0aAll\x20custom\x20rules\x20must\x20be\x20explicitly\x20documented\x20in\x20configs\x20to\x20ensure\x20intentional\x20decisions\x20about\x20their\x20usage.'},'schema':[{'type':'object','properties':{'configContents':{'type':jsBasicTypes['array'],'items':{'type':'string'}}},'additionalProperties':![]}]}},createRule=ESLintUtils['RuleCreator'](_0x17cb4f=>''+url+_0x17cb4f),configCache=new Map();let hasReadConfigs=![],lastWorkspaceKey='',lastGitHead='',lastConfigFilesKey='';const mustAddCustomRuleInConfig=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[{'configContents':[]}],'create'(_0xf2ad05){const _0x40b70e=firstOrUndefined(_0xf2ad05['options'])?.['configContents'],_0x217f01=_0xf2ad05['filename'],_0x2ab82b=getFileName(_0x217f01,_0x1869d0__default['extname'](_0x217f01));if(_0x2ab82b===fileBaseNames['index']||_0x2ab82b===ruleName)return {};return {[eslintRuleSyntax['programExitSelector']](_0x63c212){resetCacheIfWorkspaceChanged(_0xf2ad05['cwd']);if(Array['isArray'](_0x40b70e)&&_0x40b70e['length']>0x1*-0x47c+0xd*-0xbf+0xe2f)configCache['clear'](),_0x40b70e['forEach']((_0x5cd09e,_0x4980bb)=>{configCache['set']('test-config-'+_0x4980bb+'.js',_0x5cd09e);}),hasReadConfigs=!![];else {if(!hasReadConfigs){const _0x51c5b0=_0x1869d0__default['resolve'](nonRootProjectPaths['parentDirRef']+'/'+folders['flintInfra']),_0x55cd2d=Array['from'](constants['configFileNames'])['map'](_0x5a1f64=>_0x1869d0__default['join'](_0x51c5b0,_0x5a1f64));for(const _0x11639a of _0x55cd2d){const _0x1a291b=readConfigFile(_0x11639a);configCache['set'](_0x11639a,_0x1a291b);}hasReadConfigs=!![];}}let _0x2a947f=![];for(const _0x9f2d37 of configCache['values']()){if(isRuleMentionedInContent(_0x9f2d37,_0x2ab82b)){_0x2a947f=!![];break;}}!_0x2a947f&&_0xf2ad05['report']({'node':_0x63c212,'messageId':'mustAddCustomRuleInConfig','data':{'fullRuleName':''+constants['pluginName']+_0x2ab82b}});}};}});function readConfigFile(_0x221009){try{if(_0x3881d1__default['existsSync'](_0x221009))return _0x3881d1__default['readFileSync'](_0x221009,'utf-8');}catch(_0x4168ca){eslintLoggerLogError('['+ruleName+']\x20Error\x20reading\x20file:\x20'+_0x221009+'\x20'+(_0x4168ca instanceof Error?_0x4168ca['message']:String(_0x4168ca)));}return '';}__name(readConfigFile,'readConfigFile');function resetCacheIfWorkspaceChanged(_0xcb46a9){const _0x490e0d=readGitHead(_0xcb46a9,ruleName),_0x140653=_0xcb46a9,_0x54f951=createConfigFilesKey(_0xcb46a9,constants['configFileNames']);(_0x140653!==lastWorkspaceKey||_0x490e0d!==lastGitHead||_0x54f951!==lastConfigFilesKey)&&(configCache['clear'](),hasReadConfigs=![],lastWorkspaceKey=_0x140653,lastGitHead=_0x490e0d,lastConfigFilesKey=_0x54f951);}__name(resetCacheIfWorkspaceChanged,'resetCacheIfWorkspaceChanged');function isRuleMentionedInContent(_0x3135b3,_0x3dcf31){const _0x24fed4='\x22'+constants['pluginName']+_0x3dcf31+'\x22';return _0x3135b3['includes'](_0x24fed4);}__name(isRuleMentionedInContent,'isRuleMentionedInContent');

export { mustAddCustomRuleInConfig as default, ruleName };
