Grouping Functions In JSDoc Generated Documentation
Asked Answered
M

3

8

I'm using documentationjs (which uses jsdoc under the hood) to handle the generation of docs for a lib I'm working on. My lib is written is ES6 and is fully functional, and at present the documentation generated is an alphabetical list of all the functions from all the modules in the lib. This makes it very hard to find what you are looking for. How should I use jsdoc comments so that functions from one file are grouped together in the documentation?

For example, given the following file …

/**
 * Docs for alpha
 */
export const alpha = () {};

/**
 * Docs for beta
 */
export const beta = ()  {};

/**
 * Docs for charlie
 */
export const charlie = () {};

… how should I use jsdoc comments to ensure the three functions are grouped together under 'Example' in the documentation?

I have tried defining a module at the top of the class: /** @module Example */ but although this generates an item called 'Example' in the docs, the functions are not grouped underneath it.

I have tried adding @memberof Example to the documentation of the individual functions, but this has no effect.

I am aware of this question, but it doesn't work for me, possibly because of the ES6 imports. There is no mention of its use with @module in the docs.

Mischief answered 27/9, 2017 at 17:59 Comment(7)
When I do what you describe having tried, it works perfectly. Maybe I'm unknowingly correcting a mistake you made. You should edit your question to show exactly what you tried.Theodolite
Thanks. Are you using documentationjs or just jsdoc?Mischief
I use jsdoc directly.Theodolite
Thnaks. Looks like it might be an issue with documentationjsMischief
You might be hitting this github.com/documentationjs/documentation/issues/803 ?Ernieernst
In fact documentationjs doesn't seem to use jsdoc. It just states to supports "jsdoc-styled" comments, but I can't see any dependencies on jsdoc. jsdoc works perfectly in the case you described. documentationjs also works for me, but only if I add @memberof Example .Engaging
Can you provide a sample repo?Kearse
M
5

It appears that documentationjs doesn't support JSDoc style grouping in its generated docs, however, it is possible to group functions using a slightly different syntax. I discovered this through trial and error due to documentationjs's (ironically) poor documentation:

/** @module Example **/

/**
 * @memberof Example
 */
const alpha = () => {};

Note: there is no module: prefix for the @member argument.

Mischief answered 9/10, 2017 at 9:25 Comment(0)
E
1

Perhaps you can try this workaround for now, until jsdoc implements grouping.

How to display Javascript methods in a 'group' in JSDOC?

Ergener answered 6/10, 2017 at 20:37 Comment(0)
F
-1

I think you need to use @module in this way:

/** @module myModule */

/** will be module:myModule~foo */
var foo = 1;

/** will be module:myModule.bar */
var bar = function() {};

As described here.

Funds answered 7/10, 2017 at 1:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.