Skip to content

Commit 2635b76

Browse files
authored
refactor(prefer-ending-with-an-expect): move function definition out of rule creation (#1751)
1 parent 1250371 commit 2635b76

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/rules/prefer-ending-with-an-expect.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff 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+
4361
export 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) ?? '';

0 commit comments

Comments
 (0)