@@ -7,6 +7,30 @@ module.exports.options = {
77 }
88} ;
99
10+ var nativeUnderscoredProperties = [
11+ // standard
12+ '__proto__' ,
13+ // underscore
14+ '_' ,
15+ // node.js
16+ '__filename' ,
17+ '__dirname' ,
18+ 'super_' , // util.inherits
19+ // moz
20+ '__count__' ,
21+ '__parent__' ,
22+ '__defineGetter__' ,
23+ '__defineSetter__' ,
24+ '__lookupGetter__' ,
25+ '__lookupSetter__' ,
26+ '__noSuchMethod__' ,
27+ // dfilatov/inherit
28+ '__constructor' ,
29+ '__self' ,
30+ '__base' ,
31+ '__parent' ,
32+ ] ;
33+
1034/**
1135 * validator for jsdoc data existance
1236 * @param {(FunctionDeclaration|FunctionExpression) } node
@@ -20,31 +44,43 @@ function validateLeadingUnderscoresAccess(node, err) {
2044
2145 // fetch name from variable, property or function
2246 var name ;
47+ var nameLocation ;
2348 switch ( node . parentNode . type ) {
2449 case 'VariableDeclarator' :
2550 name = node . parentNode . id . name ;
51+ nameLocation = node . parentNode . id . loc ;
2652 break ;
2753 case 'Property' :
2854 name = node . parentNode . key . name ;
55+ nameLocation = node . parentNode . key . loc ;
2956 break ;
3057 default : // try to use func name itself (if not anonymous)
3158 name = ( node . id || { } ) . name ;
59+ nameLocation = ( node . id || { } ) . loc ;
3260 break ;
3361 }
3462
63+ if ( nativeUnderscoredProperties . indexOf ( name ) !== - 1 ) {
64+ return ;
65+ }
66+
3567 // skip anonymous and names without underscores at begin
3668 if ( ! name || name [ 0 ] !== '_' ) {
3769 return ;
3870 }
3971
4072 var access ;
73+ var accessTag ;
4174 node . jsdoc . iterate ( function ( tag ) {
4275 if ( ! access && [ 'private' , 'protected' , 'public' , 'access' ] . indexOf ( tag . id ) !== - 1 ) {
4376 access = ( tag . id === 'access' ? tag . name . value : tag . id ) ;
77+ accessTag = tag ;
4478 }
4579 } ) ;
4680
47- if ( ! access || [ true , access ] . indexOf ( option ) === - 1 ) {
48- err ( 'Method access doesn\'t match' ) ;
81+ if ( ! access || ! accessTag ) {
82+ err ( 'Missing access tag for ' + ( name || 'anonymous function' ) , ( nameLocation || node . loc ) . start ) ;
83+ } else if ( [ true , access ] . indexOf ( option ) === - 1 ) {
84+ err ( 'Method access doesn\'t match' , accessTag . loc ) ;
4985 }
5086}
0 commit comments