eslint-plugin-react-x 5.30.0-beta.7 → 5.30.0-beta.8
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 +58 -70
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -130,7 +130,7 @@ const rules$6 = {
|
|
|
130
130
|
};
|
|
131
131
|
// package.json
|
|
132
132
|
var name$6 = "eslint-plugin-react-x";
|
|
133
|
-
var version = "5.30.0-beta.
|
|
133
|
+
var version = "5.30.0-beta.8";
|
|
134
134
|
// src/utils/create-rule.ts
|
|
135
135
|
function getDocsUrl(ruleName) {
|
|
136
136
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
@@ -2281,24 +2281,6 @@ function isAssignmentToThisState(node) {
|
|
|
2281
2281
|
}
|
|
2282
2282
|
return false;
|
|
2283
2283
|
}
|
|
2284
|
-
// src/utils/jsx-iterator.ts
|
|
2285
|
-
const KNOWN_CALLBACK_POSITIONS = /* @__PURE__ */ new Map([
|
|
2286
|
-
["flatMap", 0],
|
|
2287
|
-
["from", 1],
|
|
2288
|
-
["map", 0]
|
|
2289
|
-
]);
|
|
2290
|
-
function getIteratorCallback(node) {
|
|
2291
|
-
const callee = Extract.unwrap(node.callee);
|
|
2292
|
-
if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
2293
|
-
if (!Check.isIdentifier(callee.property)) return null;
|
|
2294
|
-
const position = KNOWN_CALLBACK_POSITIONS.get(callee.property.name);
|
|
2295
|
-
if (position == null) return null;
|
|
2296
|
-
const argument = node.arguments[position];
|
|
2297
|
-
if (argument == null) return null;
|
|
2298
|
-
const callback = Extract.unwrap(argument);
|
|
2299
|
-
if (!Check.isFunction(callback)) return null;
|
|
2300
|
-
return callback;
|
|
2301
|
-
}
|
|
2302
2284
|
var no_duplicate_key_default = createRule({
|
|
2303
2285
|
meta: {
|
|
2304
2286
|
type: "problem",
|
|
@@ -2311,74 +2293,61 @@ var no_duplicate_key_default = createRule({
|
|
|
2311
2293
|
});
|
|
2312
2294
|
function create$32(context) {
|
|
2313
2295
|
if (!/\bkey\b/u.test(context.sourceCode.text)) return {};
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
}
|
|
2322
|
-
function
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
}
|
|
2328
|
-
function isStaticKey(node) {
|
|
2329
|
-
const value = getKeyValue(node);
|
|
2330
|
-
if (value == null) return true;
|
|
2331
|
-
if (value.type === AST_NODE_TYPES.Literal) return typeof value.value === "string" || typeof value.value === "number";
|
|
2332
|
-
return value.type === AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0;
|
|
2333
|
-
}
|
|
2334
|
-
function isChildrenRekeyingCall(node) {
|
|
2335
|
-
return core.isChildrenToArrayCall(context, node) || core.isChildrenMapCall(context, node);
|
|
2296
|
+
const keyGroups = /* @__PURE__ */ new Map();
|
|
2297
|
+
function recordSiblingKey(root, key) {
|
|
2298
|
+
const prevKeys = keyGroups.get(root)?.keys ?? [];
|
|
2299
|
+
keyGroups.set(root, {
|
|
2300
|
+
hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, key)),
|
|
2301
|
+
keys: [...prevKeys, key]
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
function recordMapCallbackKey(call, key) {
|
|
2305
|
+
keyGroups.set(call, {
|
|
2306
|
+
hasDuplicate: key.value?.type === AST_NODE_TYPES.Literal,
|
|
2307
|
+
keys: [key]
|
|
2308
|
+
});
|
|
2336
2309
|
}
|
|
2337
2310
|
return {
|
|
2338
2311
|
"JSXAttribute[name.name='key']"(node) {
|
|
2339
|
-
if (childrenRekeyingDepth > 0) return;
|
|
2340
2312
|
const jsxElement = node.parent.parent;
|
|
2341
2313
|
switch (jsxElement.parent.type) {
|
|
2342
2314
|
case AST_NODE_TYPES.ArrayExpression:
|
|
2343
2315
|
case AST_NODE_TYPES.JSXElement:
|
|
2344
|
-
case AST_NODE_TYPES.JSXFragment:
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
for (const prevKey of prevKeys) {
|
|
2348
|
-
if (!isKeyValueEqual(prevKey, node)) continue;
|
|
2349
|
-
duplicateKeys.add(prevKey);
|
|
2350
|
-
duplicateKeys.add(node);
|
|
2351
|
-
break;
|
|
2352
|
-
}
|
|
2353
|
-
siblingKeys.set(root, [...prevKeys, node]);
|
|
2354
|
-
break;
|
|
2355
|
-
}
|
|
2316
|
+
case AST_NODE_TYPES.JSXFragment:
|
|
2317
|
+
recordSiblingKey(jsxElement.parent, node);
|
|
2318
|
+
return;
|
|
2356
2319
|
default: {
|
|
2357
|
-
const call = Traverse.findParent(jsxElement, (n) =>
|
|
2320
|
+
const call = Traverse.findParent(jsxElement, (n) => {
|
|
2321
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
2322
|
+
const callee = Extract.unwrap(n.callee);
|
|
2323
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
2324
|
+
return Check.isIdentifier(callee.property, "map");
|
|
2325
|
+
});
|
|
2358
2326
|
if (call == null) return;
|
|
2359
|
-
const callback =
|
|
2327
|
+
const callback = call.arguments[0];
|
|
2360
2328
|
if (callback == null) return;
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
if (callback !== iter) return;
|
|
2364
|
-
if (isStaticKey(node)) duplicateKeys.add(node);
|
|
2329
|
+
if (Traverse.findParent(jsxElement, Check.isFunction, (n) => n === call) !== Extract.unwrap(callback)) return;
|
|
2330
|
+
recordMapCallbackKey(call, node);
|
|
2365
2331
|
}
|
|
2366
2332
|
}
|
|
2367
2333
|
},
|
|
2368
|
-
CallExpression(node) {
|
|
2369
|
-
if (isChildrenRekeyingCall(node)) childrenRekeyingDepth += 1;
|
|
2370
|
-
},
|
|
2371
|
-
"CallExpression:exit"(node) {
|
|
2372
|
-
if (isChildrenRekeyingCall(node)) childrenRekeyingDepth -= 1;
|
|
2373
|
-
},
|
|
2374
2334
|
"Program:exit"() {
|
|
2375
|
-
for (const
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2335
|
+
for (const { hasDuplicate, keys } of keyGroups.values()) {
|
|
2336
|
+
if (!hasDuplicate) continue;
|
|
2337
|
+
for (const key of keys) context.report({
|
|
2338
|
+
messageId: "default",
|
|
2339
|
+
node: key
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2379
2342
|
}
|
|
2380
2343
|
};
|
|
2381
2344
|
}
|
|
2345
|
+
function isKeyValueEqual(a, b) {
|
|
2346
|
+
const aValue = a.value;
|
|
2347
|
+
const bValue = b.value;
|
|
2348
|
+
if (aValue == null || bValue == null) return false;
|
|
2349
|
+
return Compare.isEqual(aValue, bValue);
|
|
2350
|
+
}
|
|
2382
2351
|
var no_forward_ref_default = createRule({
|
|
2383
2352
|
meta: {
|
|
2384
2353
|
type: "suggestion",
|
|
@@ -2706,6 +2675,7 @@ function create$25(context) {
|
|
|
2706
2675
|
if (declaration == null || declaration.type !== AST_NODE_TYPES.VariableDeclaration) return [];
|
|
2707
2676
|
switch (declaration.parent.type) {
|
|
2708
2677
|
case AST_NODE_TYPES.BlockStatement:
|
|
2678
|
+
case AST_NODE_TYPES.ExportNamedDeclaration:
|
|
2709
2679
|
case AST_NODE_TYPES.Program:
|
|
2710
2680
|
case AST_NODE_TYPES.StaticBlock:
|
|
2711
2681
|
case AST_NODE_TYPES.SwitchCase:
|
|
@@ -2733,6 +2703,24 @@ function create$25(context) {
|
|
|
2733
2703
|
}
|
|
2734
2704
|
};
|
|
2735
2705
|
}
|
|
2706
|
+
// src/utils/jsx-iterator.ts
|
|
2707
|
+
const KNOWN_CALLBACK_POSITIONS = /* @__PURE__ */ new Map([
|
|
2708
|
+
["flatMap", 0],
|
|
2709
|
+
["from", 1],
|
|
2710
|
+
["map", 0]
|
|
2711
|
+
]);
|
|
2712
|
+
function getIteratorCallback(node) {
|
|
2713
|
+
const callee = Extract.unwrap(node.callee);
|
|
2714
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
2715
|
+
if (!Check.isIdentifier(callee.property)) return null;
|
|
2716
|
+
const position = KNOWN_CALLBACK_POSITIONS.get(callee.property.name);
|
|
2717
|
+
if (position == null) return null;
|
|
2718
|
+
const argument = node.arguments[position];
|
|
2719
|
+
if (argument == null) return null;
|
|
2720
|
+
const callback = Extract.unwrap(argument);
|
|
2721
|
+
if (!Check.isFunction(callback)) return null;
|
|
2722
|
+
return callback;
|
|
2723
|
+
}
|
|
2736
2724
|
var no_missing_key_default = createRule({
|
|
2737
2725
|
meta: {
|
|
2738
2726
|
type: "problem",
|
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.8",
|
|
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.8",
|
|
40
|
+
"@eslint-react/core": "5.30.0-beta.8",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.8",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.8",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.8",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.8",
|
|
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",
|