File tree Expand file tree Collapse file tree 5 files changed +100
-3
lines changed
Expand file tree Collapse file tree 5 files changed +100
-3
lines changed Original file line number Diff line number Diff line change @@ -47,3 +47,13 @@ const lol = () => {
4747 } catch { }
4848} ;
4949lol ( ) ;
50+
51+ function factory ( ) {
52+ /**
53+ * @throws {Error }
54+ */
55+ return function ( ) {
56+ throw new Error ( ) ;
57+ }
58+ }
59+ factory ( ) ;
Original file line number Diff line number Diff line change @@ -33,3 +33,10 @@ const lol = () => {
3333 console . log ( egg . ham . spam ) ;
3434} ;
3535lol ( ) ;
36+
37+ function factory ( ) {
38+ return function ( ) {
39+ throw new Error ( ) ;
40+ }
41+ }
42+ factory ( ) ;
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ module.exports = createRule({
7575 const isCommented =
7676 comments . length &&
7777 comments
78- . map ( ( { value } ) => value )
79- . some ( hasThrowsTag ) ;
78+ . map ( ( { value } ) => value )
79+ . some ( hasThrowsTag ) ;
8080
8181 /** @type {import('typescript').Type[] } */
8282 const throwTypes = throwStatementNodes
@@ -176,11 +176,13 @@ module.exports = createRule({
176176 'VariableDeclaration > VariableDeclarator[id.type="Identifier"] > ArrowFunctionExpression:exit' : visitOnExit ,
177177 'Property > ArrowFunctionExpression:exit' : visitOnExit ,
178178 'PropertyDefinition > ArrowFunctionExpression:exit' : visitOnExit ,
179+ 'ReturnStatement > ArrowFunctionExpression:exit' : visitOnExit ,
179180
180181 'VariableDeclaration > VariableDeclarator[id.type="Identifier"] > FunctionExpression:exit' : visitOnExit ,
181182 'Property > FunctionExpression:exit' : visitOnExit ,
182183 'PropertyDefinition > FunctionExpression:exit' : visitOnExit ,
183184 'MethodDefinition > FunctionExpression:exit' : visitOnExit ,
185+ 'ReturnStatement > FunctionExpression:exit' : visitOnExit ,
184186 } ;
185187 } ,
186188} ) ;
Original file line number Diff line number Diff line change @@ -568,6 +568,74 @@ ruleTester.run(
568568 { messageId : 'missingThrowsTag' } ,
569569 ] ,
570570 } ,
571+ {
572+ code : `
573+ function factory() {
574+ return function () {
575+ throw new Error();
576+ }
577+ }
578+ ` ,
579+ output : `
580+ function factory() {
581+ /**
582+ * @throws {Error}
583+ */
584+ return function () {
585+ throw new Error();
586+ }
587+ }
588+ ` ,
589+ errors : [
590+ { messageId : 'missingThrowsTag' } ,
591+ ] ,
592+ } ,
593+ {
594+ code : `
595+ function factory() {
596+ return () => {
597+ throw new Error();
598+ }
599+ }
600+ ` ,
601+ output : `
602+ function factory() {
603+ /**
604+ * @throws {Error}
605+ */
606+ return () => {
607+ throw new Error();
608+ }
609+ }
610+ ` ,
611+ errors : [
612+ { messageId : 'missingThrowsTag' } ,
613+ ] ,
614+ } ,
615+ {
616+ code : `
617+ function factory() {
618+ function inner() {
619+ throw new Error();
620+ }
621+ return inner;
622+ }
623+ ` ,
624+ output : `
625+ function factory() {
626+ /**
627+ * @throws {Error}
628+ */
629+ function inner() {
630+ throw new Error();
631+ }
632+ return inner;
633+ }
634+ ` ,
635+ errors : [
636+ { messageId : 'missingThrowsTag' } ,
637+ ] ,
638+ } ,
571639 ] ,
572640 } ,
573641) ;
Original file line number Diff line number Diff line change @@ -239,7 +239,17 @@ const findNodeToComment = (node) => {
239239 * const target = () => { ... };
240240 * ```
241241 */
242- findParent ( node , ( n ) => n . type === AST_NODE_TYPES . VariableDeclaration )
242+ findParent ( node , ( n ) => n . type === AST_NODE_TYPES . VariableDeclaration ) ??
243+ /**
244+ * @example
245+ * ```
246+ * function factory() {
247+ * // here
248+ * return function target() { ... };
249+ * }
250+ * ```
251+ */
252+ findParent ( node , ( n ) => n . type === AST_NODE_TYPES . ReturnStatement )
243253 ) ;
244254 default :
245255 break ;
You can’t perform that action at this time.
0 commit comments