File tree Expand file tree Collapse file tree 1 file changed +18
-18
lines changed Expand file tree Collapse file tree 1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,24 @@ function matchesAssertFunctionName(
4040 ) ;
4141}
4242
43+ function getLastStatement ( fn : FunctionExpression ) : TSESTree . Node | null {
44+ if ( fn . body . type === AST_NODE_TYPES . BlockStatement ) {
45+ if ( fn . body . body . length === 0 ) {
46+ return null ;
47+ }
48+
49+ const lastStatement = fn . body . body [ fn . body . body . length - 1 ] ;
50+
51+ if ( lastStatement . type === AST_NODE_TYPES . ExpressionStatement ) {
52+ return lastStatement . expression ;
53+ }
54+
55+ return lastStatement ;
56+ }
57+
58+ return fn . body ;
59+ }
60+
4361export default createRule <
4462 [
4563 Partial < {
@@ -85,24 +103,6 @@ export default createRule<
85103 context ,
86104 [ { assertFunctionNames = [ 'expect' ] , additionalTestBlockFunctions = [ ] } ] ,
87105 ) {
88- function getLastStatement ( fn : FunctionExpression ) : TSESTree . Node | null {
89- if ( fn . body . type === AST_NODE_TYPES . BlockStatement ) {
90- if ( fn . body . body . length === 0 ) {
91- return null ;
92- }
93-
94- const lastStatement = fn . body . body [ fn . body . body . length - 1 ] ;
95-
96- if ( lastStatement . type === AST_NODE_TYPES . ExpressionStatement ) {
97- return lastStatement . expression ;
98- }
99-
100- return lastStatement ;
101- }
102-
103- return fn . body ;
104- }
105-
106106 return {
107107 CallExpression ( node ) {
108108 const name = getNodeName ( node . callee ) ?? '' ;
You can’t perform that action at this time.
0 commit comments