eslint-plugin-absolute 0.11.5 → 0.11.6

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1731,6 +1731,48 @@ var noExplicitReturnTypes = createRule({
1731
1731
  return parent.parent;
1732
1732
  return node;
1733
1733
  };
1734
+ const collectTypeReferenceNames = (root) => {
1735
+ const names = new Set;
1736
+ const visit = (value) => {
1737
+ if (!value || typeof value !== "object") {
1738
+ return;
1739
+ }
1740
+ if (Array.isArray(value)) {
1741
+ value.forEach(visit);
1742
+ return;
1743
+ }
1744
+ const candidate = value;
1745
+ if (typeof candidate.type !== "string") {
1746
+ return;
1747
+ }
1748
+ const astNode = value;
1749
+ if (astNode.type === "TSTypeReference" && astNode.typeName.type === "Identifier") {
1750
+ names.add(astNode.typeName.name);
1751
+ }
1752
+ for (const key of Object.keys(astNode)) {
1753
+ if (key === "parent") {
1754
+ continue;
1755
+ }
1756
+ visit(astNode[key]);
1757
+ }
1758
+ };
1759
+ visit(root);
1760
+ return names;
1761
+ };
1762
+ const hasReturnOnlyTypeParameter = (node) => {
1763
+ const declaredTypeParams = node.typeParameters?.params;
1764
+ if (!declaredTypeParams || declaredTypeParams.length === 0) {
1765
+ return false;
1766
+ }
1767
+ const returnTypeNames = collectTypeReferenceNames(node.returnType);
1768
+ const parameterTypeNames = new Set;
1769
+ for (const parameter of node.params) {
1770
+ for (const name of collectTypeReferenceNames(parameter)) {
1771
+ parameterTypeNames.add(name);
1772
+ }
1773
+ }
1774
+ return declaredTypeParams.some((typeParam) => returnTypeNames.has(typeParam.name.name) && !parameterTypeNames.has(typeParam.name.name));
1775
+ };
1734
1776
  const referencesOwnName = (node) => {
1735
1777
  const ownName = getOwnName(node);
1736
1778
  if (!ownName)
@@ -1759,6 +1801,9 @@ var noExplicitReturnTypes = createRule({
1759
1801
  if (referencesOwnName(node)) {
1760
1802
  return;
1761
1803
  }
1804
+ if (hasReturnOnlyTypeParameter(node)) {
1805
+ return;
1806
+ }
1762
1807
  context.report({
1763
1808
  messageId: "noExplicitReturnType",
1764
1809
  node: returnType
@@ -1769,7 +1814,7 @@ var noExplicitReturnTypes = createRule({
1769
1814
  defaultOptions: [],
1770
1815
  meta: {
1771
1816
  docs: {
1772
- description: "Disallow explicit return type annotations on functions, except when using type predicates for type guards or inline object literal returns (e.g., style objects)."
1817
+ description: "Disallow explicit return type annotations on functions, except when the annotation is load-bearing: type predicates for type guards, inline object literal returns (e.g., style objects), recursive functions, or generics whose type parameter appears only in the return type."
1773
1818
  },
1774
1819
  messages: {
1775
1820
  noExplicitReturnType: "Explicit return types are disallowed; rely on TypeScript's inference instead."
package/package.json CHANGED
@@ -41,5 +41,5 @@
41
41
  "typecheck": "bun run tsc --noEmit"
42
42
  },
43
43
  "type": "module",
44
- "version": "0.11.5"
44
+ "version": "0.11.6"
45
45
  }