Is it possible to tell jsdoc to look in a file separate from the source code for documentation of that code?

被刻印的时光 ゝ 提交于 2019-12-22 05:23:17

问题


I would like to keep inline comments as short as possible, since my experience is that comments of more than 3 or 4 lines tend to be glossed over, creating a lot of unnecessary "read the manual lines".

I'm required by legacy to adhere to a jsdoc-compatible format for documenting code. It requires that a lot of self evident things be declared explicitly if they're to be documented correctly. Practically every tag can fall in this category. Even the ones that don't are often useless to a working developer.

My vision is to have a quick summary inside the code itself that developers will actually read, but refer to a separate file (or even a comment dump in the same file, separate from where developers will be working) for additional tagging, like this:

/**
 *  Used when making an example of the argument.
 *  @include someotherplace
 */
function example(argument) { stuff;}

...lots more code...

/**
 *  someotherplace
 *  @param argument The victim
 *  @since forever
 *  @other stuff
 */

A different tool or a plugin would be acceptable, I'm really only stuck with the syntax. Another alternative would be a tool with some really good implicit documentation creation


回答1:


With jsdoc3, I do not think there is a way to get what a perfect solution without having to write a new plugin. (I do not know of a plugin that would already do it.)

However, it is possible to abuse the jsdoc tags to get something which is not perfect but is functional.

/**
 * @module foo
 */


/**
 * Used when making an example of the argument.
 * @see {module:foo.example_type}
 */
function example(argument) {
    //...
}

/**
 * someotherplace
 * @typedef {function} module:foo.example_type
 * @param argument The victim
 * @since forever
 */

The key is to create a type definition with a unique name, and then use @see to link to that definition. @module and module: are just there to show it can be done with modules. They can just be stripped for cases where modules are not needed.




回答2:


What about {@link} tag and tutorials {@tutorial} tags? From documentation:

{@tutorial} Tutorials

Tutorials mechanism allows you to include not only short code-related technical API documentation, but also longer, more explaining, full-page tutorials

The {@link} tag allows you to create a HTML link to some other documented symbol from within the text of any tag's description.

Usage:

@anyTag This is some text {@link otherSymbol}.


来源:https://stackoverflow.com/questions/20021085/is-it-possible-to-tell-jsdoc-to-look-in-a-file-separate-from-the-source-code-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!