eslint-plugin-react-x 2.7.5-next.1 → 2.7.5-next.10
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 +11 -12
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
|
3
3
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
4
4
|
import { P, isMatching, match } from "ts-pattern";
|
|
5
5
|
import ts from "typescript";
|
|
6
|
-
import { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, JsxEmit, findParentJsxAttribute, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, isAssignmentToThisState, isCaptureOwnerStackCall, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUpdate, isCreateContextCall, isCreateElementCall, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRefCall, isGetDerivedStateFromError, isGetDerivedStateFromProps, isInitializedFromReact, isJsxFragmentElement, isJsxHostElement, isJsxText, isLazyCall,
|
|
6
|
+
import { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, JsxEmit, findParentJsxAttribute, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, isAssignmentToThisState, isCaptureOwnerStackCall, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUpdate, isCreateContextCall, isCreateElementCall, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRefCall, isGetDerivedStateFromError, isGetDerivedStateFromProps, isHookCall, isHookName, isInitializedFromReact, isJsxFragmentElement, isJsxHostElement, isJsxText, isLazyCall, isRenderFunctionLoose, isRenderMethodLike, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseCall, isUseCallbackCall, isUseContextCall, isUseEffectLikeCall, isUseMemoCall, isUseRefCall, isUseStateCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector } from "@eslint-react/core";
|
|
7
7
|
import * as AST from "@eslint-react/ast";
|
|
8
8
|
import { findEnclosingAssignmentTarget, findVariable, getChildScopes, getObjectType, getVariableDefinitionNode, isAssignmentTargetEqual } from "@eslint-react/var";
|
|
9
9
|
import { constFalse, constTrue, flow, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
|
|
@@ -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 = "2.7.5-next.
|
|
71
|
+
var version = "2.7.5-next.10";
|
|
72
72
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/utils/create-rule.ts
|
|
@@ -1294,7 +1294,7 @@ function create$35(context) {
|
|
|
1294
1294
|
} };
|
|
1295
1295
|
}
|
|
1296
1296
|
/**
|
|
1297
|
-
*
|
|
1297
|
+
* Determine whether the given CallExpression can be safely auto-fixed by replacing
|
|
1298
1298
|
* the usage of `forwardRef` with passing `ref` as a prop
|
|
1299
1299
|
*
|
|
1300
1300
|
* @param context The rule context object
|
|
@@ -1483,7 +1483,6 @@ function create$32(context) {
|
|
|
1483
1483
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1484
1484
|
const { ctx, visitor } = useComponentCollector(context, {
|
|
1485
1485
|
collectDisplayName: true,
|
|
1486
|
-
collectHookCalls: false,
|
|
1487
1486
|
hint: DEFAULT_COMPONENT_DETECTION_HINT
|
|
1488
1487
|
});
|
|
1489
1488
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -1776,7 +1775,7 @@ function create$28(context) {
|
|
|
1776
1775
|
} });
|
|
1777
1776
|
}
|
|
1778
1777
|
/**
|
|
1779
|
-
*
|
|
1778
|
+
* Determine whether the node is inside JSX attribute value
|
|
1780
1779
|
* @param node The AST node to check
|
|
1781
1780
|
* @returns `true` if the node is inside JSX attribute value
|
|
1782
1781
|
*/
|
|
@@ -1784,7 +1783,7 @@ function isInsideJSXAttributeValue(node) {
|
|
|
1784
1783
|
return node.parent.type === AST_NODE_TYPES.JSXAttribute || findParentJsxAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1785
1784
|
}
|
|
1786
1785
|
/**
|
|
1787
|
-
*
|
|
1786
|
+
* Check whether a given node is declared inside a class component's render block
|
|
1788
1787
|
* Ex: class C extends React.Component { render() { const Nested = () => <div />; } }
|
|
1789
1788
|
* @param node The AST node being checked
|
|
1790
1789
|
* @returns `true` if the node is inside a class component's render block
|
|
@@ -1793,7 +1792,7 @@ function isInsideRenderMethod(node) {
|
|
|
1793
1792
|
return AST.findParentNode(node, (n) => isRenderMethodLike(n) && isClassComponent(n.parent.parent)) != null;
|
|
1794
1793
|
}
|
|
1795
1794
|
/**
|
|
1796
|
-
*
|
|
1795
|
+
* Determine whether the node is inside `createElement`'s props argument
|
|
1797
1796
|
* @param context The rule context
|
|
1798
1797
|
* @param node The AST node to check
|
|
1799
1798
|
* @returns `true` if the node is inside `createElement`'s props
|
|
@@ -1835,7 +1834,7 @@ function create$27(context) {
|
|
|
1835
1834
|
const classComponents = collectorLegacy.ctx.getAllComponents(program);
|
|
1836
1835
|
for (const lazy of lazyComponentDeclarations) if (AST.findParentNode(lazy, (n) => {
|
|
1837
1836
|
if (AST.isJSX(n)) return true;
|
|
1838
|
-
if (n.type === AST_NODE_TYPES.CallExpression) return
|
|
1837
|
+
if (n.type === AST_NODE_TYPES.CallExpression) return isHookCall(n) || isCreateElementCall(context, n) || isCreateContextCall(context, n);
|
|
1839
1838
|
if (AST.isFunction(n)) return functionComponents.some((c) => c.node === n);
|
|
1840
1839
|
if (AST.isClass(n)) return classComponents.some((c) => c.node === n);
|
|
1841
1840
|
return false;
|
|
@@ -2496,7 +2495,7 @@ function create$12(context) {
|
|
|
2496
2495
|
const valueExpression = value.expression;
|
|
2497
2496
|
const construction = getObjectType(valueExpression, context.sourceCode.getScope(valueExpression));
|
|
2498
2497
|
if (construction == null) return;
|
|
2499
|
-
if (
|
|
2498
|
+
if (isHookCall(construction.node)) return;
|
|
2500
2499
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2501
2500
|
},
|
|
2502
2501
|
"Program:exit"(program) {
|
|
@@ -2577,7 +2576,7 @@ function create$11(context, [options]) {
|
|
|
2577
2576
|
const { right } = value;
|
|
2578
2577
|
const construction = getObjectType(value, context.sourceCode.getScope(value));
|
|
2579
2578
|
if (construction == null) continue;
|
|
2580
|
-
if (
|
|
2579
|
+
if (isHookCall(construction.node)) continue;
|
|
2581
2580
|
if (safePatterns.length > 0) {
|
|
2582
2581
|
const identifier = extractIdentifier(right);
|
|
2583
2582
|
if (identifier != null && safePatterns.some((pattern) => pattern.test(identifier))) continue;
|
|
@@ -2969,7 +2968,7 @@ function create$7(context) {
|
|
|
2969
2968
|
const hookCalls = /* @__PURE__ */ new Set();
|
|
2970
2969
|
return {
|
|
2971
2970
|
CallExpression(node) {
|
|
2972
|
-
if (!
|
|
2971
|
+
if (!isHookCall(node)) return;
|
|
2973
2972
|
hookCalls.add(node);
|
|
2974
2973
|
},
|
|
2975
2974
|
ImportDeclaration(node) {
|
|
@@ -3353,7 +3352,7 @@ function create$1(context) {
|
|
|
3353
3352
|
}
|
|
3354
3353
|
for (const expr of AST.getNestedCallExpressions(useStateInput)) {
|
|
3355
3354
|
if (!("name" in expr.callee)) continue;
|
|
3356
|
-
if (
|
|
3355
|
+
if (isHookName(expr.callee.name)) continue;
|
|
3357
3356
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
3358
3357
|
if (AST.findParentNode(expr, isUseCall) != null) continue;
|
|
3359
3358
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.7.5-next.
|
|
3
|
+
"version": "2.7.5-next.10",
|
|
4
4
|
"description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,23 +37,23 @@
|
|
|
37
37
|
"./package.json"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
41
|
-
"@typescript-eslint/type-utils": "^8.
|
|
42
|
-
"@typescript-eslint/types": "^8.
|
|
43
|
-
"@typescript-eslint/utils": "^8.
|
|
40
|
+
"@typescript-eslint/scope-manager": "^8.54.0",
|
|
41
|
+
"@typescript-eslint/type-utils": "^8.54.0",
|
|
42
|
+
"@typescript-eslint/types": "^8.54.0",
|
|
43
|
+
"@typescript-eslint/utils": "^8.54.0",
|
|
44
44
|
"compare-versions": "^6.1.1",
|
|
45
45
|
"is-immutable-type": "^5.0.1",
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-api-utils": "^2.4.0",
|
|
48
48
|
"ts-pattern": "^5.9.0",
|
|
49
|
-
"@eslint-react/ast": "2.7.5-next.
|
|
50
|
-
"@eslint-react/core": "2.7.5-next.
|
|
51
|
-
"@eslint-react/eff": "2.7.5-next.
|
|
52
|
-
"@eslint-react/shared": "2.7.5-next.
|
|
53
|
-
"@eslint-react/var": "2.7.5-next.
|
|
49
|
+
"@eslint-react/ast": "2.7.5-next.10",
|
|
50
|
+
"@eslint-react/core": "2.7.5-next.10",
|
|
51
|
+
"@eslint-react/eff": "2.7.5-next.10",
|
|
52
|
+
"@eslint-react/shared": "2.7.5-next.10",
|
|
53
|
+
"@eslint-react/var": "2.7.5-next.10"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/react": "^19.2.
|
|
56
|
+
"@types/react": "^19.2.10",
|
|
57
57
|
"@types/react-dom": "^19.2.3",
|
|
58
58
|
"tsdown": "^0.20.1",
|
|
59
59
|
"@local/configs": "0.0.0"
|