File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -2257,6 +2257,12 @@ function quux (foo) {
22572257}
22582258// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
22592259// Message: Present JSDoc @return declaration but not available return expression in function.
2260+
2261+ /**
2262+ * @returns
2263+ */
2264+ const quux = () => {}
2265+ // Message: Present JSDoc @returns declaration but not available return expression in function.
22602266````
22612267
22622268The following patterns are not considered problems:
@@ -2291,6 +2297,11 @@ function quux () {
22912297 */
22922298function quux () {
22932299}
2300+
2301+ /**
2302+ * @returns {*} Foo.
2303+ */
2304+ const quux = () => foo;
22942305````
22952306
22962307
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import iterateJsdoc from '../iterateJsdoc';
44export default iterateJsdoc ( ( {
55 jsdoc,
66 report,
7+ functionNode,
78 utils
89} ) => {
910 const targetTagName = utils . getPreferredTagName ( 'returns' ) ;
@@ -18,6 +19,11 @@ export default iterateJsdoc(({
1819 return [ 'undefined' , 'void' ] . indexOf ( vundef . type ) !== - 1 ;
1920 } ) === - 1 ;
2021
22+ // Implicit return like `() => foo` is ok
23+ if ( functionNode . type === 'ArrowFunctionExpression' && functionNode . expression ) {
24+ return ;
25+ }
26+
2127 if ( JSON . stringify ( jsdocTags ) !== '[]' && voidReturn && sourcecode . indexOf ( 'return' ) < 1 ) {
2228 report ( 'Present JSDoc @' + targetTagName + ' declaration but not available return expression in function.' ) ;
2329 }
Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ export default {
3838 }
3939 }
4040 }
41+ } ,
42+ {
43+ code : `
44+ /**
45+ * @returns
46+ */
47+ const quux = () => {}
48+ ` ,
49+ errors : [
50+ {
51+ line : 2 ,
52+ message : 'Present JSDoc @returns declaration but not available return expression in function.'
53+ }
54+ ]
4155 }
4256 ] ,
4357 valid : [
@@ -82,6 +96,14 @@ export default {
8296 function quux () {
8397 }
8498 `
99+ } ,
100+ {
101+ code : `
102+ /**
103+ * @returns {*} Foo.
104+ */
105+ const quux = () => foo;
106+ `
85107 }
86108 ]
87109} ;
You can’t perform that action at this time.
0 commit comments