@@ -229,4 +229,75 @@ describe('rules/validate-jsdoc', function () {
229229
230230 } ) ;
231231
232+ describe ( 'bugfixes' , function ( ) {
233+
234+ it ( 'should not throw exception on `@returns {null|undefined}` directive. issue #7' , function ( ) {
235+
236+ checker . configure ( { jsDoc : { requireReturnTypes : true , checkReturnTypes : true } } ) ;
237+ assert (
238+ checker . checkString (
239+ '/**\n' +
240+ ' * @return {null}\n' +
241+ ' */\n' +
242+ 'function funcName() {\n' +
243+ 'return null;\n' +
244+ '}\n' +
245+ '/**\n' +
246+ ' * @return {undefined}\n' +
247+ ' */\n' +
248+ 'function funcName() {\n' +
249+ 'return undefined;\n' +
250+ '}\n' +
251+ '/**\n' +
252+ ' * @return {null|undefined}\n' +
253+ ' */\n' +
254+ 'function funcName(flag) {\n' +
255+ ' if (flag) {\n' +
256+ ' return null;\n' +
257+ ' }\n' +
258+ ' return undefined;\n' +
259+ '}\n'
260+ ) . isEmpty ( )
261+ ) ;
262+
263+ } ) ;
264+
265+ it ( 'should report on `@returns {null|undefined}` vs (string|number|regexp). issue #7' , function ( ) {
266+ checker . configure ( { jsDoc : { requireReturnTypes : true , checkReturnTypes : true } } ) ;
267+ assert (
268+ checker . checkString (
269+ '/**\n' +
270+ ' * @return {null|undefined}\n' +
271+ ' */\n' +
272+ 'function funcName(flag) {\n' +
273+ ' if (flag) {\n' +
274+ ' return /qwe/i;\n' +
275+ ' } else {\n' +
276+ ' return 2;\n' +
277+ ' }\n' +
278+ ' return "";\n' +
279+ '}\n'
280+ ) . getErrorCount ( ) === 3
281+ ) ;
282+ } ) ;
283+
284+ it ( 'should report on `@returns {null|undefined}` vs (array|object). issue #7' , function ( ) {
285+ checker . configure ( { jsDoc : { requireReturnTypes : true , checkReturnTypes : true } } ) ;
286+ assert (
287+ checker . checkString (
288+ '/**\n' +
289+ ' * @return {null|undefined}\n' +
290+ ' */\n' +
291+ 'function funcName(flag) {\n' +
292+ ' if (flag) {\n' +
293+ ' return [];\n' +
294+ ' }\n' +
295+ ' return {q: 1};\n' +
296+ '}\n'
297+ ) . getErrorCount ( ) === 2
298+ ) ;
299+ } ) ;
300+
301+ } ) ;
302+
232303} ) ;
0 commit comments