eslint-plugin-react-x 5.30.0-beta.23 → 5.30.0-beta.25
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 +107 -21
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DEFAULT_ESLINT_REACT_SETTINGS, getSettingsFromContext, toRegExp } from
|
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
3
|
import { Analyze, Check, Collect, Compare, Extract, Traverse } from "@eslint-react/ast";
|
|
4
4
|
import * as core from "@eslint-react/core";
|
|
5
|
+
import { isChildrenMap, isChildrenMapCall, isChildrenToArray, isChildrenToArrayCall } from "@eslint-react/core";
|
|
5
6
|
import { getConstrainedTypeAtLocation, getText, merge, report } from "@eslint-react/eslint";
|
|
6
7
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
7
8
|
import { P, isMatching, match } from "ts-pattern";
|
|
@@ -38,7 +39,6 @@ const conflictingRules$1 = [
|
|
|
38
39
|
"react/hook-use-state",
|
|
39
40
|
"react/iframe-missing-sandbox",
|
|
40
41
|
"react/jsx-boolean-value",
|
|
41
|
-
"react/jsx-filename-extension",
|
|
42
42
|
"react/jsx-fragments",
|
|
43
43
|
"react/jsx-key",
|
|
44
44
|
"react/jsx-no-comment-textnodes",
|
|
@@ -60,12 +60,13 @@ const conflictingRules$1 = [
|
|
|
60
60
|
"react/no-find-dom-node",
|
|
61
61
|
"react/no-namespace",
|
|
62
62
|
"react/no-object-type-as-default-prop",
|
|
63
|
+
"react/no-redundant-should-component-update",
|
|
63
64
|
"react/no-render-return-value",
|
|
64
65
|
"react/no-string-refs",
|
|
65
66
|
"react/no-unknown-property",
|
|
66
67
|
"react/no-unsafe",
|
|
67
68
|
"react/no-unstable-nested-components",
|
|
68
|
-
"react/no-unused-class-component-
|
|
69
|
+
"react/no-unused-class-component-methods",
|
|
69
70
|
"react/no-unused-state",
|
|
70
71
|
"react/no-will-update-set-state",
|
|
71
72
|
"react/prop-types",
|
|
@@ -129,7 +130,7 @@ const rules$6 = {
|
|
|
129
130
|
};
|
|
130
131
|
// package.json
|
|
131
132
|
var name$6 = "eslint-plugin-react-x";
|
|
132
|
-
var version = "5.30.0-beta.
|
|
133
|
+
var version = "5.30.0-beta.25";
|
|
133
134
|
// src/utils/create-rule.ts
|
|
134
135
|
function getDocsUrl(ruleName) {
|
|
135
136
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
@@ -2288,6 +2289,79 @@ function isAssignmentToThisState(node) {
|
|
|
2288
2289
|
}
|
|
2289
2290
|
return false;
|
|
2290
2291
|
}
|
|
2292
|
+
// src/rules/no-duplicate-key/lib.ts
|
|
2293
|
+
function isReturnedBy(element, fn) {
|
|
2294
|
+
let node = element;
|
|
2295
|
+
let viaReturn = false;
|
|
2296
|
+
while (true) {
|
|
2297
|
+
const parent = node.parent;
|
|
2298
|
+
if (parent == null) return false;
|
|
2299
|
+
if (parent === fn) {
|
|
2300
|
+
if (viaReturn) return true;
|
|
2301
|
+
return parent.type === AST_NODE_TYPES.ArrowFunctionExpression && parent.body === node;
|
|
2302
|
+
}
|
|
2303
|
+
if (Check.isTypeOrChainExpression(parent) || parent.type === AST_NODE_TYPES.LogicalExpression) {
|
|
2304
|
+
node = parent;
|
|
2305
|
+
continue;
|
|
2306
|
+
}
|
|
2307
|
+
switch (parent.type) {
|
|
2308
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
2309
|
+
if (parent.test === node) return false;
|
|
2310
|
+
node = parent;
|
|
2311
|
+
continue;
|
|
2312
|
+
case AST_NODE_TYPES.SequenceExpression:
|
|
2313
|
+
if (parent.expressions[parent.expressions.length - 1] !== node) return false;
|
|
2314
|
+
node = parent;
|
|
2315
|
+
continue;
|
|
2316
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
2317
|
+
viaReturn = true;
|
|
2318
|
+
node = parent;
|
|
2319
|
+
continue;
|
|
2320
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
2321
|
+
case AST_NODE_TYPES.IfStatement:
|
|
2322
|
+
if (!viaReturn) return false;
|
|
2323
|
+
node = parent;
|
|
2324
|
+
continue;
|
|
2325
|
+
default: return false;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
function isRekeyedByChildrenCall(context, root) {
|
|
2330
|
+
if (root.type === AST_NODE_TYPES.JSXElement) return false;
|
|
2331
|
+
let node = root.parent;
|
|
2332
|
+
while (node != null) {
|
|
2333
|
+
if (isChildrenToArrayCall(context, node) || isChildrenMapCall(context, node)) return true;
|
|
2334
|
+
switch (node.type) {
|
|
2335
|
+
case AST_NODE_TYPES.ArrayExpression:
|
|
2336
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
2337
|
+
case AST_NODE_TYPES.JSXExpressionContainer:
|
|
2338
|
+
case AST_NODE_TYPES.JSXFragment:
|
|
2339
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
2340
|
+
case AST_NODE_TYPES.SpreadElement:
|
|
2341
|
+
node = node.parent;
|
|
2342
|
+
continue;
|
|
2343
|
+
default:
|
|
2344
|
+
if (Check.isTypeOrChainExpression(node)) {
|
|
2345
|
+
node = node.parent;
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
return false;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
return false;
|
|
2352
|
+
}
|
|
2353
|
+
function mapsProvablyAtMostOneElement(call) {
|
|
2354
|
+
const callee = Extract.unwrap(call.callee);
|
|
2355
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
2356
|
+
const object = Extract.unwrap(callee.object);
|
|
2357
|
+
return object.type === AST_NODE_TYPES.ArrayExpression && object.elements.length <= 1 && !object.elements.some((element) => element?.type === AST_NODE_TYPES.SpreadElement);
|
|
2358
|
+
}
|
|
2359
|
+
function isKeyValueEqual(a, b) {
|
|
2360
|
+
const aValue = a.value;
|
|
2361
|
+
const bValue = b.value;
|
|
2362
|
+
if (aValue == null || bValue == null) return false;
|
|
2363
|
+
return Compare.isEqual(aValue, bValue);
|
|
2364
|
+
}
|
|
2291
2365
|
var no_duplicate_key_default = createRule({
|
|
2292
2366
|
meta: {
|
|
2293
2367
|
type: "problem",
|
|
@@ -2301,17 +2375,31 @@ var no_duplicate_key_default = createRule({
|
|
|
2301
2375
|
function create$32(context) {
|
|
2302
2376
|
if (!/\bkey\b/u.test(context.sourceCode.text)) return {};
|
|
2303
2377
|
const keyGroups = /* @__PURE__ */ new Map();
|
|
2378
|
+
function getGroup(root) {
|
|
2379
|
+
let group = keyGroups.get(root);
|
|
2380
|
+
if (group == null) {
|
|
2381
|
+
group = { keys: [] };
|
|
2382
|
+
keyGroups.set(root, group);
|
|
2383
|
+
}
|
|
2384
|
+
return group;
|
|
2385
|
+
}
|
|
2304
2386
|
function recordSiblingKey(root, key) {
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2387
|
+
if (isRekeyedByChildrenCall(context, root)) return;
|
|
2388
|
+
const group = getGroup(root);
|
|
2389
|
+
let duplicate = false;
|
|
2390
|
+
for (const entry of group.keys) if (isKeyValueEqual(entry.node, key)) {
|
|
2391
|
+
entry.duplicate = true;
|
|
2392
|
+
duplicate = true;
|
|
2393
|
+
}
|
|
2394
|
+
group.keys.push({
|
|
2395
|
+
duplicate,
|
|
2396
|
+
node: key
|
|
2309
2397
|
});
|
|
2310
2398
|
}
|
|
2311
2399
|
function recordMapCallbackKey(call, key) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2400
|
+
getGroup(call).keys.push({
|
|
2401
|
+
duplicate: key.value?.type === AST_NODE_TYPES.Literal,
|
|
2402
|
+
node: key
|
|
2315
2403
|
});
|
|
2316
2404
|
}
|
|
2317
2405
|
return {
|
|
@@ -2331,30 +2419,28 @@ function create$32(context) {
|
|
|
2331
2419
|
return Check.isIdentifier(callee.property, "map");
|
|
2332
2420
|
});
|
|
2333
2421
|
if (call == null) return;
|
|
2422
|
+
if (isChildrenMap(context, call.callee) || isChildrenToArray(context, call.callee)) return;
|
|
2334
2423
|
const callback = call.arguments[0];
|
|
2335
2424
|
if (callback == null) return;
|
|
2336
|
-
|
|
2425
|
+
const callbackFn = Extract.unwrap(callback);
|
|
2426
|
+
if (!Check.isFunction(callbackFn)) return;
|
|
2427
|
+
if (!isReturnedBy(jsxElement, callbackFn)) return;
|
|
2428
|
+
if (mapsProvablyAtMostOneElement(call)) return;
|
|
2337
2429
|
recordMapCallbackKey(call, node);
|
|
2338
2430
|
}
|
|
2339
2431
|
}
|
|
2340
2432
|
},
|
|
2341
2433
|
"Program:exit"() {
|
|
2342
|
-
for (const {
|
|
2343
|
-
if (!
|
|
2344
|
-
|
|
2434
|
+
for (const { keys } of keyGroups.values()) for (const { duplicate, node } of keys) {
|
|
2435
|
+
if (!duplicate) continue;
|
|
2436
|
+
context.report({
|
|
2345
2437
|
messageId: "default",
|
|
2346
|
-
node
|
|
2438
|
+
node
|
|
2347
2439
|
});
|
|
2348
2440
|
}
|
|
2349
2441
|
}
|
|
2350
2442
|
};
|
|
2351
2443
|
}
|
|
2352
|
-
function isKeyValueEqual(a, b) {
|
|
2353
|
-
const aValue = a.value;
|
|
2354
|
-
const bValue = b.value;
|
|
2355
|
-
if (aValue == null || bValue == null) return false;
|
|
2356
|
-
return Compare.isEqual(aValue, bValue);
|
|
2357
|
-
}
|
|
2358
2444
|
var no_forward_ref_default = createRule({
|
|
2359
2445
|
meta: {
|
|
2360
2446
|
type: "suggestion",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.30.0-beta.
|
|
3
|
+
"version": "5.30.0-beta.25",
|
|
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.30.0-beta.
|
|
40
|
-
"@eslint-react/core": "5.30.0-beta.
|
|
41
|
-
"@eslint-react/eslint": "5.30.0-beta.
|
|
42
|
-
"@eslint-react/jsx": "5.30.0-beta.
|
|
43
|
-
"@eslint-react/shared": "5.30.0-beta.
|
|
44
|
-
"@eslint-react/var": "5.30.0-beta.
|
|
39
|
+
"@eslint-react/ast": "5.30.0-beta.25",
|
|
40
|
+
"@eslint-react/core": "5.30.0-beta.25",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.25",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.25",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.25",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.25",
|
|
45
45
|
"@typescript-eslint/scope-manager": "^8.72.1",
|
|
46
46
|
"@typescript-eslint/types": "^8.72.1",
|
|
47
47
|
"@typescript-eslint/utils": "^8.72.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"eslint": "^10.14.0",
|
|
64
64
|
"react": "^19.3.1",
|
|
65
65
|
"react-dom": "^19.3.1",
|
|
66
|
-
"tsdown": "^0.23.
|
|
66
|
+
"tsdown": "^0.23.5",
|
|
67
67
|
"tsl": "^1.0.30",
|
|
68
68
|
"tsl-dx": "^0.15.2",
|
|
69
69
|
"typescript": "6.0.3"
|