eslint-plugin-react-x 5.8.4-next.1 → 5.8.4-next.2
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 +16 -17
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -143,7 +143,7 @@ const rules$6 = {
|
|
|
143
143
|
//#endregion
|
|
144
144
|
//#region package.json
|
|
145
145
|
var name$6 = "eslint-plugin-react-x";
|
|
146
|
-
var version = "5.8.4-next.
|
|
146
|
+
var version = "5.8.4-next.2";
|
|
147
147
|
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/utils/create-rule.ts
|
|
@@ -1731,13 +1731,13 @@ function create$47(context) {
|
|
|
1731
1731
|
setStateStack.pop();
|
|
1732
1732
|
},
|
|
1733
1733
|
ClassDeclaration(node) {
|
|
1734
|
-
classStack.push([node, core.isClassComponent(
|
|
1734
|
+
classStack.push([node, core.isClassComponent(node)]);
|
|
1735
1735
|
},
|
|
1736
1736
|
"ClassDeclaration:exit"() {
|
|
1737
1737
|
classStack.pop();
|
|
1738
1738
|
},
|
|
1739
1739
|
ClassExpression(node) {
|
|
1740
|
-
classStack.push([node, core.isClassComponent(
|
|
1740
|
+
classStack.push([node, core.isClassComponent(node)]);
|
|
1741
1741
|
},
|
|
1742
1742
|
"ClassExpression:exit"() {
|
|
1743
1743
|
classStack.pop();
|
|
@@ -2246,7 +2246,7 @@ var no_create_ref_default = createRule({
|
|
|
2246
2246
|
});
|
|
2247
2247
|
function create$34(context) {
|
|
2248
2248
|
return merge({ CallExpression(node) {
|
|
2249
|
-
if (core.isCreateRefCall(context, node) && Traverse.findParent(node,
|
|
2249
|
+
if (core.isCreateRefCall(context, node) && Traverse.findParent(node, core.isClassComponent) == null) context.report({
|
|
2250
2250
|
messageId: "default",
|
|
2251
2251
|
node
|
|
2252
2252
|
});
|
|
@@ -2275,7 +2275,7 @@ function create$33(context) {
|
|
|
2275
2275
|
if (!core.isAssignmentToThisState(node)) return;
|
|
2276
2276
|
const parentClass = Traverse.findParent(node, isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
|
|
2277
2277
|
if (parentClass == null) return;
|
|
2278
|
-
if (core.isClassComponent(
|
|
2278
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== Traverse.findParent(node, isConstructorFunction)) context.report({
|
|
2279
2279
|
messageId: "default",
|
|
2280
2280
|
node
|
|
2281
2281
|
});
|
|
@@ -2971,12 +2971,11 @@ function isInsideJSXAttributeValue(node) {
|
|
|
2971
2971
|
/**
|
|
2972
2972
|
* Check whether a given node is declared inside a class component's render block
|
|
2973
2973
|
* Ex: class C extends React.Component { render() { const Nested = () => <div />; } }
|
|
2974
|
-
* @param context The rule context
|
|
2975
2974
|
* @param node The AST node being checked
|
|
2976
2975
|
* @returns `true` if the node is inside a class component's render block
|
|
2977
2976
|
*/
|
|
2978
|
-
function isInsideRenderMethod(
|
|
2979
|
-
return Traverse.findParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(
|
|
2977
|
+
function isInsideRenderMethod(node) {
|
|
2978
|
+
return Traverse.findParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(n.parent.parent)) != null;
|
|
2980
2979
|
}
|
|
2981
2980
|
/**
|
|
2982
2981
|
* Determine whether the node is inside `createElement`'s props argument
|
|
@@ -3055,7 +3054,7 @@ function create$22(context) {
|
|
|
3055
3054
|
});
|
|
3056
3055
|
continue;
|
|
3057
3056
|
}
|
|
3058
|
-
if (isInsideRenderMethod(
|
|
3057
|
+
if (isInsideRenderMethod(component)) context.report({
|
|
3059
3058
|
data: {
|
|
3060
3059
|
name,
|
|
3061
3060
|
suggestion: "Move it to the top level."
|
|
@@ -3134,7 +3133,7 @@ function create$20(context) {
|
|
|
3134
3133
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
3135
3134
|
return merge({ CallExpression(node) {
|
|
3136
3135
|
if (!core.isThisSetStateCall(node)) return;
|
|
3137
|
-
const enclosingClassNode = Traverse.findParent(node,
|
|
3136
|
+
const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
|
|
3138
3137
|
const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidMount(n));
|
|
3139
3138
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3140
3139
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
@@ -3164,7 +3163,7 @@ function create$19(context) {
|
|
|
3164
3163
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
3165
3164
|
return merge({ CallExpression(node) {
|
|
3166
3165
|
if (!core.isThisSetStateCall(node)) return;
|
|
3167
|
-
const enclosingClassNode = Traverse.findParent(node,
|
|
3166
|
+
const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
|
|
3168
3167
|
const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidUpdate(n));
|
|
3169
3168
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3170
3169
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
@@ -3194,7 +3193,7 @@ function create$18(context) {
|
|
|
3194
3193
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
3195
3194
|
return merge({ CallExpression(node) {
|
|
3196
3195
|
if (!core.isThisSetStateCall(node)) return;
|
|
3197
|
-
const enclosingClassNode = Traverse.findParent(node,
|
|
3196
|
+
const enclosingClassNode = Traverse.findParent(node, core.isClassComponent);
|
|
3198
3197
|
const enclosingMethodNode = Traverse.findParent(node, (n) => n === enclosingClassNode || core.isComponentWillUpdate(n));
|
|
3199
3198
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3200
3199
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
@@ -3540,13 +3539,13 @@ function create$11(context) {
|
|
|
3540
3539
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
3541
3540
|
function classEnter(node) {
|
|
3542
3541
|
classStack.push(node);
|
|
3543
|
-
if (!core.isClassComponent(
|
|
3542
|
+
if (!core.isClassComponent(node)) return;
|
|
3544
3543
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
3545
3544
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
3546
3545
|
}
|
|
3547
3546
|
function classExit() {
|
|
3548
3547
|
const currentClass = classStack.pop();
|
|
3549
|
-
if (currentClass == null || !core.isClassComponent(
|
|
3548
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) return;
|
|
3550
3549
|
const id = core.getClassId(currentClass);
|
|
3551
3550
|
const defs = propertyDefs.get(currentClass);
|
|
3552
3551
|
const usages = propertyUsages.get(currentClass);
|
|
@@ -3569,7 +3568,7 @@ function create$11(context) {
|
|
|
3569
3568
|
function methodEnter(node) {
|
|
3570
3569
|
methodStack.push(node);
|
|
3571
3570
|
const currentClass = classStack.at(-1);
|
|
3572
|
-
if (currentClass == null || !core.isClassComponent(
|
|
3571
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) return;
|
|
3573
3572
|
if (node.static) return;
|
|
3574
3573
|
if (isKeyLiteral(node, node.key)) propertyDefs.get(currentClass)?.add(node.key);
|
|
3575
3574
|
}
|
|
@@ -3585,7 +3584,7 @@ function create$11(context) {
|
|
|
3585
3584
|
const currentClass = classStack.at(-1);
|
|
3586
3585
|
const currentMethod = methodStack.at(-1);
|
|
3587
3586
|
if (currentClass == null || currentMethod == null) return;
|
|
3588
|
-
if (!core.isClassComponent(
|
|
3587
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3589
3588
|
if (node.object.type !== AST_NODE_TYPES.ThisExpression || !isKeyLiteral(node, node.property)) return;
|
|
3590
3589
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
3591
3590
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
@@ -3602,7 +3601,7 @@ function create$11(context) {
|
|
|
3602
3601
|
const currentClass = classStack.at(-1);
|
|
3603
3602
|
const currentMethod = methodStack.at(-1);
|
|
3604
3603
|
if (currentClass == null || currentMethod == null) return;
|
|
3605
|
-
if (!core.isClassComponent(
|
|
3604
|
+
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3606
3605
|
if (node.init != null && node.init.type === AST_NODE_TYPES.ThisExpression && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
3607
3606
|
for (const prop of node.id.properties) if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key)) {
|
|
3608
3607
|
const keyName = Extract.getPropertyName(prop.key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.8.4-next.
|
|
3
|
+
"version": "5.8.4-next.2",
|
|
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,12 +45,12 @@
|
|
|
45
45
|
"string-ts": "^2.3.1",
|
|
46
46
|
"ts-api-utils": "^2.5.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "5.8.4-next.
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/jsx": "5.8.4-next.
|
|
52
|
-
"@eslint-react/shared": "5.8.4-next.
|
|
53
|
-
"@eslint-react/var": "5.8.4-next.
|
|
48
|
+
"@eslint-react/ast": "5.8.4-next.2",
|
|
49
|
+
"@eslint-react/eslint": "5.8.4-next.2",
|
|
50
|
+
"@eslint-react/core": "5.8.4-next.2",
|
|
51
|
+
"@eslint-react/jsx": "5.8.4-next.2",
|
|
52
|
+
"@eslint-react/shared": "5.8.4-next.2",
|
|
53
|
+
"@eslint-react/var": "5.8.4-next.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.2.14",
|