eslint-plugin-react-x 3.0.0-next.14 → 3.0.0-next.16
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 +35 -36
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -48,7 +48,8 @@ const rules$8 = {
|
|
|
48
48
|
"react-x/no-unused-props": "off",
|
|
49
49
|
"react-x/prefer-read-only-props": "off",
|
|
50
50
|
"react-x/refs": "off",
|
|
51
|
-
"react-x/rules-of-hooks": "off"
|
|
51
|
+
"react-x/rules-of-hooks": "off",
|
|
52
|
+
"react-x/set-state-in-render": "off"
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
//#endregion
|
|
@@ -68,7 +69,7 @@ const rules$7 = {
|
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region package.json
|
|
70
71
|
var name$6 = "eslint-plugin-react-x";
|
|
71
|
-
var version = "3.0.0-next.
|
|
72
|
+
var version = "3.0.0-next.16";
|
|
72
73
|
|
|
73
74
|
//#endregion
|
|
74
75
|
//#region src/utils/create-rule.ts
|
|
@@ -3861,7 +3862,7 @@ function isWriteAfterNullCheckIf(node, refName) {
|
|
|
3861
3862
|
var refs_default = createRule({
|
|
3862
3863
|
meta: {
|
|
3863
3864
|
type: "problem",
|
|
3864
|
-
docs: { description: "Validates correct usage of refs by checking that ref.current is not read or written during render." },
|
|
3865
|
+
docs: { description: "Validates correct usage of refs by checking that 'ref.current' is not read or written during render." },
|
|
3865
3866
|
messages: {
|
|
3866
3867
|
readDuringRender: "Do not read 'ref.current' during render. Refs are not available during rendering and their values may be stale or inconsistent. Move this read into an effect or event handler.",
|
|
3867
3868
|
writeDuringRender: "Do not write to 'ref.current' during render. Refs should only be mutated in effects or event handlers. Move this write into an effect or event handler."
|
|
@@ -4208,6 +4209,17 @@ function create$2(context) {
|
|
|
4208
4209
|
default: return false;
|
|
4209
4210
|
}
|
|
4210
4211
|
}
|
|
4212
|
+
function isHookDecl(node) {
|
|
4213
|
+
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
4214
|
+
if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
|
|
4215
|
+
const init = node.init;
|
|
4216
|
+
if (init == null || init.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
4217
|
+
switch (init.callee.type) {
|
|
4218
|
+
case AST_NODE_TYPES.Identifier: return core.isHookName(init.callee.name);
|
|
4219
|
+
case AST_NODE_TYPES.MemberExpression: return init.callee.property.type === AST_NODE_TYPES.Identifier && core.isHookName(init.callee.property.name);
|
|
4220
|
+
default: return false;
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4211
4223
|
return defineRuleListener({
|
|
4212
4224
|
":function"(node) {
|
|
4213
4225
|
const kind = getFunctionKind(node);
|
|
@@ -4234,7 +4246,19 @@ function create$2(context) {
|
|
|
4234
4246
|
case entry.kind === "immediate" && ast.findParentNode(entry.node, ast.isFunction) === setupFunction: {
|
|
4235
4247
|
const args0 = node.arguments.at(0);
|
|
4236
4248
|
if (args0 == null) return;
|
|
4237
|
-
|
|
4249
|
+
function isArgumentUsingRefValue(context, node) {
|
|
4250
|
+
const isUsingRefValue = (n) => {
|
|
4251
|
+
switch (n.type) {
|
|
4252
|
+
case AST_NODE_TYPES.Identifier: return core.isInitializedFromRef(n.name, context.sourceCode.getScope(n));
|
|
4253
|
+
case AST_NODE_TYPES.MemberExpression: return isUsingRefValue(n.object);
|
|
4254
|
+
case AST_NODE_TYPES.CallExpression: return isUsingRefValue(n.callee) || ast.getNestedIdentifiers(n).some(isUsingRefValue);
|
|
4255
|
+
default: return false;
|
|
4256
|
+
}
|
|
4257
|
+
};
|
|
4258
|
+
if (isUsingRefValue(node)) return true;
|
|
4259
|
+
return ast.isFunction(node) && context.sourceCode.getScope(node.body).references.some((r) => isUsingRefValue(r.identifier));
|
|
4260
|
+
}
|
|
4261
|
+
if (isArgumentUsingRefValue(context, args0)) return;
|
|
4238
4262
|
context.report({
|
|
4239
4263
|
messageId: "default",
|
|
4240
4264
|
node,
|
|
@@ -4243,7 +4267,7 @@ function create$2(context) {
|
|
|
4243
4267
|
return;
|
|
4244
4268
|
}
|
|
4245
4269
|
default: {
|
|
4246
|
-
const init = ast.findParentNode(node,
|
|
4270
|
+
const init = ast.findParentNode(node, isHookDecl)?.init;
|
|
4247
4271
|
if (init == null) getOrElseUpdate(setStateCallsByFn, entry.node, () => []).push(node);
|
|
4248
4272
|
else getOrElseUpdate(setStateInHookCallbacks, init, () => []).push(node);
|
|
4249
4273
|
}
|
|
@@ -4264,14 +4288,14 @@ function create$2(context) {
|
|
|
4264
4288
|
const parent = node.parent.parent;
|
|
4265
4289
|
if (parent.type !== AST_NODE_TYPES.CallExpression) break;
|
|
4266
4290
|
if (!core.isUseMemoCall(parent)) break;
|
|
4267
|
-
const init = ast.findParentNode(parent,
|
|
4291
|
+
const init = ast.findParentNode(parent, isHookDecl)?.init;
|
|
4268
4292
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4269
4293
|
break;
|
|
4270
4294
|
}
|
|
4271
4295
|
case AST_NODE_TYPES.CallExpression:
|
|
4272
4296
|
if (node !== node.parent.arguments.at(0)) break;
|
|
4273
4297
|
if (core.isUseCallbackCall(node.parent)) {
|
|
4274
|
-
const init = ast.findParentNode(node.parent,
|
|
4298
|
+
const init = ast.findParentNode(node.parent, isHookDecl)?.init;
|
|
4275
4299
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
4276
4300
|
break;
|
|
4277
4301
|
}
|
|
@@ -4315,31 +4339,6 @@ function create$2(context) {
|
|
|
4315
4339
|
}
|
|
4316
4340
|
});
|
|
4317
4341
|
}
|
|
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
4342
|
|
|
4344
4343
|
//#endregion
|
|
4345
4344
|
//#region src/rules/set-state-in-render.ts
|
|
@@ -4415,15 +4414,15 @@ function create$1(context) {
|
|
|
4415
4414
|
}
|
|
4416
4415
|
return false;
|
|
4417
4416
|
}
|
|
4418
|
-
function
|
|
4417
|
+
function isComponentOrHookLikeFunction(node) {
|
|
4419
4418
|
const id = ast.getFunctionId(node);
|
|
4420
4419
|
if (id == null) return false;
|
|
4421
|
-
if (id.type === AST_NODE_TYPES.Identifier) return core.isComponentName(id.name);
|
|
4422
|
-
if (id.type === AST_NODE_TYPES.MemberExpression && id.property.type === AST_NODE_TYPES.Identifier) return core.isComponentName(id.property.name);
|
|
4420
|
+
if (id.type === AST_NODE_TYPES.Identifier) return core.isComponentName(id.name) || core.isHookName(id.name);
|
|
4421
|
+
if (id.type === AST_NODE_TYPES.MemberExpression && id.property.type === AST_NODE_TYPES.Identifier) return core.isComponentName(id.property.name) || core.isHookName(id.property.name);
|
|
4423
4422
|
return false;
|
|
4424
4423
|
}
|
|
4425
4424
|
function getFunctionKind(node) {
|
|
4426
|
-
if (
|
|
4425
|
+
if (isComponentOrHookLikeFunction(node)) return "component";
|
|
4427
4426
|
const parent = ast.findParentNode(node, not(ast.isTypeExpression)) ?? node.parent;
|
|
4428
4427
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
|
|
4429
4428
|
return "other";
|
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.16",
|
|
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/core": "3.0.0-next.
|
|
50
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
51
|
-
"@eslint-react/shared": "3.0.0-next.
|
|
52
|
-
"@eslint-react/var": "3.0.0-next.
|
|
48
|
+
"@eslint-react/ast": "3.0.0-next.16",
|
|
49
|
+
"@eslint-react/core": "3.0.0-next.16",
|
|
50
|
+
"@eslint-react/eff": "3.0.0-next.16",
|
|
51
|
+
"@eslint-react/shared": "3.0.0-next.16",
|
|
52
|
+
"@eslint-react/var": "3.0.0-next.16"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|