@blumintinc/eslint-plugin-blumint 1.20.122 → 1.20.123
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.
- package/lib/index.js +1 -1
- package/lib/rules/enforce-mock-firestore.js +42 -15
- package/package.json +1 -1
- package/release-manifest.json +14 -0
package/lib/index.js
CHANGED
|
@@ -8,6 +8,36 @@ const FIRESTORE_PATHS = [
|
|
|
8
8
|
'firebase-admin',
|
|
9
9
|
'firebase-admin/firestore',
|
|
10
10
|
];
|
|
11
|
+
/**
|
|
12
|
+
* A `jest.mock` factory produces the same module shape whether it is written as
|
|
13
|
+
* a concise arrow, a block-bodied arrow, or a `function` expression. Matching
|
|
14
|
+
* the factory argument itself would only ever see the concise arrow, letting an
|
|
15
|
+
* identical mock evade the rule on a body-form choice alone. Resolving to the
|
|
16
|
+
* produced object keeps every spelling on one matching path.
|
|
17
|
+
*
|
|
18
|
+
* A body with more than a lone `return` is deliberately unresolved: the object
|
|
19
|
+
* reaching the caller can no longer be read off a single expression.
|
|
20
|
+
*/
|
|
21
|
+
const resolveFactoryReturn = (factory) => {
|
|
22
|
+
if (!factory ||
|
|
23
|
+
(factory.type !== utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
|
24
|
+
factory.type !== utils_1.AST_NODE_TYPES.FunctionExpression)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
// A concise arrow body is the produced expression itself. Parentheses around
|
|
28
|
+
// an object body are not part of the AST, so the node is matched directly.
|
|
29
|
+
if (factory.body.type !== utils_1.AST_NODE_TYPES.BlockStatement) {
|
|
30
|
+
return factory.body;
|
|
31
|
+
}
|
|
32
|
+
const statements = factory.body.body;
|
|
33
|
+
if (statements.length !== 1) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const [statement] = statements;
|
|
37
|
+
return statement.type === utils_1.AST_NODE_TYPES.ReturnStatement
|
|
38
|
+
? statement.argument ?? undefined
|
|
39
|
+
: undefined;
|
|
40
|
+
};
|
|
11
41
|
exports.enforceFirestoreMock = (0, createRule_1.createRule)({
|
|
12
42
|
name: 'enforce-mock-firestore',
|
|
13
43
|
meta: {
|
|
@@ -39,21 +69,18 @@ exports.enforceFirestoreMock = (0, createRule_1.createRule)({
|
|
|
39
69
|
typeof node.arguments[0].value === 'string' &&
|
|
40
70
|
node.arguments[0].value?.includes(path))) {
|
|
41
71
|
// Check if the mock includes Firestore-related properties
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
prop.key.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
messageId: 'noManualFirestoreMock',
|
|
55
|
-
});
|
|
56
|
-
}
|
|
72
|
+
const mockedModule = resolveFactoryReturn(node.arguments[1]);
|
|
73
|
+
if (mockedModule &&
|
|
74
|
+
mockedModule.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
75
|
+
mockedModule.properties.some((prop) => prop.type === utils_1.AST_NODE_TYPES.Property &&
|
|
76
|
+
prop.key.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
77
|
+
(prop.key.name === 'db' ||
|
|
78
|
+
prop.key.name === 'firestore' ||
|
|
79
|
+
prop.key.name === 'getFirestore'))) {
|
|
80
|
+
context.report({
|
|
81
|
+
node,
|
|
82
|
+
messageId: 'noManualFirestoreMock',
|
|
83
|
+
});
|
|
57
84
|
}
|
|
58
85
|
}
|
|
59
86
|
},
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.123",
|
|
4
|
+
"date": "2026-08-06T11:53:46.588Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "enforce-mock-firestore",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1798
|
|
11
|
+
],
|
|
12
|
+
"summary": "resolve the jest.mock factory's returned object in every body form (closes #1798)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.20.122",
|
|
4
18
|
"date": "2026-08-06T11:06:53.595Z",
|