'use strict';
import _0x1869d0__default from 'path';
import { fileURLToPath } from 'url';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { stringDuplicationConstants } from '../../../base-repo/constants/string-duplication-constants.js';
import { extractStringsFromSource } from '@tools/string-duplication/string-extractor';
import { buildDuplicatesMap } from '@tools/string-duplication/analyze-code-base';
import { normalizeString } from '@tools/string-duplication/normalizer';
import { sourceDir } from '../../../base-repo/app-constants/internal-system-constants.js';
import { eslintRuleSyntax } from '@flint/infra/constants/eslint-rule-syntax';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x420c0d,_0x42e7fd)=>__defProp(_0x420c0d,'name',{'value':_0x42e7fd,'configurable':!![]});const ruleName='no-literal-duplication';const ruleContent='\x0a###\x20**Must\x20not**\x20duplicate\x20literals\x20in\x20a\x20file.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20foo\x20=\x20\x22bar/baz/qux\x22;\x0aconst\x20bar\x20=\x20\x22bar/baz/qux\x22;\x0a\x0afoo(\x22quux\x22);\x0abar(\x22quux\x22);\x0a\x0a####\x20Correct\x0a\x0aconst\x20duplicatedPath\x20=\x20\x22bar/baz/qux\x22;\x0a\x0aconst\x20foo\x20=\x20duplicatedPath;\x0aconst\x20bar\x20=\x20duplicatedPath;\x0a\x0afoo(\x22quux\x22);\x0abar(\x22corge\x22);\x0a\x0a####\x20Why\x0a\x0aDuplicated\x20literals\x20are\x20fragile.\x20Extract\x20shared\x20strings\x20into\x20constants\x20to\x20ensure\x20a\x20single\x20source\x20of\x20truth.',monorepoRootDir=_0x1869d0__default['resolve'](_0x1869d0__default['dirname'](fileURLToPath(import.meta.url)),sourceDir);var noLiteralDuplication = createEslintRule(ruleName,ruleContent,_0x4053a4=>{const _0x1c792d=firstOrUndefined(_0x4053a4['options'])??{},_0x5c16f1=new Set([...stringDuplicationConstants['excludedStrings'],..._0x1c792d['excludedStrings']??[]]);return {[eslintRuleSyntax['programExitSelector']](){if(isExcludedFile(_0x4053a4['filename']))return;const _0x557572=extractStringsFromSource(_0x4053a4['filename'],_0x4053a4['sourceCode']['text'],[..._0x5c16f1]),_0x12f4c9=buildDuplicatesMap(_0x557572,normalizeString);_0x12f4c9['forEach'](_0x12fb9f=>{if(_0x12fb9f['length']<=0x1*0x12df+-0x6e1+-0xbfd)return;_0x12fb9f['forEach'](_0x4069c2=>{_0x4053a4['report']({'loc':{'start':_0x4053a4['sourceCode']['getLocFromIndex'](_0x4069c2['start']),'end':_0x4053a4['sourceCode']['getLocFromIndex'](_0x4069c2['end'])},'messageId':ruleName,'data':{'literal':_0x4069c2['original']}});});});}};},{'dynamicMessage':'Literal:\x20\x27{{literal}}\x27\x20is\x20duplicated.\x20Extract\x20it\x20into\x20a\x20constant.','schema':[{'type':'object','properties':{'excludedStrings':{'type':jsBasicTypes['array'],'items':{'type':'string'},'uniqueItems':!![]}},'additionalProperties':![]}],'defaultOptions':[{'excludedStrings':[...stringDuplicationConstants['excludedStrings']]}]});function isExcludedFile(_0x27a812){const _0x4e2e2e=_0x1869d0__default['isAbsolute'](_0x27a812)?_0x1869d0__default['relative'](monorepoRootDir,_0x27a812):_0x27a812,_0x1dfba1=_0x4e2e2e['replace'](/\\/g,'/');return stringDuplicationConstants['excludePatterns']['some'](_0x471b53=>matchesExcludePattern(_0x1dfba1,_0x471b53));}__name(isExcludedFile,'isExcludedFile');function matchesExcludePattern(_0x31a216,_0x4d29f8){const _0x3ad672=_0x4d29f8['replace'](/\\/g,'/')['replace'](/\/{2,}/g,'/'),_0x3eb36a=/[*?[\]{}()!+@]/['test'](_0x3ad672);if(_0x1869d0__default['matchesGlob'](_0x31a216,_0x3ad672))return !![];if(!_0x3eb36a){const _0x18dd91=_0x3ad672['replace'](/\/$/,'');return _0x31a216===_0x18dd91||_0x31a216['startsWith'](_0x18dd91+'/');}return ![];}__name(matchesExcludePattern,'matchesExcludePattern');

export { noLiteralDuplication as default, ruleName };
