Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 688
user2999782 Avatar asked Nov 16 '13 16:11

user2999782


People also ask

How do I view a JSDoc file?

Press Ctrl+Shift+O for viewing all the methods and corresponding JSDoc opens up when you select a method there and hover over the method.

What is JSDoc used for?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.

Is JSDoc built in?

By default, JSDoc uses the built-in "default" template to turn the documentation into HTML. You can edit this template to suit your own needs or create an entirely new template if that is what you prefer. This command will create a directory named out/ in the current working directory.

Does JSDoc work with TypeScript?

TypeScript has very rich JSDoc support, for a lot of cases you can even skip making your files . ts and just use JSDoc annotations to create a rich development environment. A JSDoc comment is a multi-line comment which starts with two stars instead of one.


1 Answers

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.

like image 181
Louis Avatar answered Oct 21 '22 10:10

Louis