@blumintinc/eslint-plugin-blumint 0.1.19 → 0.1.21
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/dynamic-https-errors.js +1 -1
- package/lib/rules/require-memo.js +23 -17
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ exports.dynamicHttpsErrors = (0, createRule_1.createRule)({
|
|
|
25
25
|
},
|
|
26
26
|
schema: [],
|
|
27
27
|
messages: {
|
|
28
|
-
dynamicHttpsErrors: 'Found dynamic error details in the "message" field. Move any dynamic details third argument.',
|
|
28
|
+
dynamicHttpsErrors: 'Found dynamic error details in the second argument of the HttpsError constructor - the "message" field. This field is hashed to produce a unique id for error monitoring. Move any dynamic details to the third argument - the "details" field - to preserve the unique id and to monitor the error correctly.',
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
defaultOptions: [],
|
|
@@ -24,35 +24,41 @@ function isHigherOrderFunctionReturningJSX(node) {
|
|
|
24
24
|
}
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
|
+
const isUnmemoizedArrowFunction = (parentNode) => {
|
|
28
|
+
return (parentNode.type === 'VariableDeclarator' &&
|
|
29
|
+
parentNode.id.type === 'Identifier' &&
|
|
30
|
+
!isComponentExplicitlyUnmemoized(parentNode.id.name));
|
|
31
|
+
};
|
|
32
|
+
const isUnmemoizedFunctionComponent = (parentNode, node) => {
|
|
33
|
+
return (node.type === 'FunctionDeclaration' &&
|
|
34
|
+
parentNode.type === 'Program' &&
|
|
35
|
+
node.id &&
|
|
36
|
+
!isComponentExplicitlyUnmemoized(node.id.name));
|
|
37
|
+
};
|
|
38
|
+
const isUnmemoizedExportedFunctionComponent = (parentNode, node) => {
|
|
39
|
+
return (node.type === 'FunctionDeclaration' &&
|
|
40
|
+
parentNode.type === 'ExportNamedDeclaration' &&
|
|
41
|
+
node.id &&
|
|
42
|
+
!isComponentExplicitlyUnmemoized(node.id.name));
|
|
43
|
+
};
|
|
27
44
|
function checkFunction(context, node) {
|
|
28
45
|
const fileName = context.getFilename();
|
|
29
46
|
if (!fileName.endsWith('.tsx')) {
|
|
30
47
|
return;
|
|
31
48
|
}
|
|
32
49
|
if (isHigherOrderFunctionReturningJSX(node)) {
|
|
33
|
-
console.log('Found HOF');
|
|
34
50
|
return;
|
|
35
51
|
}
|
|
36
|
-
const
|
|
52
|
+
const parentNode = node.parent;
|
|
37
53
|
if (node.parent.type === 'CallExpression') {
|
|
38
54
|
return;
|
|
39
55
|
}
|
|
40
|
-
// while (currentNode.type === 'CallExpression') {
|
|
41
|
-
// if (isMemoCallExpression(currentNode) || true) {
|
|
42
|
-
// return;
|
|
43
|
-
// }
|
|
44
|
-
// currentNode = currentNode.parent;
|
|
45
|
-
// }
|
|
46
56
|
if (ASTHelpers_1.ASTHelpers.returnsJSX(node.body) && ASTHelpers_1.ASTHelpers.hasParameters(node)) {
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
else if (node.type === 'FunctionDeclaration' &&
|
|
53
|
-
currentNode.type === 'Program' &&
|
|
54
|
-
node.id &&
|
|
55
|
-
!isComponentExplicitlyUnmemoized(node.id.name)) {
|
|
57
|
+
if ([
|
|
58
|
+
isUnmemoizedArrowFunction,
|
|
59
|
+
isUnmemoizedFunctionComponent,
|
|
60
|
+
isUnmemoizedExportedFunctionComponent,
|
|
61
|
+
].some((fn) => fn(parentNode, node))) {
|
|
56
62
|
context.report({ node, messageId: 'requireMemo' });
|
|
57
63
|
}
|
|
58
64
|
}
|