@solvro/config 2.0.0 → 2.0.1

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  typescriptStrict,
3
3
  unicorn
4
- } from "./chunk-OEFF22F3.js";
4
+ } from "./chunk-VD4FWSAD.js";
5
5
  import {
6
6
  imports
7
7
  } from "./chunk-VSUL3MI5.js";
@@ -444,16 +444,16 @@ function getInnermostScope(initialScope, node) {
444
444
  return scope;
445
445
  }
446
446
  function findVariable(initialScope, nameOrNode) {
447
- let name8 = "";
447
+ let name10 = "";
448
448
  let scope = initialScope;
449
449
  if (typeof nameOrNode === "string") {
450
- name8 = nameOrNode;
450
+ name10 = nameOrNode;
451
451
  } else {
452
- name8 = nameOrNode.name;
452
+ name10 = nameOrNode.name;
453
453
  scope = getInnermostScope(scope, nameOrNode);
454
454
  }
455
455
  while (scope != null) {
456
- const variable = scope.set.get(name8);
456
+ const variable = scope.set.get(name10);
457
457
  if (variable != null) {
458
458
  return variable;
459
459
  }
@@ -611,10 +611,10 @@ var callPassThrough = /* @__PURE__ */ new Set([
611
611
  Object.preventExtensions,
612
612
  Object.seal
613
613
  ]);
614
- function getPropertyDescriptor(object, name8) {
614
+ function getPropertyDescriptor(object, name10) {
615
615
  let x = object;
616
616
  while ((typeof x === "object" || typeof x === "function") && x !== null) {
617
- const d = Object.getOwnPropertyDescriptor(x, name8);
617
+ const d = Object.getOwnPropertyDescriptor(x, name10);
618
618
  if (d) {
619
619
  return d;
620
620
  }
@@ -622,8 +622,8 @@ function getPropertyDescriptor(object, name8) {
622
622
  }
623
623
  return null;
624
624
  }
625
- function isGetter(object, name8) {
626
- const d = getPropertyDescriptor(object, name8);
625
+ function isGetter(object, name10) {
626
+ const d = getPropertyDescriptor(object, name10);
627
627
  return d != null && d.get != null;
628
628
  }
629
629
  function getElementValues(nodeList, initialScope) {
@@ -1484,8 +1484,8 @@ ReferenceTracker.READ = READ;
1484
1484
  ReferenceTracker.CALL = CALL;
1485
1485
  ReferenceTracker.CONSTRUCT = CONSTRUCT;
1486
1486
  ReferenceTracker.ESM = ESM;
1487
- function exceptDefault(name8, index) {
1488
- return !(index === 1 && name8 === "default");
1487
+ function exceptDefault(name10, index) {
1488
+ return !(index === 1 && name10 === "default");
1489
1489
  }
1490
1490
 
1491
1491
  // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/ast.js
@@ -1506,17 +1506,13 @@ var findDownstreamNodes = (context, topNode, type) => {
1506
1506
  });
1507
1507
  return nodes;
1508
1508
  };
1509
- var getUpstreamVariables = (context, node, filter, visited = /* @__PURE__ */ new Set()) => {
1510
- if (visited.has(node)) {
1509
+ var getUpstreamVariables = (context, variable, filter, visited = /* @__PURE__ */ new Set()) => {
1510
+ if (visited.has(variable)) {
1511
1511
  return [];
1512
1512
  }
1513
- visited.add(node);
1514
- const variable = findVariable(context.sourceCode.getScope(node), node);
1515
- if (!variable) {
1516
- return [];
1517
- }
1518
- const upstreamVariables = variable.defs.filter((def) => !!def.node.init).filter((def) => filter(def.node)).flatMap((def) => findDownstreamNodes(context, def.node.init, "Identifier")).flatMap(
1519
- (identifier) => getUpstreamVariables(context, identifier, filter, visited)
1513
+ visited.add(variable);
1514
+ 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(
1515
+ (variable2) => getUpstreamVariables(context, variable2, filter, visited)
1520
1516
  );
1521
1517
  return upstreamVariables.length === 0 ? [variable] : upstreamVariables;
1522
1518
  };
@@ -1550,6 +1546,7 @@ var isUseState = (node) => node.type === "VariableDeclarator" && node.init && no
1550
1546
  (node.id.elements.length === 1 || node.id.elements.length === 2) && node.id.elements.every((el) => {
1551
1547
  return !el || el.type === "Identifier";
1552
1548
  });
1549
+ var isUseRef = (node) => node.type === "VariableDeclarator" && node.init && node.init.type === "CallExpression" && node.init.callee.name === "useRef" && node.id.type === "Identifier";
1553
1550
  var isUseEffect = (node) => node.type === "CallExpression" && (node.callee.type === "Identifier" && (node.callee.name === "useEffect" || node.callee.name === "useLayoutEffect") || node.callee.type === "MemberExpression" && node.callee.object.name === "React" && (node.callee.property.name === "useEffect" || node.callee.property.name === "useLayoutEffect"));
1554
1551
  var getEffectFn = (node) => {
1555
1552
  if (!isUseEffect(node) || node.arguments.length < 1) {
@@ -1579,13 +1576,14 @@ function getDependenciesRefs(context, node) {
1579
1576
  return getDownstreamRefs(context, depsArr);
1580
1577
  }
1581
1578
  var isFnRef = (ref) => getCallExpr(ref) !== void 0;
1582
- var isStateSetter = (context, ref) => isFnRef(ref) && getUpstreamReactVariables(context, ref.identifier).notEmptyEvery(
1579
+ var isStateSetter = (context, ref) => isFnRef(ref) && getUpstreamReactVariables(context, ref.resolved).notEmptyEvery(
1583
1580
  (variable) => isState(variable)
1584
1581
  );
1585
- var isPropCallback = (context, ref) => isFnRef(ref) && getUpstreamReactVariables(context, ref.identifier).notEmptyEvery(
1582
+ var isPropCallback = (context, ref) => isFnRef(ref) && getUpstreamReactVariables(context, ref.resolved).notEmptyEvery(
1586
1583
  (variable) => isProp(variable)
1587
1584
  );
1588
1585
  var isState = (variable) => variable.defs.some((def) => isUseState(def.node));
1586
+ var isRef = (variable) => variable.defs.some((def) => isUseRef(def.node));
1589
1587
  var isProp = (variable) => variable.defs.some(
1590
1588
  (def) => def.type === "Parameter" && (isReactFunctionalComponent(getDeclNode(def.node)) || isCustomHook(getDeclNode(def.node)))
1591
1589
  );
@@ -1594,7 +1592,7 @@ var isHOCProp = (variable) => variable.defs.some(
1594
1592
  );
1595
1593
  var getDeclNode = (node) => node.type === "ArrowFunctionExpression" ? node.parent.type === "CallExpression" ? node.parent.parent : node.parent : node;
1596
1594
  var getUseStateNode = (context, ref) => {
1597
- return getUpstreamReactVariables(context, ref.identifier).find((variable) => isState(variable))?.defs.find((def) => isUseState(def.node))?.node;
1595
+ return getUpstreamReactVariables(context, ref.resolved).find((variable) => isState(variable))?.defs.find((def) => isUseState(def.node))?.node;
1598
1596
  };
1599
1597
  var isDirectCall = (node) => {
1600
1598
  if (!node) {
@@ -1635,6 +1633,9 @@ var countUseStates = (context, componentNode) => {
1635
1633
  });
1636
1634
  return count;
1637
1635
  };
1636
+ var countCalls = (ref) => ref.resolved.references.filter(
1637
+ (ref2) => ref2.identifier.parent.type === "CallExpression"
1638
+ ).length;
1638
1639
  var findContainingNode = (node) => {
1639
1640
  if (!node) {
1640
1641
  return void 0;
@@ -1644,18 +1645,18 @@ var findContainingNode = (node) => {
1644
1645
  return findContainingNode(node.parent);
1645
1646
  }
1646
1647
  };
1647
- var getUpstreamReactVariables = (context, node) => getUpstreamVariables(
1648
+ var getUpstreamReactVariables = (context, variable) => getUpstreamVariables(
1648
1649
  context,
1649
- node,
1650
+ variable,
1650
1651
  // Stop at the *usage* of `useState` - don't go up to the `useState` variable.
1651
1652
  // Not needed for props - they don't go "too far".
1652
1653
  // We could remove this and check for the `useState` variable instead,
1653
1654
  // but then all our tests need to import it so we can traverse up to it.
1654
1655
  // And would need to change `getUseStateNode()` too?
1655
1656
  // TODO: Could probably organize these filters better.
1656
- (node2) => !isUseState(node2)
1657
+ (node) => !isUseState(node)
1657
1658
  ).filter(
1658
- (variable) => isProp(variable) || variable.defs.every((def) => def.type !== "Parameter")
1659
+ (variable2) => isProp(variable2) || variable2.defs.every((def) => def.type !== "Parameter")
1659
1660
  );
1660
1661
 
1661
1662
  // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-empty-effect.js
@@ -1754,9 +1755,7 @@ var rule3 = {
1754
1755
  const depsRefs = getDependenciesRefs(context, node);
1755
1756
  if (!effectFnRefs || !depsRefs) return;
1756
1757
  findDownstreamNodes(context, node, "IfStatement").filter((ifNode) => !ifNode.alternate).filter(
1757
- (ifNode) => getDownstreamRefs(context, ifNode.test).flatMap(
1758
- (ref) => getUpstreamReactVariables(context, ref.identifier)
1759
- ).notEmptyEvery((variable) => isState(variable))
1758
+ (ifNode) => getDownstreamRefs(context, ifNode.test).flatMap((ref) => getUpstreamReactVariables(context, ref.resolved)).notEmptyEvery((variable) => isState(variable))
1760
1759
  ).forEach((ifNode) => {
1761
1760
  context.report({
1762
1761
  node: ifNode.test,
@@ -1767,22 +1766,22 @@ var rule3 = {
1767
1766
  })
1768
1767
  };
1769
1768
 
1770
- // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-parent-child-coupling.js
1769
+ // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-pass-live-state-to-parent.js
1771
1770
  init_esm_shims();
1772
- var name4 = "no-parent-child-coupling";
1771
+ var name4 = "no-pass-live-state-to-parent";
1773
1772
  var messages4 = {
1774
- avoidParentChildCoupling: "avoidParentChildCoupling"
1773
+ avoidPassingLiveStateToParent: "avoidPassingLiveStateToParent"
1775
1774
  };
1776
1775
  var rule4 = {
1777
1776
  meta: {
1778
1777
  type: "suggestion",
1779
1778
  docs: {
1780
- description: "Disallow coupling parent behavior or state to a child component in an effect.",
1779
+ description: "Disallow passing live state to parent components in an effect.",
1781
1780
  url: "https://react.dev/learn/you-might-not-need-an-effect#notifying-parent-components-about-state-changes"
1782
1781
  },
1783
1782
  schema: [],
1784
1783
  messages: {
1785
- [messages4.avoidParentChildCoupling]: "Avoid coupling parent behavior or state to a child component. Instead, lift shared logic or state up to the parent."
1784
+ [messages4.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."
1786
1785
  }
1787
1786
  },
1788
1787
  create: (context) => ({
@@ -1791,11 +1790,15 @@ var rule4 = {
1791
1790
  const effectFnRefs = getEffectFnRefs(context, node);
1792
1791
  const depsRefs = getDependenciesRefs(context, node);
1793
1792
  if (!effectFnRefs || !depsRefs) return;
1794
- effectFnRefs.filter(isFnRef).filter((ref) => isDirectCall(ref.identifier)).forEach((ref) => {
1795
- if (isPropCallback(context, ref) && !isHOCProp(ref.resolved)) {
1793
+ effectFnRefs.filter(isFnRef).filter((ref) => isDirectCall(ref.identifier)).filter(
1794
+ (ref) => isPropCallback(context, ref) && !isHOCProp(ref.resolved)
1795
+ ).forEach((ref) => {
1796
+ const callExpr = getCallExpr(ref);
1797
+ const argsUpstreamVariables = callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref2) => getUpstreamReactVariables(context, ref2.resolved));
1798
+ if (argsUpstreamVariables.some((variable) => isState(variable))) {
1796
1799
  context.report({
1797
- node: getCallExpr(ref),
1798
- messageId: messages4.avoidParentChildCoupling
1800
+ node: callExpr,
1801
+ messageId: messages4.avoidPassingLiveStateToParent
1799
1802
  });
1800
1803
  }
1801
1804
  });
@@ -1864,17 +1867,12 @@ var rule6 = {
1864
1867
  const effectFnRefs = getEffectFnRefs(context, node);
1865
1868
  const depsRefs = getDependenciesRefs(context, node);
1866
1869
  if (!effectFnRefs || !depsRefs) return;
1867
- const isAllDepsInternal = depsRefs.flatMap((ref) => getUpstreamReactVariables(context, ref.identifier)).notEmptyEvery(
1870
+ const isAllDepsInternal = depsRefs.flatMap((ref) => getUpstreamReactVariables(context, ref.resolved)).notEmptyEvery(
1868
1871
  (variable) => isState(variable) || isProp(variable) && !isHOCProp(variable)
1869
1872
  );
1870
1873
  effectFnRefs.filter(isFnRef).filter((ref) => isDirectCall(ref.identifier)).filter((ref) => isStateSetter(context, ref)).forEach((ref) => {
1871
1874
  const callExpr = getCallExpr(ref);
1872
- const argsRefs = callExpr.arguments.flatMap(
1873
- (arg) => getDownstreamRefs(context, arg)
1874
- );
1875
- const argsUpstreamVariables = argsRefs.flatMap(
1876
- (ref2) => getUpstreamReactVariables(context, ref2.identifier)
1877
- );
1875
+ const argsUpstreamVariables = callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref2) => getUpstreamReactVariables(context, ref2.resolved));
1878
1876
  const isAllArgsInternal = argsUpstreamVariables.notEmptyEvery(
1879
1877
  (variable) => isState(variable) || isProp(variable) && !isHOCProp(variable)
1880
1878
  );
@@ -1894,20 +1892,6 @@ var rule6 = {
1894
1892
 
1895
1893
  // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-derived-state.js
1896
1894
  init_esm_shims();
1897
-
1898
- // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/javascript.js
1899
- init_esm_shims();
1900
- Array.prototype.notEmptyEvery = function(predicate) {
1901
- return this.length > 0 && this.every(predicate);
1902
- };
1903
- var arraysEqual = (arr1, arr2) => {
1904
- if (arr1.length !== arr2.length) {
1905
- return false;
1906
- }
1907
- return arr1.every((element, index) => element === arr2[index]);
1908
- };
1909
-
1910
- // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-derived-state.js
1911
1895
  var name7 = "no-derived-state";
1912
1896
  var messages7 = {
1913
1897
  avoidDerivedState: "avoidDerivedState"
@@ -1934,27 +1918,19 @@ var rule7 = {
1934
1918
  const callExpr = getCallExpr(ref);
1935
1919
  const useStateNode = getUseStateNode(context, ref);
1936
1920
  const stateName = (useStateNode.id.elements[0] ?? useStateNode.id.elements[1])?.name;
1937
- const argsRefs = callExpr.arguments.flatMap(
1938
- (arg) => getDownstreamRefs(context, arg)
1939
- );
1940
- const argsUpstreamVariables = argsRefs.flatMap(
1941
- (ref2) => getUpstreamReactVariables(context, ref2.identifier)
1921
+ const argsUpstreamVars = callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref2) => getUpstreamReactVariables(context, ref2.resolved));
1922
+ const depsUpstreamVars = depsRefs.flatMap(
1923
+ (ref2) => getUpstreamReactVariables(context, ref2.resolved)
1942
1924
  );
1943
- const isAllArgsInternal = argsUpstreamVariables.notEmptyEvery(
1925
+ const isAllArgsInternal = argsUpstreamVars.notEmptyEvery(
1944
1926
  (variable) => isState(variable) || isProp(variable) && !isHOCProp(variable)
1945
1927
  );
1946
- const isAllArgsInDeps = argsRefs.filter(
1947
- (ref2) => ref2.resolved.defs.every((def) => def.type !== "Parameter")
1948
- ).notEmptyEvery(
1949
- (argRef) => depsRefs.some(
1950
- (depRef) => arraysEqual(
1951
- getUpstreamReactVariables(context, argRef.identifier),
1952
- getUpstreamReactVariables(context, depRef.identifier)
1953
- )
1954
- )
1928
+ const isAllArgsInDeps = argsUpstreamVars.notEmptyEvery(
1929
+ (argVar) => depsUpstreamVars.some((depVar) => argVar.name === depVar.name)
1955
1930
  );
1956
- const isStateSetterCalledOnce = ref.resolved.references.length - 1 === 1;
1957
- if (isAllArgsInternal || isAllArgsInDeps && isStateSetterCalledOnce) {
1931
+ if (isAllArgsInternal || // In this case the derived state will always be in sync,
1932
+ // thus it could be computed directly during render
1933
+ isAllArgsInDeps && countCalls(ref) === 1) {
1958
1934
  context.report({
1959
1935
  node: callExpr,
1960
1936
  messageId: messages7.avoidDerivedState,
@@ -1966,8 +1942,92 @@ var rule7 = {
1966
1942
  })
1967
1943
  };
1968
1944
 
1945
+ // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-pass-data-to-parent.js
1946
+ init_esm_shims();
1947
+ var name8 = "no-pass-data-to-parent";
1948
+ var messages8 = {
1949
+ avoidPassingDataToParent: "avoidPassingDataToParent"
1950
+ };
1951
+ var rule8 = {
1952
+ meta: {
1953
+ type: "suggestion",
1954
+ docs: {
1955
+ description: "Disallow passing data to parents in an effect.",
1956
+ url: "https://react.dev/learn/you-might-not-need-an-effect#passing-data-to-the-parent"
1957
+ },
1958
+ schema: [],
1959
+ messages: {
1960
+ [messages8.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."
1961
+ }
1962
+ },
1963
+ create: (context) => ({
1964
+ CallExpression: (node) => {
1965
+ if (!isUseEffect(node)) return;
1966
+ const effectFnRefs = getEffectFnRefs(context, node);
1967
+ const depsRefs = getDependenciesRefs(context, node);
1968
+ if (!effectFnRefs || !depsRefs) return;
1969
+ effectFnRefs.filter(isFnRef).filter((ref) => isDirectCall(ref.identifier)).filter(
1970
+ (ref) => isPropCallback(context, ref) && !isHOCProp(ref.resolved)
1971
+ ).forEach((ref) => {
1972
+ const callExpr = getCallExpr(ref);
1973
+ const argsUpstreamVariables = callExpr.arguments.flatMap((arg) => getDownstreamRefs(context, arg)).flatMap((ref2) => getUpstreamReactVariables(context, ref2.resolved));
1974
+ if (callExpr.arguments.some((arg) => arg.type === "Literal") || argsUpstreamVariables.some(
1975
+ (variable) => !isState(variable) && !isRef(variable)
1976
+ )) {
1977
+ context.report({
1978
+ node: callExpr,
1979
+ messageId: messages8.avoidPassingDataToParent
1980
+ });
1981
+ }
1982
+ });
1983
+ }
1984
+ })
1985
+ };
1986
+
1987
+ // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/no-manage-parent.js
1988
+ init_esm_shims();
1989
+ var name9 = "no-manage-parent";
1990
+ var messages9 = {
1991
+ avoidManagingParent: "avoidManagingParent"
1992
+ };
1993
+ var rule9 = {
1994
+ meta: {
1995
+ type: "problem",
1996
+ docs: {
1997
+ description: "Disallow effects that only use props."
1998
+ },
1999
+ schema: [],
2000
+ messages: {
2001
+ [messages9.avoidManagingParent]: "This effect only uses props. Consider lifting the logic up to the parent."
2002
+ }
2003
+ },
2004
+ create: (context) => ({
2005
+ CallExpression: (node) => {
2006
+ if (!isUseEffect(node)) return;
2007
+ const effectFnRefs = getEffectFnRefs(context, node);
2008
+ const depsRefs = getDependenciesRefs(context, node);
2009
+ if (!effectFnRefs || !depsRefs) return;
2010
+ if (effectFnRefs.length === 0) return;
2011
+ if (effectFnRefs.concat(depsRefs).every((ref) => isProp(ref.resolved) && !isHOCProp(ref.resolved))) {
2012
+ context.report({
2013
+ node,
2014
+ messageId: messages9.avoidManagingParent
2015
+ });
2016
+ }
2017
+ }
2018
+ })
2019
+ };
2020
+
1969
2021
  // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/index.js
1970
2022
  import globals2 from "globals";
2023
+
2024
+ // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/util/javascript.js
2025
+ init_esm_shims();
2026
+ Array.prototype.notEmptyEvery = function(predicate) {
2027
+ return this.length > 0 && this.every(predicate);
2028
+ };
2029
+
2030
+ // node_modules/eslint-plugin-react-you-might-not-need-an-effect/src/index.js
1971
2031
  var plugin = {
1972
2032
  meta: {
1973
2033
  name: "react-you-might-not-need-an-effect"
@@ -1978,6 +2038,8 @@ var plugin = {
1978
2038
  [name2]: rule2,
1979
2039
  [name3]: rule3,
1980
2040
  [name4]: rule4,
2041
+ [name8]: rule8,
2042
+ [name9]: rule9,
1981
2043
  [name5]: rule5,
1982
2044
  [name6]: rule6,
1983
2045
  [name7]: rule7
@@ -2018,12 +2080,14 @@ Object.assign(plugin.configs, {
2018
2080
  var src_default = plugin;
2019
2081
 
2020
2082
  // src/eslint/configs/react.ts
2021
- import { isPackageExists } from "local-pkg";
2083
+ import { isPackageListedSync } from "local-pkg";
2022
2084
  var nextJsPackages = ["next"];
2023
2085
  var vitePackages = ["vite"];
2024
2086
  async function react() {
2025
- const isUsingNext = nextJsPackages.some((index) => isPackageExists(index));
2026
- const isUsingVite = vitePackages.some((index) => isPackageExists(index));
2087
+ const isUsingNext = nextJsPackages.some(
2088
+ (index) => isPackageListedSync(index)
2089
+ );
2090
+ const isUsingVite = vitePackages.some((index) => isPackageListedSync(index));
2027
2091
  const nextjsConfig = [];
2028
2092
  if (isUsingNext) {
2029
2093
  const nextPlugin = await import("@next/eslint-plugin-next").then(
@@ -2138,4 +2202,4 @@ export {
2138
2202
  eslint-utils/index.mjs:
2139
2203
  (*! @author Toru Nagashima <https://github.com/mysticatea> *)
2140
2204
  */
2141
- //# sourceMappingURL=react-UAVCCK2N.js.map
2205
+ //# sourceMappingURL=react-PWJWWBLW.js.map