-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkTypes: split rule logic and add checkin for other typed tags
- Loading branch information
Alexej Yaroshevich
committed
Nov 9, 2014
1 parent
d846a5b
commit f74570c
Showing
8 changed files
with
206 additions
and
49 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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var jsdoc = require('../../jsdoc'); | ||
|
||
module.exports = validateTypesInTags; | ||
module.exports.scopes = ['file']; | ||
module.exports.options = { | ||
checkTypes: {allowedValues: [true]} | ||
}; | ||
|
||
var allowedTags = { | ||
// common | ||
typedef: true, | ||
type: true, | ||
param: true, | ||
'return': true, | ||
returns: true, | ||
'enum': true, | ||
|
||
// jsdoc | ||
'var': true, | ||
prop: true, | ||
property: true, | ||
arg: true, | ||
argument: true, | ||
|
||
// jsduck | ||
cfg: true, | ||
|
||
// closure | ||
lends: true, | ||
extends: true, | ||
implements: true, | ||
define: true | ||
}; | ||
|
||
/** | ||
* validator for types in tags | ||
* @param {JSCS.JSFile} file | ||
* @param {JSCS.Errors} errors | ||
*/ | ||
function validateTypesInTags(file, errors) { | ||
var comments = file.getComments(); | ||
comments.forEach(function(commentNode) { | ||
if (commentNode.type !== 'Block' || commentNode.value[0] !== '*') { | ||
return; | ||
} | ||
|
||
// trying to create DocComment object | ||
var node = jsdoc.createDocComment(commentNode); | ||
if (!node.valid) { | ||
return; | ||
} | ||
|
||
node.iterateByType(Object.keys(allowedTags), function(tag) { | ||
if (!tag.type) { | ||
// skip untyped params | ||
return; | ||
} | ||
if (!tag.type.valid) { | ||
// throw an error if not valid | ||
errors.add('jsDoc checkTypes: Expected valid type instead of ' + tag.value, | ||
node.loc.start.line + tag.line, node.loc.start.column + tag.id.length + 1); | ||
} | ||
}); | ||
}); | ||
} |
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
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