|
| 1 | +# jsdoc |
| 2 | +[](http://travis-ci.org/zxqfox/jscs-jsdoc) |
| 3 | +[](http://badge.fury.io/js/jsdoc) |
| 4 | +[](https://david-dm.org/zxqfox/jscs-jsdoc) |
| 5 | + |
| 6 | +`jscs-jsdoc` plugin for [jscs](https://github.com/mdevils/node-jscs/). |
| 7 | + |
| 8 | +## Friendly packages |
| 9 | + |
| 10 | + * JSCS: https://github.com/mdevils/node-jscs/ |
| 11 | + |
| 12 | +## Plugin installation |
| 13 | + |
| 14 | +`jscs-jsdoc` can be installed using `npm`. |
| 15 | +Install it globally if you are using globally installed `jscs` |
| 16 | + |
| 17 | + npm -g install jscs-jsdoc |
| 18 | + |
| 19 | +Or install it into your project |
| 20 | + |
| 21 | + npm install jscs-jsdoc --save-dev |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +To use plugin you should add it to configuration file `.jscsrc`: |
| 26 | + |
| 27 | +```json |
| 28 | +{ |
| 29 | + "additionalRules": [ |
| 30 | + "node_modules/jscs-jsdoc/lib/rules/*.js" |
| 31 | + ], |
| 32 | + "jsDoc": { |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +### jsDoc |
| 40 | + |
| 41 | +Enables JsDoc validation. |
| 42 | + |
| 43 | +Type: `Object` |
| 44 | + |
| 45 | +Values: |
| 46 | + |
| 47 | + - "checkParamNames" ensures param names in jsdoc and in function declaration are equal |
| 48 | + - "requireParamTypes" ensures params in jsdoc contains type |
| 49 | + - "checkRedundantParams" reports redundant params in jsdoc |
| 50 | + - "checkReturnTypes" tries to compare function result type with declared type in jsdoc |
| 51 | + - "requireReturnTypes" ensures returns in jsdoc contains type |
| 52 | + - "checkRedundantReturns" reports redundant returns in jsdoc |
| 53 | + - "checkTypes" reports invalid types in jsdoc |
| 54 | + |
| 55 | +#### Example |
| 56 | + |
| 57 | +```js |
| 58 | +"jsDoc": { |
| 59 | + "checkParamNames": true, |
| 60 | + "checkRedundantParams": true, |
| 61 | + "requireParamTypes": true, |
| 62 | + "checkReturnTypes": true, |
| 63 | + "checkRedundantReturns": true, |
| 64 | + "requireReturnTypes": true, |
| 65 | + "checkTypes": true |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +##### Valid |
| 70 | + |
| 71 | +```js |
| 72 | +/** |
| 73 | + * Adds style error to the list |
| 74 | + * |
| 75 | + * @param {String} message |
| 76 | + * @param {Number|Object} line |
| 77 | + * @param {Number} [column] |
| 78 | + * @returns {String[]} |
| 79 | + */ |
| 80 | +add: function(message, line, column) { |
| 81 | + return ['foo', 'bar']; |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +##### Invalid |
| 86 | + |
| 87 | +```js |
| 88 | +/** |
| 89 | + * Adds style error to the list |
| 90 | + * |
| 91 | + * @param {String} message |
| 92 | + * @param {Number,Object} line |
| 93 | + * @param {Number} [column] |
| 94 | + * @returns {String} |
| 95 | + */ |
| 96 | +add: function() { |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Browser Usage |
| 101 | + |
| 102 | +File [jscs-jsdoc-browser.js](jscs-jsdoc-browser.js) contains browser-compatible version of `jscs-jsdoc`. |
| 103 | + |
| 104 | +Download and include `jscs-jsdoc-browser.js` into your page just after `jscs-browser.js`. |
| 105 | + |
| 106 | +```html |
| 107 | +<script src="jscs-browser.js"></script> |
| 108 | +<script src="jscs-jsdoc-browser.js"></script> |
| 109 | +<script> |
| 110 | + var checker = new JscsStringChecker(); |
| 111 | + checker.registerDefaultRules(); |
| 112 | + checker.configure({'jsDoc': {/*...*/}}); |
| 113 | + var errors = checker.checkString('var x, y = 1;'); |
| 114 | + errors.getErrorList().forEach(function(error) { |
| 115 | + console.log(errors.explainError(error)); |
| 116 | + }); |
| 117 | +</script> |
| 118 | +``` |
0 commit comments