Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSDoc preserve order of comments in output

I have a JavaScript object, that introduces some public methods and I want to use JSDoc to document them.

In the source file I have these functions grouped and ordered in a reasonable order, but after generating JSDoc I receive all of them in an alphabetical order, that doesn't make much sense.

Is there any way to keep the order in the output? I couldn't find any answer, but I also couldn't find that it's impossible.

like image 878
Anton Vernigor Avatar asked Dec 18 '13 21:12

Anton Vernigor


People also ask

How to use JSDoc comment?

JSDoc comments should generally be placed immediately before the code being documented. Each comment must start with a /** sequence in order to be recognized by the JSDoc parser. Comments beginning with /* , /*** , or more than 3 stars will be ignored.

What is JSDoc comments?

JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.

How to add JSDoc comments?

Using. In a typescript or javascript file, select a function signature, ideally one that contains one or more parameters. Select the whole function signature then invoke the Add Doc Comments extension (open the command palette (F1 on Windows) and look for the command 'Add doc comments'. Hit enter.)

How to write JS Docs?

JavaScript has various data types like strings, numbers, arrays, and objects. The snippets below show how to document each of them using JSDocs. /** * Documentaion for a string * Article Name * @type {string} */ const articleName = "Javascript Documentation"; Number.


1 Answers

The short answer:

Within your conf.json file, add an opts element of "sort": false, where sort is flagging whether JSDoc should use alphabetical sorting.

Assuming you are using a conf.json file to designate your JSDOC configuration options:

jsdoc -c path/to/conf.json

For example:

{
    "tags": {
        "allowUnknownTags": false
    },
    "source": {
        "includePattern": ".+\\.js(doc)?$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "plugins": [],
    "templates": {
        "cleverLinks": true,
        "monospaceLinks": false,
    },
    "opts": {
        "encoding": "utf8",
        "lenient": false,
        "sort": false
    }
}

I also came across Docstrap, a Bootstrap template for JSDoc3.

You can then use the 'sort' option within the templates section. Example of a conf.json file for this case might appear as:

{
    "tags": {
        "allowUnknownTags": true,
        "dictionaries": ["jsdoc","closure"]
    },
    "source": {
        "includePattern": ".+\\.js(doc|x)?$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "plugins": [],
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": false
        "sort": false
    }
}

The description given from the Docstrap site is:

sort Defaults to true. Specifies whether jsdoc should sort data or use file order. Can also be a string and if so it is passed to jsdoc directly. The default string is "longname, version, since".

like image 143
treavg Avatar answered Sep 30 '22 19:09

treavg