@zayne-labs/eslint-config 0.10.9 → 0.11.0
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/README.md +268 -162
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +938 -50
- package/dist/index.js +325 -155
- package/dist/index.js.map +1 -1
- package/dist/{src-CqhpNkRz.js → src-MgbFTVE-.js} +96 -76
- package/dist/src-MgbFTVE-.js.map +1 -0
- package/package.json +32 -20
- package/dist/src-CqhpNkRz.js.map +0 -1
|
@@ -207,7 +207,7 @@ var require_lib = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/eslint-
|
|
|
207
207
|
}) });
|
|
208
208
|
|
|
209
209
|
//#endregion
|
|
210
|
-
//#region ../../node_modules/.pnpm/eslint-utils@3.0.0_eslint@9.
|
|
210
|
+
//#region ../../node_modules/.pnpm/eslint-utils@3.0.0_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-utils/index.mjs
|
|
211
211
|
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
212
212
|
/**
|
|
213
213
|
* Get the innermost scope which contains a given location.
|
|
@@ -1318,39 +1318,12 @@ function exceptDefault(name, index) {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
|
|
1320
1320
|
//#endregion
|
|
1321
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
};
|
|
1328
|
-
const findDownstreamNodes = (context, topNode, type) => {
|
|
1329
|
-
const nodes = [];
|
|
1330
|
-
traverse(context, topNode, (node) => {
|
|
1331
|
-
if (node.type === type) nodes.push(node);
|
|
1332
|
-
});
|
|
1333
|
-
return nodes;
|
|
1334
|
-
};
|
|
1335
|
-
const getUpstreamVariables = (context, variable, filter, visited = /* @__PURE__ */ new Set()) => {
|
|
1336
|
-
if (visited.has(variable)) return [];
|
|
1337
|
-
visited.add(variable);
|
|
1338
|
-
const upstreamVariables = variable.defs.filter((def) => !!def.node.init).filter((def) => filter(def.node)).flatMap((def) => getDownstreamRefs(context, def.node.init)).map((ref) => ref.resolved).filter(Boolean).flatMap((variable$1) => getUpstreamVariables(context, variable$1, filter, visited));
|
|
1339
|
-
return upstreamVariables.length === 0 ? [variable] : upstreamVariables;
|
|
1340
|
-
};
|
|
1341
|
-
const getDownstreamRefs = (context, node) => findDownstreamNodes(context, node, "Identifier").map((identifier) => getRef(context, identifier)).filter(Boolean);
|
|
1342
|
-
const getRef = (context, identifier) => findVariable(context.sourceCode.getScope(identifier), identifier)?.references.find((ref) => ref.identifier === identifier);
|
|
1343
|
-
const getCallExpr = (ref, current = ref.identifier.parent) => {
|
|
1344
|
-
if (current.type === "CallExpression") {
|
|
1345
|
-
let node = ref.identifier;
|
|
1346
|
-
while (node.parent.type === "MemberExpression") node = node.parent;
|
|
1347
|
-
if (current.callee === node) return current;
|
|
1348
|
-
}
|
|
1349
|
-
if (current.type === "MemberExpression") return getCallExpr(ref, current.parent);
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
//#endregion
|
|
1353
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.6_eslint@9.37.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/react.js
|
|
1321
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/ast.js
|
|
1322
|
+
/**
|
|
1323
|
+
* @import {Scope} from 'eslint'
|
|
1324
|
+
* @import {Rule} from 'eslint'
|
|
1325
|
+
* @import {AST} from 'eslint'
|
|
1326
|
+
*/
|
|
1354
1327
|
const isReactFunctionalComponent = (node) => (node.type === "FunctionDeclaration" || node.type === "VariableDeclarator" && (node.init.type === "ArrowFunctionExpression" || node.init.type === "CallExpression")) && node.id.type === "Identifier" && node.id.name[0].toUpperCase() === node.id.name[0];
|
|
1355
1328
|
const isReactFunctionalHOC = (node) => node.type === "VariableDeclarator" && node.init && node.init.type === "CallExpression" && node.init.callee.type === "Identifier" && !["memo", "forwardRef"].includes(node.init.callee.name) && node.init.arguments.length > 0 && (node.init.arguments[0].type === "ArrowFunctionExpression" || node.init.arguments[0].type === "FunctionExpression") && node.id.type === "Identifier" && node.id.name[0].toUpperCase() === node.id.name[0];
|
|
1356
1329
|
const isCustomHook = (node) => (node.type === "FunctionDeclaration" || node.type === "VariableDeclarator" && node.init && (node.init.type === "ArrowFunctionExpression" || node.init.type === "FunctionExpression")) && node.id.type === "Identifier" && node.id.name.startsWith("use") && node.id.name[3] === node.id.name[3].toUpperCase();
|
|
@@ -1377,13 +1350,13 @@ function getEffectDepsRefs(context, node) {
|
|
|
1377
1350
|
if (depsArr?.type !== "ArrayExpression") return;
|
|
1378
1351
|
return getDownstreamRefs(context, depsArr);
|
|
1379
1352
|
}
|
|
1380
|
-
const isStateSetter = (context, ref) => getCallExpr(ref) !== void 0 &&
|
|
1381
|
-
const isPropCallback = (context, ref) => getCallExpr(ref) !== void 0 &&
|
|
1382
|
-
const isState = (
|
|
1383
|
-
const isProp = (
|
|
1384
|
-
const isRef = (
|
|
1353
|
+
const isStateSetter = (context, ref) => getCallExpr(ref) !== void 0 && getUpstreamRefs(context, ref).some((ref$1) => isState(ref$1));
|
|
1354
|
+
const isPropCallback = (context, ref) => getCallExpr(ref) !== void 0 && getUpstreamRefs(context, ref).some((ref$1) => isProp(ref$1));
|
|
1355
|
+
const isState = (ref) => ref.resolved.defs.some((def) => isUseState(def.node));
|
|
1356
|
+
const isProp = (ref) => ref.resolved.defs.some((def) => isPropDef(def));
|
|
1357
|
+
const isRef = (ref) => ref.resolved.defs.some((def) => isUseRef(def.node));
|
|
1385
1358
|
const getUseStateNode = (context, ref) => {
|
|
1386
|
-
return
|
|
1359
|
+
return getUpstreamRefs(context, ref).map((ref$1) => ref$1.resolved).find((variable) => variable.defs.some((def) => isUseState(def.node)))?.defs.find((def) => isUseState(def.node))?.node;
|
|
1387
1360
|
};
|
|
1388
1361
|
/**
|
|
1389
1362
|
* Walks up the AST until a `useEffect` call, returning `false` if never found, or finds any of the following on the way:
|
|
@@ -1401,11 +1374,51 @@ const isImmediateCall = (node) => {
|
|
|
1401
1374
|
else if (node.async || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") return false;
|
|
1402
1375
|
else return isImmediateCall(node.parent);
|
|
1403
1376
|
};
|
|
1404
|
-
|
|
1405
|
-
|
|
1377
|
+
/**
|
|
1378
|
+
* @param {Rule.RuleContext} context
|
|
1379
|
+
* @param {Scope.Reference} ref
|
|
1380
|
+
*
|
|
1381
|
+
* @returns {Scope.Reference[]}
|
|
1382
|
+
*/
|
|
1383
|
+
const getUpstreamRefs = (context, ref, visited = /* @__PURE__ */ new Set()) => {
|
|
1384
|
+
if (visited.has(ref)) return [];
|
|
1385
|
+
else if (!ref.resolved) return [];
|
|
1386
|
+
else if (ref.resolved.defs.notEmptyEvery((def) => def.type === "Parameter" && !isPropDef(def))) return [];
|
|
1387
|
+
visited.add(ref);
|
|
1388
|
+
const upstreamRefs = ref.resolved.defs.filter((def) => !!def.node.init).filter((def) => !isUseState(def.node)).flatMap((def) => getDownstreamRefs(context, def.node.init)).flatMap((ref$1) => getUpstreamRefs(context, ref$1, visited));
|
|
1389
|
+
return upstreamRefs.length === 0 ? [ref] : upstreamRefs;
|
|
1390
|
+
};
|
|
1391
|
+
const traverse = (context, node, visit, visited = /* @__PURE__ */ new Set()) => {
|
|
1392
|
+
if (visited.has(node)) return;
|
|
1393
|
+
visited.add(node);
|
|
1394
|
+
visit(node);
|
|
1395
|
+
(context.sourceCode.visitorKeys[node.type] || []).map((key) => node[key]).filter(Boolean).flatMap((child) => Array.isArray(child) ? child : [child]).filter(Boolean).filter((child) => typeof child.type === "string").forEach((child) => traverse(context, child, visit, visited));
|
|
1396
|
+
};
|
|
1397
|
+
const findDownstreamNodes = (context, topNode, type) => {
|
|
1398
|
+
const nodes = [];
|
|
1399
|
+
traverse(context, topNode, (node) => {
|
|
1400
|
+
if (node.type === type) nodes.push(node);
|
|
1401
|
+
});
|
|
1402
|
+
return nodes;
|
|
1403
|
+
};
|
|
1404
|
+
/**
|
|
1405
|
+
* @param {Rule.RuleContext} context
|
|
1406
|
+
* @param {Rule.Node} node
|
|
1407
|
+
*/
|
|
1408
|
+
const getDownstreamRefs = (context, node) => findDownstreamNodes(context, node, "Identifier").map((identifier) => getRef(context, identifier)).filter(Boolean);
|
|
1409
|
+
const getRef = (context, identifier) => findVariable(context.sourceCode.getScope(identifier), identifier)?.references.find((ref) => ref.identifier === identifier);
|
|
1410
|
+
const getCallExpr = (ref, current = ref.identifier.parent) => {
|
|
1411
|
+
if (current.type === "CallExpression") {
|
|
1412
|
+
let node = ref.identifier;
|
|
1413
|
+
while (node.parent.type === "MemberExpression") node = node.parent;
|
|
1414
|
+
if (current.callee === node) return current;
|
|
1415
|
+
}
|
|
1416
|
+
if (current.type === "MemberExpression") return getCallExpr(ref, current.parent);
|
|
1417
|
+
};
|
|
1418
|
+
const isArgsAllLiterals = (context, callExpr) => callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref) => getUpstreamRefs(context, ref)).length === 0;
|
|
1406
1419
|
|
|
1407
1420
|
//#endregion
|
|
1408
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1421
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-empty-effect.js
|
|
1409
1422
|
/**
|
|
1410
1423
|
* @type {import("eslint").Rule.RuleModule}
|
|
1411
1424
|
*/
|
|
@@ -1426,7 +1439,7 @@ var no_empty_effect_default = {
|
|
|
1426
1439
|
};
|
|
1427
1440
|
|
|
1428
1441
|
//#endregion
|
|
1429
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1442
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-adjust-state-on-prop-change.js
|
|
1430
1443
|
/**
|
|
1431
1444
|
* @type {import("eslint").Rule.RuleModule}
|
|
1432
1445
|
*/
|
|
@@ -1445,7 +1458,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1445
1458
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1446
1459
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1447
1460
|
if (!effectFnRefs || !depsRefs) return;
|
|
1448
|
-
const isAllDepsProps = depsRefs.
|
|
1461
|
+
const isAllDepsProps = depsRefs.flatMap((ref) => getUpstreamRefs(context, ref)).notEmptyEvery((ref) => isProp(ref));
|
|
1449
1462
|
effectFnRefs.filter((ref) => isStateSetter(context, ref)).filter((ref) => isImmediateCall(ref.identifier)).forEach((ref) => {
|
|
1450
1463
|
const callExpr = getCallExpr(ref);
|
|
1451
1464
|
if (isAllDepsProps && isArgsAllLiterals(context, callExpr)) context.report({
|
|
@@ -1457,7 +1470,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1457
1470
|
};
|
|
1458
1471
|
|
|
1459
1472
|
//#endregion
|
|
1460
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1473
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-reset-all-state-on-prop-change.js
|
|
1461
1474
|
/**
|
|
1462
1475
|
* @type {import("eslint").Rule.RuleModule}
|
|
1463
1476
|
*/
|
|
@@ -1488,7 +1501,7 @@ var no_reset_all_state_on_prop_change_default = {
|
|
|
1488
1501
|
};
|
|
1489
1502
|
const findPropUsedToResetAllState = (context, effectFnRefs, depsRefs, useEffectNode) => {
|
|
1490
1503
|
const stateSetterRefs = effectFnRefs.filter((ref) => isStateSetter(context, ref));
|
|
1491
|
-
return stateSetterRefs.length > 0 && stateSetterRefs.every((ref) => isSetStateToInitialValue(context, ref)) && stateSetterRefs.length === countUseStates(context, findContainingNode(useEffectNode)) ? depsRefs.
|
|
1504
|
+
return stateSetterRefs.length > 0 && stateSetterRefs.every((ref) => isSetStateToInitialValue(context, ref)) && stateSetterRefs.length === countUseStates(context, findContainingNode(useEffectNode)) ? depsRefs.flatMap((ref) => getUpstreamRefs(context, ref)).find((ref) => isProp(ref)) : void 0;
|
|
1492
1505
|
};
|
|
1493
1506
|
const isSetStateToInitialValue = (context, setterRef) => {
|
|
1494
1507
|
const setStateToValue = getCallExpr(setterRef).arguments[0];
|
|
@@ -1514,7 +1527,7 @@ const findContainingNode = (node) => {
|
|
|
1514
1527
|
};
|
|
1515
1528
|
|
|
1516
1529
|
//#endregion
|
|
1517
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1530
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-event-handler.js
|
|
1518
1531
|
/**
|
|
1519
1532
|
* @type {import("eslint").Rule.RuleModule}
|
|
1520
1533
|
*/
|
|
@@ -1533,7 +1546,7 @@ var no_event_handler_default = {
|
|
|
1533
1546
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1534
1547
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1535
1548
|
if (!effectFnRefs || !depsRefs) return;
|
|
1536
|
-
findDownstreamNodes(context, node, "IfStatement").filter((ifNode) => !ifNode.alternate).filter((ifNode) => getDownstreamRefs(context, ifNode.test).
|
|
1549
|
+
findDownstreamNodes(context, node, "IfStatement").filter((ifNode) => !ifNode.alternate).filter((ifNode) => getDownstreamRefs(context, ifNode.test).flatMap((ref) => getUpstreamRefs(context, ref)).notEmptyEvery((ref) => isState(ref))).forEach((ifNode) => {
|
|
1537
1550
|
context.report({
|
|
1538
1551
|
node: ifNode.test,
|
|
1539
1552
|
messageId: "avoidEventHandler"
|
|
@@ -1543,7 +1556,7 @@ var no_event_handler_default = {
|
|
|
1543
1556
|
};
|
|
1544
1557
|
|
|
1545
1558
|
//#endregion
|
|
1546
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1559
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-pass-live-state-to-parent.js
|
|
1547
1560
|
/**
|
|
1548
1561
|
* @type {import("eslint").Rule.RuleModule}
|
|
1549
1562
|
*/
|
|
@@ -1564,7 +1577,7 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1564
1577
|
if (!effectFnRefs || !depsRefs) return;
|
|
1565
1578
|
effectFnRefs.filter((ref) => isPropCallback(context, ref)).filter((ref) => isImmediateCall(ref.identifier)).forEach((ref) => {
|
|
1566
1579
|
const callExpr = getCallExpr(ref);
|
|
1567
|
-
if (callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).
|
|
1580
|
+
if (callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref$1) => getUpstreamRefs(context, ref$1)).some((ref$1) => isState(ref$1))) context.report({
|
|
1568
1581
|
node: callExpr,
|
|
1569
1582
|
messageId: "avoidPassingLiveStateToParent"
|
|
1570
1583
|
});
|
|
@@ -1573,16 +1586,19 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1573
1586
|
};
|
|
1574
1587
|
|
|
1575
1588
|
//#endregion
|
|
1576
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1589
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-initialize-state.js
|
|
1577
1590
|
/**
|
|
1578
1591
|
* @type {import("eslint").Rule.RuleModule}
|
|
1579
1592
|
*/
|
|
1580
1593
|
var no_initialize_state_default = {
|
|
1581
1594
|
meta: {
|
|
1582
1595
|
type: "suggestion",
|
|
1583
|
-
docs: {
|
|
1596
|
+
docs: {
|
|
1597
|
+
description: "Disallow initializing state in an effect.",
|
|
1598
|
+
url: "https://tkdodo.eu/blog/avoiding-hydration-mismatches-with-use-sync-external-store"
|
|
1599
|
+
},
|
|
1584
1600
|
schema: [],
|
|
1585
|
-
messages: { avoidInitializingState: "Avoid initializing state in an effect. Instead, pass \"{{state}}\"'s initial value to its `useState`." }
|
|
1601
|
+
messages: { avoidInitializingState: "Avoid initializing state in an effect. Instead, pass \"{{state}}\"'s initial value to its `useState`. For SSR hydration, prefer `useSyncExternalStore`." }
|
|
1586
1602
|
},
|
|
1587
1603
|
create: (context) => ({ CallExpression: (node) => {
|
|
1588
1604
|
if (!isUseEffect(node)) return;
|
|
@@ -1603,7 +1619,7 @@ var no_initialize_state_default = {
|
|
|
1603
1619
|
};
|
|
1604
1620
|
|
|
1605
1621
|
//#endregion
|
|
1606
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1622
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-chain-state-updates.js
|
|
1607
1623
|
/**
|
|
1608
1624
|
* @type {import("eslint").Rule.RuleModule}
|
|
1609
1625
|
*/
|
|
@@ -1622,7 +1638,7 @@ var no_chain_state_updates_default = {
|
|
|
1622
1638
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1623
1639
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1624
1640
|
if (!effectFnRefs || !depsRefs) return;
|
|
1625
|
-
const isAllDepsState = depsRefs.
|
|
1641
|
+
const isAllDepsState = depsRefs.flatMap((ref) => getUpstreamRefs(context, ref)).notEmptyEvery((ref) => isState(ref));
|
|
1626
1642
|
effectFnRefs.filter((ref) => isStateSetter(context, ref)).filter((ref) => isImmediateCall(ref.identifier)).forEach((ref) => {
|
|
1627
1643
|
const callExpr = getCallExpr(ref);
|
|
1628
1644
|
if (isAllDepsState && isArgsAllLiterals(context, callExpr)) context.report({
|
|
@@ -1634,7 +1650,7 @@ var no_chain_state_updates_default = {
|
|
|
1634
1650
|
};
|
|
1635
1651
|
|
|
1636
1652
|
//#endregion
|
|
1637
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1653
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-derived-state.js
|
|
1638
1654
|
/**
|
|
1639
1655
|
* @type {import('eslint').Rule.RuleModule}
|
|
1640
1656
|
*/
|
|
@@ -1646,7 +1662,10 @@ var no_derived_state_default = {
|
|
|
1646
1662
|
url: "https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state"
|
|
1647
1663
|
},
|
|
1648
1664
|
schema: [],
|
|
1649
|
-
messages: {
|
|
1665
|
+
messages: {
|
|
1666
|
+
avoidDerivedState: "Avoid storing derived state. Compute \"{{state}}\" directly during render, optionally with `useMemo` if it's expensive.",
|
|
1667
|
+
avoidSingleSetter: "Avoid storing derived state. \"{{state}}\" is only set here, and thus could be computed directly during render."
|
|
1668
|
+
}
|
|
1650
1669
|
},
|
|
1651
1670
|
create: (context) => ({ CallExpression: (node) => {
|
|
1652
1671
|
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
@@ -1657,23 +1676,27 @@ var no_derived_state_default = {
|
|
|
1657
1676
|
const callExpr = getCallExpr(ref);
|
|
1658
1677
|
const useStateNode = getUseStateNode(context, ref);
|
|
1659
1678
|
const stateName = (useStateNode.id.elements[0] ?? useStateNode.id.elements[1])?.name;
|
|
1660
|
-
const
|
|
1661
|
-
const
|
|
1662
|
-
const
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
if (isAllArgsInternal || isValueAlwaysInSync) context.report({
|
|
1679
|
+
const argsUpstreamRefs = callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref$1) => getUpstreamRefs(context, ref$1));
|
|
1680
|
+
const depsUpstreamRefs = depsRefs.flatMap((ref$1) => getUpstreamRefs(context, ref$1));
|
|
1681
|
+
const isAllArgsInternal = argsUpstreamRefs.notEmptyEvery((ref$1) => isState(ref$1) || isProp(ref$1));
|
|
1682
|
+
const isValueAlwaysInSync = argsUpstreamRefs.notEmptyEvery((argRef) => depsUpstreamRefs.some((depRef) => argRef.resolved.name === depRef.resolved.name)) && countCalls(ref) === 1;
|
|
1683
|
+
if (isAllArgsInternal) context.report({
|
|
1666
1684
|
node: callExpr,
|
|
1667
1685
|
messageId: "avoidDerivedState",
|
|
1668
1686
|
data: { state: stateName }
|
|
1669
1687
|
});
|
|
1688
|
+
else if (isValueAlwaysInSync) context.report({
|
|
1689
|
+
node: callExpr,
|
|
1690
|
+
messageId: "avoidSingleSetter",
|
|
1691
|
+
data: { state: stateName }
|
|
1692
|
+
});
|
|
1670
1693
|
});
|
|
1671
1694
|
} })
|
|
1672
1695
|
};
|
|
1673
1696
|
const countCalls = (ref) => ref.resolved.references.filter((ref$1) => ref$1.identifier.parent.type === "CallExpression").length;
|
|
1674
1697
|
|
|
1675
1698
|
//#endregion
|
|
1676
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1699
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-pass-data-to-parent.js
|
|
1677
1700
|
/**
|
|
1678
1701
|
* @type {import("eslint").Rule.RuleModule}
|
|
1679
1702
|
*/
|
|
@@ -1694,7 +1717,7 @@ var no_pass_data_to_parent_default = {
|
|
|
1694
1717
|
if (!effectFnRefs || !depsRefs) return;
|
|
1695
1718
|
effectFnRefs.filter((ref) => isPropCallback(context, ref)).forEach((ref) => {
|
|
1696
1719
|
const callExpr = getCallExpr(ref);
|
|
1697
|
-
if (callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).
|
|
1720
|
+
if (callExpr.arguments.length & callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref$1) => getUpstreamRefs(context, ref$1)).every((ref$1) => !isState(ref$1) && !isProp(ref$1) && !isRef(ref$1))) context.report({
|
|
1698
1721
|
node: callExpr,
|
|
1699
1722
|
messageId: "avoidPassingDataToParent"
|
|
1700
1723
|
});
|
|
@@ -1703,7 +1726,7 @@ var no_pass_data_to_parent_default = {
|
|
|
1703
1726
|
};
|
|
1704
1727
|
|
|
1705
1728
|
//#endregion
|
|
1706
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1729
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/rules/no-manage-parent.js
|
|
1707
1730
|
/**
|
|
1708
1731
|
* @type {import("eslint").Rule.RuleModule}
|
|
1709
1732
|
*/
|
|
@@ -1720,7 +1743,7 @@ var no_manage_parent_default = {
|
|
|
1720
1743
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1721
1744
|
if (!effectFnRefs || !depsRefs) return;
|
|
1722
1745
|
if (effectFnRefs.length === 0) return;
|
|
1723
|
-
if (effectFnRefs.concat(depsRefs).
|
|
1746
|
+
if (effectFnRefs.concat(depsRefs).flatMap((ref) => getUpstreamRefs(context, ref)).notEmptyEvery((ref) => isProp(ref))) context.report({
|
|
1724
1747
|
node,
|
|
1725
1748
|
messageId: "avoidManagingParent"
|
|
1726
1749
|
});
|
|
@@ -1728,13 +1751,7 @@ var no_manage_parent_default = {
|
|
|
1728
1751
|
};
|
|
1729
1752
|
|
|
1730
1753
|
//#endregion
|
|
1731
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.
|
|
1732
|
-
Array.prototype.notEmptyEvery = function(predicate) {
|
|
1733
|
-
return this.length > 0 && this.every(predicate);
|
|
1734
|
-
};
|
|
1735
|
-
|
|
1736
|
-
//#endregion
|
|
1737
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.6_eslint@9.37.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/index.js
|
|
1754
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.6.1_eslint@9.38.0_jiti@2.6.1_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/index.js
|
|
1738
1755
|
/**
|
|
1739
1756
|
* @type {import("eslint").ESLint.Plugin}
|
|
1740
1757
|
*/
|
|
@@ -1776,7 +1793,10 @@ Object.assign(plugin.configs, {
|
|
|
1776
1793
|
}
|
|
1777
1794
|
});
|
|
1778
1795
|
var src_default = plugin;
|
|
1796
|
+
Array.prototype.notEmptyEvery = function(predicate) {
|
|
1797
|
+
return this.length > 0 && this.every(predicate);
|
|
1798
|
+
};
|
|
1779
1799
|
|
|
1780
1800
|
//#endregion
|
|
1781
1801
|
export { src_default as default };
|
|
1782
|
-
//# sourceMappingURL=src-
|
|
1802
|
+
//# sourceMappingURL=src-MgbFTVE-.js.map
|