@eslint-react/core 1.23.3-next.5 → 1.23.3-next.7

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
@@ -135,10 +135,10 @@ function isCallFromReactMember(pragmaMemberName, name) {
135
135
 
136
136
  // src/utils/is-react-api.ts
137
137
  function isReactAPIWithName(name, member) {
138
- return member ? isFromReactMember(name, member) : isFromReact(name);
138
+ return member == null ? isFromReact(name) : isFromReactMember(name, member);
139
139
  }
140
140
  function isReactAPICallWithName(name, member) {
141
- return member ? isCallFromReactMember(name, member) : isCallFromReact(name);
141
+ return member == null ? isCallFromReact(name) : isCallFromReactMember(name, member);
142
142
  }
143
143
  var isChildrenCount = isReactAPIWithName("Children", "count");
144
144
  var isChildrenForEach = isReactAPIWithName("Children", "forEach");
@@ -325,7 +325,7 @@ function useHookCollector() {
325
325
  return;
326
326
  }
327
327
  const [fNode, hookId] = fStack.at(-1) ?? [];
328
- if (!fNode || !hookId) {
328
+ if (fNode == null || hookId == null) {
329
329
  return;
330
330
  }
331
331
  eff.F.pipe(
@@ -409,10 +409,10 @@ function getComponentNameFromIdentifier(node) {
409
409
  return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
410
410
  }
411
411
  function isComponentName(name) {
412
- return !!name && RE_COMPONENT_NAME.test(name);
412
+ return RE_COMPONENT_NAME.test(name);
413
413
  }
414
414
  function isClassComponent(node) {
415
- if ("superClass" in node && node.superClass) {
415
+ if ("superClass" in node && node.superClass != null) {
416
416
  const re = /^(?:Pure)?Component$/u;
417
417
  switch (true) {
418
418
  case node.superClass.type === types$1.AST_NODE_TYPES.Identifier:
@@ -424,7 +424,7 @@ function isClassComponent(node) {
424
424
  return false;
425
425
  }
426
426
  function isPureComponent(node) {
427
- if ("superClass" in node && node.superClass) {
427
+ if ("superClass" in node && node.superClass != null) {
428
428
  const re = /^PureComponent$/u;
429
429
  switch (true) {
430
430
  case node.superClass.type === types$1.AST_NODE_TYPES.Identifier:
@@ -456,7 +456,7 @@ function hasNoneOrValidComponentName(node, context) {
456
456
  }
457
457
  const id2 = mbIdentifier.value;
458
458
  const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
459
- return !!name && isComponentName(name);
459
+ return name != null && isComponentName(name);
460
460
  }
461
461
 
462
462
  // src/component/component-collector.ts
@@ -515,7 +515,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
515
515
  return functionEntries.pop();
516
516
  }
517
517
  const shouldDrop = AST8__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
518
- return context.sourceCode.getScope(r).block === entry.node && r.argument !== null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
518
+ return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
519
519
  });
520
520
  if (shouldDrop) {
521
521
  components.delete(entry.key);
@@ -570,7 +570,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
570
570
  }
571
571
  const componentName = mbComponentName.value;
572
572
  const component = Array.from(components.values()).findLast(({ name }) => eff.O.exists(name, (n) => n === componentName));
573
- if (!component) {
573
+ if (component == null) {
574
574
  return;
575
575
  }
576
576
  components.set(component._, {
@@ -662,16 +662,15 @@ function isSetupFunction(node) {
662
662
  return node.parent?.type === types$1.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types$1.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
663
663
  }
664
664
  function isCleanupFunction(node) {
665
- const nearestRet = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types$1.AST_NODE_TYPES.ReturnStatement)));
666
- if (!nearestRet) {
667
- return false;
668
- }
669
- const nearestFunction = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(node, AST8__namespace.isFunction));
670
- const nearestFunctionOfRet = eff.O.getOrNull(AST8__namespace.findParentNodeGuard(nearestRet, AST8__namespace.isFunction));
671
- if (!nearestFunction || !nearestFunctionOfRet) {
672
- return false;
673
- }
674
- return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
665
+ return eff.F.pipe(
666
+ eff.O.Do,
667
+ eff.O.bind("nearReturn", () => AST8__namespace.findParentNodeGuard(node, AST8__namespace.is(types$1.AST_NODE_TYPES.ReturnStatement))),
668
+ eff.O.bind("nearFunction", () => AST8__namespace.findParentNodeGuard(node, AST8__namespace.isFunction)),
669
+ eff.O.bind("nearFunctionOfReturn", ({ nearReturn }) => AST8__namespace.findParentNodeGuard(nearReturn, AST8__namespace.isFunction)),
670
+ eff.O.exists(
671
+ ({ nearFunction, nearFunctionOfReturn }) => nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction)
672
+ )
673
+ );
675
674
  }
676
675
  function isComponentDidMount(node) {
677
676
  return AST8__namespace.isOneOf([types$1.AST_NODE_TYPES.MethodDefinition, types$1.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types$1.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
@@ -691,14 +690,10 @@ var ERPhaseRelevance = types.birecord({
691
690
  });
692
691
  var isInversePhase = eff.F.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
693
692
  function isDirectValueOfRenderPropertyLoose(node) {
694
- const matching = tsPattern.isMatching({
695
- key: {
696
- type: types$1.AST_NODE_TYPES.Identifier,
697
- name: tsPattern.P.string.startsWith("render")
698
- },
699
- type: types$1.AST_NODE_TYPES.Property
700
- });
701
- return matching(node) || matching(node.parent);
693
+ const matching = (node2) => {
694
+ return node2.type === types$1.AST_NODE_TYPES.Property && node2.key.type === types$1.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
695
+ };
696
+ return matching(node) || node.parent != null && matching(node.parent);
702
697
  }
703
698
  function isDeclaredInRenderPropLoose(node) {
704
699
  if (isDirectValueOfRenderPropertyLoose(node)) {
@@ -709,10 +704,9 @@ function isDeclaredInRenderPropLoose(node) {
709
704
  eff.O.flatMapNullable((c) => c.parent),
710
705
  eff.O.filter(AST8__namespace.is(types$1.AST_NODE_TYPES.JSXAttribute)),
711
706
  eff.O.flatMapNullable((a) => a.name),
712
- eff.O.exists(tsPattern.isMatching({
713
- type: types$1.AST_NODE_TYPES.JSXIdentifier,
714
- name: tsPattern.P.string.startsWith("render")
715
- }))
707
+ eff.O.exists(
708
+ (n) => n.type === types$1.AST_NODE_TYPES.JSXIdentifier && n.name.startsWith("render")
709
+ )
716
710
  );
717
711
  }
718
712
  function isRenderFunctionLoose(node, context) {
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import * as AST8 from '@eslint-react/ast';
2
2
  import { F, isString, O } from '@eslint-react/eff';
3
3
  import * as JSX4 from '@eslint-react/jsx';
4
4
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
- import { isMatching, P, match } from 'ts-pattern';
5
+ import { match } from 'ts-pattern';
6
6
  import { getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
7
7
  import * as VAR from '@eslint-react/var';
8
8
  import { birecord } from '@eslint-react/types';
@@ -111,10 +111,10 @@ function isCallFromReactMember(pragmaMemberName, name) {
111
111
 
112
112
  // src/utils/is-react-api.ts
113
113
  function isReactAPIWithName(name, member) {
114
- return member ? isFromReactMember(name, member) : isFromReact(name);
114
+ return member == null ? isFromReact(name) : isFromReactMember(name, member);
115
115
  }
116
116
  function isReactAPICallWithName(name, member) {
117
- return member ? isCallFromReactMember(name, member) : isCallFromReact(name);
117
+ return member == null ? isCallFromReact(name) : isCallFromReactMember(name, member);
118
118
  }
119
119
  var isChildrenCount = isReactAPIWithName("Children", "count");
120
120
  var isChildrenForEach = isReactAPIWithName("Children", "forEach");
@@ -301,7 +301,7 @@ function useHookCollector() {
301
301
  return;
302
302
  }
303
303
  const [fNode, hookId] = fStack.at(-1) ?? [];
304
- if (!fNode || !hookId) {
304
+ if (fNode == null || hookId == null) {
305
305
  return;
306
306
  }
307
307
  F.pipe(
@@ -385,10 +385,10 @@ function getComponentNameFromIdentifier(node) {
385
385
  return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
386
386
  }
387
387
  function isComponentName(name) {
388
- return !!name && RE_COMPONENT_NAME.test(name);
388
+ return RE_COMPONENT_NAME.test(name);
389
389
  }
390
390
  function isClassComponent(node) {
391
- if ("superClass" in node && node.superClass) {
391
+ if ("superClass" in node && node.superClass != null) {
392
392
  const re = /^(?:Pure)?Component$/u;
393
393
  switch (true) {
394
394
  case node.superClass.type === AST_NODE_TYPES.Identifier:
@@ -400,7 +400,7 @@ function isClassComponent(node) {
400
400
  return false;
401
401
  }
402
402
  function isPureComponent(node) {
403
- if ("superClass" in node && node.superClass) {
403
+ if ("superClass" in node && node.superClass != null) {
404
404
  const re = /^PureComponent$/u;
405
405
  switch (true) {
406
406
  case node.superClass.type === AST_NODE_TYPES.Identifier:
@@ -432,7 +432,7 @@ function hasNoneOrValidComponentName(node, context) {
432
432
  }
433
433
  const id2 = mbIdentifier.value;
434
434
  const name = Array.isArray(id2) ? id2.at(-1)?.name : id2.name;
435
- return !!name && isComponentName(name);
435
+ return name != null && isComponentName(name);
436
436
  }
437
437
 
438
438
  // src/component/component-collector.ts
@@ -491,7 +491,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
491
491
  return functionEntries.pop();
492
492
  }
493
493
  const shouldDrop = AST8.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
494
- return context.sourceCode.getScope(r).block === entry.node && r.argument !== null && !JSX4.isJSXValue(r.argument, jsxCtx, hint);
494
+ return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX4.isJSXValue(r.argument, jsxCtx, hint);
495
495
  });
496
496
  if (shouldDrop) {
497
497
  components.delete(entry.key);
@@ -546,7 +546,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
546
546
  }
547
547
  const componentName = mbComponentName.value;
548
548
  const component = Array.from(components.values()).findLast(({ name }) => O.exists(name, (n) => n === componentName));
549
- if (!component) {
549
+ if (component == null) {
550
550
  return;
551
551
  }
552
552
  components.set(component._, {
@@ -638,16 +638,15 @@ function isSetupFunction(node) {
638
638
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
639
639
  }
640
640
  function isCleanupFunction(node) {
641
- const nearestRet = O.getOrNull(AST8.findParentNodeGuard(node, AST8.is(AST_NODE_TYPES.ReturnStatement)));
642
- if (!nearestRet) {
643
- return false;
644
- }
645
- const nearestFunction = O.getOrNull(AST8.findParentNodeGuard(node, AST8.isFunction));
646
- const nearestFunctionOfRet = O.getOrNull(AST8.findParentNodeGuard(nearestRet, AST8.isFunction));
647
- if (!nearestFunction || !nearestFunctionOfRet) {
648
- return false;
649
- }
650
- return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
641
+ return F.pipe(
642
+ O.Do,
643
+ O.bind("nearReturn", () => AST8.findParentNodeGuard(node, AST8.is(AST_NODE_TYPES.ReturnStatement))),
644
+ O.bind("nearFunction", () => AST8.findParentNodeGuard(node, AST8.isFunction)),
645
+ O.bind("nearFunctionOfReturn", ({ nearReturn }) => AST8.findParentNodeGuard(nearReturn, AST8.isFunction)),
646
+ O.exists(
647
+ ({ nearFunction, nearFunctionOfReturn }) => nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction)
648
+ )
649
+ );
651
650
  }
652
651
  function isComponentDidMount(node) {
653
652
  return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
@@ -667,14 +666,10 @@ var ERPhaseRelevance = birecord({
667
666
  });
668
667
  var isInversePhase = F.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
669
668
  function isDirectValueOfRenderPropertyLoose(node) {
670
- const matching = isMatching({
671
- key: {
672
- type: AST_NODE_TYPES.Identifier,
673
- name: P.string.startsWith("render")
674
- },
675
- type: AST_NODE_TYPES.Property
676
- });
677
- return matching(node) || matching(node.parent);
669
+ const matching = (node2) => {
670
+ return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
671
+ };
672
+ return matching(node) || node.parent != null && matching(node.parent);
678
673
  }
679
674
  function isDeclaredInRenderPropLoose(node) {
680
675
  if (isDirectValueOfRenderPropertyLoose(node)) {
@@ -685,10 +680,9 @@ function isDeclaredInRenderPropLoose(node) {
685
680
  O.flatMapNullable((c) => c.parent),
686
681
  O.filter(AST8.is(AST_NODE_TYPES.JSXAttribute)),
687
682
  O.flatMapNullable((a) => a.name),
688
- O.exists(isMatching({
689
- type: AST_NODE_TYPES.JSXIdentifier,
690
- name: P.string.startsWith("render")
691
- }))
683
+ O.exists(
684
+ (n) => n.type === AST_NODE_TYPES.JSXIdentifier && n.name.startsWith("render")
685
+ )
692
686
  );
693
687
  }
694
688
  function isRenderFunctionLoose(node, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.23.3-next.5",
3
+ "version": "1.23.3-next.7",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
5
5
  "homepage": "https://github.com/rEl1cx/eslint-react",
6
6
  "bugs": {
@@ -38,12 +38,12 @@
38
38
  "@typescript-eslint/types": "^8.19.1",
39
39
  "@typescript-eslint/utils": "^8.19.1",
40
40
  "ts-pattern": "^5.6.0",
41
- "@eslint-react/ast": "1.23.3-next.5",
42
- "@eslint-react/eff": "1.23.3-next.5",
43
- "@eslint-react/shared": "1.23.3-next.5",
44
- "@eslint-react/jsx": "1.23.3-next.5",
45
- "@eslint-react/types": "1.23.3-next.5",
46
- "@eslint-react/var": "1.23.3-next.5"
41
+ "@eslint-react/eff": "1.23.3-next.7",
42
+ "@eslint-react/ast": "1.23.3-next.7",
43
+ "@eslint-react/jsx": "1.23.3-next.7",
44
+ "@eslint-react/types": "1.23.3-next.7",
45
+ "@eslint-react/shared": "1.23.3-next.7",
46
+ "@eslint-react/var": "1.23.3-next.7"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.3.5",