Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate JSDoc comments for functions when no comment exists?

I'm trying to create a plugin for JSDoc. I'm following the documentation (which, ironically, is lacking) and I'm not sure how to do this.

My plugin is loaded properly, and I'm trying a simple example. Here's my plugin (which loads, because I can throw an error from there to stop jsdoc from running):

visitNode: function(node, e, parser, currentSourceName) {

    if(node.type === 109){
        if(!e.comment || e.comment ==="@undocumented"){

            var startComment = '/**',
                endComment = '\n*/';
            var params = node.getParams(),
                paramsComment = '';
            for(var i=0; i<params.length; i++){
                paramsComment += '\n* @param ' + params[i];
            }

            e.comment = startComment +
                paramsComment +
                endComment;
        }
    }

please note that node.type === 109 is equivalent to Token.FUNCTION, which should be available as per their example here, but Token is undefined in the plugin.

If you know of a better site which explains how to write a JSDoc plugin, then that would be very much appreciated too... thanks

like image 283
Etai Avatar asked Jan 23 '14 17:01

Etai


1 Answers

I also had this problem and it seems strange that JSDoc does not have some kind of already made option for that or at least a plugin.

Anyway creating this plugin has solved my problem. I am using JSDoc version 3.4:

'use strict';
exports.handlers = {

    symbolFound:function(e) {
        if(e.astnode.type === "FunctionDeclaration" ) {
            if( (e.comment==="@undocumented")){
                e.comment = '/** undocumented */';
            }
        }
    }
};
like image 165
Natan Rubinstein Avatar answered Nov 07 '22 23:11

Natan Rubinstein