{"version":3,"sources":["../../src/rules/checkParamNames.js"],"names":["validateParameterNames","targetTagName","allowExtraTrailingParamDocs","functionParameterNames","jsdoc","jsdocNode","utils","report","paramTags","Object","entries","tags","filter","tag","paramTagsNonNested","name","includes","dotted","some","index","tagsIndex","dupeTagInfo","find","tgsIndex","tg","idx","reportJSDoc","splice","functionParameterName","trim","expectedNames","join","actualNames","map","validateParameterNamesDeep","jsdocParameterNames","lastRealParameter","jsdocParameterName","isPropertyPath","pathRootNodeName","slice","indexOf","endsWith","context","options","jsdocParameterNamesDeep","getJsdocTagsDeep","length","getFunctionParameterNames","getPreferredTagName","tagName","isError","meta","fixable","schema","additionalProperties","properties","type"],"mappings":";;;;;;;AAAA;;;;AAEA,MAAMA,sBAAsB,GAAG,CAC7BC,aAD6B,EACLC,2BADK,EAE7BC,sBAF6B,EAEWC,KAFX,EAEkBC,SAFlB,EAE6BC,KAF7B,EAEoCC,MAFpC,KAG1B;AACH,QAAMC,SAAS,GAAGC,MAAM,CAACC,OAAP,CAAeN,KAAK,CAACO,IAArB,EAA2BC,MAA3B,CAAkC,CAAC,GAAGC,GAAH,CAAD,KAAa;AAC/D,WAAOA,GAAG,CAACA,GAAJ,KAAYZ,aAAnB;AACD,GAFiB,CAAlB;AAGA,QAAMa,kBAAkB,GAAGN,SAAS,CAACI,MAAV,CAAiB,CAAC,GAAGC,GAAH,CAAD,KAAa;AACvD,WAAO,CAACA,GAAG,CAACE,IAAJ,CAASC,QAAT,CAAkB,GAAlB,CAAR;AACD,GAF0B,CAA3B;AAIA,MAAIC,MAAM,GAAG,CAAb;AAEA,SAAOT,SAAS,CAACU,IAAV,CAAe,CAAC,GAAGL,GAAH,CAAD,EAAUM,KAAV,KAAoB;AACxC,QAAIC,SAAJ;AACA,UAAMC,WAAW,GAAGb,SAAS,CAACc,IAAV,CAAe,CAAC,CAACC,QAAD,EAAWC,EAAX,CAAD,EAAiBC,GAAjB,KAAyB;AAC1DL,MAAAA,SAAS,GAAGG,QAAZ;AAE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M,CAFJ;AAaJA,IAAAA,IAAI,EAAE;AAbF;AADL,CA5BY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nconst validateParameterNames = (\n targetTagName : string, allowExtraTrailingParamDocs: boolean,\n functionParameterNames : Array, jsdoc, jsdocNode, utils, report,\n) => {\n const paramTags = Object.entries(jsdoc.tags).filter(([, tag]) => {\n return tag.tag === targetTagName;\n });\n const paramTagsNonNested = paramTags.filter(([, tag]) => {\n return !tag.name.includes('.');\n });\n\n let dotted = 0;\n\n return paramTags.some(([, tag], index) => {\n let tagsIndex;\n const dupeTagInfo = paramTags.find(([tgsIndex, tg], idx) => {\n tagsIndex = tgsIndex;\n\n return tg.name === tag.name && idx !== index;\n });\n if (dupeTagInfo) {\n utils.reportJSDoc(`Duplicate @${targetTagName} \"${tag.name}\"`, dupeTagInfo[1], () => {\n jsdoc.tags.splice(tagsIndex, 1);\n });\n\n return true;\n }\n if (tag.name.includes('.')) {\n dotted++;\n\n return false;\n }\n\n const functionParameterName = functionParameterNames[index - dotted];\n\n if (!functionParameterName) {\n if (allowExtraTrailingParamDocs) {\n return false;\n }\n\n report(\n `@${targetTagName} \"${tag.name}\" does not match an existing function parameter.`,\n null,\n tag,\n );\n\n return true;\n }\n\n if (functionParameterName === '' || functionParameterName === '') {\n return false;\n }\n\n if (functionParameterName !== tag.name.trim()) {\n const expectedNames = functionParameterNames.join(', ');\n const actualNames = paramTagsNonNested.map(([, {name}]) => {\n return name.trim();\n }).join(', ');\n\n report(\n `Expected @${targetTagName} names to be \"${expectedNames}\". Got \"${actualNames}\".`,\n null,\n tag,\n );\n\n return true;\n }\n\n return false;\n });\n};\n\nconst validateParameterNamesDeep = (\n targetTagName : string, allowExtraTrailingParamDocs: boolean,\n jsdocParameterNames : Array, jsdoc, report : Function,\n) => {\n let lastRealParameter;\n\n return jsdocParameterNames.some(({name: jsdocParameterName, idx}) => {\n const isPropertyPath = jsdocParameterName.includes('.');\n\n if (isPropertyPath) {\n if (!lastRealParameter) {\n report(`@${targetTagName} path declaration (\"${jsdocParameterName}\") appears before any real parameter.`, null, jsdoc.tags[idx]);\n\n return true;\n }\n\n let pathRootNodeName = jsdocParameterName.slice(0, jsdocParameterName.indexOf('.'));\n\n if (pathRootNodeName.endsWith('[]')) {\n pathRootNodeName = pathRootNodeName.slice(0, -2);\n }\n\n if (pathRootNodeName !== lastRealParameter) {\n report(\n `@${targetTagName} path declaration (\"${jsdocParameterName}\") root node name (\"${pathRootNodeName}\") ` +\n `does not match previous real parameter name (\"${lastRealParameter}\").`,\n null,\n jsdoc.tags[idx],\n );\n\n return true;\n }\n } else {\n lastRealParameter = jsdocParameterName;\n }\n\n return false;\n });\n};\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n jsdocNode,\n report,\n utils,\n}) => {\n const {allowExtraTrailingParamDocs} = context.options[0] || {};\n\n const jsdocParameterNamesDeep = utils.getJsdocTagsDeep('param');\n if (!jsdocParameterNamesDeep.length) {\n return;\n }\n const functionParameterNames = utils.getFunctionParameterNames();\n const targetTagName = utils.getPreferredTagName({tagName: 'param'});\n const isError = validateParameterNames(\n targetTagName, allowExtraTrailingParamDocs, functionParameterNames,\n jsdoc, jsdocNode, utils, report,\n );\n\n if (isError) {\n return;\n }\n\n validateParameterNamesDeep(\n targetTagName, allowExtraTrailingParamDocs, jsdocParameterNamesDeep,\n jsdoc, report,\n );\n}, {\n meta: {\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowExtraTrailingParamDocs: {\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"checkParamNames.js"}