'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isNameMatch } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { eslintFixTypeNames } from '../../../base-repo/constants/internal-common-strings.js';
import { firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

const ruleName='must-not-use-redundant-string';const constants={'messageIds':{'mustNotUseRedundantString':'mustNotUseRedundantString'},'meta':{'type':ruleTypes['suggestion'],'docs':{'description':'Redundant\x20use\x20of\x20String()\x20for\x20already\x20string-typed\x20value.'},'messages':{'mustNotUseRedundantString':'must-not-use-redundant-string\x0aRedundant\x20use\x20of\x20String()\x20for\x20already\x20string-typed\x20value\x20\x27{{name}}\x27.\x0a\x0a###\x20**Must\x20not**\x20use\x20redundant\x20String().\x0a\x0a####\x20Wrong\x0a\x0afunction\x20foo(bar:\x20string)\x20{\x0a\x20\x20\x20\x20const\x20baz\x20=\x20String(bar);\x0a\x20\x20\x20\x20…\x0a}\x0a\x0a####\x20Correct\x0a\x0afunction\x20foo(bar:\x20string)\x20{\x0a\x20\x20\x20\x20…\x0a}\x0a\x0a####\x20Why\x0a\x0aIf\x20the\x20type\x20of\x20a\x20property\x20is\x20a\x20string,\x20it\x20is\x20expected\x20that\x20it\x20contains\x20a\x20string,\x20therefore\x20no\x20need\x20to\x20convert\x20it\x20using\x20String().\x20If\x20there\x20is\x20a\x20point\x20in\x20conversion,\x20then\x20the\x20type\x20shouldn’t\x20be\x20string\x20in\x20the\x20first\x20place.'},'schema':[],'fixable':eslintFixTypeNames['code']}},createRule=ESLintUtils['RuleCreator'](_0x123f3d=>''+url+_0x123f3d),mustNotUseRedundantString=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x87a0fa){const _0xd9732e=_0x87a0fa['sourceCode']['parserServices'];if(!_0xd9732e?.['program']||!_0xd9732e['esTreeNodeToTSNodeMap'])return {};const _0x424052=_0xd9732e['program']['getTypeChecker']();return {'CallExpression'(_0x425f0d){if(_0x425f0d['callee']['type']===nodeTypes['identifier']&&isNameMatch(_0x425f0d['callee'],'String')&&_0x425f0d['arguments']['length']===0x15*0x18e+0x1*0xe7d+-0x1*0x2f22){const _0x3106e7=firstOrUndefined(_0x425f0d['arguments']);if(_0x3106e7){const _0x1a2a73=_0xd9732e['esTreeNodeToTSNodeMap']?.['get'](_0x3106e7);if(!_0x1a2a73)return;const _0x36709e=_0x424052['getTypeAtLocation'](_0x1a2a73),_0x9367cc=_0x424052['getStringType']();if(_0x424052['isTypeAssignableTo'](_0x36709e,_0x9367cc)){const _0x476665=_0x87a0fa['sourceCode'];_0x87a0fa['report']({'node':_0x425f0d,'messageId':constants['messageIds']['mustNotUseRedundantString'],'data':{'name':_0x476665['getText'](_0x3106e7)},'fix'(_0x130222){const _0xb136cf=_0x476665['getText'](_0x3106e7);return _0x130222['replaceText'](_0x425f0d,_0xb136cf);}});}}}}};}});

export { mustNotUseRedundantString as default, ruleName };
