eslint-plugin-react-x 5.28.3 → 5.28.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 +35 -33
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ const rules$6 = {
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region package.json
|
|
137
137
|
var name$6 = "eslint-plugin-react-x";
|
|
138
|
-
var version = "5.28.
|
|
138
|
+
var version = "5.28.5";
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/utils/create-rule.ts
|
|
141
141
|
function getDocsUrl(ruleName) {
|
|
@@ -157,7 +157,7 @@ var error_boundaries_default = createRule({
|
|
|
157
157
|
});
|
|
158
158
|
function create$50(context) {
|
|
159
159
|
if (!context.sourceCode.text.includes("try")) return {};
|
|
160
|
-
const hint = core.
|
|
160
|
+
const hint = core.JSXDetectionHint.DoNotIncludeJSXWithNullValue | core.JSXDetectionHint.DoNotIncludeJSXWithNumberValue | core.JSXDetectionHint.DoNotIncludeJSXWithBigIntValue | core.JSXDetectionHint.DoNotIncludeJSXWithStringValue | core.JSXDetectionHint.DoNotIncludeJSXWithBooleanValue | core.JSXDetectionHint.DoNotIncludeJSXWithUndefinedValue | core.JSXDetectionHint.DoNotIncludeJSXWithEmptyArrayValue;
|
|
161
161
|
const fc = core.getFunctionComponentCollector(context);
|
|
162
162
|
const hc = core.getHookCollector(context);
|
|
163
163
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -184,7 +184,7 @@ function create$50(context) {
|
|
|
184
184
|
}
|
|
185
185
|
for (const { rets } of funcs) for (const ret of rets) {
|
|
186
186
|
if (ret == null) continue;
|
|
187
|
-
if (!core.
|
|
187
|
+
if (!core.isJSXLike(context, ret, hint)) continue;
|
|
188
188
|
const stmt = Traverse.findEnclosingTryBlock(ret);
|
|
189
189
|
if (stmt != null && !reported.has(stmt)) {
|
|
190
190
|
context.report({
|
|
@@ -2920,7 +2920,7 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2920
2920
|
create: create$22
|
|
2921
2921
|
});
|
|
2922
2922
|
function create$22(context) {
|
|
2923
|
-
const hint = core.FunctionComponentDetectionHint.
|
|
2923
|
+
const hint = core.FunctionComponentDetectionHint.DoNotIncludeJSXWithNumberValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithBooleanValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithNullValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithStringValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithUndefinedValue | core.FunctionComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJSX | core.FunctionComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJSX | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback;
|
|
2924
2924
|
const fc = core.getFunctionComponentCollector(context, { hint });
|
|
2925
2925
|
const cc = core.getClassComponentCollector(context);
|
|
2926
2926
|
return merge(fc.visitor, cc.visitor, { "Program:exit"(program) {
|
|
@@ -3232,36 +3232,38 @@ function create$13(context) {
|
|
|
3232
3232
|
if (compilationMode === "annotation" && context.sourceCode.ast.body.some((stmt) => Check.isDirective(stmt, "use memo"))) return {};
|
|
3233
3233
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
3234
3234
|
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3235
|
-
const
|
|
3235
|
+
const constructions = /* @__PURE__ */ new WeakMap();
|
|
3236
3236
|
return merge(visitor, {
|
|
3237
3237
|
JSXOpeningElement(node) {
|
|
3238
3238
|
const selfName = getElementFullType(node.parent).split(".").at(-1);
|
|
3239
3239
|
if (selfName == null) return;
|
|
3240
3240
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
3241
|
+
const enclosingFunction = Traverse.findParent(node, Check.isFunction);
|
|
3242
|
+
if (enclosingFunction == null) return;
|
|
3243
|
+
if (compilationMode === "annotation" && core.isFunctionHasDirective(enclosingFunction, "use memo")) return;
|
|
3241
3244
|
const attribute = node.attributes.findLast(isAttribute("value"));
|
|
3242
3245
|
if (attribute?.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
3243
|
-
const
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
+
const valueExpression = attribute.value.expression;
|
|
3247
|
+
const construction = resolveObjectType(context, valueExpression);
|
|
3248
|
+
if (construction == null) return;
|
|
3249
|
+
if (core.isHookCall(construction.node)) return;
|
|
3250
|
+
getOrInsertComputed(constructions, enclosingFunction, () => []).push(construction);
|
|
3246
3251
|
},
|
|
3247
3252
|
"Program:exit"(program) {
|
|
3248
|
-
const
|
|
3249
|
-
|
|
3250
|
-
const
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
messageId: "unstable-context-value",
|
|
3263
|
-
node: constructionNode
|
|
3264
|
-
});
|
|
3253
|
+
for (const { directives, node: component } of api.getAllComponents(program)) {
|
|
3254
|
+
if (compilationMode === "annotation" && directives.some((d) => d.directive === "use memo")) continue;
|
|
3255
|
+
for (const construction of constructions.get(component) ?? []) {
|
|
3256
|
+
const { kind, node: constructionNode } = construction;
|
|
3257
|
+
const suggestion = kind === "function" ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
3258
|
+
context.report({
|
|
3259
|
+
data: {
|
|
3260
|
+
kind: getHumanReadableKind$1(constructionNode),
|
|
3261
|
+
suggestion
|
|
3262
|
+
},
|
|
3263
|
+
messageId: "unstable-context-value",
|
|
3264
|
+
node: constructionNode
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3265
3267
|
}
|
|
3266
3268
|
}
|
|
3267
3269
|
});
|
|
@@ -3309,28 +3311,28 @@ function create$12(context, [options]) {
|
|
|
3309
3311
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3310
3312
|
if (compilationMode === "annotation" && context.sourceCode.ast.body.some((stmt) => Check.isDirective(stmt, "use memo"))) return {};
|
|
3311
3313
|
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3312
|
-
const declarators =
|
|
3314
|
+
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3313
3315
|
const { safeDefaultProps = [] } = options;
|
|
3314
3316
|
const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
|
|
3315
3317
|
return merge(visitor, {
|
|
3316
3318
|
[SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR](node) {
|
|
3317
|
-
|
|
3319
|
+
const enclosingFunction = Traverse.findParent(node, Check.isFunction);
|
|
3320
|
+
if (enclosingFunction == null) return;
|
|
3321
|
+
getOrInsertComputed(declarators, enclosingFunction, () => []).push(node);
|
|
3318
3322
|
},
|
|
3319
3323
|
"Program:exit"(program) {
|
|
3320
|
-
const
|
|
3321
|
-
const innermostComponentOf = (node) => components.find((component) => component.range[0] <= node.range[0] && node.range[1] <= component.range[1]);
|
|
3322
|
-
for (const component of components) {
|
|
3324
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
3323
3325
|
const { params } = component;
|
|
3324
3326
|
const [props] = params;
|
|
3325
3327
|
if (props == null) continue;
|
|
3326
3328
|
const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => properties).with({ type: AST_NODE_TYPES.Identifier }, ({ name }) => {
|
|
3327
|
-
return declarators.filter((d) => d.init.name === name
|
|
3329
|
+
return declarators.get(component)?.filter((d) => d.init.name === name).flatMap((d) => d.id.properties) ?? [];
|
|
3328
3330
|
}).otherwise(() => []);
|
|
3329
3331
|
for (const prop of properties) {
|
|
3330
3332
|
if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
|
|
3331
3333
|
const { value } = prop;
|
|
3332
3334
|
const { right } = value;
|
|
3333
|
-
const construction = resolveObjectType(context, value
|
|
3335
|
+
const construction = resolveObjectType(context, value);
|
|
3334
3336
|
if (construction == null) continue;
|
|
3335
3337
|
if (core.isHookCall(construction.node)) continue;
|
|
3336
3338
|
if (safePatterns.length > 0) {
|
|
@@ -7130,7 +7132,7 @@ var static_components_default = createRule({
|
|
|
7130
7132
|
create: create$3
|
|
7131
7133
|
});
|
|
7132
7134
|
function create$3(context) {
|
|
7133
|
-
const hint = core.FunctionComponentDetectionHint.
|
|
7135
|
+
const hint = core.FunctionComponentDetectionHint.DoNotIncludeJSXWithNumberValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithBooleanValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithNullValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithStringValue | core.FunctionComponentDetectionHint.DoNotIncludeJSXWithUndefinedValue | core.FunctionComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJSX | core.FunctionComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJSX | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
7134
7136
|
const fc = core.getFunctionComponentCollector(context, { hint });
|
|
7135
7137
|
const cc = core.getClassComponentCollector(context);
|
|
7136
7138
|
const { facts, visitor } = createFactCollector$1();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.28.
|
|
3
|
+
"version": "5.28.5",
|
|
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",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@eslint-react/ast": "5.28.
|
|
40
|
-
"@eslint-react/core": "5.28.
|
|
41
|
-
"@eslint-react/eslint": "5.28.
|
|
42
|
-
"@eslint-react/jsx": "5.28.
|
|
43
|
-
"@eslint-react/shared": "5.28.
|
|
44
|
-
"@eslint-react/var": "5.28.
|
|
39
|
+
"@eslint-react/ast": "5.28.5",
|
|
40
|
+
"@eslint-react/core": "5.28.5",
|
|
41
|
+
"@eslint-react/eslint": "5.28.5",
|
|
42
|
+
"@eslint-react/jsx": "5.28.5",
|
|
43
|
+
"@eslint-react/shared": "5.28.5",
|
|
44
|
+
"@eslint-react/var": "5.28.5",
|
|
45
45
|
"@typescript-eslint/scope-manager": "^8.72.0",
|
|
46
46
|
"@typescript-eslint/types": "^8.72.0",
|
|
47
47
|
"@typescript-eslint/typescript-estree": "^8.72.0",
|