11var assert = require ( 'assert' ) ;
22
33var jsDocHelpers = require ( '../jsdoc-helpers' ) ;
4+ var validatorsByName = require ( './validate-jsdoc/index' ) ;
45
56module . exports = function ( ) { } ;
67
@@ -17,66 +18,46 @@ module.exports.prototype = {
1718 } ,
1819
1920 check : function ( file , errors ) {
20- var lineValidators = this . loadLineValidators ( ) ;
21+ var validators = this . loadValidators ( ) ;
2122
2223 // skip if there is nothing to check
23- if ( ! lineValidators . length ) {
24+ if ( ! validators . length ) {
2425 return ;
2526 }
2627
2728 var jsDocs = jsDocHelpers . parseComments ( file . getComments ( ) ) ;
29+ var that = this ;
2830
2931 file . iterateNodesByType ( [
3032 'FunctionDeclaration' ,
3133 'FunctionExpression'
34+
3235 ] , function ( node ) {
33- var jsDoc = jsDocs . node ( node ) ;
34- if ( ! jsDoc ) {
35- return ;
36- }
36+ node . jsDoc = jsDocs . node ( node ) ;
3737
38- node . jsDoc = jsDoc . value . split ( '\n' ) ;
39- node . jsDoc = node . jsDoc || { } ;
40- node . jsDoc . paramIndex = 0 ;
41-
42- function addError ( text , locStart ) {
43- locStart = locStart || { } ;
44- errors . add (
45- text ,
46- locStart . line || ( jsDoc . loc . start . line + i ) ,
47- locStart . column || ( node . jsDoc [ i ] . indexOf ( '@' ) )
48- ) ;
38+ for ( var j = 0 , k = validators . length ; j < k ; j += 1 ) {
39+ validators [ j ] . call ( that , node , addError ) ;
4940 }
5041
51- for ( var i = 0 , l = node . jsDoc . length ; i < l ; i ++ ) {
52- var line = node . jsDoc [ i ] . trim ( ) ;
53- if ( line . charAt ( 0 ) !== '*' ) {
54- continue ;
55- }
56-
57- line = line . substr ( 1 ) . trim ( ) ;
58-
59- for ( var j = 0 , k = lineValidators . length ; j < k ; j ++ ) {
60- lineValidators [ j ] ( node , line , addError ) ;
61- }
42+ function addError ( text , loc ) {
43+ loc = loc || { } ;
44+ loc . line = loc . hasOwnProperty ( 'line' ) ? loc . line : ( node . jsDoc . loc . start . line ) ;
45+ loc . column = loc . hasOwnProperty ( 'column' ) ? loc . column : 0 ; //node.jsDoc[i].indexOf('@');
46+ errors . add ( text , loc . line , loc . column ) ;
6247 }
6348 } ) ;
6449
6550 } ,
6651
67- loadLineValidators : function ( ) {
52+ loadValidators : function ( ) {
6853 var passedOptions = this . _optionsList ;
6954 var validators = [ ] ;
7055 if ( ! passedOptions ) {
7156 return validators ;
7257 }
7358
74- var availableValidators = [
75- 'param' ,
76- 'returns'
77- ] ;
78- availableValidators . forEach ( function ( name ) {
79- var v = require ( './validate-jsdoc/' + name ) ;
59+ Object . keys ( validatorsByName ) . forEach ( function ( name ) {
60+ var v = validatorsByName [ name ] ;
8061 if ( ! v . coveredOptions ) {
8162 return ;
8263 }
0 commit comments