Jack
Jack

Reputation: 2223

Require JSDoc on all functions with JSCS

I'm using JSCS to enforce a consistent code style in one of my projects.

Is there a way to use JSCS to check that every function has some JSDoc?

Something that would say this is invalid:

var add = function(x, y) {
    return x + y;
};

But this is valid:

/**
 * Adds two numbers together
 * @param {number} x
 * @param {number} y
 * @returns The sum of x and y
 */
var add = function(x, y) {
    return x + y;
};

Upvotes: 1

Views: 557

Answers (2)

Jack
Jack

Reputation: 2223

It looks like jscs-jsdoc does it! It comes as a plugin for JSCS, and you can include the following in your .jscsrc:

"plugins": ["jscs-jsdoc"],
"jsDoc": {
    "enforceExistence": true
}

Upvotes: 3

atmd
atmd

Reputation: 7490

Using grunt you could use a grunt reg ex check.

This allows you to run regEx based checks on the contents. The example on the github repo is to test for console.log's but could be used to find function without jsdoc comments.

Not ideal, but would do the job, proving the regEx are up to scratch

Upvotes: 1

Related Questions