elearning/Frontend-Learner/node_modules/eslint-plugin-jsdoc/dist/rules/tsNoUnnecessaryTemplateExpression.cjs.map

1 line
7.3 KiB
Text
Raw Normal View History

2026-01-13 10:46:40 +07:00
{"version":3,"file":"tsNoUnnecessaryTemplateExpression.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdocUtils","_jsdoccomment","e","__esModule","default","_default","exports","iterateJsdoc","context","indent","jsdoc","settings","utils","mode","enableFixer","options","checkType","tag","potentialType","type","parsedType","parseType","traverse","nde","parentNode","property","index","stringInterpolationIndex","interpolations","findIndex","interpolation","reportJSDoc","literals","splice","value","rewireByParsedType","length","tags","filterTags","Boolean","tagMightHaveTypePosition","iterateAllJsdocs","meta","docs","description","url","fixable","schema","additionalProperties","properties","module"],"sources":["../../src/rules/tsNoUnnecessaryTemplateExpression.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n rewireByParsedType,\n} from '../jsdocUtils.js';\nimport {\n parse as parseType,\n traverse,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n context,\n indent,\n jsdoc,\n settings,\n utils,\n}) => {\n if (settings.mode !== 'typescript') {\n return;\n }\n\n const {\n enableFixer = true,\n } = context.options[0] ?? {};\n\n /**\n * @param {import('@es-joy/jsdoccomment').JsdocTagWithInline} tag\n */\n const checkType = (tag) => {\n const potentialType = tag.type;\n /** @type {import('jsdoc-type-pratt-parser').RootResult} */\n let parsedType;\n try {\n parsedType = parseType(\n /** @type {string} */ (potentialType), 'typescript',\n );\n } catch {\n return;\n }\n\n traverse(parsedType, (nde, parentNode, property, index) => {\n switch (nde.type) {\n case 'JsdocTypeTemplateLiteral': {\n const stringInterpolationIndex = nde.interpolations.findIndex((interpolation) => {\n return interpolation.type === 'JsdocTypeStringValue';\n });\n if (stringInterpolationIndex > -1) {\n utils.reportJSDoc(\n 'Found an unnecessary string literal within a template.',\n tag,\n enableFixer ? () => {\n nde.literals.splice(\n stringInterpolationIndex,\n 2,\n nde.literals[stringInterpolationIndex] +\n /** @type {import('jsdoc-type-pratt-parser').StringValueResult} */\n (nde.interpolations[stringInterpolationIndex]).value +\n nde.literals[stringInterpolationIndex + 1],\n );\n\n nde.interpolations.splice(\n stringInterpolationIndex, 1,\n );\n\n rewireByParsedType(jsdoc, tag, parsedType, indent);\n } : null,\n );\n } else if (nde.literals.length === 2 && nde.literals[0] === '' &&\n nde.literals[1] === ''\n ) {\n utils.reportJSDoc(\n 'Found a lone template expression within a template.',\n tag,\n enableFixer ? () => {\n const interpolation = nde.interpolations[0];\n\n if (parentNode && property) {\n if (typeof index === 'number') {\n // @ts-expect-error Safe\n parentNode[property][index] = interpolation;\n } else {\n // @ts-expect-error Safe\n parentNode[property] = interpolation;\n }\n } else {\n parsedType = interpolation;\n }\n\n rewireByParsedType(jsdoc, tag, parsedType, indent);\n } : null,\n );\n }\n }\n }\n });\n };\n\n const tags = utils.filterTags(({\n tag,\n }) => {\n return Boolean(tag !== 'import' && utils.tagMightHaveTypePosition(tag));\n });\n\n for (const tag of tags) {\n if (tag.type) {\n checkType(tag);\n }\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Catches unnecessary template expressi