eslint-plugin-jest 28.13.0 → 28.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -26,6 +26,19 @@ function matchesAssertFunctionName(nodeName, patterns) {
|
|
|
26
26
|
return x.replace(/\*/gu, '[a-z\\d]*');
|
|
27
27
|
}).join('\\.')}(\\.|$)`, 'ui').test(nodeName));
|
|
28
28
|
}
|
|
29
|
+
function getLastStatement(fn) {
|
|
30
|
+
if (fn.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
31
|
+
if (fn.body.body.length === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const lastStatement = fn.body.body[fn.body.body.length - 1];
|
|
35
|
+
if (lastStatement.type === _utils.AST_NODE_TYPES.ExpressionStatement) {
|
|
36
|
+
return lastStatement.expression;
|
|
37
|
+
}
|
|
38
|
+
return lastStatement;
|
|
39
|
+
}
|
|
40
|
+
return fn.body;
|
|
41
|
+
}
|
|
29
42
|
var _default = exports.default = (0, _utils2.createRule)({
|
|
30
43
|
name: __filename,
|
|
31
44
|
meta: {
|
|
@@ -63,19 +76,6 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
63
76
|
assertFunctionNames = ['expect'],
|
|
64
77
|
additionalTestBlockFunctions = []
|
|
65
78
|
}]) {
|
|
66
|
-
function getLastStatement(fn) {
|
|
67
|
-
if (fn.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
68
|
-
if (fn.body.body.length === 0) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const lastStatement = fn.body.body[fn.body.body.length - 1];
|
|
72
|
-
if (lastStatement.type === _utils.AST_NODE_TYPES.ExpressionStatement) {
|
|
73
|
-
return lastStatement.expression;
|
|
74
|
-
}
|
|
75
|
-
return lastStatement;
|
|
76
|
-
}
|
|
77
|
-
return fn.body;
|
|
78
|
-
}
|
|
79
79
|
return {
|
|
80
80
|
CallExpression(node) {
|
|
81
81
|
const name = (0, _utils2.getNodeName)(node.callee) ?? '';
|
|
@@ -85,7 +85,10 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
85
85
|
if (node.arguments.length < 2 || !(0, _utils2.isFunction)(node.arguments[1])) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
let lastStatement = getLastStatement(node.arguments[1]);
|
|
89
|
+
if (lastStatement?.type === _utils.AST_NODE_TYPES.AwaitExpression) {
|
|
90
|
+
lastStatement = lastStatement.argument;
|
|
91
|
+
}
|
|
89
92
|
if (lastStatement?.type === _utils.AST_NODE_TYPES.CallExpression && ((0, _utils2.isTypeOfJestFnCall)(lastStatement, context, ['expect']) || matchesAssertFunctionName((0, _utils2.getNodeName)(lastStatement.callee), assertFunctionNames))) {
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
@@ -80,7 +80,12 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
80
80
|
if (importNode?.type === _utils.AST_NODE_TYPES.ImportDeclaration) {
|
|
81
81
|
for (const specifier of importNode.specifiers) {
|
|
82
82
|
if (specifier.type === _utils.AST_NODE_TYPES.ImportSpecifier && specifier.imported?.name) {
|
|
83
|
-
|
|
83
|
+
let importName = specifier.imported.name;
|
|
84
|
+
const local = (0, _utils2.getAccessorValue)(specifier.local);
|
|
85
|
+
if (local !== importName) {
|
|
86
|
+
importName = `${importName} as ${local}`;
|
|
87
|
+
}
|
|
88
|
+
functionsToImport.add(importName);
|
|
84
89
|
}
|
|
85
90
|
if (specifier.type === _utils.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
86
91
|
functionsToImport.add(specifier.local.name);
|