MCPcopy Create free account
hub / github.com/denoland/std / assertFunctionDocs

Function assertFunctionDocs

_tools/check_docs.ts:224–260  ·  view source on GitHub ↗

* 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>,
)

Source from the content-addressed store, hash-verified

222 * a code snippet that executes successfully.
223 */
224function 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:

Callers 2

assertClassDocsFunction · 0.85
assertDocsFunction · 0.85

Calls 8

assertHasParamTagFunction · 0.85
assertHasParamDefinitionFunction · 0.85
assertHasTypeParamTagsFunction · 0.85
isVoidOrPromiseVoidFunction · 0.85
isTypeAssertsFunction · 0.85
assertHasReturnTagFunction · 0.85
assertHasExampleTagFunction · 0.85
includesMethod · 0.80

Tested by

no test coverage detected