简体   繁体   中英

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;
};

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
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM