'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { normalizePathSeparators, isInsideFolder, isFilenameWithSuffix, getStringLiterals, isStringLiteral, nodeTypes, isIdentifier } from '@flint/infra/analysis';
import { packagesPath, folders } from '../../../base-repo/app-constants/project-paths.js';
import { urlUpperCaseWord } from '../../../base-repo/constants/internal-common-strings.js';

var __defProp=Object['defineProperty'],__name=(_0x150b02,_0x51a105)=>__defProp(_0x150b02,'name',{'value':_0x51a105,'configurable':!![]});const ruleName='must-use-path-constants-for-paths';const ruleContent='\x0a###\x20**Must**\x20use\x20path\x20constants\x20for\x20paths.\x0a\x0a####\x20Wrong\x0a\x0a//\x20packages/infra/foo.ts\x0afooFunc(\x22packages/infra/foo/bar\x22);\x0a\x0a//\x20packages/internal-cli/foo.ts\x0afooFunc(\x22packages/internal-cli/foo/bar\x22);\x0a\x0a//\x20foo.ts\x0afooFunc(\x22packages/test/foo\x22);\x0a\x0a####\x20Correct\x0a\x0a//\x20packages/infra/foo.ts\x0aimport\x20{\x20infraPaths\x20}\x20from\x20\x22@infra/constants\x22;\x0a\x0afooFunc(`${infraPaths.bar}`);\x0a\x0a//\x20packages/internal-cli/foo.ts\x0aimport\x20{\x20internalCliPaths\x20}\x20from\x20\x22@internal-cli/constants\x22;\x0a\x0afooFunc(`${internalCliPaths.bar}`);\x0a\x0a//\x20foo.ts\x0aimport\x20{\x20packagesPaths\x20}\x20from\x20\x22@base-repo/app-constants/project-paths\x22;\x0a\x0aconst\x20fooPath\x20=\x20`${packagesPaths.packagesTest}foo`;\x0afooFunc(fooPath);\x0a\x0a####\x20Why\x0a\x0aThis\x20helps\x20avoiding\x20code\x20duplication.',pathLikeRegex=/^\/?[a-zA-Z0-9._-]*(\/[a-zA-Z0-9._-]+)+\/?$/,ignoredFiles=[''+packagesPath['packagesFlint']+folders['tests'],packagesPath['packagesBaseRepo']+'app-constants'];var mustUsePathConstantsForPaths = createEslintRule(ruleName,ruleContent,_0x516d80=>{const _0x279a45=normalizePathSeparators(_0x516d80['filename']);if(ignoredFiles['some'](_0x18ba7f=>_0x279a45['includes'](_0x18ba7f))||isInsideFolder(_0x279a45,folders['constants'])||isFilenameWithSuffix(_0x279a45,'-'+folders['constants']))return {};return {'Literal'(_0x278c5f){!isInsideNewUrl(_0x278c5f)&&isStringLiteral(_0x278c5f)&&_0x278c5f['parent']['type']!==nodeTypes['importDeclaration']&&pathLikeRegex['test'](_0x278c5f['value'])&&_0x516d80['report']({'node':_0x278c5f,'messageId':ruleName,'data':{'message':getDynamicMessage(_0x279a45)}});},'TemplateLiteral'(_0x201bbb){if(!isInsideNewUrl(_0x201bbb)){const _0x3d22af=getStringLiterals(_0x201bbb);_0x3d22af['some'](_0x2a4306=>pathLikeRegex['test'](_0x2a4306))&&_0x516d80['report']({'node':_0x201bbb,'messageId':ruleName,'data':{'message':getDynamicMessage(_0x279a45)}});}}};},{'dynamicMessage':'{{message}}'});function isInsideNewUrl(_0x3b4712){return _0x3b4712['parent']['type']===nodeTypes['newExpression']&&isIdentifier(_0x3b4712['parent']['callee'])&&_0x3b4712['parent']['callee']['name']===urlUpperCaseWord;}__name(isInsideNewUrl,'isInsideNewUrl');function getDynamicMessage(_0x10a523){for(const _0x41489b of Object['values'](packagesPath)){if(_0x10a523['includes'](_0x41489b)&&_0x41489b!==packagesPath['packagesBaseRepo']){const _0x158763=_0x41489b['split']('/')['filter'](Boolean)['pop'](),_0x3f1431=_0x158763?.['replace'](/-./g,_0x5ca233=>_0x5ca233[-0x1e3+-0x261d*0x1+0x2801]['toUpperCase']());return 'use\x20'+_0x3f1431+'Paths\x20from\x20\x22@'+_0x158763+'/constants\x22';}}return 'use\x20constants\x20from\x20@base-repo/app-constants/project-paths';}__name(getDynamicMessage,'getDynamicMessage');

export { mustUsePathConstantsForPaths as default, ruleName };
