forked from jscs-dev/node-jscs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes jscs-dev#59
- Loading branch information
Joel Kemp
committed
Sep 19, 2014
1 parent
b615bd7
commit f29ca0d
Showing
6 changed files
with
26 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.