@eslint-react/core 1.17.4-beta.0 → 1.17.4-beta.12
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -8
- package/dist/index.mjs +24 -10
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -158,6 +158,8 @@ type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
|
158
158
|
declare function isSetupFunction(node: TSESTree.Node): boolean;
|
|
159
159
|
declare function isCleanupFunction(node: TSESTree.Node): boolean;
|
|
160
160
|
|
|
161
|
+
declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
|
|
162
|
+
|
|
161
163
|
/**
|
|
162
164
|
* Determines whether inside createElement's props.
|
|
163
165
|
* @param node The AST node to check
|
|
@@ -2373,4 +2375,4 @@ declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_typ
|
|
|
2373
2375
|
declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
|
|
2374
2376
|
declare const isMemoCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
|
|
2375
2377
|
|
|
2376
|
-
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
2378
|
+
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,8 @@ type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
|
158
158
|
declare function isSetupFunction(node: TSESTree.Node): boolean;
|
|
159
159
|
declare function isCleanupFunction(node: TSESTree.Node): boolean;
|
|
160
160
|
|
|
161
|
+
declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
|
|
162
|
+
|
|
161
163
|
/**
|
|
162
164
|
* Determines whether inside createElement's props.
|
|
163
165
|
* @param node The AST node to check
|
|
@@ -2373,4 +2375,4 @@ declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_typ
|
|
|
2373
2375
|
declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
|
|
2374
2376
|
declare const isMemoCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
|
|
2375
2377
|
|
|
2376
|
-
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
2378
|
+
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var AST9 = require('@eslint-react/ast');
|
|
4
|
-
var
|
|
4
|
+
var JSX4 = require('@eslint-react/jsx');
|
|
5
5
|
var tools = require('@eslint-react/tools');
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var ShortUniqueId = require('short-unique-id');
|
|
@@ -31,12 +31,26 @@ function _interopNamespace(e) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
|
|
34
|
-
var
|
|
34
|
+
var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
|
|
35
35
|
var ShortUniqueId__default = /*#__PURE__*/_interopDefault(ShortUniqueId);
|
|
36
36
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
37
37
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
38
38
|
|
|
39
39
|
// src/component/component-collector.ts
|
|
40
|
+
function getElementRepresentName(node, context) {
|
|
41
|
+
const rawElementName = JSX4__namespace.getElementName(node);
|
|
42
|
+
if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
|
|
43
|
+
const { components, polymorphicPropName } = shared.normalizeSettings(shared.decodeSettings(context.settings));
|
|
44
|
+
const asElementName = components.get(rawElementName);
|
|
45
|
+
if (tools.isString(asElementName)) return asElementName;
|
|
46
|
+
return tools.F.pipe(
|
|
47
|
+
tools.O.fromNullable(polymorphicPropName),
|
|
48
|
+
tools.O.flatMap(JSX4__namespace.findPropInAttributes(node.attributes, context.sourceCode.getScope(node))),
|
|
49
|
+
tools.O.flatMap((attr) => JSX4__namespace.getPropValue(attr, context.sourceCode.getScope(attr))),
|
|
50
|
+
tools.O.filter(tools.isString),
|
|
51
|
+
tools.O.getOrElse(() => rawElementName)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
40
54
|
function isInitializedFromReact(name, initialScope, settings) {
|
|
41
55
|
if (!settings.strictImportCheck) return true;
|
|
42
56
|
if (name.toLowerCase() === "react") return true;
|
|
@@ -299,7 +313,7 @@ function useHookCollector() {
|
|
|
299
313
|
return { ctx, listeners };
|
|
300
314
|
}
|
|
301
315
|
var ERComponentHint = {
|
|
302
|
-
...
|
|
316
|
+
...JSX4__namespace.JSXValueHint,
|
|
303
317
|
// 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
304
318
|
// Skip function component created by React.memo
|
|
305
319
|
SkipMemo: 1n << 64n,
|
|
@@ -523,7 +537,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
523
537
|
const [key, fn, isComponent] = functionStack.at(-1) ?? [];
|
|
524
538
|
if (!key || !fn || !isComponent) return functionStack.pop();
|
|
525
539
|
const shouldDrop = AST9__namespace.getNestedReturnStatements(fn.body).slice().reverse().some((r) => {
|
|
526
|
-
return context.sourceCode.getScope(r).block === fn && r.argument !== null && !
|
|
540
|
+
return context.sourceCode.getScope(r).block === fn && r.argument !== null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
527
541
|
});
|
|
528
542
|
if (shouldDrop) components.delete(key);
|
|
529
543
|
return functionStack.pop();
|
|
@@ -548,7 +562,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
548
562
|
if (tools.O.isNone(maybeCurrentFn)) return;
|
|
549
563
|
const [_key, currentFn, _isComponent, hookCalls] = maybeCurrentFn.value;
|
|
550
564
|
const { body } = currentFn;
|
|
551
|
-
const isComponent = hasNoneOrValidComponentName(currentFn, context) &&
|
|
565
|
+
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
552
566
|
if (!isComponent) return;
|
|
553
567
|
const initPath = AST9__namespace.getFunctionInitPath(currentFn);
|
|
554
568
|
const id = getFunctionComponentIdentifier(currentFn, context);
|
|
@@ -593,7 +607,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
593
607
|
if (tools.O.isNone(maybeCurrentFn)) return;
|
|
594
608
|
const [key, currentFn, isKnown, hookCalls] = maybeCurrentFn.value;
|
|
595
609
|
if (isKnown) return;
|
|
596
|
-
const isComponent = hasNoneOrValidComponentName(currentFn, context) &&
|
|
610
|
+
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
597
611
|
if (!isComponent) return;
|
|
598
612
|
functionStack.pop();
|
|
599
613
|
functionStack.push([key, currentFn, true, []]);
|
|
@@ -664,10 +678,10 @@ function isRenderFunctionLoose(node, context) {
|
|
|
664
678
|
return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
665
679
|
}
|
|
666
680
|
const jsxCtx = { getScope: (node2) => context.sourceCode.getScope(node2) };
|
|
667
|
-
return
|
|
681
|
+
return JSX4__namespace.isJSXValue(
|
|
668
682
|
body,
|
|
669
683
|
jsxCtx,
|
|
670
|
-
|
|
684
|
+
JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefinedLiteral | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
|
|
671
685
|
);
|
|
672
686
|
}
|
|
673
687
|
function isRenderPropLoose(node, context) {
|
|
@@ -687,6 +701,7 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
|
687
701
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
688
702
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
689
703
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
704
|
+
exports.getElementRepresentName = getElementRepresentName;
|
|
690
705
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
691
706
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
692
707
|
exports.isCallFromReact = isCallFromReact;
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import * as AST9 from '@eslint-react/ast';
|
|
2
|
-
import * as
|
|
3
|
-
import { F, O } from '@eslint-react/tools';
|
|
2
|
+
import * as JSX4 from '@eslint-react/jsx';
|
|
3
|
+
import { F, isString, O } from '@eslint-react/tools';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import ShortUniqueId from 'short-unique-id';
|
|
6
6
|
import { isMatching, P, match } from 'ts-pattern';
|
|
7
|
-
import {
|
|
7
|
+
import { normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
|
|
8
8
|
import * as VAR from '@eslint-react/var';
|
|
9
9
|
import birecord from 'birecord';
|
|
10
10
|
|
|
11
11
|
// src/component/component-collector.ts
|
|
12
|
+
function getElementRepresentName(node, context) {
|
|
13
|
+
const rawElementName = JSX4.getElementName(node);
|
|
14
|
+
if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
|
|
15
|
+
const { components, polymorphicPropName } = normalizeSettings(decodeSettings(context.settings));
|
|
16
|
+
const asElementName = components.get(rawElementName);
|
|
17
|
+
if (isString(asElementName)) return asElementName;
|
|
18
|
+
return F.pipe(
|
|
19
|
+
O.fromNullable(polymorphicPropName),
|
|
20
|
+
O.flatMap(JSX4.findPropInAttributes(node.attributes, context.sourceCode.getScope(node))),
|
|
21
|
+
O.flatMap((attr) => JSX4.getPropValue(attr, context.sourceCode.getScope(attr))),
|
|
22
|
+
O.filter(isString),
|
|
23
|
+
O.getOrElse(() => rawElementName)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
12
26
|
function isInitializedFromReact(name, initialScope, settings) {
|
|
13
27
|
if (!settings.strictImportCheck) return true;
|
|
14
28
|
if (name.toLowerCase() === "react") return true;
|
|
@@ -271,7 +285,7 @@ function useHookCollector() {
|
|
|
271
285
|
return { ctx, listeners };
|
|
272
286
|
}
|
|
273
287
|
var ERComponentHint = {
|
|
274
|
-
...
|
|
288
|
+
...JSX4.JSXValueHint,
|
|
275
289
|
// 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
276
290
|
// Skip function component created by React.memo
|
|
277
291
|
SkipMemo: 1n << 64n,
|
|
@@ -495,7 +509,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
495
509
|
const [key, fn, isComponent] = functionStack.at(-1) ?? [];
|
|
496
510
|
if (!key || !fn || !isComponent) return functionStack.pop();
|
|
497
511
|
const shouldDrop = AST9.getNestedReturnStatements(fn.body).slice().reverse().some((r) => {
|
|
498
|
-
return context.sourceCode.getScope(r).block === fn && r.argument !== null && !
|
|
512
|
+
return context.sourceCode.getScope(r).block === fn && r.argument !== null && !JSX4.isJSXValue(r.argument, jsxCtx, hint);
|
|
499
513
|
});
|
|
500
514
|
if (shouldDrop) components.delete(key);
|
|
501
515
|
return functionStack.pop();
|
|
@@ -520,7 +534,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
520
534
|
if (O.isNone(maybeCurrentFn)) return;
|
|
521
535
|
const [_key, currentFn, _isComponent, hookCalls] = maybeCurrentFn.value;
|
|
522
536
|
const { body } = currentFn;
|
|
523
|
-
const isComponent = hasNoneOrValidComponentName(currentFn, context) &&
|
|
537
|
+
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
524
538
|
if (!isComponent) return;
|
|
525
539
|
const initPath = AST9.getFunctionInitPath(currentFn);
|
|
526
540
|
const id = getFunctionComponentIdentifier(currentFn, context);
|
|
@@ -565,7 +579,7 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
565
579
|
if (O.isNone(maybeCurrentFn)) return;
|
|
566
580
|
const [key, currentFn, isKnown, hookCalls] = maybeCurrentFn.value;
|
|
567
581
|
if (isKnown) return;
|
|
568
|
-
const isComponent = hasNoneOrValidComponentName(currentFn, context) &&
|
|
582
|
+
const isComponent = hasNoneOrValidComponentName(currentFn, context) && JSX4.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(currentFn, context, hint);
|
|
569
583
|
if (!isComponent) return;
|
|
570
584
|
functionStack.pop();
|
|
571
585
|
functionStack.push([key, currentFn, true, []]);
|
|
@@ -636,10 +650,10 @@ function isRenderFunctionLoose(node, context) {
|
|
|
636
650
|
return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
637
651
|
}
|
|
638
652
|
const jsxCtx = { getScope: (node2) => context.sourceCode.getScope(node2) };
|
|
639
|
-
return
|
|
653
|
+
return JSX4.isJSXValue(
|
|
640
654
|
body,
|
|
641
655
|
jsxCtx,
|
|
642
|
-
|
|
656
|
+
JSX4.JSXValueHint.SkipNullLiteral | JSX4.JSXValueHint.SkipUndefinedLiteral | JSX4.JSXValueHint.StrictLogical | JSX4.JSXValueHint.StrictConditional
|
|
643
657
|
);
|
|
644
658
|
}
|
|
645
659
|
function isRenderPropLoose(node, context) {
|
|
@@ -651,4 +665,4 @@ function isThisSetState(node) {
|
|
|
651
665
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST9.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
652
666
|
}
|
|
653
667
|
|
|
654
|
-
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
668
|
+
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.17.4-beta.
|
|
3
|
+
"version": "1.17.4-beta.12",
|
|
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": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"short-unique-id": "^5.2.0",
|
|
44
44
|
"ts-pattern": "^5.5.0",
|
|
45
|
-
"@eslint-react/ast": "1.17.4-beta.
|
|
46
|
-
"@eslint-react/jsx": "1.17.4-beta.
|
|
47
|
-
"@eslint-react/shared": "1.17.4-beta.
|
|
48
|
-
"@eslint-react/tools": "1.17.4-beta.
|
|
49
|
-
"@eslint-react/types": "1.17.4-beta.
|
|
50
|
-
"@eslint-react/var": "1.17.4-beta.
|
|
45
|
+
"@eslint-react/ast": "1.17.4-beta.12",
|
|
46
|
+
"@eslint-react/jsx": "1.17.4-beta.12",
|
|
47
|
+
"@eslint-react/shared": "1.17.4-beta.12",
|
|
48
|
+
"@eslint-react/tools": "1.17.4-beta.12",
|
|
49
|
+
"@eslint-react/types": "1.17.4-beta.12",
|
|
50
|
+
"@eslint-react/var": "1.17.4-beta.12"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"tsup": "^8.3.5"
|