JSDoc plugin to detect private ‘_’ prefixed members automatically

JSDoc plugin to detect private ‘_’ prefixed members automatically

Lately I’ve been using a lot of JSDoc under Netflix TVUI Team projects. JSDoc used to run with Java and Rhino, which sucked a little bit, but since 3.3.0 they have it with Node.JS!

Personally I think their engine is the best, since it’s built with no framework assumptions and it’s highly extensible. Even if you do use a framework – like with helpers to create classes such as Class.create, Class.define, makeClass, etc. – it still can tie things together.

So, taking advantage of their hooks to extend core functionality, I’ve written a small plugin that automatically marks a member (method, properties, attributes) as private if it’s prefixed with “_”.

Some projects follow this convention, so you can take advantage of this little plugin to save some work.

You can just save this under a JS file (e.g. plugins/autoPrivate.js) and reference it (JSDoc readme on how to use plugins).

Enjoy!

/*
 * Automatically marks member as private if name starts with '_' prefix.
 */
exports.handlers = {
    newDoclet: function(e) {
        var doclet = e.doclet;

        if (typeof doclet.access === 'undefined' && doclet.name && doclet.name[0] === '_') {
            doclet.access = 'private';
        }
    }
};