@eslint-react/core 1.23.3-next.4 → 1.23.3-next.6
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 +18 -19
- package/dist/index.mjs +18 -19
- package/package.json +7 -7
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 ?
|
|
138
|
+
return member == null ? isFromReact(name) : isFromReactMember(name, member);
|
|
139
139
|
}
|
|
140
140
|
function isReactAPICallWithName(name, member) {
|
|
141
|
-
return member ?
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
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 (
|
|
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
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
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";
|
package/dist/index.mjs
CHANGED
|
@@ -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 ?
|
|
114
|
+
return member == null ? isFromReact(name) : isFromReactMember(name, member);
|
|
115
115
|
}
|
|
116
116
|
function isReactAPICallWithName(name, member) {
|
|
117
|
-
return member ?
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
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 (
|
|
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
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.23.3-next.
|
|
3
|
+
"version": "1.23.3-next.6",
|
|
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.
|
|
42
|
-
"@eslint-react/eff": "1.23.3-next.
|
|
43
|
-
"@eslint-react/jsx": "1.23.3-next.
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
41
|
+
"@eslint-react/ast": "1.23.3-next.6",
|
|
42
|
+
"@eslint-react/eff": "1.23.3-next.6",
|
|
43
|
+
"@eslint-react/jsx": "1.23.3-next.6",
|
|
44
|
+
"@eslint-react/shared": "1.23.3-next.6",
|
|
45
|
+
"@eslint-react/var": "1.23.3-next.6",
|
|
46
|
+
"@eslint-react/types": "1.23.3-next.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|