@eslint-react/core 1.37.4-next.0 → 1.38.0-beta.11
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 +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +15 -14
- package/dist/index.mjs +14 -13
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { _ } from '@eslint-react/eff';
|
|
3
|
-
import { RuleContext } from '@eslint-react/shared';
|
|
1
|
+
import { RuleContext } from '@eslint-react/kit';
|
|
4
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
3
|
import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
|
+
import * as AST from '@eslint-react/ast';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
6
6
|
import * as birecord from 'birecord';
|
|
7
7
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
8
8
|
|
|
@@ -20,9 +20,9 @@ declare const ERComponentHint: {
|
|
|
20
20
|
*/
|
|
21
21
|
readonly SkipForwardRef: bigint;
|
|
22
22
|
/**
|
|
23
|
-
* Skip function component defined
|
|
23
|
+
* Skip function component defined as array map argument
|
|
24
24
|
*/
|
|
25
|
-
readonly
|
|
25
|
+
readonly SkipArrayMapArgument: bigint;
|
|
26
26
|
/**
|
|
27
27
|
* Skip function component defined on object method
|
|
28
28
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { _ } from '@eslint-react/eff';
|
|
3
|
-
import { RuleContext } from '@eslint-react/shared';
|
|
1
|
+
import { RuleContext } from '@eslint-react/kit';
|
|
4
2
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
3
|
import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
|
+
import * as AST from '@eslint-react/ast';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
6
6
|
import * as birecord from 'birecord';
|
|
7
7
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
8
8
|
|
|
@@ -20,9 +20,9 @@ declare const ERComponentHint: {
|
|
|
20
20
|
*/
|
|
21
21
|
readonly SkipForwardRef: bigint;
|
|
22
22
|
/**
|
|
23
|
-
* Skip function component defined
|
|
23
|
+
* Skip function component defined as array map argument
|
|
24
24
|
*/
|
|
25
|
-
readonly
|
|
25
|
+
readonly SkipArrayMapArgument: bigint;
|
|
26
26
|
/**
|
|
27
27
|
* Skip function component defined on object method
|
|
28
28
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var AST6 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
|
-
var
|
|
5
|
+
var JSX4 = require('@eslint-react/jsx');
|
|
6
6
|
var shared = require('@eslint-react/shared');
|
|
7
7
|
var types = require('@typescript-eslint/types');
|
|
8
8
|
var VAR = require('@eslint-react/var');
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
|
+
require('@eslint-react/kit');
|
|
10
11
|
var birecord = require('birecord');
|
|
11
12
|
|
|
12
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -30,7 +31,7 @@ function _interopNamespace(e) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
var AST6__namespace = /*#__PURE__*/_interopNamespace(AST6);
|
|
33
|
-
var
|
|
34
|
+
var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
|
|
34
35
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
35
36
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
36
37
|
|
|
@@ -818,7 +819,7 @@ var ERComponentHint = {
|
|
|
818
819
|
/**
|
|
819
820
|
* 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
820
821
|
*/
|
|
821
|
-
...
|
|
822
|
+
...JSX4__namespace.JSXValueHint,
|
|
822
823
|
/**
|
|
823
824
|
* Skip function component created by React.memo
|
|
824
825
|
*/
|
|
@@ -828,9 +829,9 @@ var ERComponentHint = {
|
|
|
828
829
|
*/
|
|
829
830
|
SkipForwardRef: 1n << 65n,
|
|
830
831
|
/**
|
|
831
|
-
* Skip function component defined
|
|
832
|
+
* Skip function component defined as array map argument
|
|
832
833
|
*/
|
|
833
|
-
|
|
834
|
+
SkipArrayMapArgument: 1n << 66n,
|
|
834
835
|
/**
|
|
835
836
|
* Skip function component defined on object method
|
|
836
837
|
*/
|
|
@@ -844,7 +845,7 @@ var ERComponentHint = {
|
|
|
844
845
|
*/
|
|
845
846
|
SkipClassProperty: 1n << 69n
|
|
846
847
|
};
|
|
847
|
-
var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipEmptyArray | ERComponentHint.
|
|
848
|
+
var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipEmptyArray | ERComponentHint.SkipArrayMapArgument | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefined | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
|
|
848
849
|
|
|
849
850
|
// src/component/component-flag.ts
|
|
850
851
|
var ERComponentFlag = {
|
|
@@ -958,9 +959,6 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
958
959
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
959
960
|
return false;
|
|
960
961
|
}
|
|
961
|
-
if (hint & ERComponentHint.SkipMapCallback && AST6__namespace.isMapCallLoose(node.parent)) {
|
|
962
|
-
return false;
|
|
963
|
-
}
|
|
964
962
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
965
963
|
return false;
|
|
966
964
|
}
|
|
@@ -970,6 +968,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
970
968
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
971
969
|
return false;
|
|
972
970
|
}
|
|
971
|
+
if (hint & ERComponentHint.SkipArrayMapArgument && AST6__namespace.isArrayMapCallLoose(node.parent)) {
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
973
974
|
const boundaryNode = AST6__namespace.findParentNode(
|
|
974
975
|
node,
|
|
975
976
|
AST6__namespace.isOneOf([
|
|
@@ -1018,7 +1019,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1018
1019
|
if (entry == null) return;
|
|
1019
1020
|
if (!entry.isComponent) return functionEntries.pop();
|
|
1020
1021
|
const shouldDrop = AST6__namespace.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
1021
|
-
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !
|
|
1022
|
+
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX4__namespace.isJSXValue(r.argument, jsxCtx, hint);
|
|
1022
1023
|
});
|
|
1023
1024
|
if (shouldDrop) {
|
|
1024
1025
|
components.delete(entry.key);
|
|
@@ -1042,7 +1043,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1042
1043
|
const entry = getCurrentEntry();
|
|
1043
1044
|
if (entry == null) return;
|
|
1044
1045
|
const { body } = entry.node;
|
|
1045
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) &&
|
|
1046
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX4__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1046
1047
|
if (!isComponent) return;
|
|
1047
1048
|
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
1048
1049
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
@@ -1082,7 +1083,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1082
1083
|
"ReturnStatement[type]"(node) {
|
|
1083
1084
|
const entry = getCurrentEntry();
|
|
1084
1085
|
if (entry == null) return;
|
|
1085
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) &&
|
|
1086
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX4__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1086
1087
|
if (!isComponent) return;
|
|
1087
1088
|
entry.isComponent = true;
|
|
1088
1089
|
const initPath = AST6__namespace.getFunctionInitPath(entry.node);
|
|
@@ -1162,12 +1163,12 @@ function isRenderFunctionLoose(context, node) {
|
|
|
1162
1163
|
if (AST6__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1163
1164
|
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");
|
|
1164
1165
|
}
|
|
1165
|
-
return
|
|
1166
|
+
return JSX4__namespace.isJSXValue(
|
|
1166
1167
|
body,
|
|
1167
1168
|
{
|
|
1168
1169
|
getScope: (node2) => context.sourceCode.getScope(node2)
|
|
1169
1170
|
},
|
|
1170
|
-
|
|
1171
|
+
JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefined | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
|
|
1171
1172
|
);
|
|
1172
1173
|
}
|
|
1173
1174
|
function isRenderPropLoose(context, node) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as AST6 from '@eslint-react/ast';
|
|
2
2
|
import { flip, dual, constFalse, identity, _ } from '@eslint-react/eff';
|
|
3
|
-
import * as
|
|
3
|
+
import * as JSX4 from '@eslint-react/jsx';
|
|
4
4
|
import { DEFAULT_ESLINT_REACT_SETTINGS as DEFAULT_ESLINT_REACT_SETTINGS$1, unsafeDecodeSettings, getId } from '@eslint-react/shared';
|
|
5
5
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
6
6
|
import * as VAR from '@eslint-react/var';
|
|
7
7
|
import { match, P } from 'ts-pattern';
|
|
8
|
+
import '@eslint-react/kit';
|
|
8
9
|
import birecord from 'birecord';
|
|
9
10
|
|
|
10
11
|
// src/component/component-collector.ts
|
|
@@ -791,7 +792,7 @@ var ERComponentHint = {
|
|
|
791
792
|
/**
|
|
792
793
|
* 1n << 0n - 1n << 63n are reserved for JSXValueHint
|
|
793
794
|
*/
|
|
794
|
-
...
|
|
795
|
+
...JSX4.JSXValueHint,
|
|
795
796
|
/**
|
|
796
797
|
* Skip function component created by React.memo
|
|
797
798
|
*/
|
|
@@ -801,9 +802,9 @@ var ERComponentHint = {
|
|
|
801
802
|
*/
|
|
802
803
|
SkipForwardRef: 1n << 65n,
|
|
803
804
|
/**
|
|
804
|
-
* Skip function component defined
|
|
805
|
+
* Skip function component defined as array map argument
|
|
805
806
|
*/
|
|
806
|
-
|
|
807
|
+
SkipArrayMapArgument: 1n << 66n,
|
|
807
808
|
/**
|
|
808
809
|
* Skip function component defined on object method
|
|
809
810
|
*/
|
|
@@ -817,7 +818,7 @@ var ERComponentHint = {
|
|
|
817
818
|
*/
|
|
818
819
|
SkipClassProperty: 1n << 69n
|
|
819
820
|
};
|
|
820
|
-
var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipEmptyArray | ERComponentHint.
|
|
821
|
+
var DEFAULT_COMPONENT_HINT = 0n | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipEmptyArray | ERComponentHint.SkipArrayMapArgument | ERComponentHint.SkipNumberLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipUndefined | ERComponentHint.StrictArray | ERComponentHint.StrictConditional | ERComponentHint.StrictLogical;
|
|
821
822
|
|
|
822
823
|
// src/component/component-flag.ts
|
|
823
824
|
var ERComponentFlag = {
|
|
@@ -931,9 +932,6 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
931
932
|
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
932
933
|
return false;
|
|
933
934
|
}
|
|
934
|
-
if (hint & ERComponentHint.SkipMapCallback && AST6.isMapCallLoose(node.parent)) {
|
|
935
|
-
return false;
|
|
936
|
-
}
|
|
937
935
|
if (hint & ERComponentHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
|
|
938
936
|
return false;
|
|
939
937
|
}
|
|
@@ -943,6 +941,9 @@ function hasValidHierarchy(context, node, hint) {
|
|
|
943
941
|
if (hint & ERComponentHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
|
|
944
942
|
return false;
|
|
945
943
|
}
|
|
944
|
+
if (hint & ERComponentHint.SkipArrayMapArgument && AST6.isArrayMapCallLoose(node.parent)) {
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
946
947
|
const boundaryNode = AST6.findParentNode(
|
|
947
948
|
node,
|
|
948
949
|
AST6.isOneOf([
|
|
@@ -991,7 +992,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
991
992
|
if (entry == null) return;
|
|
992
993
|
if (!entry.isComponent) return functionEntries.pop();
|
|
993
994
|
const shouldDrop = AST6.getNestedReturnStatements(entry.node.body).slice().reverse().some((r) => {
|
|
994
|
-
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !
|
|
995
|
+
return context.sourceCode.getScope(r).block === entry.node && r.argument != null && !JSX4.isJSXValue(r.argument, jsxCtx, hint);
|
|
995
996
|
});
|
|
996
997
|
if (shouldDrop) {
|
|
997
998
|
components.delete(entry.key);
|
|
@@ -1015,7 +1016,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1015
1016
|
const entry = getCurrentEntry();
|
|
1016
1017
|
if (entry == null) return;
|
|
1017
1018
|
const { body } = entry.node;
|
|
1018
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) &&
|
|
1019
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX4.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1019
1020
|
if (!isComponent) return;
|
|
1020
1021
|
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
1021
1022
|
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
@@ -1055,7 +1056,7 @@ function useComponentCollector(context, options = {}) {
|
|
|
1055
1056
|
"ReturnStatement[type]"(node) {
|
|
1056
1057
|
const entry = getCurrentEntry();
|
|
1057
1058
|
if (entry == null) return;
|
|
1058
|
-
const isComponent = hasNoneOrLooseComponentName(context, entry.node) &&
|
|
1059
|
+
const isComponent = hasNoneOrLooseComponentName(context, entry.node) && JSX4.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
1059
1060
|
if (!isComponent) return;
|
|
1060
1061
|
entry.isComponent = true;
|
|
1061
1062
|
const initPath = AST6.getFunctionInitPath(entry.node);
|
|
@@ -1135,12 +1136,12 @@ function isRenderFunctionLoose(context, node) {
|
|
|
1135
1136
|
if (AST6.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
1136
1137
|
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");
|
|
1137
1138
|
}
|
|
1138
|
-
return
|
|
1139
|
+
return JSX4.isJSXValue(
|
|
1139
1140
|
body,
|
|
1140
1141
|
{
|
|
1141
1142
|
getScope: (node2) => context.sourceCode.getScope(node2)
|
|
1142
1143
|
},
|
|
1143
|
-
|
|
1144
|
+
JSX4.JSXValueHint.SkipNullLiteral | JSX4.JSXValueHint.SkipUndefined | JSX4.JSXValueHint.StrictLogical | JSX4.JSXValueHint.StrictConditional
|
|
1144
1145
|
);
|
|
1145
1146
|
}
|
|
1146
1147
|
function isRenderPropLoose(context, node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0-beta.11",
|
|
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": {
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.27.0",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.6.2",
|
|
44
|
-
"@eslint-react/ast": "1.
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "1.38.0-beta.11",
|
|
45
|
+
"@eslint-react/jsx": "1.38.0-beta.11",
|
|
46
|
+
"@eslint-react/eff": "1.38.0-beta.11",
|
|
47
|
+
"@eslint-react/kit": "1.38.0-beta.11",
|
|
48
|
+
"@eslint-react/shared": "1.38.0-beta.11",
|
|
49
|
+
"@eslint-react/var": "1.38.0-beta.11"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"tsup": "^8.4.0",
|