eslint-plugin-react-x 3.0.0-next.13 → 3.0.0-next.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 +32 -18
- 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-next.
|
|
71
|
+
var version = "3.0.0-next.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);
|
|
@@ -4231,15 +4242,31 @@ function create$2(context) {
|
|
|
4231
4242
|
case entry.kind === "deferred":
|
|
4232
4243
|
case entry.node.async: break;
|
|
4233
4244
|
case entry.node === setupFunction:
|
|
4234
|
-
case entry.kind === "immediate" && ast.findParentNode(entry.node, ast.isFunction) === setupFunction:
|
|
4245
|
+
case entry.kind === "immediate" && ast.findParentNode(entry.node, ast.isFunction) === setupFunction: {
|
|
4246
|
+
const args0 = node.arguments.at(0);
|
|
4247
|
+
if (args0 == null) return;
|
|
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;
|
|
4235
4261
|
context.report({
|
|
4236
4262
|
messageId: "default",
|
|
4237
4263
|
node,
|
|
4238
4264
|
data: { name: context.sourceCode.getText(node.callee) }
|
|
4239
4265
|
});
|
|
4240
4266
|
return;
|
|
4267
|
+
}
|
|
4241
4268
|
default: {
|
|
4242
|
-
const init = ast.findParentNode(node,
|
|
4269
|
+
const init = ast.findParentNode(node, isHookDecl)?.init;
|
|
4243
4270
|
if (init == null) getOrElseUpdate(setStateCallsByFn, entry.node, () => []).push(node);
|
|
4244
4271
|
else getOrElseUpdate(setStateInHookCallbacks, init, () => []).push(node);
|
|
4245
4272
|
}
|
|
@@ -4260,14 +4287,14 @@ function create$2(context) {
|
|
|
4260
4287
|
const parent = node.parent.parent;
|
|
4261
4288
|
if (parent.type !== AST_NODE_TYPES.CallExpression) break;
|
|
4262
4289
|
if (!core.isUseMemoCall(parent)) break;
|
|
4263
|
-
const init = ast.findParentNode(parent,
|
|
4290
|
+
const init = ast.findParentNode(parent, isHookDecl)?.init;
|
|
4264
4291
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4265
4292
|
break;
|
|
4266
4293
|
}
|
|
4267
4294
|
case AST_NODE_TYPES.CallExpression:
|
|
4268
4295
|
if (node !== node.parent.arguments.at(0)) break;
|
|
4269
4296
|
if (core.isUseCallbackCall(node.parent)) {
|
|
4270
|
-
const init = ast.findParentNode(node.parent,
|
|
4297
|
+
const init = ast.findParentNode(node.parent, isHookDecl)?.init;
|
|
4271
4298
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4272
4299
|
break;
|
|
4273
4300
|
}
|
|
@@ -4311,19 +4338,6 @@ function create$2(context) {
|
|
|
4311
4338
|
}
|
|
4312
4339
|
});
|
|
4313
4340
|
}
|
|
4314
|
-
function isInitFromHookCall(init) {
|
|
4315
|
-
if (init?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
4316
|
-
switch (init.callee.type) {
|
|
4317
|
-
case AST_NODE_TYPES.Identifier: return core.isHookName(init.callee.name);
|
|
4318
|
-
case AST_NODE_TYPES.MemberExpression: return init.callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(init.callee.property.name);
|
|
4319
|
-
default: return false;
|
|
4320
|
-
}
|
|
4321
|
-
}
|
|
4322
|
-
function isVariableDeclaratorFromHookCall(node) {
|
|
4323
|
-
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
4324
|
-
if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
|
|
4325
|
-
return isInitFromHookCall(node.init);
|
|
4326
|
-
}
|
|
4327
4341
|
|
|
4328
4342
|
//#endregion
|
|
4329
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-next.
|
|
3
|
+
"version": "3.0.0-next.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-next.
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/var": "3.0.0-next.
|
|
52
|
-
"@eslint-react/
|
|
48
|
+
"@eslint-react/ast": "3.0.0-next.15",
|
|
49
|
+
"@eslint-react/core": "3.0.0-next.15",
|
|
50
|
+
"@eslint-react/eff": "3.0.0-next.15",
|
|
51
|
+
"@eslint-react/var": "3.0.0-next.15",
|
|
52
|
+
"@eslint-react/shared": "3.0.0-next.15"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|