eslint-plugin-react-x 3.0.0-beta.14 → 3.0.0-beta.15
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 +28 -30
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ const rules$7 = {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region package.json
|
|
70
70
|
var name$6 = "eslint-plugin-react-x";
|
|
71
|
-
var version = "3.0.0-beta.
|
|
71
|
+
var version = "3.0.0-beta.15";
|
|
72
72
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/utils/create-rule.ts
|
|
@@ -4208,6 +4208,17 @@ function create$2(context) {
|
|
|
4208
4208
|
default: return false;
|
|
4209
4209
|
}
|
|
4210
4210
|
}
|
|
4211
|
+
function isHookDecl(node) {
|
|
4212
|
+
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
4213
|
+
if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
|
|
4214
|
+
const init = node.init;
|
|
4215
|
+
if (init == null || init.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
4216
|
+
switch (init.callee.type) {
|
|
4217
|
+
case AST_NODE_TYPES.Identifier: return core.isHookName(init.callee.name);
|
|
4218
|
+
case AST_NODE_TYPES.MemberExpression: return init.callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(init.callee.property.name);
|
|
4219
|
+
default: return false;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4211
4222
|
return defineRuleListener({
|
|
4212
4223
|
":function"(node) {
|
|
4213
4224
|
const kind = getFunctionKind(node);
|
|
@@ -4234,7 +4245,19 @@ function create$2(context) {
|
|
|
4234
4245
|
case entry.kind === "immediate" && ast.findParentNode(entry.node, ast.isFunction) === setupFunction: {
|
|
4235
4246
|
const args0 = node.arguments.at(0);
|
|
4236
4247
|
if (args0 == null) return;
|
|
4237
|
-
|
|
4248
|
+
function isArgumentUsingRefValue(context, node) {
|
|
4249
|
+
const isUsingRefValue = (n) => {
|
|
4250
|
+
switch (n.type) {
|
|
4251
|
+
case AST_NODE_TYPES.Identifier: return core.isInitializedFromRef(n.name, context.sourceCode.getScope(n));
|
|
4252
|
+
case AST_NODE_TYPES.MemberExpression: return isUsingRefValue(n.object);
|
|
4253
|
+
case AST_NODE_TYPES.CallExpression: return isUsingRefValue(n.callee) || ast.getNestedIdentifiers(n).some(isUsingRefValue);
|
|
4254
|
+
default: return false;
|
|
4255
|
+
}
|
|
4256
|
+
};
|
|
4257
|
+
if (isUsingRefValue(node)) return true;
|
|
4258
|
+
return ast.isFunction(node) && context.sourceCode.getScope(node.body).references.some((r) => isUsingRefValue(r.identifier));
|
|
4259
|
+
}
|
|
4260
|
+
if (isArgumentUsingRefValue(context, args0)) return;
|
|
4238
4261
|
context.report({
|
|
4239
4262
|
messageId: "default",
|
|
4240
4263
|
node,
|
|
@@ -4243,7 +4266,7 @@ function create$2(context) {
|
|
|
4243
4266
|
return;
|
|
4244
4267
|
}
|
|
4245
4268
|
default: {
|
|
4246
|
-
const init = ast.findParentNode(node,
|
|
4269
|
+
const init = ast.findParentNode(node, isHookDecl)?.init;
|
|
4247
4270
|
if (init == null) getOrElseUpdate(setStateCallsByFn, entry.node, () => []).push(node);
|
|
4248
4271
|
else getOrElseUpdate(setStateInHookCallbacks, init, () => []).push(node);
|
|
4249
4272
|
}
|
|
@@ -4264,14 +4287,14 @@ function create$2(context) {
|
|
|
4264
4287
|
const parent = node.parent.parent;
|
|
4265
4288
|
if (parent.type !== AST_NODE_TYPES.CallExpression) break;
|
|
4266
4289
|
if (!core.isUseMemoCall(parent)) break;
|
|
4267
|
-
const init = ast.findParentNode(parent,
|
|
4290
|
+
const init = ast.findParentNode(parent, isHookDecl)?.init;
|
|
4268
4291
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4269
4292
|
break;
|
|
4270
4293
|
}
|
|
4271
4294
|
case AST_NODE_TYPES.CallExpression:
|
|
4272
4295
|
if (node !== node.parent.arguments.at(0)) break;
|
|
4273
4296
|
if (core.isUseCallbackCall(node.parent)) {
|
|
4274
|
-
const init = ast.findParentNode(node.parent,
|
|
4297
|
+
const init = ast.findParentNode(node.parent, isHookDecl)?.init;
|
|
4275
4298
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4276
4299
|
break;
|
|
4277
4300
|
}
|
|
@@ -4315,31 +4338,6 @@ function create$2(context) {
|
|
|
4315
4338
|
}
|
|
4316
4339
|
});
|
|
4317
4340
|
}
|
|
4318
|
-
function isSetterUsingRefValue(context, node) {
|
|
4319
|
-
const isUsingRefValue = (n) => {
|
|
4320
|
-
switch (n.type) {
|
|
4321
|
-
case AST_NODE_TYPES.Identifier: return core.isInitializedFromRef(n.name, context.sourceCode.getScope(n));
|
|
4322
|
-
case AST_NODE_TYPES.MemberExpression: return isUsingRefValue(n.object);
|
|
4323
|
-
case AST_NODE_TYPES.CallExpression: return isUsingRefValue(n.callee) || ast.getNestedIdentifiers(n).some(isUsingRefValue);
|
|
4324
|
-
default: return false;
|
|
4325
|
-
}
|
|
4326
|
-
};
|
|
4327
|
-
if (isUsingRefValue(node)) return true;
|
|
4328
|
-
return ast.isFunction(node) && context.sourceCode.getScope(node.body).references.some((r) => isUsingRefValue(r.identifier));
|
|
4329
|
-
}
|
|
4330
|
-
function isInitFromHookCall(init) {
|
|
4331
|
-
if (init?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
4332
|
-
switch (init.callee.type) {
|
|
4333
|
-
case AST_NODE_TYPES.Identifier: return core.isHookName(init.callee.name);
|
|
4334
|
-
case AST_NODE_TYPES.MemberExpression: return init.callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(init.callee.property.name);
|
|
4335
|
-
default: return false;
|
|
4336
|
-
}
|
|
4337
|
-
}
|
|
4338
|
-
function isVariableDeclaratorFromHookCall(node) {
|
|
4339
|
-
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
4340
|
-
if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
|
|
4341
|
-
return isInitFromHookCall(node.init);
|
|
4342
|
-
}
|
|
4343
4341
|
|
|
4344
4342
|
//#endregion
|
|
4345
4343
|
//#region src/rules/set-state-in-render.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.15",
|
|
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
|
"is-immutable-type": "^5.0.1",
|
|
46
46
|
"ts-api-utils": "^2.4.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "3.0.0-beta.
|
|
49
|
-
"@eslint-react/core": "3.0.0-beta.
|
|
50
|
-
"@eslint-react/eff": "3.0.0-beta.
|
|
51
|
-
"@eslint-react/shared": "3.0.0-beta.
|
|
52
|
-
"@eslint-react/var": "3.0.0-beta.
|
|
48
|
+
"@eslint-react/ast": "3.0.0-beta.15",
|
|
49
|
+
"@eslint-react/core": "3.0.0-beta.15",
|
|
50
|
+
"@eslint-react/eff": "3.0.0-beta.15",
|
|
51
|
+
"@eslint-react/shared": "3.0.0-beta.15",
|
|
52
|
+
"@eslint-react/var": "3.0.0-beta.15"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|