@blumintinc/eslint-plugin-blumint 0.1.15 → 0.1.17

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.
@@ -2,14 +2,14 @@
2
2
 
3
3
  <!-- end auto-generated rule header -->
4
4
 
5
- This rule enforces that React components (that are not pure) to be memoized.
5
+ This rule enforces that React components (that are not pure) to be memoized. If the component name includes "Unmemoized", then this rule is ignored.
6
6
 
7
7
  ## Rule Details
8
8
 
9
9
  Examples of **incorrect** code for this rule:
10
10
 
11
11
  ```jsx
12
- const UnmemoizedComponent = ({foo, bar}) => return (
12
+ const Component = ({foo, bar}) => return (
13
13
  <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
14
14
  )
15
15
  ```
@@ -17,10 +17,13 @@ const UnmemoizedComponent = ({foo, bar}) => return (
17
17
  Examples of **correct** code for this rule:
18
18
 
19
19
  ```jsx
20
- const MemoizedComponent = memo(function UnmemoizedComponent({foo, bar}) {
20
+ const MemoizedComponent = memo(function BigComponent({foo, bar}) {
21
21
  return (
22
22
  <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
23
23
  )
24
24
  })
25
+ const ComponentUnmemoized = ({foo, bar}) => return (
26
+ <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
27
+ )
25
28
  ```
26
29
 
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ const require_memo_1 = require("./rules/require-memo");
17
17
  module.exports = {
18
18
  meta: {
19
19
  name: '@blumintinc/eslint-plugin-blumint',
20
- version: '0.1.15',
20
+ version: '0.1.17',
21
21
  },
22
22
  parseOptions: {
23
23
  ecmaVersion: 2020,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireMemo = void 0;
4
4
  const ASTHelpers_1 = require("../utils/ASTHelpers");
5
+ const isComponentExplicitlyUnmemoized = (componentName) => componentName.toLowerCase().includes('unmemoized');
5
6
  function isMemoCallExpression(node) {
6
7
  if (node.type !== 'CallExpression')
7
8
  return false;
@@ -46,12 +47,14 @@ function checkFunction(context, node) {
46
47
  }
47
48
  if (ASTHelpers_1.ASTHelpers.returnsJSX(node.body) && ASTHelpers_1.ASTHelpers.hasParameters(node)) {
48
49
  if (currentNode.type === 'VariableDeclarator' &&
49
- currentNode.id.type === 'Identifier') {
50
+ currentNode.id.type === 'Identifier' &&
51
+ !isComponentExplicitlyUnmemoized(currentNode.id.name)) {
50
52
  context.report({ node, messageId: 'requireMemo' });
51
53
  }
52
54
  else if (node.type === 'FunctionDeclaration' &&
53
55
  currentNode.type === 'Program' &&
54
- node.id) {
56
+ node.id &&
57
+ !isComponentExplicitlyUnmemoized(node.id.name)) {
55
58
  context.report({ node, messageId: 'requireMemo' });
56
59
  }
57
60
  }
@@ -143,13 +143,14 @@ class ASTHelpers {
143
143
  return false;
144
144
  }
145
145
  static returnsJSX(node) {
146
- if (node.type === 'JSXElement') {
146
+ if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
147
147
  return true;
148
148
  }
149
149
  if (node.type === 'BlockStatement') {
150
150
  for (const statement of node.body) {
151
151
  if (statement.type === 'ReturnStatement' &&
152
- statement.argument?.type === 'JSXElement') {
152
+ (statement.argument?.type === 'JSXElement' ||
153
+ statement.argument?.type === 'JSXFragment')) {
153
154
  return true;
154
155
  }
155
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Custom eslint rules for use at BluMint",
5
5
  "keywords": [
6
6
  "eslint",