eslint-plugin-react-x 2.7.2-beta.3 → 2.7.2-beta.4
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 -36
- package/package.json +6 -6
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, findEnclosingAssignmentTarget, 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,
|
|
6
|
+
import { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, JsxEmit, findEnclosingAssignmentTarget, 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, isInstanceIdEqual, isJsxFragmentElement, isJsxHostElement, isJsxText, isLazyCall, isReactHookCall, isReactHookName, 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 { findVariable, getChildScopes, getObjectType, getVariableDefinitionNode } 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.2-beta.
|
|
71
|
+
var version = "2.7.2-beta.4";
|
|
72
72
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/utils/create-rule.ts
|
|
@@ -3194,9 +3194,6 @@ function trimLikeReact(text) {
|
|
|
3194
3194
|
//#endregion
|
|
3195
3195
|
//#region src/rules/prefer-destructuring-assignment.ts
|
|
3196
3196
|
const RULE_NAME$4 = "prefer-destructuring-assignment";
|
|
3197
|
-
function isMemberExpressionWithObjectName(node) {
|
|
3198
|
-
return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
|
|
3199
|
-
}
|
|
3200
3197
|
var prefer_destructuring_assignment_default = createRule({
|
|
3201
3198
|
meta: {
|
|
3202
3199
|
type: "problem",
|
|
@@ -3210,42 +3207,25 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3210
3207
|
});
|
|
3211
3208
|
function create$4(context) {
|
|
3212
3209
|
const { ctx, visitors } = useComponentCollector(context);
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
if (
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
const
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
if (comp.name == null && comp.isExportDefaultDeclaration) return false;
|
|
3226
|
-
return true;
|
|
3227
|
-
});
|
|
3228
|
-
}
|
|
3229
|
-
for (const expr of exprs) {
|
|
3230
|
-
let scope = context.sourceCode.getScope(expr);
|
|
3231
|
-
let isComponent = isFunctionComponent(scope.block);
|
|
3232
|
-
while (!isComponent && scope.upper != null && scope.upper !== scope) {
|
|
3233
|
-
scope = scope.upper;
|
|
3234
|
-
isComponent = isFunctionComponent(scope.block);
|
|
3235
|
-
}
|
|
3236
|
-
if (!isComponent) continue;
|
|
3237
|
-
const component = scope.block;
|
|
3238
|
-
if (!("params" in component)) continue;
|
|
3239
|
-
const props = component.params.at(0);
|
|
3240
|
-
const isMatch = (node) => node != null && node.type === AST_NODE_TYPES.Identifier && node.name === expr.object.name;
|
|
3241
|
-
if (isMatch(props)) context.report({
|
|
3210
|
+
return defineRuleListener(visitors, { "Program:exit"(program) {
|
|
3211
|
+
for (const component of ctx.getAllComponents(program)) {
|
|
3212
|
+
if (component.name == null && component.isExportDefaultDeclaration) return;
|
|
3213
|
+
const [props] = component.node.params;
|
|
3214
|
+
if (props == null) continue;
|
|
3215
|
+
if (props.type !== AST_NODE_TYPES.Identifier) continue;
|
|
3216
|
+
const propName = props.name;
|
|
3217
|
+
const propReferences = context.sourceCode.getScope(component.node).variables.find((v) => v.name === propName)?.references ?? [];
|
|
3218
|
+
for (const ref of propReferences) {
|
|
3219
|
+
const parent = ref.identifier.parent;
|
|
3220
|
+
if (parent.type !== AST_NODE_TYPES.MemberExpression) continue;
|
|
3221
|
+
context.report({
|
|
3242
3222
|
messageId: "preferDestructuringAssignment",
|
|
3243
|
-
node:
|
|
3223
|
+
node: parent,
|
|
3244
3224
|
data: { name: "props" }
|
|
3245
3225
|
});
|
|
3246
3226
|
}
|
|
3247
3227
|
}
|
|
3248
|
-
});
|
|
3228
|
+
} });
|
|
3249
3229
|
}
|
|
3250
3230
|
|
|
3251
3231
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.7.2-beta.
|
|
3
|
+
"version": "2.7.2-beta.4",
|
|
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",
|
|
@@ -46,11 +46,11 @@
|
|
|
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.2-beta.
|
|
50
|
-
"@eslint-react/core": "2.7.2-beta.
|
|
51
|
-
"@eslint-react/eff": "2.7.2-beta.
|
|
52
|
-
"@eslint-react/shared": "2.7.2-beta.
|
|
53
|
-
"@eslint-react/var": "2.7.2-beta.
|
|
49
|
+
"@eslint-react/ast": "2.7.2-beta.4",
|
|
50
|
+
"@eslint-react/core": "2.7.2-beta.4",
|
|
51
|
+
"@eslint-react/eff": "2.7.2-beta.4",
|
|
52
|
+
"@eslint-react/shared": "2.7.2-beta.4",
|
|
53
|
+
"@eslint-react/var": "2.7.2-beta.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.2.8",
|