eslint-plugin-react-x 3.0.0-next.60 → 3.0.0-next.62
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 +65 -26
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { ESLintUtils } from "@typescript-eslint/utils";
|
|
|
5
5
|
import { P, isMatching, match } from "ts-pattern";
|
|
6
6
|
import ts from "typescript";
|
|
7
7
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
8
|
-
import { findEnclosingAssignmentTarget, findVariable, getObjectType, getVariableInitializer, isAssignmentTargetEqual } from "@eslint-react/var";
|
|
9
|
-
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
10
8
|
import { constFalse, constTrue, constVoid, flow, getOrElseUpdate, identity, not, unit } from "@eslint-react/eff";
|
|
9
|
+
import { findEnclosingAssignmentTarget, findVariable, getObjectType, isAssignmentTargetEqual } from "@eslint-react/var";
|
|
10
|
+
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
11
11
|
import { compare } from "compare-versions";
|
|
12
12
|
import { getConstrainedTypeAtLocation } from "@typescript-eslint/type-utils";
|
|
13
13
|
import { unionConstituents } from "ts-api-utils";
|
|
@@ -69,7 +69,7 @@ const rules$7 = {
|
|
|
69
69
|
//#endregion
|
|
70
70
|
//#region package.json
|
|
71
71
|
var name$6 = "eslint-plugin-react-x";
|
|
72
|
-
var version = "3.0.0-next.
|
|
72
|
+
var version = "3.0.0-next.62";
|
|
73
73
|
|
|
74
74
|
//#endregion
|
|
75
75
|
//#region src/utils/create-rule.ts
|
|
@@ -1289,7 +1289,7 @@ function create$61(context) {
|
|
|
1289
1289
|
* @returns True if `id` is a state variable, false otherwise.
|
|
1290
1290
|
*/
|
|
1291
1291
|
function isStateValue(id) {
|
|
1292
|
-
const initNode =
|
|
1292
|
+
const initNode = resolve$4(findVariable(id, context.sourceCode.getScope(id)));
|
|
1293
1293
|
if (initNode == null || initNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
1294
1294
|
if (!isUseStateCall(initNode)) return false;
|
|
1295
1295
|
const declarator = initNode.parent;
|
|
@@ -1388,6 +1388,13 @@ function create$61(context) {
|
|
|
1388
1388
|
}
|
|
1389
1389
|
});
|
|
1390
1390
|
}
|
|
1391
|
+
function resolve$4(v) {
|
|
1392
|
+
if (v == null) return unit;
|
|
1393
|
+
const def = v.defs.at(0);
|
|
1394
|
+
if (def == null) return unit;
|
|
1395
|
+
if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
|
|
1396
|
+
return def.node;
|
|
1397
|
+
}
|
|
1391
1398
|
|
|
1392
1399
|
//#endregion
|
|
1393
1400
|
//#region src/rules/jsx-dollar/jsx-dollar.ts
|
|
@@ -3144,7 +3151,7 @@ function create$22(context) {
|
|
|
3144
3151
|
const [arg0, arg1] = init.arguments;
|
|
3145
3152
|
if (arg0 == null || arg1 == null) return;
|
|
3146
3153
|
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
3147
|
-
const initNode =
|
|
3154
|
+
const initNode = resolve$3(findVariable(n.name, scope));
|
|
3148
3155
|
if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
3149
3156
|
return initNode.elements.length === 0;
|
|
3150
3157
|
}).otherwise(() => false)) {
|
|
@@ -3155,7 +3162,7 @@ function create$22(context) {
|
|
|
3155
3162
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
3156
3163
|
return n;
|
|
3157
3164
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
3158
|
-
const initNode =
|
|
3165
|
+
const initNode = resolve$3(findVariable(n.name, scope));
|
|
3159
3166
|
if (initNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && initNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
3160
3167
|
return initNode;
|
|
3161
3168
|
}).otherwise(() => null);
|
|
@@ -3192,6 +3199,13 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
|
3192
3199
|
node
|
|
3193
3200
|
};
|
|
3194
3201
|
}
|
|
3202
|
+
function resolve$3(v) {
|
|
3203
|
+
if (v == null) return unit;
|
|
3204
|
+
const def = v.defs.at(0);
|
|
3205
|
+
if (def == null) return unit;
|
|
3206
|
+
if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
|
|
3207
|
+
return def.node;
|
|
3208
|
+
}
|
|
3195
3209
|
|
|
3196
3210
|
//#endregion
|
|
3197
3211
|
//#region src/rules/no-unnecessary-use-memo/no-unnecessary-use-memo.ts
|
|
@@ -3228,7 +3242,7 @@ function create$21(context) {
|
|
|
3228
3242
|
return;
|
|
3229
3243
|
}
|
|
3230
3244
|
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
3231
|
-
const initNode =
|
|
3245
|
+
const initNode = resolve$2(findVariable(n.name, scope));
|
|
3232
3246
|
if (initNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
3233
3247
|
return initNode.elements.length === 0;
|
|
3234
3248
|
}).otherwise(() => false)) {
|
|
@@ -3239,7 +3253,7 @@ function create$21(context) {
|
|
|
3239
3253
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
3240
3254
|
return n;
|
|
3241
3255
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
3242
|
-
const variableNode =
|
|
3256
|
+
const variableNode = resolve$2(findVariable(n.name, scope));
|
|
3243
3257
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
3244
3258
|
return variableNode;
|
|
3245
3259
|
}).otherwise(() => null);
|
|
@@ -3276,6 +3290,13 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
|
3276
3290
|
node
|
|
3277
3291
|
};
|
|
3278
3292
|
}
|
|
3293
|
+
function resolve$2(v) {
|
|
3294
|
+
if (v == null) return unit;
|
|
3295
|
+
const def = v.defs.at(0);
|
|
3296
|
+
if (def == null) return unit;
|
|
3297
|
+
if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
|
|
3298
|
+
return def.node;
|
|
3299
|
+
}
|
|
3279
3300
|
|
|
3280
3301
|
//#endregion
|
|
3281
3302
|
//#region src/rules/no-unnecessary-use-prefix/no-unnecessary-use-prefix.ts
|
|
@@ -6545,7 +6566,7 @@ function create$5(context) {
|
|
|
6545
6566
|
}
|
|
6546
6567
|
}
|
|
6547
6568
|
function isIdFromUseStateCall(id, at) {
|
|
6548
|
-
const initNode =
|
|
6569
|
+
const initNode = resolve$1(findVariable(id, context.sourceCode.getScope(id)));
|
|
6549
6570
|
if (initNode == null) return false;
|
|
6550
6571
|
if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
6551
6572
|
if (!isUseStateCall(initNode)) return false;
|
|
@@ -6668,7 +6689,7 @@ function create$5(context) {
|
|
|
6668
6689
|
},
|
|
6669
6690
|
"Program:exit"() {
|
|
6670
6691
|
const getSetStateCalls = (id, initialScope) => {
|
|
6671
|
-
const node =
|
|
6692
|
+
const node = resolve$1(findVariable(id, initialScope));
|
|
6672
6693
|
switch (node?.type) {
|
|
6673
6694
|
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
6674
6695
|
case AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -6703,6 +6724,17 @@ function create$5(context) {
|
|
|
6703
6724
|
}
|
|
6704
6725
|
});
|
|
6705
6726
|
}
|
|
6727
|
+
function resolve$1(v) {
|
|
6728
|
+
if (v == null) return unit;
|
|
6729
|
+
const def = v.defs.at(0);
|
|
6730
|
+
if (def == null) return unit;
|
|
6731
|
+
switch (true) {
|
|
6732
|
+
case def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration: return def.node;
|
|
6733
|
+
case def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration: return def.node;
|
|
6734
|
+
case "init" in def.node && def.node.init != null && !("declarations" in def.node.init): return def.node.init;
|
|
6735
|
+
default: return unit;
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6706
6738
|
|
|
6707
6739
|
//#endregion
|
|
6708
6740
|
//#region src/rules/set-state-in-render/set-state-in-render.ts
|
|
@@ -6727,7 +6759,7 @@ function create$4(context) {
|
|
|
6727
6759
|
return core.isUseStateLikeCall(node, additionalStateHooks);
|
|
6728
6760
|
}
|
|
6729
6761
|
function isIdFromUseStateCall(topLevelId, at) {
|
|
6730
|
-
const initNode =
|
|
6762
|
+
const initNode = resolve(findVariable(topLevelId, context.sourceCode.getScope(topLevelId)));
|
|
6731
6763
|
if (initNode == null) return false;
|
|
6732
6764
|
if (initNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
6733
6765
|
if (!isUseStateCall(initNode)) return false;
|
|
@@ -6840,6 +6872,13 @@ function create$4(context) {
|
|
|
6840
6872
|
}
|
|
6841
6873
|
});
|
|
6842
6874
|
}
|
|
6875
|
+
function resolve(v) {
|
|
6876
|
+
if (v == null) return unit;
|
|
6877
|
+
const def = v.defs.at(0);
|
|
6878
|
+
if (def == null) return unit;
|
|
6879
|
+
if ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)) return def.node.init;
|
|
6880
|
+
return def.node;
|
|
6881
|
+
}
|
|
6843
6882
|
|
|
6844
6883
|
//#endregion
|
|
6845
6884
|
//#region src/rules/unsupported-syntax/unsupported-syntax.ts
|
|
@@ -7097,14 +7136,6 @@ function create$1(context) {
|
|
|
7097
7136
|
//#endregion
|
|
7098
7137
|
//#region src/rules/unstable-rules-of-props/unstable-rules-of-props.ts
|
|
7099
7138
|
const RULE_NAME = "unstable-rules-of-props";
|
|
7100
|
-
/**
|
|
7101
|
-
* Pairs of [controlled prop, uncontrolled prop] that must not appear together
|
|
7102
|
-
* on the same JSX element.
|
|
7103
|
-
*
|
|
7104
|
-
* - `value` → controlled; `defaultValue` → uncontrolled
|
|
7105
|
-
* - `checked` → controlled; `defaultChecked` → uncontrolled
|
|
7106
|
-
*/
|
|
7107
|
-
const CONTROLLED_UNCONTROLLED_PAIRS = [["value", "defaultValue"], ["checked", "defaultChecked"]];
|
|
7108
7139
|
var unstable_rules_of_props_default = createRule({
|
|
7109
7140
|
meta: {
|
|
7110
7141
|
type: "problem",
|
|
@@ -7117,25 +7148,33 @@ var unstable_rules_of_props_default = createRule({
|
|
|
7117
7148
|
defaultOptions: []
|
|
7118
7149
|
});
|
|
7119
7150
|
function create(context) {
|
|
7151
|
+
/**
|
|
7152
|
+
* Pairs of [controlled prop, uncontrolled prop] that must not appear together
|
|
7153
|
+
* on the same JSX element.
|
|
7154
|
+
*
|
|
7155
|
+
* - `value` → controlled; `defaultValue` → uncontrolled
|
|
7156
|
+
* - `checked` → controlled; `defaultChecked` → uncontrolled
|
|
7157
|
+
*/
|
|
7158
|
+
const pairs = [["value", "defaultValue"], ["checked", "defaultChecked"]];
|
|
7120
7159
|
return defineRuleListener({ JSXOpeningElement(node) {
|
|
7121
|
-
const
|
|
7160
|
+
const map = /* @__PURE__ */ new Map();
|
|
7122
7161
|
for (const attr of node.attributes) {
|
|
7123
7162
|
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) continue;
|
|
7124
7163
|
const { name } = attr.name;
|
|
7125
7164
|
if (typeof name !== "string") continue;
|
|
7126
|
-
|
|
7165
|
+
map.set(name, attr);
|
|
7127
7166
|
}
|
|
7128
|
-
for (const [controlled, uncontrolled] of
|
|
7129
|
-
if (!
|
|
7130
|
-
const
|
|
7131
|
-
if (
|
|
7167
|
+
for (const [controlled, uncontrolled] of pairs) {
|
|
7168
|
+
if (!map.has(controlled) || !map.has(uncontrolled)) continue;
|
|
7169
|
+
const attr = map.get(uncontrolled);
|
|
7170
|
+
if (attr == null) continue;
|
|
7132
7171
|
context.report({
|
|
7133
7172
|
data: {
|
|
7134
7173
|
controlled,
|
|
7135
7174
|
uncontrolled
|
|
7136
7175
|
},
|
|
7137
7176
|
messageId: "noControlledAndUncontrolledTogether",
|
|
7138
|
-
node:
|
|
7177
|
+
node: attr
|
|
7139
7178
|
});
|
|
7140
7179
|
}
|
|
7141
7180
|
} });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.62",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"string-ts": "^2.3.1",
|
|
46
46
|
"ts-api-utils": "^2.4.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/shared": "3.0.0-next.
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
48
|
+
"@eslint-react/eff": "3.0.0-next.62",
|
|
49
|
+
"@eslint-react/ast": "3.0.0-next.62",
|
|
50
|
+
"@eslint-react/shared": "3.0.0-next.62",
|
|
51
|
+
"@eslint-react/var": "3.0.0-next.62",
|
|
52
|
+
"@eslint-react/core": "3.0.0-next.62"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|