eslint-plugin-react-hooks-extra 1.7.0 → 1.7.1-beta.1

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/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var R__namespace = /*#__PURE__*/_interopNamespace(R);
30
30
 
31
31
  // package.json
32
32
  var name = "eslint-plugin-react-hooks-extra";
33
- var version = "1.7.0";
33
+ var version = "1.7.1-beta.1";
34
34
  var createRule = shared.createRuleForPlugin("hooks-extra");
35
35
  function isFromUseStateCall(context, useStateAlias) {
36
36
  return (topLevelId) => {
@@ -233,30 +233,39 @@ var z = class _z {
233
233
  // src/utils/is-set-state-call.ts
234
234
  function isSetStateCall(context, useStateAlias) {
235
235
  return (node) => {
236
- const topLevelId = $(node.callee).with({ type: ast.NodeType.Identifier }, tools.O.some).with({ type: ast.NodeType.MemberExpression }, (n2) => {
237
- if (!("name" in n2.object)) return tools.O.none();
238
- const initialScope = context.sourceCode.getScope(n2);
239
- const property = astUtils.getStaticValue(n2.property, initialScope);
240
- if (property?.value === 1) return tools.O.fromNullable(n2.object);
241
- return tools.O.none();
242
- }).with({ type: ast.NodeType.CallExpression }, (n2) => {
243
- if (!ast.is(ast.NodeType.MemberExpression)(n2.callee)) return tools.O.none();
244
- if (!("name" in n2.callee.object)) return tools.O.none();
245
- const isAt = a({
246
- type: ast.NodeType.MemberExpression,
247
- property: {
248
- type: ast.NodeType.Identifier,
249
- name: "at"
250
- }
251
- }, n2.callee);
252
- const [index] = n2.arguments;
253
- if (!isAt || !index) return tools.O.none();
254
- const initialScope = context.sourceCode.getScope(n2);
255
- const value = astUtils.getStaticValue(index, initialScope);
256
- if (value?.value === 1) return tools.O.fromNullable(n2.callee.object);
257
- return tools.O.none();
258
- }).otherwise(tools.O.none);
259
- return tools.O.exists(topLevelId, isFromUseStateCall(context, useStateAlias));
236
+ switch (node.callee.type) {
237
+ case ast.NodeType.Identifier: {
238
+ return isFromUseStateCall(context, useStateAlias)(node.callee);
239
+ }
240
+ case ast.NodeType.MemberExpression: {
241
+ if (!("name" in node.callee.object)) return false;
242
+ const initialScope = context.sourceCode.getScope(node);
243
+ const property = astUtils.getStaticValue(node.callee.property, initialScope);
244
+ if (property?.value === 1) return isFromUseStateCall(context, useStateAlias)(node.callee.object);
245
+ return false;
246
+ }
247
+ case ast.NodeType.CallExpression: {
248
+ const callee = node.callee.callee;
249
+ if (callee.type !== ast.NodeType.MemberExpression) return false;
250
+ if (!("name" in callee.object)) return false;
251
+ const isAt = a({
252
+ type: ast.NodeType.MemberExpression,
253
+ property: {
254
+ type: ast.NodeType.Identifier,
255
+ name: "at"
256
+ }
257
+ }, callee);
258
+ const [index] = node.callee.arguments;
259
+ if (!isAt || !index) return false;
260
+ const initialScope = context.sourceCode.getScope(node);
261
+ const value = astUtils.getStaticValue(index, initialScope);
262
+ if (value?.value === 1) return isFromUseStateCall(context, useStateAlias)(callee.object);
263
+ return false;
264
+ }
265
+ default: {
266
+ return false;
267
+ }
268
+ }
260
269
  };
261
270
  }
262
271
  function isThenCall(node) {
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import * as R from 'remeda';
8
8
 
9
9
  // package.json
10
10
  var name = "eslint-plugin-react-hooks-extra";
11
- var version = "1.7.0";
11
+ var version = "1.7.1-beta.1";
12
12
  var createRule = createRuleForPlugin("hooks-extra");
13
13
  function isFromUseStateCall(context, useStateAlias) {
14
14
  return (topLevelId) => {
@@ -211,30 +211,39 @@ var z = class _z {
211
211
  // src/utils/is-set-state-call.ts
212
212
  function isSetStateCall(context, useStateAlias) {
213
213
  return (node) => {
214
- const topLevelId = $(node.callee).with({ type: NodeType.Identifier }, O.some).with({ type: NodeType.MemberExpression }, (n2) => {
215
- if (!("name" in n2.object)) return O.none();
216
- const initialScope = context.sourceCode.getScope(n2);
217
- const property = getStaticValue(n2.property, initialScope);
218
- if (property?.value === 1) return O.fromNullable(n2.object);
219
- return O.none();
220
- }).with({ type: NodeType.CallExpression }, (n2) => {
221
- if (!is(NodeType.MemberExpression)(n2.callee)) return O.none();
222
- if (!("name" in n2.callee.object)) return O.none();
223
- const isAt = a({
224
- type: NodeType.MemberExpression,
225
- property: {
226
- type: NodeType.Identifier,
227
- name: "at"
228
- }
229
- }, n2.callee);
230
- const [index] = n2.arguments;
231
- if (!isAt || !index) return O.none();
232
- const initialScope = context.sourceCode.getScope(n2);
233
- const value = getStaticValue(index, initialScope);
234
- if (value?.value === 1) return O.fromNullable(n2.callee.object);
235
- return O.none();
236
- }).otherwise(O.none);
237
- return O.exists(topLevelId, isFromUseStateCall(context, useStateAlias));
214
+ switch (node.callee.type) {
215
+ case NodeType.Identifier: {
216
+ return isFromUseStateCall(context, useStateAlias)(node.callee);
217
+ }
218
+ case NodeType.MemberExpression: {
219
+ if (!("name" in node.callee.object)) return false;
220
+ const initialScope = context.sourceCode.getScope(node);
221
+ const property = getStaticValue(node.callee.property, initialScope);
222
+ if (property?.value === 1) return isFromUseStateCall(context, useStateAlias)(node.callee.object);
223
+ return false;
224
+ }
225
+ case NodeType.CallExpression: {
226
+ const callee = node.callee.callee;
227
+ if (callee.type !== NodeType.MemberExpression) return false;
228
+ if (!("name" in callee.object)) return false;
229
+ const isAt = a({
230
+ type: NodeType.MemberExpression,
231
+ property: {
232
+ type: NodeType.Identifier,
233
+ name: "at"
234
+ }
235
+ }, callee);
236
+ const [index] = node.callee.arguments;
237
+ if (!isAt || !index) return false;
238
+ const initialScope = context.sourceCode.getScope(node);
239
+ const value = getStaticValue(index, initialScope);
240
+ if (value?.value === 1) return isFromUseStateCall(context, useStateAlias)(callee.object);
241
+ return false;
242
+ }
243
+ default: {
244
+ return false;
245
+ }
246
+ }
238
247
  };
239
248
  }
240
249
  function isThenCall(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.7.0",
3
+ "version": "1.7.1-beta.1",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -40,13 +40,13 @@
40
40
  "@typescript-eslint/types": "^7.18.0",
41
41
  "@typescript-eslint/utils": "^7.18.0",
42
42
  "remeda": "^2.6.0",
43
- "@eslint-react/ast": "1.7.0",
44
- "@eslint-react/core": "1.7.0",
45
- "@eslint-react/jsx": "1.7.0",
46
- "@eslint-react/tools": "1.7.0",
47
- "@eslint-react/shared": "1.7.0",
48
- "@eslint-react/types": "1.7.0",
49
- "@eslint-react/var": "1.7.0"
43
+ "@eslint-react/ast": "1.7.1-beta.1",
44
+ "@eslint-react/jsx": "1.7.1-beta.1",
45
+ "@eslint-react/core": "1.7.1-beta.1",
46
+ "@eslint-react/shared": "1.7.1-beta.1",
47
+ "@eslint-react/tools": "1.7.1-beta.1",
48
+ "@eslint-react/var": "1.7.1-beta.1",
49
+ "@eslint-react/types": "1.7.1-beta.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/react": "^18.3.3",