File tree Expand file tree Collapse file tree
test/lib/rules/validate-jsdoc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,15 @@ module.exports.options = {
1010 * @param {Function } err
1111 */
1212function enforceExistence ( node , err ) {
13- if ( ! node . jsDoc && node . id ) {
13+ // if function is not anonymous or in variabledeclarator or in assignmentexpression
14+ var parentNode = node . parentNode || { } ;
15+ var needCheck = node . id ||
16+ parentNode . type === 'VariableDeclarator' ||
17+ parentNode . type === 'Property' ||
18+ parentNode . type === 'AssignmentExpression' && parentNode . operator === '=' ;
19+
20+ // and report unless jsdoc exists
21+ if ( needCheck && ! node . jsDoc ) {
1422 err ( 'jsdoc definition required' , node . loc . start ) ;
1523 }
1624}
Original file line number Diff line number Diff line change @@ -36,12 +36,72 @@ describe('rules/validate-jsdoc', function () {
3636 function funcName ( p ) {
3737 }
3838 }
39+ } , {
40+ it : 'should report jsdoc absence for function expressions' ,
41+ errors : 1 ,
42+ code : function ( ) {
43+ var myFunc = function ( v ) {
44+ } ;
45+ }
3946 } , {
4047 it : 'should not report jsdoc absence for anonymous functions' ,
4148 code : function ( ) {
4249 [ ] . forEach ( function ( v ) {
4350 } ) ;
4451 }
52+ } , {
53+ it : 'should report nested jsdoc absence' ,
54+ errors : 4 ,
55+ code : function ( ) {
56+ var MyNamespace = MyNamespace || { } ;
57+
58+ MyNamespace . Test = function ( ) {
59+ } ;
60+
61+ MyNamespace . Test . Sub = {
62+ yellow : function ( ) {
63+ }
64+ } ;
65+
66+ ( function ( ) {
67+ MyNamespace . Test . prototype . foo = function ( ) {
68+ function bar ( ) {
69+ }
70+ } ;
71+ } ) ( ) ;
72+ }
73+ } , {
74+ it : 'shouldn\'t report nested jsdocs existence' ,
75+ code : function ( ) {
76+ var MyNamespace = MyNamespace || { } ;
77+
78+ /**
79+ * Test
80+ */
81+ MyNamespace . Test = function ( ) {
82+ } ;
83+
84+ MyNamespace . Test . Sub = {
85+ /**
86+ * yellow submarine
87+ */
88+ yellow : function ( ) {
89+ }
90+ } ;
91+
92+ ( function ( ) {
93+ /**
94+ * Test.foo
95+ */
96+ MyNamespace . Test . prototype . foo = function ( ) {
97+ /**
98+ * bar
99+ */
100+ function bar ( ) {
101+ }
102+ } ;
103+ } ) ( ) ;
104+ }
45105 }
46106 /* jshint ignore:end */
47107 ] ) ;
You can’t perform that action at this time.
0 commit comments