@zayne-labs/eslint-config 0.10.2 → 0.10.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/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +265 -22
- package/dist/index.js +143 -93
- package/dist/index.js.map +1 -1
- package/dist/{src-DwSufEpw.js → src-tkLps0qA.js} +31 -20
- package/dist/{src-DwSufEpw.js.map → src-tkLps0qA.js.map} +1 -1
- package/package.json +20 -20
|
@@ -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.36.0_jiti@2.
|
|
210
|
+
//#region ../../node_modules/.pnpm/eslint-utils@3.0.0_eslint@9.36.0_jiti@2.6.0_/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.5_eslint@9.36.0_jiti@2.6.0_/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,13 +1350,17 @@ 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.5_eslint@9.36.0_jiti@2.6.0_/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();
|
|
1357
1357
|
const isUseState = (node) => node.type === "VariableDeclarator" && node.init && node.init.type === "CallExpression" && node.init.callee.name === "useState" && node.id.type === "ArrayPattern" && (node.id.elements.length === 1 || node.id.elements.length === 2) && node.id.elements.every((el) => {
|
|
1358
1358
|
return !el || el.type === "Identifier";
|
|
1359
1359
|
});
|
|
1360
|
+
const hasCleanup = (node) => {
|
|
1361
|
+
const effectFn = node.arguments[0];
|
|
1362
|
+
return (effectFn.type === "ArrowFunctionExpression" || effectFn.type === "FunctionExpression") && effectFn.body.type === "BlockStatement" && effectFn.body.body.some((stmt) => stmt.type === "ReturnStatement" && stmt.argument);
|
|
1363
|
+
};
|
|
1360
1364
|
const isPropDef = (def) => {
|
|
1361
1365
|
const declaringNode = def.node.type === "ArrowFunctionExpression" ? def.node.parent.type === "CallExpression" ? def.node.parent.parent : def.node.parent : def.node;
|
|
1362
1366
|
return def.type === "Parameter" && (isReactFunctionalComponent(declaringNode) && !isReactFunctionalHOC(declaringNode) || isCustomHook(declaringNode));
|
|
@@ -1364,15 +1368,13 @@ const isPropDef = (def) => {
|
|
|
1364
1368
|
const isUseRef = (node) => node.type === "VariableDeclarator" && node.init && node.init.type === "CallExpression" && node.init.callee.name === "useRef" && node.id.type === "Identifier";
|
|
1365
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");
|
|
1366
1370
|
const getEffectFnRefs = (context, node) => {
|
|
1367
|
-
if (!isUseEffect(node) || node.arguments.length < 1) return;
|
|
1368
1371
|
const effectFn = node.arguments[0];
|
|
1369
|
-
if (effectFn
|
|
1372
|
+
if (effectFn?.type !== "ArrowFunctionExpression" && effectFn?.type !== "FunctionExpression") return;
|
|
1370
1373
|
return getDownstreamRefs(context, effectFn);
|
|
1371
1374
|
};
|
|
1372
1375
|
function getEffectDepsRefs(context, node) {
|
|
1373
|
-
if (!isUseEffect(node) || node.arguments.length < 2) return;
|
|
1374
1376
|
const depsArr = node.arguments[1];
|
|
1375
|
-
if (depsArr
|
|
1377
|
+
if (depsArr?.type !== "ArrayExpression") return;
|
|
1376
1378
|
return getDownstreamRefs(context, depsArr);
|
|
1377
1379
|
}
|
|
1378
1380
|
const isStateSetter = (context, ref) => getCallExpr(ref) !== void 0 && isState(context, ref);
|
|
@@ -1403,7 +1405,7 @@ const isArgsAllLiterals = (context, callExpr) => callExpr.arguments.flatMap((arg
|
|
|
1403
1405
|
const getUpstreamReactVariables = (context, variable) => getUpstreamVariables(context, variable, (node) => !isUseState(node)).filter((variable$1) => variable$1.defs.every((def) => isPropDef(def) || def.type !== "Parameter"));
|
|
1404
1406
|
|
|
1405
1407
|
//#endregion
|
|
1406
|
-
//#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.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-empty-effect.js
|
|
1407
1409
|
/**
|
|
1408
1410
|
* @type {import("eslint").Rule.RuleModule}
|
|
1409
1411
|
*/
|
|
@@ -1424,7 +1426,7 @@ var no_empty_effect_default = {
|
|
|
1424
1426
|
};
|
|
1425
1427
|
|
|
1426
1428
|
//#endregion
|
|
1427
|
-
//#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.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-adjust-state-on-prop-change.js
|
|
1428
1430
|
/**
|
|
1429
1431
|
* @type {import("eslint").Rule.RuleModule}
|
|
1430
1432
|
*/
|
|
@@ -1439,6 +1441,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1439
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." }
|
|
1440
1442
|
},
|
|
1441
1443
|
create: (context) => ({ CallExpression: (node) => {
|
|
1444
|
+
if (!isUseEffect(node)) return;
|
|
1442
1445
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1443
1446
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1444
1447
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1454,7 +1457,7 @@ var no_adjust_state_on_prop_change_default = {
|
|
|
1454
1457
|
};
|
|
1455
1458
|
|
|
1456
1459
|
//#endregion
|
|
1457
|
-
//#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.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-reset-all-state-on-prop-change.js
|
|
1458
1461
|
/**
|
|
1459
1462
|
* @type {import("eslint").Rule.RuleModule}
|
|
1460
1463
|
*/
|
|
@@ -1469,6 +1472,7 @@ var no_reset_all_state_on_prop_change_default = {
|
|
|
1469
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." }
|
|
1470
1473
|
},
|
|
1471
1474
|
create: (context) => ({ CallExpression: (node) => {
|
|
1475
|
+
if (!isUseEffect(node)) return;
|
|
1472
1476
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1473
1477
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1474
1478
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1508,7 +1512,7 @@ const findContainingNode = (node) => {
|
|
|
1508
1512
|
};
|
|
1509
1513
|
|
|
1510
1514
|
//#endregion
|
|
1511
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1515
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-event-handler.js
|
|
1512
1516
|
/**
|
|
1513
1517
|
* @type {import("eslint").Rule.RuleModule}
|
|
1514
1518
|
*/
|
|
@@ -1523,6 +1527,7 @@ var no_event_handler_default = {
|
|
|
1523
1527
|
messages: { avoidEventHandler: "Avoid using state and effects as an event handler. Instead, call the event handling code directly when the event occurs." }
|
|
1524
1528
|
},
|
|
1525
1529
|
create: (context) => ({ CallExpression: (node) => {
|
|
1530
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1526
1531
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1527
1532
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1528
1533
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1536,7 +1541,7 @@ var no_event_handler_default = {
|
|
|
1536
1541
|
};
|
|
1537
1542
|
|
|
1538
1543
|
//#endregion
|
|
1539
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1544
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-pass-live-state-to-parent.js
|
|
1540
1545
|
/**
|
|
1541
1546
|
* @type {import("eslint").Rule.RuleModule}
|
|
1542
1547
|
*/
|
|
@@ -1551,6 +1556,7 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1551
1556
|
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." }
|
|
1552
1557
|
},
|
|
1553
1558
|
create: (context) => ({ CallExpression: (node) => {
|
|
1559
|
+
if (!isUseEffect(node)) return;
|
|
1554
1560
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1555
1561
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1556
1562
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1565,7 +1571,7 @@ var no_pass_live_state_to_parent_default = {
|
|
|
1565
1571
|
};
|
|
1566
1572
|
|
|
1567
1573
|
//#endregion
|
|
1568
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1574
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-initialize-state.js
|
|
1569
1575
|
/**
|
|
1570
1576
|
* @type {import("eslint").Rule.RuleModule}
|
|
1571
1577
|
*/
|
|
@@ -1577,6 +1583,7 @@ var no_initialize_state_default = {
|
|
|
1577
1583
|
messages: { avoidInitializingState: "Avoid initializing state in an effect. Instead, pass \"{{state}}\"'s initial value to its `useState`." }
|
|
1578
1584
|
},
|
|
1579
1585
|
create: (context) => ({ CallExpression: (node) => {
|
|
1586
|
+
if (!isUseEffect(node)) return;
|
|
1580
1587
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1581
1588
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1582
1589
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1594,7 +1601,7 @@ var no_initialize_state_default = {
|
|
|
1594
1601
|
};
|
|
1595
1602
|
|
|
1596
1603
|
//#endregion
|
|
1597
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1604
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-chain-state-updates.js
|
|
1598
1605
|
/**
|
|
1599
1606
|
* @type {import("eslint").Rule.RuleModule}
|
|
1600
1607
|
*/
|
|
@@ -1609,6 +1616,7 @@ var no_chain_state_updates_default = {
|
|
|
1609
1616
|
messages: { avoidChainingStateUpdates: "Avoid chaining state changes. When possible, update all relevant state simultaneously." }
|
|
1610
1617
|
},
|
|
1611
1618
|
create: (context) => ({ CallExpression: (node) => {
|
|
1619
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1612
1620
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1613
1621
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1614
1622
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1624,7 +1632,7 @@ var no_chain_state_updates_default = {
|
|
|
1624
1632
|
};
|
|
1625
1633
|
|
|
1626
1634
|
//#endregion
|
|
1627
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1635
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-derived-state.js
|
|
1628
1636
|
/**
|
|
1629
1637
|
* @type {import('eslint').Rule.RuleModule}
|
|
1630
1638
|
*/
|
|
@@ -1639,6 +1647,7 @@ var no_derived_state_default = {
|
|
|
1639
1647
|
messages: { avoidDerivedState: "Avoid storing derived state. Compute \"{{state}}\" directly during render, optionally with `useMemo` if it's expensive." }
|
|
1640
1648
|
},
|
|
1641
1649
|
create: (context) => ({ CallExpression: (node) => {
|
|
1650
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1642
1651
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1643
1652
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1644
1653
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1662,7 +1671,7 @@ var no_derived_state_default = {
|
|
|
1662
1671
|
const countCalls = (ref) => ref.resolved.references.filter((ref$1) => ref$1.identifier.parent.type === "CallExpression").length;
|
|
1663
1672
|
|
|
1664
1673
|
//#endregion
|
|
1665
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1674
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-pass-data-to-parent.js
|
|
1666
1675
|
/**
|
|
1667
1676
|
* @type {import("eslint").Rule.RuleModule}
|
|
1668
1677
|
*/
|
|
@@ -1677,6 +1686,7 @@ var no_pass_data_to_parent_default = {
|
|
|
1677
1686
|
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." }
|
|
1678
1687
|
},
|
|
1679
1688
|
create: (context) => ({ CallExpression: (node) => {
|
|
1689
|
+
if (!isUseEffect(node) || hasCleanup(node)) return;
|
|
1680
1690
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1681
1691
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1682
1692
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1691,7 +1701,7 @@ var no_pass_data_to_parent_default = {
|
|
|
1691
1701
|
};
|
|
1692
1702
|
|
|
1693
1703
|
//#endregion
|
|
1694
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1704
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-manage-parent.js
|
|
1695
1705
|
/**
|
|
1696
1706
|
* @type {import("eslint").Rule.RuleModule}
|
|
1697
1707
|
*/
|
|
@@ -1703,6 +1713,7 @@ var no_manage_parent_default = {
|
|
|
1703
1713
|
messages: { avoidManagingParent: "This effect only uses props. Consider lifting the logic up to the parent." }
|
|
1704
1714
|
},
|
|
1705
1715
|
create: (context) => ({ CallExpression: (node) => {
|
|
1716
|
+
if (!isUseEffect(node)) return;
|
|
1706
1717
|
const effectFnRefs = getEffectFnRefs(context, node);
|
|
1707
1718
|
const depsRefs = getEffectDepsRefs(context, node);
|
|
1708
1719
|
if (!effectFnRefs || !depsRefs) return;
|
|
@@ -1715,13 +1726,13 @@ var no_manage_parent_default = {
|
|
|
1715
1726
|
};
|
|
1716
1727
|
|
|
1717
1728
|
//#endregion
|
|
1718
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1729
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/javascript.js
|
|
1719
1730
|
Array.prototype.notEmptyEvery = function(predicate) {
|
|
1720
1731
|
return this.length > 0 && this.every(predicate);
|
|
1721
1732
|
};
|
|
1722
1733
|
|
|
1723
1734
|
//#endregion
|
|
1724
|
-
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.
|
|
1735
|
+
//#region ../../node_modules/.pnpm/eslint-plugin-react-you-might-not-need-an-effect@0.5.5_eslint@9.36.0_jiti@2.6.0_/node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/index.js
|
|
1725
1736
|
/**
|
|
1726
1737
|
* @type {import("eslint").ESLint.Plugin}
|
|
1727
1738
|
*/
|
|
@@ -1766,4 +1777,4 @@ var src_default = plugin;
|
|
|
1766
1777
|
|
|
1767
1778
|
//#endregion
|
|
1768
1779
|
export { src_default as default };
|
|
1769
|
-
//# sourceMappingURL=src-
|
|
1780
|
+
//# sourceMappingURL=src-tkLps0qA.js.map
|