@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 CHANGED
@@ -18,7 +18,7 @@ const require_memo_1 = require("./rules/require-memo");
18
18
  module.exports = {
19
19
  meta: {
20
20
  name: '@blumintinc/eslint-plugin-blumint',
21
- version: '0.1.19',
21
+ version: '0.1.21',
22
22
  },
23
23
  parseOptions: {
24
24
  ecmaVersion: 2020,
@@ -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 currentNode = node.parent;
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 (currentNode.type === 'VariableDeclarator' &&
48
- currentNode.id.type === 'Identifier' &&
49
- !isComponentExplicitlyUnmemoized(currentNode.id.name)) {
50
- context.report({ node, messageId: 'requireMemo' });
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Custom eslint rules for use at BluMint",
5
5
  "keywords": [
6
6
  "eslint",