Skip to content

Commit

Permalink
validateJSDoc: Deprecate rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Kemp committed Sep 19, 2014
1 parent b615bd7 commit f29ca0d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 353 deletions.
48 changes: 2 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2850,54 +2850,10 @@ function a(b, c) {}
function a(b , c) {}
```

### validateJSDoc
### ~~validateJSDoc~~

Enables JSDoc validation.
Please use the [JSCS-JSDoc](https://github.com/jscs-dev/jscs-jsdoc) plugin instead.

Type: `Object`

Values:

- "checkParamNames" ensures param names in jsdoc and in function declaration are equal
- "requireParamTypes" ensures params in jsdoc contains type
- "checkRedundantParams" reports redundant params in jsdoc

#### Example

```js
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
```

##### Valid

```js
/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
*/
add: function(message, line, column) {
}
```

##### Invalid

```js
/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
*/
add: function() {
}
```
### safeContextKeyword
Expand Down
86 changes: 7 additions & 79 deletions lib/rules/validate-jsdoc.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,19 @@
var assert = require('assert');

module.exports = function() {};

module.exports.prototype = {

configure: function(options) {
assert(typeof options === 'object', 'validateJSDoc option requires object value');
this._options = options;
},
configure: function() {},

getOptionName: function() {
return 'validateJSDoc';
},

check: function(file, errors) {
var options = this._options;
var comments = file.getComments();
file.iterateNodesByType(['FunctionDeclaration', 'FunctionExpression'], function(node) {
var jsDoc = getJsDocForLine(node.loc.start.line);
if (jsDoc) {
var jsDocData = jsDoc.value;
var jsDocLines = jsDocData.split('\n');
var paramIndex = 0;
if (options.checkParamNames || options.checkRedundantParams || options.requireParamTypes) {
for (var i = 0, l = jsDocLines.length; i < l; i++) {
var line = jsDocLines[i].trim();
if (line.charAt(0) === '*') {
line = line.substr(1).trim();
if (line.indexOf('@param') === 0) {
var match = line.match(/^@param\s+(?:{(.+?)})?\s*(?:\[)?([a-zA-Z0-9_\.\$]+)/);
if (match) {
var jsDocParamType = match[1];
var jsDocParamName = match[2];
if (options.requireParamTypes && !jsDocParamType) {
errors.add(
'Missing JSDoc @param type',
jsDoc.loc.start.line + i,
jsDocLines[i].indexOf('@param')
);
}
if (jsDocParamName.indexOf('.') === -1) {
var param = node.params[paramIndex];
if (param) {
if (jsDocParamName !== param.name) {
if (options.checkParamNames) {
errors.add(
'Invalid JSDoc @param argument name',
jsDoc.loc.start.line + i,
jsDocLines[i].indexOf('@param')
);
}
}
} else {
if (options.checkRedundantParams) {
errors.add(
'Redundant JSDoc @param',
jsDoc.loc.start.line + i,
jsDocLines[i].indexOf('@param')
);
}
}
paramIndex++;
}
} else {
errors.add(
'Invalid JSDoc @param',
jsDoc.loc.start.line + i,
jsDocLines[i].indexOf('@param')
);
}
}
}
}
}
}
});

function getJsDocForLine(line) {
line--;
for (var i = 0, l = comments.length; i < l; i++) {
var comment = comments[i];
if (comment.loc.end.line === line && comment.type === 'Block' && comment.value.charAt(0) === '*') {
return comment;
}
}
return null;
}
errors.add(
'The validateJSDoc rule is no longer supported.' +
'\nPlease use the JSCS-JSDoc plugininstead',
1,
0
);
}

};
2 changes: 1 addition & 1 deletion lib/string-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ StringChecker.prototype = {
this.registerRule(new (require('./rules/disallow-left-sticked-operators'))());
this.registerRule(new (require('./rules/require-right-sticked-operators'))());
this.registerRule(new (require('./rules/disallow-right-sticked-operators'))());
this.registerRule(new (require('./rules/validate-jsdoc'))());
/* deprecated rules (end) */

this.registerRule(new (require('./rules/require-operator-before-line-break'))());
Expand All @@ -60,7 +61,6 @@ StringChecker.prototype = {
this.registerRule(new (require('./rules/disallow-keywords-on-new-line'))());
this.registerRule(new (require('./rules/require-line-feed-at-file-end'))());
this.registerRule(new (require('./rules/maximum-line-length'))());
this.registerRule(new (require('./rules/validate-jsdoc'))());
this.registerRule(new (require('./rules/require-yoda-conditions'))());
this.registerRule(new (require('./rules/disallow-yoda-conditions'))());
this.registerRule(new (require('./rules/require-spaces-inside-object-brackets'))());
Expand Down
6 changes: 0 additions & 6 deletions presets/google.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,5 @@
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,


"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},

"disallowMultipleLineBreaks": true
}
5 changes: 0 additions & 5 deletions presets/yandex.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@
"disallowSpacesInsideObjectBrackets": true,
"disallowQuotedKeysInObjects": true,

"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},

"maximumLineLength": {
"value": 120,
"allowUrlComments": true
Expand Down
Loading

0 comments on commit f29ca0d

Please sign in to comment.