'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { normalizePathSeparators, isConstantsFileOrFolder, nodeTypes, isIdentifier, isCommonNamedIdentifier, isInsideConstAssertedExpression } from '@flint/infra/analysis';
import { folders } from '../../../base-repo/app-constants/project-paths.js';

const ruleName='must-not-use-common-constants-outside-constants-files';const ruleContent='\x0a###\x20**Must\x20not**\x20use\x20constants\x20whose\x20names\x20start\x20with\x20\x27common\x27\x20outside\x20constants\x20files\x20or\x20object\x20literals\x20that\x20end\x20with\x20\x27as\x20const\x27.\x0a\x0a####\x20Wrong\x0a\x0a//\x20foo.ts\x0aexport\x20const\x20foo\x20=\x20{\x0a\x20\x20\x20\x20bar:\x20commonLowerCaseWords.foo,\x0a};\x0a\x0abaz\x20=\x20commonLowerCaseWords.foo,\x0a\x0a####\x20Correct\x0a\x0a//\x20constants.ts\x0aexport\x20const\x20foo\x20=\x20{\x0a\x20\x20\x20\x20bar:\x20commonLowerCaseWords.foo,\x0a}\x20as\x20const;\x0a\x0a//\x20foo.ts\x0aexport\x20const\x20foo\x20=\x20{\x0a\x20\x20\x20\x20bar:\x20commonLowerCaseWords.foo,\x0a}\x20as\x20const;\x0a\x0a####\x20Why\x0a\x0aCommon\x20constants\x20should\x20stay\x20either\x20in\x20dedicated\x20constants\x20files\x20or\x20in\x20readonly\x20object\x20literals\x20with\x20explicit\x20\x27as\x20const\x27\x20boundaries.',constantsKeyword=folders['constants'],commonKeywords=[folders['common']];var mustNotUseCommonConstantsOutsideConstantsFiles = createEslintRule(ruleName,ruleContent,_0x50f897=>{const _0x65aff8=normalizePathSeparators(_0x50f897['filename'])['toLowerCase']();if(isConstantsFileOrFolder(_0x65aff8,constantsKeyword))return {};return {'MemberExpression'(_0x521620){isIdentifier(_0x521620['object'])&&isCommonNamedIdentifier(_0x521620['object']['name'],commonKeywords)&&!isInsideConstAssertedExpression(_0x521620)&&_0x50f897['report']({'node':_0x521620,'messageId':ruleName,'data':{'constantName':_0x521620['object']['name']}});},'SpreadElement'(_0x5615d4){isIdentifier(_0x5615d4['argument'])&&isCommonNamedIdentifier(_0x5615d4['argument']['name'],commonKeywords)&&!isInsideConstAssertedExpression(_0x5615d4)&&_0x50f897['report']({'node':_0x5615d4,'messageId':ruleName,'data':{'constantName':_0x5615d4['argument']['name']}});},'VariableDeclarator'(_0x3b6349){_0x3b6349['id']['type']===nodeTypes['objectPattern']&&_0x3b6349['init']&&isIdentifier(_0x3b6349['init'])&&isCommonNamedIdentifier(_0x3b6349['init']['name'],commonKeywords)&&_0x50f897['report']({'node':_0x3b6349['init'],'messageId':ruleName,'data':{'constantName':_0x3b6349['init']['name']}});}};},{'dynamicMessage':'Constant\x20structure\x20\x27{{constantName}}\x27\x20can\x20be\x20used\x20only\x20in\x20files\x20or\x20folders\x20whose\x20name\x20contains\x20\x27constants\x27\x20or\x20inside\x20object\x20literals\x20that\x20end\x20with\x20\x27as\x20const\x27.'});

export { mustNotUseCommonConstantsOutsideConstantsFiles as default, ruleName };
