|
1 |
- {"version":3,"sources":["../../src/rules/checkParamNames.js"],"names":["validateParameterNames","targetTagName","allowExtraTrailingParamDocs","checkDestructured","checkRestProperty","checkTypesRegex","disableExtraPropertyReporting","enableFixer","functionParameterNames","jsdoc","_jsdocNode","utils","report","paramTags","Object","entries","tags","filter","tag","paramTagsNonNested","name","includes","dotted","some","index","tagsIndex","dupeTagInfo","find","tgsIndex","tg","idx","reportJSDoc","removeTag","functionParameterName","Array","isArray","type","search","parameterName","names","properties","hasPropertyRest","rests","annotationParamName","undefined","trim","tagName","expectedNames","map","actualNames","paramTag","actualTypes","missingProperties","notCheckingNames","forEach","notCheckingName","startsWith","actualNameIdx","findIndex","actualName","comparePaths","missingIndex","pathDoesNotBeginWith","line","source","number","length","push","tagPlacement","hasMissing","missingProperty","extraProperties","match","prop","split","extraProperty","funcParamName","item","join","validateParameterNamesDeep","_allowExtraTrailingParamDocs","jsdocParameterNames","lastRealParameter","jsdocParameterName","isPropertyPath","pathRootNodeName","slice","indexOf","endsWith","context","jsdocNode","checkTypesPattern","useDefaultObjectProperties","options","getRegexFromString","jsdocParameterNamesDeep","getJsdocTagsDeep","getFunctionParameterNames","getPreferredTagName","isError","meta","docs","description","url","fixable","schema","additionalProperties"],"mappings":";;;;;;;AAAA;;;;AAEA,MAAMA,sBAAsB,GAAG,CAC7BC,aAD6B,EAE7BC,2BAF6B,EAG7BC,iBAH6B,EAI7BC,iBAJ6B,EAK7BC,eAL6B,EAM7BC,6BAN6B,EAO7BC,WAP6B,EAQ7BC,sBAR6B,EAQWC,KARX,EAQkBC,UARlB,EAQ8BC,KAR9B,EAQqCC,MARrC,KAS1B;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,KAAYjB,aAAnB;AACD,GAFiB,CAAlB;AAGA,QAAMkB,kBAAkB,GA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HwB,EAGjBG,MAHiB,CAA1B;AAKD,CA9Cc,EA8CZ;AACDwF,EAAAA,IAAI,EAAE;AACJC,IAAAA,IAAI,EAAE;AACJC,MAAAA,WAAW,EAAE,gFADT;AAEJC,MAAAA,GAAG,EAAE;AAFD,KADF;AAKJC,IAAAA,OAAO,EAAE,MALL;AAMJC,IAAAA,MAAM,EAAE,CACN;AACEC,MAAAA,oBAAoB,EAAE,KADxB;AAEElE,MAAAA,UAAU,EAAE;AACVtC,QAAAA,2BAA2B,EAAE;AAC3BkC,UAAAA,IAAI,EAAE;AADqB,SADnB;AAIVjC,QAAAA,iBAAiB,EAAE;AACjBiC,UAAAA,IAAI,EAAE;AADW,SAJT;AAOVhC,QAAAA,iBAAiB,EAAE;AACjBgC,UAAAA,IAAI,EAAE;AADW,SAPT;AAUVuD,QAAAA,iBAAiB,EAAE;AACjBvD,UAAAA,IAAI,EAAE;AADW,SAVT;AAaV9B,QAAAA,6BAA6B,EAAE;AAC7B8B,UAAAA,IAAI,EAAE;AADuB,SAbrB;AAgBV7B,QAAAA,WAAW,EAAE;AACX6B,UAAAA,IAAI,EAAE;AADK,SAhBH;AAmBVwD,QAAAA,0BAA0B,EAAE;AAC1BxD,UAAAA,IAAI,EAAE;AADoB;AAnBlB,OAFd;AAyBEA,MAAAA,IAAI,EAAE;AAzBR,KADM,CANJ;AAmCJA,IAAAA,IAAI,EAAE;AAnCF;AADL,CA9CY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\n\nconst validateParameterNames = (\n targetTagName : string,\n allowExtraTrailingParamDocs: boolean,\n checkDestructured : boolean,\n checkRestProperty : boolean,\n checkTypesRegex : RegExp,\n disableExtraPropertyReporting,\n enableFixer: boolean,\n functionParameterNames : Array<string>, 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], enableFixer ? () => {\n utils.removeTag(tagsIndex);\n } : null);\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 (Array.isArray(functionParameterName)) {\n if (!checkDestructured) {\n return false;\n }\n if (tag.type && tag.type.search(checkTypesRegex) === -1) {\n return false;\n }\n\n const [parameterName, {\n names: properties, hasPropertyRest, rests, annotationParamName,\n }] = functionParameterName;\n if (annotationParamName !== undefined) {\n const name = tag.name.trim();\n if (name !== annotationParamName) {\n report(`@${targetTagName} \"${name}\" does not match parameter name \"${annotationParamName}\"`, null, tag);\n }\n }\n const tagName = parameterName === undefined ? tag.name.trim() : parameterName;\n const expectedNames = properties.map((name) => {\n return `${tagName}.${name}`;\n });\n const actualNames = paramTags.map(([, paramTag]) => {\n return paramTag.name.trim();\n });\n const actualTypes = paramTags.map(([, paramTag]) => {\n return paramTag.type;\n });\n\n const missingProperties = [];\n const notCheckingNames = [];\n\n expectedNames.forEach((name, idx) => {\n if (notCheckingNames.some((notCheckingName) => {\n return name.startsWith(notCheckingName);\n })) {\n return;\n }\n const actualNameIdx = actualNames.findIndex((actualName) => {\n return utils.comparePaths(name)(actualName);\n });\n if (actualNameIdx === -1) {\n if (!checkRestProperty && rests[idx]) {\n return;\n }\n const missingIndex = actualNames.findIndex((actualName) => {\n return utils.pathDoesNotBeginWith(name, actualName);\n });\n const line = tag.source[0].number - 1 + (missingIndex > -1 ? missingIndex : actualNames.length);\n missingProperties.push({\n name,\n tagPlacement: {\n line: line === 0 ? 1 : line,\n },\n });\n } else if (actualTypes[actualNameIdx].search(checkTypesRegex) === -1 && actualTypes[actualNameIdx] !== '') {\n notCheckingNames.push(name);\n }\n });\n\n const hasMissing = missingProperties.length;\n if (hasMissing) {\n missingProperties.forEach(({tagPlacement, name: missingProperty}) => {\n report(`Missing @${targetTagName} \"${missingProperty}\"`, null, tagPlacement);\n });\n }\n\n if (!hasPropertyRest || checkRestProperty) {\n const extraProperties = [];\n actualNames.forEach((name, idx) => {\n const match = name.startsWith(tag.name.trim() + '.');\n if (\n match && !expectedNames.some(\n utils.comparePaths(name),\n ) && !utils.comparePaths(name)(tag.name) &&\n (!disableExtraPropertyReporting || properties.some((prop) => {\n return prop.split('.').length >= name.split('.').length - 1;\n }))\n ) {\n extraProperties.push([name, paramTags[idx][1]]);\n }\n });\n if (extraProperties.length) {\n extraProperties.forEach(([extraProperty, tg]) => {\n report(`@${targetTagName} \"${extraProperty}\" does not exist on ${tag.name}`, null, tg);\n });\n\n return true;\n }\n }\n\n return hasMissing;\n }\n\n let funcParamName;\n if (typeof functionParameterName === 'object') {\n const {name} = functionParameterName;\n funcParamName = name;\n } else {\n funcParamName = functionParameterName;\n }\n\n if (funcParamName !== tag.name.trim()) {\n // Todo: Improve for array or object child items\n const actualNames = paramTagsNonNested.map(([, {name}]) => {\n return name.trim();\n });\n const expectedNames = functionParameterNames.map((item, idx) => {\n if (item?.[1]?.names) {\n return actualNames[idx];\n }\n\n return item;\n }).join(', ');\n\n report(\n `Expected @${targetTagName} names to be \"${expectedNames}\". Got \"${actualNames.join(', ')}\".`,\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<string>, 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 {\n allowExtraTrailingParamDocs,\n checkDestructured = true,\n checkRestProperty = false,\n checkTypesPattern = '/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/',\n enableFixer = false,\n useDefaultObjectProperties = false,\n disableExtraPropertyReporting = false,\n } = context.options[0] || {};\n\n const checkTypesRegex = utils.getRegexFromString(checkTypesPattern);\n\n const jsdocParameterNamesDeep = utils.getJsdocTagsDeep('param');\n if (!jsdocParameterNamesDeep.length) {\n return;\n }\n const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties);\n const targetTagName = utils.getPreferredTagName({tagName: 'param'});\n const isError = validateParameterNames(\n targetTagName,\n allowExtraTrailingParamDocs,\n checkDestructured,\n checkRestProperty,\n checkTypesRegex,\n disableExtraPropertyReporting,\n enableFixer,\n functionParameterNames,\n jsdoc, jsdocNode, utils, report,\n );\n\n if (isError || !checkDestructured) {\n return;\n }\n\n validateParameterNamesDeep(\n targetTagName, allowExtraTrailingParamDocs,\n jsdocParameterNamesDeep,\n jsdoc, report,\n );\n}, {\n meta: {\n docs: {\n description: 'Ensures that parameter names in JSDoc match those in the function declaration.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n allowExtraTrailingParamDocs: {\n type: 'boolean',\n },\n checkDestructured: {\n type: 'boolean',\n },\n checkRestProperty: {\n type: 'boolean',\n },\n checkTypesPattern: {\n type: 'string',\n },\n disableExtraPropertyReporting: {\n type: 'boolean',\n },\n enableFixer: {\n type: 'boolean',\n },\n useDefaultObjectProperties: {\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"checkParamNames.js"}
|