@zayne-labs/eslint-config 0.10.3 → 0.10.5
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/cli/index.js +35 -38
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +312 -7
- package/dist/index.js +56 -26
- package/dist/index.js.map +1 -1
- package/dist/{src-ZlDTU7nv.js → src-CqhpNkRz.js} +29 -24
- package/dist/{src-ZlDTU7nv.js.map → src-CqhpNkRz.js.map} +1 -1
- package/package.json +24 -24
|
@@ -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.37.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,7 +1318,7 @@ 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.5.
|
|
1321
|
+
//#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/ast.js
|
|
1322
1322
|
const traverse = (context, node, visit, visited = /* @__PURE__ */ new Set()) => {
|
|
1323
1323
|
if (visited.has(node)) return;
|
|
1324
1324
|
visited.add(node);
|
|
@@ -1350,7 +1350,7 @@ const getCallExpr = (ref, current = ref.identifier.parent) => {
|
|
|
1350
1350
|
};
|
|
1351
1351
|
|
|
1352
1352
|
//#endregion
|
|
1353
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
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
|
|
1354
1354
|
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
1355
|
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
1356
|
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();
|
|
@@ -1368,15 +1368,13 @@ const isPropDef = (def) => {
|
|
|
1368
1368
|
const isUseRef = (node) => node.type === "VariableDeclarator" && node.init && node.init.type === "CallExpression" && node.init.callee.name === "useRef" && node.id.type === "Identifier";
|
|
1369
1369
|
const isUseEffect = (node) => node.type === "CallExpression" && (node.callee.type === "Identifier" && node.callee.name === "useEffect" || node.callee.type === "MemberExpression" && node.callee.object.name === "React" && node.callee.property.name === "useEffect");
|
|
1370
1370
|
const getEffectFnRefs = (context, node) => {
|
|
1371
|
-
if (!isUseEffect(node) || node.arguments.length < 1) return;
|
|
1372
1371
|
const effectFn = node.arguments[0];
|
|
1373
|
-
if (effectFn
|
|
1372
|
+
if (effectFn?.type !== "ArrowFunctionExpression" && effectFn?.type !== "FunctionExpression") return;
|
|
1374
1373
|
return getDownstreamRefs(context, effectFn);
|
|
1375
1374
|
};
|
|
1376
1375
|
function getEffectDepsRefs(context, node) {
|
|
1377
|
-
if (!isUseEffect(node) || node.arguments.length < 2) return;
|
|
1378
1376
|
const depsArr = node.arguments[1];
|
|
1379
|
-
if (depsArr
|
|
1377
|
+
if (depsArr?.type !== "ArrayExpression") return;
|
|
1380
1378
|
return getDownstreamRefs(context, depsArr);
|
|
1381
1379
|
}
|
|
1382
1380
|
const isStateSetter = (context, ref) => getCallExpr(ref) !== void 0 && isState(context, ref);
|
|
@@ -1407,7 +1405,7 @@ const isArgsAllLiterals = (context, callExpr) => callExpr.arguments.flatMap((arg
|
|
|
1407
1405
|
const getUpstreamReactVariables = (context, variable) => getUpstreamVariables(context, variable, (node) => !isUseState(node)).filter((variable$1) => variable$1.defs.every((def) => isPropDef(def) || def.type !== "Parameter"));
|
|
1408
1406
|
|
|
1409
1407
|
//#endregion
|
|
1410
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1408
|
+
//#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/no-empty-effect.js
|
|
1411
1409
|
/**
|
|
1412
1410
|
* @type {import("eslint").Rule.RuleModule}
|
|
1413
1411
|
*/
|
|
@@ -1428,7 +1426,7 @@ var no_empty_effect_default = {
|
|
|
1428
1426
|
};
|
|
1429
1427
|
|
|
1430
1428
|
//#endregion
|
|
1431
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1429
|
+
//#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/no-adjust-state-on-prop-change.js
|
|
1432
1430
|
/**
|
|
1433
1431
|
* @type {import("eslint").Rule.RuleModule}
|
|
1434
1432
|
*/
|
|
@@ -1443,6 +1441,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1443
1441
|
messages: { avoidAdjustingStateWhenAPropChanges: "Avoid adjusting state when a prop changes. Instead, adjust the state directly during render, or refactor your state to avoid this need entirely." }
|
|
1444
1442
|
},
|
|
1445
1443
|
create: (context) => ({ CallExpression: (node) => {
|
|
1444
|
+
if (!isUseEffect(node)) return;
|
|
1446
1445
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1447
1446
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1448
1447
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1458,7 +1457,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1458
1457
|
};
|
|
1459
1458
|
|
|
1460
1459
|
//#endregion
|
|
1461
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1460
|
+
//#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/no-reset-all-state-on-prop-change.js
|
|
1462
1461
|
/**
|
|
1463
1462
|
* @type {import("eslint").Rule.RuleModule}
|
|
1464
1463
|
*/
|
|
@@ -1473,9 +1472,12 @@ var no_reset_all_state_on_prop_change_default = {
|
|
|
1473
1472
|
messages: { avoidResettingAllStateWhenAPropChanges: "Avoid resetting all state when a prop changes. If \"{{prop}}\" is a key, pass it as `key` instead so React will reset the component." }
|
|
1474
1473
|
},
|
|
1475
1474
|
create: (context) => ({ CallExpression: (node) => {
|
|
1475
|
+
if (!isUseEffect(node)) return;
|
|
1476
1476
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1477
1477
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1478
1478
|
if (!effectFnRefs || !depsRefs) return;
|
|
1479
|
+
const containingNode = findContainingNode(node);
|
|
1480
|
+
if (containingNode && isCustomHook(containingNode)) return;
|
|
1479
1481
|
const propUsedToResetAllState = findPropUsedToResetAllState(context, effectFnRefs, depsRefs, node);
|
|
1480
1482
|
if (propUsedToResetAllState) context.report({
|
|
1481
1483
|
node,
|
|
@@ -1512,7 +1514,7 @@ const findContainingNode = (node) => {
|
|
|
1512
1514
|
};
|
|
1513
1515
|
|
|
1514
1516
|
//#endregion
|
|
1515
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1517
|
+
//#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/no-event-handler.js
|
|
1516
1518
|
/**
|
|
1517
1519
|
* @type {import("eslint").Rule.RuleModule}
|
|
1518
1520
|
*/
|
|
@@ -1527,10 +1529,10 @@ var no_event_handler_default = {
|
|
|
1527
1529
|
messages: { avoidEventHandler: "Avoid using state and effects as an event handler. Instead, call the event handling code directly when the event occurs." }
|
|
1528
1530
|
},
|
|
1529
1531
|
create: (context) => ({ CallExpression: (node) => {
|
|
1532
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1530
1533
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1531
1534
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1532
1535
|
if (!effectFnRefs || !depsRefs) return;
|
|
1533
|
-
if (hasCleanup(node)) return;
|
|
1534
1536
|
findDownstreamNodes(context, node, "IfStatement").filter((ifNode) => !ifNode.alternate).filter((ifNode) => getDownstreamRefs(context, ifNode.test).notEmptyEvery((ref) => isState(context, ref))).forEach((ifNode) => {
|
|
1535
1537
|
context.report({
|
|
1536
1538
|
node: ifNode.test,
|
|
@@ -1541,7 +1543,7 @@ var no_event_handler_default = {
|
|
|
1541
1543
|
};
|
|
1542
1544
|
|
|
1543
1545
|
//#endregion
|
|
1544
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1546
|
+
//#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/no-pass-live-state-to-parent.js
|
|
1545
1547
|
/**
|
|
1546
1548
|
* @type {import("eslint").Rule.RuleModule}
|
|
1547
1549
|
*/
|
|
@@ -1556,6 +1558,7 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1556
1558
|
messages: { avoidPassingLiveStateToParent: "Avoid passing live state to parents in an effect. Instead, lift the state to the parent and pass it down to the child as a prop." }
|
|
1557
1559
|
},
|
|
1558
1560
|
create: (context) => ({ CallExpression: (node) => {
|
|
1561
|
+
if (!isUseEffect(node)) return;
|
|
1559
1562
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1560
1563
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1561
1564
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1570,7 +1573,7 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1570
1573
|
};
|
|
1571
1574
|
|
|
1572
1575
|
//#endregion
|
|
1573
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1576
|
+
//#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/no-initialize-state.js
|
|
1574
1577
|
/**
|
|
1575
1578
|
* @type {import("eslint").Rule.RuleModule}
|
|
1576
1579
|
*/
|
|
@@ -1582,6 +1585,7 @@ var no_initialize_state_default = {
|
|
|
1582
1585
|
messages: { avoidInitializingState: "Avoid initializing state in an effect. Instead, pass \"{{state}}\"'s initial value to its `useState`." }
|
|
1583
1586
|
},
|
|
1584
1587
|
create: (context) => ({ CallExpression: (node) => {
|
|
1588
|
+
if (!isUseEffect(node)) return;
|
|
1585
1589
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1586
1590
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1587
1591
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1599,7 +1603,7 @@ var no_initialize_state_default = {
|
|
|
1599
1603
|
};
|
|
1600
1604
|
|
|
1601
1605
|
//#endregion
|
|
1602
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1606
|
+
//#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/no-chain-state-updates.js
|
|
1603
1607
|
/**
|
|
1604
1608
|
* @type {import("eslint").Rule.RuleModule}
|
|
1605
1609
|
*/
|
|
@@ -1614,10 +1618,10 @@ var no_chain_state_updates_default = {
|
|
|
1614
1618
|
messages: { avoidChainingStateUpdates: "Avoid chaining state changes. When possible, update all relevant state simultaneously." }
|
|
1615
1619
|
},
|
|
1616
1620
|
create: (context) => ({ CallExpression: (node) => {
|
|
1621
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1617
1622
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1618
1623
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1619
1624
|
if (!effectFnRefs || !depsRefs) return;
|
|
1620
|
-
if (hasCleanup(node)) return;
|
|
1621
1625
|
const isAllDepsState = depsRefs.notEmptyEvery((ref) => isState(context, ref));
|
|
1622
1626
|
effectFnRefs.filter((ref) => isStateSetter(context, ref)).filter((ref) => isImmediateCall(ref.identifier)).forEach((ref) => {
|
|
1623
1627
|
const callExpr = getCallExpr(ref);
|
|
@@ -1630,7 +1634,7 @@ var no_chain_state_updates_default = {
|
|
|
1630
1634
|
};
|
|
1631
1635
|
|
|
1632
1636
|
//#endregion
|
|
1633
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1637
|
+
//#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/no-derived-state.js
|
|
1634
1638
|
/**
|
|
1635
1639
|
* @type {import('eslint').Rule.RuleModule}
|
|
1636
1640
|
*/
|
|
@@ -1645,10 +1649,10 @@ var no_derived_state_default = {
|
|
|
1645
1649
|
messages: { avoidDerivedState: "Avoid storing derived state. Compute \"{{state}}\" directly during render, optionally with `useMemo` if it's expensive." }
|
|
1646
1650
|
},
|
|
1647
1651
|
create: (context) => ({ CallExpression: (node) => {
|
|
1652
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1648
1653
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1649
1654
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1650
1655
|
if (!effectFnRefs || !depsRefs) return;
|
|
1651
|
-
if (hasCleanup(node)) return;
|
|
1652
1656
|
effectFnRefs.filter((ref) => isStateSetter(context, ref)).filter((ref) => isImmediateCall(ref.identifier)).forEach((ref) => {
|
|
1653
1657
|
const callExpr = getCallExpr(ref);
|
|
1654
1658
|
const useStateNode = getUseStateNode(context, ref);
|
|
@@ -1669,7 +1673,7 @@ var no_derived_state_default = {
|
|
|
1669
1673
|
const countCalls = (ref) => ref.resolved.references.filter((ref$1) => ref$1.identifier.parent.type === "CallExpression").length;
|
|
1670
1674
|
|
|
1671
1675
|
//#endregion
|
|
1672
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1676
|
+
//#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/no-pass-data-to-parent.js
|
|
1673
1677
|
/**
|
|
1674
1678
|
* @type {import("eslint").Rule.RuleModule}
|
|
1675
1679
|
*/
|
|
@@ -1684,10 +1688,10 @@ var no_pass_data_to_parent_default = {
|
|
|
1684
1688
|
messages: { avoidPassingDataToParent: "Avoid passing data to parents in an effect. Instead, let the parent fetch the data itself and pass it down to the child as a prop." }
|
|
1685
1689
|
},
|
|
1686
1690
|
create: (context) => ({ CallExpression: (node) => {
|
|
1691
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1687
1692
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1688
1693
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1689
1694
|
if (!effectFnRefs || !depsRefs) return;
|
|
1690
|
-
if (hasCleanup(node)) return;
|
|
1691
1695
|
effectFnRefs.filter((ref) => isPropCallback(context, ref)).forEach((ref) => {
|
|
1692
1696
|
const callExpr = getCallExpr(ref);
|
|
1693
1697
|
if (callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).notEmptyEvery((ref$1) => !isState(context, ref$1) && !isProp(context, ref$1) && !isRef(context, ref$1))) context.report({
|
|
@@ -1699,7 +1703,7 @@ var no_pass_data_to_parent_default = {
|
|
|
1699
1703
|
};
|
|
1700
1704
|
|
|
1701
1705
|
//#endregion
|
|
1702
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1706
|
+
//#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/no-manage-parent.js
|
|
1703
1707
|
/**
|
|
1704
1708
|
* @type {import("eslint").Rule.RuleModule}
|
|
1705
1709
|
*/
|
|
@@ -1711,6 +1715,7 @@ var no_manage_parent_default = {
|
|
|
1711
1715
|
messages: { avoidManagingParent: "This effect only uses props. Consider lifting the logic up to the parent." }
|
|
1712
1716
|
},
|
|
1713
1717
|
create: (context) => ({ CallExpression: (node) => {
|
|
1718
|
+
if (!isUseEffect(node)) return;
|
|
1714
1719
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1715
1720
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1716
1721
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1723,13 +1728,13 @@ var no_manage_parent_default = {
|
|
|
1723
1728
|
};
|
|
1724
1729
|
|
|
1725
1730
|
//#endregion
|
|
1726
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1731
|
+
//#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/javascript.js
|
|
1727
1732
|
Array.prototype.notEmptyEvery = function(predicate) {
|
|
1728
1733
|
return this.length > 0 && this.every(predicate);
|
|
1729
1734
|
};
|
|
1730
1735
|
|
|
1731
1736
|
//#endregion
|
|
1732
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
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
|
|
1733
1738
|
/**
|
|
1734
1739
|
* @type {import("eslint").ESLint.Plugin}
|
|
1735
1740
|
*/
|
|
@@ -1774,4 +1779,4 @@ var src_default = plugin;
|
|
|
1774
1779
|
|
|
1775
1780
|
//#endregion
|
|
1776
1781
|
export { src_default as default };
|
|
1777
|
-
//# sourceMappingURL=src-
|
|
1782
|
+
//# sourceMappingURL=src-CqhpNkRz.js.map
|