@eslint-react/core 1.17.2-next.5 → 1.17.2-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.d.mts +2079 -63
- package/dist/index.d.ts +2079 -63
- package/dist/index.js +6 -43
- package/dist/index.mjs +7 -43
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -41,41 +41,10 @@ function isInitializedFromReact(name, initialScope, settings) {
|
|
|
41
41
|
if (!settings.strictImportCheck) return true;
|
|
42
42
|
if (name.toLowerCase() === "react") return true;
|
|
43
43
|
const { importSource = "react" } = settings;
|
|
44
|
-
|
|
45
|
-
if (tools.O.isNone(maybeLatestDef)) return false;
|
|
46
|
-
const latestDef = maybeLatestDef.value;
|
|
47
|
-
const { node, parent } = latestDef;
|
|
48
|
-
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init) {
|
|
49
|
-
const { init } = node;
|
|
50
|
-
if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
|
|
51
|
-
return isInitializedFromReact(init.object.name, initialScope, settings);
|
|
52
|
-
}
|
|
53
|
-
if (init.type === types.AST_NODE_TYPES.Identifier) {
|
|
54
|
-
return isInitializedFromReact(init.name, initialScope, settings);
|
|
55
|
-
}
|
|
56
|
-
const maybeRequireExpression = tsPattern.match(init).with({
|
|
57
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
58
|
-
callee: { type: types.AST_NODE_TYPES.Identifier, name: "require" }
|
|
59
|
-
}, (exp) => tools.O.some(exp)).with(
|
|
60
|
-
{
|
|
61
|
-
type: types.AST_NODE_TYPES.MemberExpression,
|
|
62
|
-
object: {
|
|
63
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
64
|
-
callee: { type: types.AST_NODE_TYPES.Identifier, name: "require" }
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
({ object }) => tools.O.some(object)
|
|
68
|
-
).otherwise(tools.O.none);
|
|
69
|
-
if (tools.O.isNone(maybeRequireExpression)) return false;
|
|
70
|
-
const requireExpression = maybeRequireExpression.value;
|
|
71
|
-
const [firstArg] = requireExpression.arguments;
|
|
72
|
-
if (firstArg?.type !== types.AST_NODE_TYPES.Literal || !tools.isString(firstArg.value)) return false;
|
|
73
|
-
return firstArg.value === importSource || firstArg.value.startsWith(`${importSource}/`);
|
|
74
|
-
}
|
|
75
|
-
return tsPattern.isMatching({ type: "ImportDeclaration", source: { value: importSource } }, parent);
|
|
44
|
+
return VAR__namespace.isInitializedFromSource(name, importSource, initialScope);
|
|
76
45
|
}
|
|
77
46
|
|
|
78
|
-
// src/is-from-react.ts
|
|
47
|
+
// src/utils/is-from-react.ts
|
|
79
48
|
function isFromReact(name) {
|
|
80
49
|
return (node, context) => {
|
|
81
50
|
const settings = shared.unsafeReadSettings(context.settings);
|
|
@@ -114,15 +83,13 @@ function isCallFromReactMember(pragmaMemberName, name) {
|
|
|
114
83
|
};
|
|
115
84
|
}
|
|
116
85
|
|
|
117
|
-
// src/is-react-api.ts
|
|
86
|
+
// src/utils/is-react-api.ts
|
|
118
87
|
function isReactAPIWithName(name, member) {
|
|
119
88
|
return member ? isFromReactMember(name, member) : isFromReact(name);
|
|
120
89
|
}
|
|
121
90
|
function isReactAPICallWithName(name, member) {
|
|
122
91
|
return member ? isCallFromReactMember(name, member) : isCallFromReact(name);
|
|
123
92
|
}
|
|
124
|
-
|
|
125
|
-
// src/react-api.ts
|
|
126
93
|
var isChildrenCount = isReactAPIWithName("Children", "count");
|
|
127
94
|
var isChildrenForEach = isReactAPIWithName("Children", "forEach");
|
|
128
95
|
var isChildrenMap = isReactAPIWithName("Children", "map");
|
|
@@ -660,14 +627,11 @@ function isCleanupFunction(node) {
|
|
|
660
627
|
if (!nearestFunction || !nearestFunctionOfRet) return false;
|
|
661
628
|
return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
|
|
662
629
|
}
|
|
663
|
-
var
|
|
630
|
+
var ERPhaseRelevance = birecord__default.default({
|
|
664
631
|
mount: "unmount",
|
|
665
632
|
setup: "cleanup"
|
|
666
633
|
});
|
|
667
|
-
var isInversePhase = tools.F.dual(2, (a, b) =>
|
|
668
|
-
function getPhaseKindOfFunction(node) {
|
|
669
|
-
return tsPattern.match(node).when(isSetupFunction, () => tools.O.some("setup")).when(isCleanupFunction, () => tools.O.some("cleanup")).when(isComponentDidMountFunction, () => tools.O.some("mount")).when(isComponentWillUnmountFunction, () => tools.O.some("unmount")).otherwise(tools.O.none);
|
|
670
|
-
}
|
|
634
|
+
var isInversePhase = tools.F.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
671
635
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
672
636
|
const matching = tsPattern.isMatching({
|
|
673
637
|
key: {
|
|
@@ -719,12 +683,11 @@ exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
|
719
683
|
exports.ERClassComponentFlag = ERClassComponentFlag;
|
|
720
684
|
exports.ERComponentHint = ERComponentHint;
|
|
721
685
|
exports.ERFunctionComponentFlag = ERFunctionComponentFlag;
|
|
722
|
-
exports.
|
|
686
|
+
exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
723
687
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
724
688
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
725
689
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
726
690
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
727
|
-
exports.getPhaseKindOfFunction = getPhaseKindOfFunction;
|
|
728
691
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
729
692
|
exports.isCallFromReact = isCallFromReact;
|
|
730
693
|
exports.isCallFromReactMember = isCallFromReactMember;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AST9 from '@eslint-react/ast';
|
|
2
2
|
import * as JSX3 from '@eslint-react/jsx';
|
|
3
|
-
import { F, O
|
|
3
|
+
import { F, 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';
|
|
@@ -13,41 +13,10 @@ function isInitializedFromReact(name, initialScope, settings) {
|
|
|
13
13
|
if (!settings.strictImportCheck) return true;
|
|
14
14
|
if (name.toLowerCase() === "react") return true;
|
|
15
15
|
const { importSource = "react" } = settings;
|
|
16
|
-
|
|
17
|
-
if (O.isNone(maybeLatestDef)) return false;
|
|
18
|
-
const latestDef = maybeLatestDef.value;
|
|
19
|
-
const { node, parent } = latestDef;
|
|
20
|
-
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init) {
|
|
21
|
-
const { init } = node;
|
|
22
|
-
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
|
|
23
|
-
return isInitializedFromReact(init.object.name, initialScope, settings);
|
|
24
|
-
}
|
|
25
|
-
if (init.type === AST_NODE_TYPES.Identifier) {
|
|
26
|
-
return isInitializedFromReact(init.name, initialScope, settings);
|
|
27
|
-
}
|
|
28
|
-
const maybeRequireExpression = match(init).with({
|
|
29
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
30
|
-
callee: { type: AST_NODE_TYPES.Identifier, name: "require" }
|
|
31
|
-
}, (exp) => O.some(exp)).with(
|
|
32
|
-
{
|
|
33
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
34
|
-
object: {
|
|
35
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
36
|
-
callee: { type: AST_NODE_TYPES.Identifier, name: "require" }
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
({ object }) => O.some(object)
|
|
40
|
-
).otherwise(O.none);
|
|
41
|
-
if (O.isNone(maybeRequireExpression)) return false;
|
|
42
|
-
const requireExpression = maybeRequireExpression.value;
|
|
43
|
-
const [firstArg] = requireExpression.arguments;
|
|
44
|
-
if (firstArg?.type !== AST_NODE_TYPES.Literal || !isString(firstArg.value)) return false;
|
|
45
|
-
return firstArg.value === importSource || firstArg.value.startsWith(`${importSource}/`);
|
|
46
|
-
}
|
|
47
|
-
return isMatching({ type: "ImportDeclaration", source: { value: importSource } }, parent);
|
|
16
|
+
return VAR.isInitializedFromSource(name, importSource, initialScope);
|
|
48
17
|
}
|
|
49
18
|
|
|
50
|
-
// src/is-from-react.ts
|
|
19
|
+
// src/utils/is-from-react.ts
|
|
51
20
|
function isFromReact(name) {
|
|
52
21
|
return (node, context) => {
|
|
53
22
|
const settings = unsafeReadSettings(context.settings);
|
|
@@ -86,15 +55,13 @@ function isCallFromReactMember(pragmaMemberName, name) {
|
|
|
86
55
|
};
|
|
87
56
|
}
|
|
88
57
|
|
|
89
|
-
// src/is-react-api.ts
|
|
58
|
+
// src/utils/is-react-api.ts
|
|
90
59
|
function isReactAPIWithName(name, member) {
|
|
91
60
|
return member ? isFromReactMember(name, member) : isFromReact(name);
|
|
92
61
|
}
|
|
93
62
|
function isReactAPICallWithName(name, member) {
|
|
94
63
|
return member ? isCallFromReactMember(name, member) : isCallFromReact(name);
|
|
95
64
|
}
|
|
96
|
-
|
|
97
|
-
// src/react-api.ts
|
|
98
65
|
var isChildrenCount = isReactAPIWithName("Children", "count");
|
|
99
66
|
var isChildrenForEach = isReactAPIWithName("Children", "forEach");
|
|
100
67
|
var isChildrenMap = isReactAPIWithName("Children", "map");
|
|
@@ -632,14 +599,11 @@ function isCleanupFunction(node) {
|
|
|
632
599
|
if (!nearestFunction || !nearestFunctionOfRet) return false;
|
|
633
600
|
return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
|
|
634
601
|
}
|
|
635
|
-
var
|
|
602
|
+
var ERPhaseRelevance = birecord({
|
|
636
603
|
mount: "unmount",
|
|
637
604
|
setup: "cleanup"
|
|
638
605
|
});
|
|
639
|
-
var isInversePhase = F.dual(2, (a, b) =>
|
|
640
|
-
function getPhaseKindOfFunction(node) {
|
|
641
|
-
return match(node).when(isSetupFunction, () => O.some("setup")).when(isCleanupFunction, () => O.some("cleanup")).when(isComponentDidMountFunction, () => O.some("mount")).when(isComponentWillUnmountFunction, () => O.some("unmount")).otherwise(O.none);
|
|
642
|
-
}
|
|
606
|
+
var isInversePhase = F.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
643
607
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
644
608
|
const matching = isMatching({
|
|
645
609
|
key: {
|
|
@@ -687,4 +651,4 @@ function isThisSetState(node) {
|
|
|
687
651
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST9.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
688
652
|
}
|
|
689
653
|
|
|
690
|
-
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.17.2-next.
|
|
3
|
+
"version": "1.17.2-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": {
|
|
@@ -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.2-next.
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/types": "1.17.2-next.
|
|
50
|
-
"@eslint-react/var": "1.17.2-next.
|
|
45
|
+
"@eslint-react/ast": "1.17.2-next.7",
|
|
46
|
+
"@eslint-react/shared": "1.17.2-next.7",
|
|
47
|
+
"@eslint-react/jsx": "1.17.2-next.7",
|
|
48
|
+
"@eslint-react/tools": "1.17.2-next.7",
|
|
49
|
+
"@eslint-react/types": "1.17.2-next.7",
|
|
50
|
+
"@eslint-react/var": "1.17.2-next.7"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"tsup": "^8.3.5"
|