eslint-plugin-react-x 1.28.1-beta.3 → 1.28.1-beta.5
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 +34 -27
- package/dist/index.mjs +35 -28
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -137,25 +137,9 @@ var settings3 = {
|
|
|
137
137
|
|
|
138
138
|
// package.json
|
|
139
139
|
var name4 = "eslint-plugin-react-x";
|
|
140
|
-
var version = "1.28.1-beta.
|
|
140
|
+
var version = "1.28.1-beta.5";
|
|
141
141
|
var createRule = shared.createRuleForPlugin("x");
|
|
142
142
|
|
|
143
|
-
// src/utils/get-associated-tokens.ts
|
|
144
|
-
function getAssociatedTokens(context, node) {
|
|
145
|
-
{
|
|
146
|
-
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
147
|
-
const tokenAfter = context.sourceCode.getTokenAfter(node);
|
|
148
|
-
const tokens = [];
|
|
149
|
-
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
|
|
150
|
-
tokens.push(tokenBefore);
|
|
151
|
-
}
|
|
152
|
-
if (tokenAfter?.value === ",") {
|
|
153
|
-
tokens.push(tokenAfter);
|
|
154
|
-
}
|
|
155
|
-
return tokens;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
143
|
// src/rules/avoid-shorthand-boolean.ts
|
|
160
144
|
var RULE_NAME = "avoid-shorthand-boolean";
|
|
161
145
|
var RULE_FEATURES = [
|
|
@@ -268,8 +252,11 @@ var RULE_NAME4 = "no-access-state-in-setstate";
|
|
|
268
252
|
var RULE_FEATURES4 = [
|
|
269
253
|
"CHK"
|
|
270
254
|
];
|
|
255
|
+
function isKeyLiteral(node, key) {
|
|
256
|
+
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
257
|
+
}
|
|
271
258
|
function getName(node) {
|
|
272
|
-
if (AST11__namespace.
|
|
259
|
+
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
273
260
|
return getName(node.expression);
|
|
274
261
|
}
|
|
275
262
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -378,7 +365,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
378
365
|
return;
|
|
379
366
|
}
|
|
380
367
|
const hasState = node.id.properties.some(
|
|
381
|
-
(prop) => prop.type === types.AST_NODE_TYPES.Property &&
|
|
368
|
+
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && getName(prop.key) === "state"
|
|
382
369
|
);
|
|
383
370
|
if (!hasState) {
|
|
384
371
|
return;
|
|
@@ -1246,7 +1233,7 @@ var RULE_FEATURES22 = [
|
|
|
1246
1233
|
"CHK"
|
|
1247
1234
|
];
|
|
1248
1235
|
function getName2(node) {
|
|
1249
|
-
if (AST11__namespace.
|
|
1236
|
+
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
1250
1237
|
return getName2(node.expression);
|
|
1251
1238
|
}
|
|
1252
1239
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -1400,7 +1387,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1400
1387
|
if (!AST11__namespace.isFunction(iter)) return;
|
|
1401
1388
|
const arg0 = call?.arguments[0];
|
|
1402
1389
|
if (call == null || arg0 == null) return;
|
|
1403
|
-
if (AST11__namespace.
|
|
1390
|
+
if (AST11__namespace.getEcmaExpression(arg0) !== iter) {
|
|
1404
1391
|
return;
|
|
1405
1392
|
}
|
|
1406
1393
|
keyedEntries.set(call, {
|
|
@@ -2692,8 +2679,11 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2692
2679
|
"UNSAFE_componentWillReceiveProps",
|
|
2693
2680
|
"UNSAFE_componentWillUpdate"
|
|
2694
2681
|
]);
|
|
2682
|
+
function isKeyLiteral2(node, key) {
|
|
2683
|
+
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
2684
|
+
}
|
|
2695
2685
|
function getName3(node) {
|
|
2696
|
-
if (AST11__namespace.
|
|
2686
|
+
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
2697
2687
|
return getName3(node.expression);
|
|
2698
2688
|
}
|
|
2699
2689
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2771,7 +2761,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2771
2761
|
if (node.static) {
|
|
2772
2762
|
return;
|
|
2773
2763
|
}
|
|
2774
|
-
if (
|
|
2764
|
+
if (isKeyLiteral2(node, node.key)) {
|
|
2775
2765
|
propertyDefs.get(currentClass)?.add(node.key);
|
|
2776
2766
|
}
|
|
2777
2767
|
}
|
|
@@ -2792,7 +2782,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2792
2782
|
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2793
2783
|
return;
|
|
2794
2784
|
}
|
|
2795
|
-
if (!AST11__namespace.isThisExpression(node.object) || !
|
|
2785
|
+
if (!AST11__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2796
2786
|
return;
|
|
2797
2787
|
}
|
|
2798
2788
|
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
@@ -2819,7 +2809,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2819
2809
|
}
|
|
2820
2810
|
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2821
2811
|
for (const prop of node.id.properties) {
|
|
2822
|
-
if (prop.type === types.AST_NODE_TYPES.Property &&
|
|
2812
|
+
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2823
2813
|
const keyName = getName3(prop.key);
|
|
2824
2814
|
if (keyName != null) {
|
|
2825
2815
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
@@ -2836,8 +2826,11 @@ var RULE_NAME44 = "no-unused-state";
|
|
|
2836
2826
|
var RULE_FEATURES44 = [
|
|
2837
2827
|
"CHK"
|
|
2838
2828
|
];
|
|
2829
|
+
function isKeyLiteral3(node, key) {
|
|
2830
|
+
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
2831
|
+
}
|
|
2839
2832
|
function getName4(node) {
|
|
2840
|
-
if (AST11__namespace.
|
|
2833
|
+
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
2841
2834
|
return getName4(node.expression);
|
|
2842
2835
|
}
|
|
2843
2836
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2989,7 +2982,7 @@ var no_unused_state_default = createRule({
|
|
|
2989
2982
|
return;
|
|
2990
2983
|
}
|
|
2991
2984
|
const hasState = node.id.properties.some((prop) => {
|
|
2992
|
-
if (prop.type === types.AST_NODE_TYPES.Property &&
|
|
2985
|
+
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2993
2986
|
return getName4(prop.key) === "state";
|
|
2994
2987
|
}
|
|
2995
2988
|
return false;
|
|
@@ -3089,6 +3082,20 @@ var no_use_context_default = createRule({
|
|
|
3089
3082
|
},
|
|
3090
3083
|
defaultOptions: []
|
|
3091
3084
|
});
|
|
3085
|
+
function getAssociatedTokens(context, node) {
|
|
3086
|
+
{
|
|
3087
|
+
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
3088
|
+
const tokenAfter = context.sourceCode.getTokenAfter(node);
|
|
3089
|
+
const tokens = [];
|
|
3090
|
+
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
|
|
3091
|
+
tokens.push(tokenBefore);
|
|
3092
|
+
}
|
|
3093
|
+
if (tokenAfter?.value === ",") {
|
|
3094
|
+
tokens.push(tokenAfter);
|
|
3095
|
+
}
|
|
3096
|
+
return tokens;
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3092
3099
|
var RULE_NAME46 = "no-useless-fragment";
|
|
3093
3100
|
var defaultOptions = [{
|
|
3094
3101
|
allowExpressions: true
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings, DEFA
|
|
|
2
2
|
import * as JSX7 from '@eslint-react/jsx';
|
|
3
3
|
import * as AST11 from '@eslint-react/ast';
|
|
4
4
|
import { isForwardRefCall, isClassComponent, isThisSetState, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERComponentFlag, DISPLAY_NAME_ASSIGNMENT_SELECTOR, isCreateContextCall, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideRenderMethod, isCreateElementCall, isReactHookCall, isReactHookCallWithNameAlias, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
5
|
-
import { _, getOrUpdate, identity } from '@eslint-react/eff';
|
|
5
|
+
import { _, getOrUpdate, constTrue, constFalse, identity } from '@eslint-react/eff';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
@@ -110,25 +110,9 @@ var settings3 = {
|
|
|
110
110
|
|
|
111
111
|
// package.json
|
|
112
112
|
var name4 = "eslint-plugin-react-x";
|
|
113
|
-
var version = "1.28.1-beta.
|
|
113
|
+
var version = "1.28.1-beta.5";
|
|
114
114
|
var createRule = createRuleForPlugin("x");
|
|
115
115
|
|
|
116
|
-
// src/utils/get-associated-tokens.ts
|
|
117
|
-
function getAssociatedTokens(context, node) {
|
|
118
|
-
{
|
|
119
|
-
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
120
|
-
const tokenAfter = context.sourceCode.getTokenAfter(node);
|
|
121
|
-
const tokens = [];
|
|
122
|
-
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
|
|
123
|
-
tokens.push(tokenBefore);
|
|
124
|
-
}
|
|
125
|
-
if (tokenAfter?.value === ",") {
|
|
126
|
-
tokens.push(tokenAfter);
|
|
127
|
-
}
|
|
128
|
-
return tokens;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
116
|
// src/rules/avoid-shorthand-boolean.ts
|
|
133
117
|
var RULE_NAME = "avoid-shorthand-boolean";
|
|
134
118
|
var RULE_FEATURES = [
|
|
@@ -241,8 +225,11 @@ var RULE_NAME4 = "no-access-state-in-setstate";
|
|
|
241
225
|
var RULE_FEATURES4 = [
|
|
242
226
|
"CHK"
|
|
243
227
|
];
|
|
228
|
+
function isKeyLiteral(node, key) {
|
|
229
|
+
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
230
|
+
}
|
|
244
231
|
function getName(node) {
|
|
245
|
-
if (AST11.
|
|
232
|
+
if (AST11.isTsOnlyExpression(node)) {
|
|
246
233
|
return getName(node.expression);
|
|
247
234
|
}
|
|
248
235
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -351,7 +338,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
351
338
|
return;
|
|
352
339
|
}
|
|
353
340
|
const hasState = node.id.properties.some(
|
|
354
|
-
(prop) => prop.type === AST_NODE_TYPES.Property &&
|
|
341
|
+
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && getName(prop.key) === "state"
|
|
355
342
|
);
|
|
356
343
|
if (!hasState) {
|
|
357
344
|
return;
|
|
@@ -1219,7 +1206,7 @@ var RULE_FEATURES22 = [
|
|
|
1219
1206
|
"CHK"
|
|
1220
1207
|
];
|
|
1221
1208
|
function getName2(node) {
|
|
1222
|
-
if (AST11.
|
|
1209
|
+
if (AST11.isTsOnlyExpression(node)) {
|
|
1223
1210
|
return getName2(node.expression);
|
|
1224
1211
|
}
|
|
1225
1212
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -1373,7 +1360,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1373
1360
|
if (!AST11.isFunction(iter)) return;
|
|
1374
1361
|
const arg0 = call?.arguments[0];
|
|
1375
1362
|
if (call == null || arg0 == null) return;
|
|
1376
|
-
if (AST11.
|
|
1363
|
+
if (AST11.getEcmaExpression(arg0) !== iter) {
|
|
1377
1364
|
return;
|
|
1378
1365
|
}
|
|
1379
1366
|
keyedEntries.set(call, {
|
|
@@ -2665,8 +2652,11 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2665
2652
|
"UNSAFE_componentWillReceiveProps",
|
|
2666
2653
|
"UNSAFE_componentWillUpdate"
|
|
2667
2654
|
]);
|
|
2655
|
+
function isKeyLiteral2(node, key) {
|
|
2656
|
+
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
2657
|
+
}
|
|
2668
2658
|
function getName3(node) {
|
|
2669
|
-
if (AST11.
|
|
2659
|
+
if (AST11.isTsOnlyExpression(node)) {
|
|
2670
2660
|
return getName3(node.expression);
|
|
2671
2661
|
}
|
|
2672
2662
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2744,7 +2734,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2744
2734
|
if (node.static) {
|
|
2745
2735
|
return;
|
|
2746
2736
|
}
|
|
2747
|
-
if (
|
|
2737
|
+
if (isKeyLiteral2(node, node.key)) {
|
|
2748
2738
|
propertyDefs.get(currentClass)?.add(node.key);
|
|
2749
2739
|
}
|
|
2750
2740
|
}
|
|
@@ -2765,7 +2755,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2765
2755
|
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2766
2756
|
return;
|
|
2767
2757
|
}
|
|
2768
|
-
if (!AST11.isThisExpression(node.object) || !
|
|
2758
|
+
if (!AST11.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2769
2759
|
return;
|
|
2770
2760
|
}
|
|
2771
2761
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
@@ -2792,7 +2782,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2792
2782
|
}
|
|
2793
2783
|
if (node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2794
2784
|
for (const prop of node.id.properties) {
|
|
2795
|
-
if (prop.type === AST_NODE_TYPES.Property &&
|
|
2785
|
+
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2796
2786
|
const keyName = getName3(prop.key);
|
|
2797
2787
|
if (keyName != null) {
|
|
2798
2788
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
@@ -2809,8 +2799,11 @@ var RULE_NAME44 = "no-unused-state";
|
|
|
2809
2799
|
var RULE_FEATURES44 = [
|
|
2810
2800
|
"CHK"
|
|
2811
2801
|
];
|
|
2802
|
+
function isKeyLiteral3(node, key) {
|
|
2803
|
+
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
2804
|
+
}
|
|
2812
2805
|
function getName4(node) {
|
|
2813
|
-
if (AST11.
|
|
2806
|
+
if (AST11.isTsOnlyExpression(node)) {
|
|
2814
2807
|
return getName4(node.expression);
|
|
2815
2808
|
}
|
|
2816
2809
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2962,7 +2955,7 @@ var no_unused_state_default = createRule({
|
|
|
2962
2955
|
return;
|
|
2963
2956
|
}
|
|
2964
2957
|
const hasState = node.id.properties.some((prop) => {
|
|
2965
|
-
if (prop.type === AST_NODE_TYPES.Property &&
|
|
2958
|
+
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2966
2959
|
return getName4(prop.key) === "state";
|
|
2967
2960
|
}
|
|
2968
2961
|
return false;
|
|
@@ -3062,6 +3055,20 @@ var no_use_context_default = createRule({
|
|
|
3062
3055
|
},
|
|
3063
3056
|
defaultOptions: []
|
|
3064
3057
|
});
|
|
3058
|
+
function getAssociatedTokens(context, node) {
|
|
3059
|
+
{
|
|
3060
|
+
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
3061
|
+
const tokenAfter = context.sourceCode.getTokenAfter(node);
|
|
3062
|
+
const tokens = [];
|
|
3063
|
+
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
|
|
3064
|
+
tokens.push(tokenBefore);
|
|
3065
|
+
}
|
|
3066
|
+
if (tokenAfter?.value === ",") {
|
|
3067
|
+
tokens.push(tokenAfter);
|
|
3068
|
+
}
|
|
3069
|
+
return tokens;
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3065
3072
|
var RULE_NAME46 = "no-useless-fragment";
|
|
3066
3073
|
var defaultOptions = [{
|
|
3067
3074
|
allowExpressions: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.28.1-beta.
|
|
3
|
+
"version": "1.28.1-beta.5",
|
|
4
4
|
"description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"is-immutable-type": "^5.0.1",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.6.2",
|
|
53
|
-
"@eslint-react/ast": "1.28.1-beta.
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/shared": "1.28.1-beta.
|
|
58
|
-
"@eslint-react/var": "1.28.1-beta.
|
|
53
|
+
"@eslint-react/ast": "1.28.1-beta.5",
|
|
54
|
+
"@eslint-react/eff": "1.28.1-beta.5",
|
|
55
|
+
"@eslint-react/jsx": "1.28.1-beta.5",
|
|
56
|
+
"@eslint-react/core": "1.28.1-beta.5",
|
|
57
|
+
"@eslint-react/shared": "1.28.1-beta.5",
|
|
58
|
+
"@eslint-react/var": "1.28.1-beta.5"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.0.10",
|