最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSDoc preserve order of comments in output - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Jan 18, 2017 at 18:39 GʀᴜᴍᴘʏCᴀᴛ 9,04820 gold badges90 silver badges160 bronze badges asked Dec 18, 2013 at 21:12 Anton VernigorAnton Vernigor 5272 gold badges5 silver badges11 bronze badges 2
  • 1 I don't think it is impossible but I would expect that with jsdoc 3.2.2 it would be a significant undertaking. I'd expect the minimum you'd have to do is produce a custom template. I base this on the experience we've had with reorganizing the list of modules and classes put in the navigation bar: we had to create our own template. I doubt reordering methods would be easier. – Louis Commented Dec 19, 2013 at 12:09
  • Thank you, I think I'll give it a try in future. Not as easy as I expected, but still may be possbile! – Anton Vernigor Commented Dec 19, 2013 at 23:00
Add a ment  | 

1 Answer 1

Reset to default 6

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".

发布评论

评论列表(0)

  1. 暂无评论