* Asserts that a function document has: * - A `@typeParam` tag for each type parameter. * - A code https://jsdoc.app/tags-param | @param tag for each parameter. * - A parameter definition inside the function for each @param tag. * - A code https://jsdoc.app/tags-returns | @returns
( document: DocNodeWithJsDoc<DocNodeFunction | ClassMethodDef>, )
| 222 | * a code snippet that executes successfully. |
| 223 | */ |
| 224 | function assertFunctionDocs( |
| 225 | document: DocNodeWithJsDoc<DocNodeFunction | ClassMethodDef>, |
| 226 | ) { |
| 227 | for (const param of document.functionDef.params) { |
| 228 | if (param.kind === "identifier") { |
| 229 | assertHasParamTag(document, param.name); |
| 230 | } |
| 231 | if (param.kind === "rest" && param.arg.kind === "identifier") { |
| 232 | assertHasParamTag(document, param.arg.name); |
| 233 | } |
| 234 | if (param.kind === "assign" && param.left.kind === "identifier") { |
| 235 | assertHasParamTag(document, param.left.name); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | const documentedParams = document.jsDoc.tags?.filter(( |
| 240 | tag, |
| 241 | ): tag is JsDocTagParam => |
| 242 | // Filter nested definitions like options.root as it is still documenting options parameter |
| 243 | tag.kind === "param" && !tag.name.includes(".") |
| 244 | ) ?? []; |
| 245 | for (const param of documentedParams) { |
| 246 | assertHasParamDefinition(document, param); |
| 247 | } |
| 248 | |
| 249 | for (const typeParam of document.functionDef.typeParams) { |
| 250 | assertHasTypeParamTags(document, typeParam.name); |
| 251 | } |
| 252 | if ( |
| 253 | document.functionDef.returnType !== undefined && |
| 254 | !isVoidOrPromiseVoid(document.functionDef.returnType) && |
| 255 | !isTypeAsserts(document.functionDef.returnType) |
| 256 | ) { |
| 257 | assertHasReturnTag(document); |
| 258 | } |
| 259 | assertHasExampleTag(document); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Asserts that a class document has: |
no test coverage detected