eslint-plugin-functype 2.121.0 → 2.122.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.
Files changed (83) hide show
  1. package/README.md +36 -20
  2. package/dist/cli/list-rules.js.map +1 -1
  3. package/dist/configs/agent.d.ts +44 -0
  4. package/dist/configs/agent.js +2 -0
  5. package/dist/configs/agent.js.map +1 -0
  6. package/dist/configs/recommended.d.ts +2 -0
  7. package/dist/configs/recommended.js.map +1 -1
  8. package/dist/configs/strict.d.ts +2 -0
  9. package/dist/configs/strict.js.map +1 -1
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/rules/collection-naming.d.ts +2 -0
  14. package/dist/rules/collection-naming.js.map +1 -1
  15. package/dist/rules/index.d.ts +2 -0
  16. package/dist/rules/index.js.map +1 -1
  17. package/dist/rules/must-fold-on-component-return.d.ts +2 -0
  18. package/dist/rules/must-fold-on-component-return.js.map +1 -1
  19. package/dist/rules/no-array-mutation.d.ts +2 -0
  20. package/dist/rules/no-array-mutation.js.map +1 -1
  21. package/dist/rules/no-floating-io.d.ts +2 -0
  22. package/dist/rules/no-floating-io.js.map +1 -1
  23. package/dist/rules/no-get-unsafe.d.ts +2 -0
  24. package/dist/rules/no-get-unsafe.js.map +1 -1
  25. package/dist/rules/no-getOrThrow-in-render.d.ts +2 -0
  26. package/dist/rules/no-getOrThrow-in-render.js.map +1 -1
  27. package/dist/rules/no-imperative-loops.d.ts +2 -0
  28. package/dist/rules/no-imperative-loops.js +1 -1
  29. package/dist/rules/no-imperative-loops.js.map +1 -1
  30. package/dist/rules/no-let.d.ts +2 -0
  31. package/dist/rules/no-let.js.map +1 -1
  32. package/dist/rules/prefer-do-notation.d.ts +2 -0
  33. package/dist/rules/prefer-do-notation.js.map +1 -1
  34. package/dist/rules/prefer-either.d.ts +2 -0
  35. package/dist/rules/prefer-either.js.map +1 -1
  36. package/dist/rules/prefer-flatmap.d.ts +2 -0
  37. package/dist/rules/prefer-flatmap.js +1 -1
  38. package/dist/rules/prefer-flatmap.js.map +1 -1
  39. package/dist/rules/prefer-fold.d.ts +2 -0
  40. package/dist/rules/prefer-fold.js.map +1 -1
  41. package/dist/rules/prefer-functype-map.d.ts +2 -0
  42. package/dist/rules/prefer-functype-map.js.map +1 -1
  43. package/dist/rules/prefer-functype-set.d.ts +2 -0
  44. package/dist/rules/prefer-functype-set.js.map +1 -1
  45. package/dist/rules/prefer-list.d.ts +2 -0
  46. package/dist/rules/prefer-list.js +1 -1
  47. package/dist/rules/prefer-list.js.map +1 -1
  48. package/dist/rules/prefer-map.d.ts +2 -0
  49. package/dist/rules/prefer-map.js.map +1 -1
  50. package/dist/rules/prefer-option.d.ts +2 -0
  51. package/dist/rules/prefer-option.js.map +1 -1
  52. package/dist/rules/prefer-try.d.ts +2 -0
  53. package/dist/rules/prefer-try.js.map +1 -1
  54. package/dist/types/ast.d.ts +2 -0
  55. package/dist/utils/array-mutation.d.ts +2 -0
  56. package/dist/utils/array-mutation.js.map +1 -1
  57. package/dist/utils/ast-walk.d.ts +2 -0
  58. package/dist/utils/ast-walk.js.map +1 -1
  59. package/dist/utils/async-detection.d.ts +2 -0
  60. package/dist/utils/async-detection.js.map +1 -1
  61. package/dist/utils/boundary-tags.d.ts +2 -0
  62. package/dist/utils/boundary-tags.js.map +1 -1
  63. package/dist/utils/collection-binding.d.ts +2 -0
  64. package/dist/utils/collection-binding.js.map +1 -1
  65. package/dist/utils/dependency-validator.d.ts +2 -1
  66. package/dist/utils/dependency-validator.js.map +1 -1
  67. package/dist/utils/functype-detection.d.ts +2 -0
  68. package/dist/utils/functype-detection.js.map +1 -1
  69. package/dist/utils/functype-predicates.d.ts +2 -0
  70. package/dist/utils/functype-predicates.js.map +1 -1
  71. package/dist/utils/import-fixer.d.ts +2 -0
  72. package/dist/utils/import-fixer.js.map +1 -1
  73. package/dist/utils/mutable-collection.d.ts +2 -0
  74. package/dist/utils/mutable-collection.js.map +1 -1
  75. package/dist/utils/react-render.d.ts +2 -0
  76. package/dist/utils/react-render.js.map +1 -1
  77. package/dist/utils/readonly-contract.d.ts +2 -0
  78. package/dist/utils/readonly-contract.js.map +1 -1
  79. package/dist/utils/type-aware.d.ts +2 -0
  80. package/dist/utils/type-aware.js.map +1 -1
  81. package/dist/utils/wire-types.d.ts +2 -0
  82. package/dist/utils/wire-types.js.map +1 -1
  83. package/package.json +6 -6
@@ -1,3 +1,4 @@
1
+ //#region src/utils/dependency-validator.d.ts
1
2
  interface PeerDependency {
2
3
  name: string;
3
4
  packageName: string;
@@ -14,5 +15,5 @@ export interface ValidationResult {
14
15
  export declare function validatePeerDependencies(): ValidationResult;
15
16
  export declare function createValidationError(result: ValidationResult): Error;
16
17
  export declare function shouldValidateDependencies(): boolean;
17
- export {};
18
+ //#endregion
18
19
  //# sourceMappingURL=dependency-validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dependency-validator.js","names":["__require","PEER_DEPENDENCIES","tryRequire","packageName","validatePeerDependencies","available","missing","ok","bad","dep","warnings","requiredMissing","installCommand","createValidationError","result","message","shouldValidateDependencies"],"sources":["../../src/utils/dependency-validator.ts"],"sourcesContent":["// Utility to validate peer dependencies and provide helpful error messages\n\ninterface PeerDependency {\n name: string\n packageName: string\n description: string\n required: boolean\n}\n\nconst PEER_DEPENDENCIES: PeerDependency[] = [\n {\n name: \"@typescript-eslint/eslint-plugin\",\n packageName: \"@typescript-eslint/eslint-plugin\",\n description: \"TypeScript-aware ESLint rules\",\n required: true,\n },\n {\n name: \"@typescript-eslint/parser\",\n packageName: \"@typescript-eslint/parser\",\n description: \"TypeScript parser for ESLint\",\n required: true,\n },\n {\n name: \"eslint-plugin-functional\",\n packageName: \"eslint-plugin-functional\",\n description: \"Functional programming ESLint rules\",\n required: true,\n },\n {\n name: \"eslint-plugin-prettier\",\n packageName: \"eslint-plugin-prettier\",\n description: \"Code formatting rules\",\n required: false,\n },\n {\n name: \"eslint-plugin-simple-import-sort\",\n packageName: \"eslint-plugin-simple-import-sort\",\n description: \"Import sorting rules\",\n required: false,\n },\n {\n name: \"prettier\",\n packageName: \"prettier\",\n description: \"Code formatter\",\n required: false,\n },\n]\n\nexport interface ValidationResult {\n isValid: boolean\n missing: PeerDependency[]\n available: PeerDependency[]\n installCommand: string\n warnings: string[]\n}\n\nfunction tryRequire(packageName: string): boolean {\n try {\n require.resolve(packageName)\n return true\n } catch {\n return false\n }\n}\n\nexport function validatePeerDependencies(): ValidationResult {\n // Partition each dep into present/absent up-front; downstream calcs are\n // pure derivations from those two arrays.\n const [available, missing] = PEER_DEPENDENCIES.reduce<[PeerDependency[], PeerDependency[]]>(\n ([ok, bad], dep) => (tryRequire(dep.packageName) ? [[...ok, dep], bad] : [ok, [...bad, dep]]),\n [[], []],\n )\n\n const warnings = missing\n .filter((dep) => !dep.required)\n .map((dep) => `Optional plugin '${dep.name}' not found. Some rules will be skipped.`)\n\n const requiredMissing = missing.filter((dep) => dep.required)\n const installCommand = missing.length > 0 ? `pnpm add -D ${missing.map((dep) => dep.packageName).join(\" \")}` : \"\"\n\n return {\n isValid: requiredMissing.length === 0,\n missing,\n available,\n installCommand,\n warnings,\n }\n}\n\nexport function createValidationError(result: ValidationResult): Error {\n const requiredMissing = result.missing.filter((dep) => dep.required)\n\n if (requiredMissing.length === 0) {\n return new Error(\"No validation errors\")\n }\n\n const missingList = requiredMissing.map((dep) => ` • ${dep.name} - ${dep.description}`).join(\"\\n\")\n\n const message = [\n \"❌ Missing required peer dependencies for eslint-plugin-functype:\",\n \"\",\n missingList,\n \"\",\n \"📦 Install missing dependencies:\",\n ` ${result.installCommand}`,\n \"\",\n \"📖 See installation guide: https://github.com/jordanburke/eslint-plugin-functype#installation\",\n ].join(\"\\n\")\n\n return new Error(message)\n}\n\nexport function shouldValidateDependencies(): boolean {\n // Skip validation in test environments or when explicitly disabled\n return process.env.NODE_ENV !== \"test\" && process.env.FUNCTYPE_SKIP_VALIDATION !== \"true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I,MAAM,sBAAsB,EAKzC,IAAMI,EAAU,CACd,mEACA,GAJkBJ,EAAgB,IAAK,GAAQ,OAAOF,EAAI,KAAK,KAAKA,EAAI,aAAa,CAAC,CAAC,KAAK;CAKlF,EACV,GACA,mCACA,MAAMK,EAAO,iBACb,GACA,+FACF,CAAC,CAAC,KAAK;CAAI,EAEX,OAAW,MAAMC,CAAO,CAC1B,CAEA,SAAgBC,GAAsC,CAEpD,OAAO,QAAQ,IAAI,WAAa,QAAU,QAAQ,IAAI,2BAA6B,MACrF,C"}
1
+ {"version":3,"file":"dependency-validator.js","names":["__require","PEER_DEPENDENCIES","tryRequire","packageName","validatePeerDependencies","available","missing","ok","bad","dep","warnings","requiredMissing","installCommand","createValidationError","result","message","shouldValidateDependencies"],"sources":["../../src/utils/dependency-validator.ts"],"sourcesContent":["// Utility to validate peer dependencies and provide helpful error messages\n\ninterface PeerDependency {\n name: string\n packageName: string\n description: string\n required: boolean\n}\n\nconst PEER_DEPENDENCIES: PeerDependency[] = [\n {\n name: \"@typescript-eslint/eslint-plugin\",\n packageName: \"@typescript-eslint/eslint-plugin\",\n description: \"TypeScript-aware ESLint rules\",\n required: true,\n },\n {\n name: \"@typescript-eslint/parser\",\n packageName: \"@typescript-eslint/parser\",\n description: \"TypeScript parser for ESLint\",\n required: true,\n },\n {\n name: \"eslint-plugin-functional\",\n packageName: \"eslint-plugin-functional\",\n description: \"Functional programming ESLint rules\",\n required: true,\n },\n {\n name: \"eslint-plugin-prettier\",\n packageName: \"eslint-plugin-prettier\",\n description: \"Code formatting rules\",\n required: false,\n },\n {\n name: \"eslint-plugin-simple-import-sort\",\n packageName: \"eslint-plugin-simple-import-sort\",\n description: \"Import sorting rules\",\n required: false,\n },\n {\n name: \"prettier\",\n packageName: \"prettier\",\n description: \"Code formatter\",\n required: false,\n },\n]\n\nexport interface ValidationResult {\n isValid: boolean\n missing: PeerDependency[]\n available: PeerDependency[]\n installCommand: string\n warnings: string[]\n}\n\nfunction tryRequire(packageName: string): boolean {\n try {\n require.resolve(packageName)\n return true\n } catch {\n return false\n }\n}\n\nexport function validatePeerDependencies(): ValidationResult {\n // Partition each dep into present/absent up-front; downstream calcs are\n // pure derivations from those two arrays.\n const [available, missing] = PEER_DEPENDENCIES.reduce<[PeerDependency[], PeerDependency[]]>(\n ([ok, bad], dep) => (tryRequire(dep.packageName) ? [[...ok, dep], bad] : [ok, [...bad, dep]]),\n [[], []],\n )\n\n const warnings = missing\n .filter((dep) => !dep.required)\n .map((dep) => `Optional plugin '${dep.name}' not found. Some rules will be skipped.`)\n\n const requiredMissing = missing.filter((dep) => dep.required)\n const installCommand = missing.length > 0 ? `pnpm add -D ${missing.map((dep) => dep.packageName).join(\" \")}` : \"\"\n\n return {\n isValid: requiredMissing.length === 0,\n missing,\n available,\n installCommand,\n warnings,\n }\n}\n\nexport function createValidationError(result: ValidationResult): Error {\n const requiredMissing = result.missing.filter((dep) => dep.required)\n\n if (requiredMissing.length === 0) {\n return new Error(\"No validation errors\")\n }\n\n const missingList = requiredMissing.map((dep) => ` • ${dep.name} - ${dep.description}`).join(\"\\n\")\n\n const message = [\n \"❌ Missing required peer dependencies for eslint-plugin-functype:\",\n \"\",\n missingList,\n \"\",\n \"📦 Install missing dependencies:\",\n ` ${result.installCommand}`,\n \"\",\n \"📖 See installation guide: https://github.com/jordanburke/eslint-plugin-functype#installation\",\n ].join(\"\\n\")\n\n return new Error(message)\n}\n\nexport function shouldValidateDependencies(): boolean {\n // Skip validation in test environments or when explicitly disabled\n return process.env.NODE_ENV !== \"test\" && process.env.FUNCTYPE_SKIP_VALIDATION !== \"true\"\n}\n"],"mappings":"qFASA,MAAMC,EAAsC,CAC1C,CACE,KAAM,mCACN,YAAa,mCACb,YAAa,gCACb,SAAU,EACZ,EACA,CACE,KAAM,4BACN,YAAa,4BACb,YAAa,+BACb,SAAU,EACZ,EACA,CACE,KAAM,2BACN,YAAa,2BACb,YAAa,sCACb,SAAU,EACZ,EACA,CACE,KAAM,yBACN,YAAa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,CAEA,SAAgBC,GAAsC,CAEpD,OAAO,QAAQ,IAAI,WAAa,QAAU,QAAQ,IAAI,2BAA6B,MACrF"}
@@ -1,5 +1,6 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
2
  import { Rule } from "eslint";
3
+ //#region src/utils/functype-detection.d.ts
3
4
  /**
4
5
  * Check if functype library is imported in the current file
5
6
  */
@@ -59,4 +60,5 @@ export declare function shouldUseDoNotation(node: ASTNode, functypeImports: Func
59
60
  shouldUse: boolean;
60
61
  reason: "nested-checks" | "chained-flatmaps" | "mixed-monads" | "async-chains" | null;
61
62
  };
63
+ //#endregion
62
64
  //# sourceMappingURL=functype-detection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functype-detection.js","names":["TYPE_NAMES","isFunctypeImport","node","hasFunctypeImport","context","categorizeSpecifier","spec","name","pickPresent","buckets","v","b","key","getFunctypeImports","getFunctypeImportsLegacy","isFunctypeType","types","functypeImports","typeName","isFunctypeCall","callee","objectName","methodName","ancestorSatisfies","parent","pred","isAlreadyUsingFunctype","hasFunctypeTypeAnnotation","isDoNotationCall","isDollarHelper","isInsideDoNotation","n","isChainedMethodCall","shouldUseDoNotation","text","flatMapChainDepth"],"sources":["../../src/utils/functype-detection.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Utility functions for detecting functype library usage in ESLint rules.\n *\n * Implementation style: pure helpers operating over native immutable\n * primitives (Array.prototype methods + ReadonlySet). No mutable\n * accumulators, no `for-of` driving state changes. The plugin's domain\n * (AST traversal) is naturally tree-shaped; the helpers compose as\n * folds/filters/maps over those trees.\n */\n\nconst TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Option\",\n \"Either\",\n \"List\",\n \"LazyList\",\n \"Task\",\n \"Try\",\n \"Map\",\n \"Set\",\n \"Stack\",\n])\n\n/** `import ... from \"functype\"` — including `functype/<subpath>` */\nconst isFunctypeImport = (node: ASTNode): boolean =>\n node.type === \"ImportDeclaration\" && node.source.type === \"Literal\" && node.source.value === \"functype\"\n\n/**\n * Check if functype library is imported in the current file\n */\nexport function hasFunctypeImport(context: Rule.RuleContext): boolean {\n return context.sourceCode.ast.body.some(isFunctypeImport)\n}\n\n/**\n * Enhanced functype imports tracking\n */\nexport interface FunctypeImports {\n types: Set<string> // Option, Either, List, etc.\n functions: Set<string> // Do, DoAsync, $, etc.\n all: Set<string> // Combined for compatibility\n}\n\ntype SpecifierBuckets = { readonly type: string | null; readonly fn: string | null; readonly all: string }\n\n/** Sort a single import specifier into the three buckets (or none). */\nfunction categorizeSpecifier(spec: ASTNode): SpecifierBuckets | null {\n if (spec.type === \"ImportSpecifier\" && spec.imported.type === \"Identifier\") {\n const name = spec.imported.name\n // Named imports split by whether they're a functype TYPE or anything else.\n // (Do/DoAsync/$ + any other named import bucket as `functions`, matching\n // the original behavior — the explicit Do/DoAsync/$ branch was redundant.)\n return TYPE_NAMES.has(name) ? { type: name, fn: null, all: name } : { type: null, fn: name, all: name }\n }\n if (spec.type === \"ImportDefaultSpecifier\") return { type: null, fn: \"default\", all: \"default\" }\n if (spec.type === \"ImportNamespaceSpecifier\") return { type: \"*\", fn: \"*\", all: \"*\" }\n return null\n}\n\nconst pickPresent = <K extends keyof SpecifierBuckets>(buckets: readonly SpecifierBuckets[], key: K): string[] =>\n buckets.flatMap((b) => {\n const v = b[key]\n return v === null ? [] : [v as string]\n })\n\n/**\n * Get imported functype symbols from the current file\n */\nexport function getFunctypeImports(context: Rule.RuleContext): FunctypeImports {\n const buckets = context.sourceCode.ast.body\n .filter(isFunctypeImport)\n .flatMap((node: ASTNode) => (node.specifiers ?? []) as ASTNode[])\n .map(categorizeSpecifier)\n .filter((b): b is SpecifierBuckets => b !== null)\n\n return {\n types: new Set(pickPresent(buckets, \"type\")),\n functions: new Set(pickPresent(buckets, \"fn\")),\n all: new Set(buckets.map((b) => b.all)),\n }\n}\n\n/**\n * Legacy compatibility - returns the 'all' set\n */\nexport function getFunctypeImportsLegacy(context: Rule.RuleContext): Set<string> {\n return getFunctypeImports(context).all\n}\n\n/**\n * Check if a type reference is using functype types\n */\nexport function isFunctypeType(node: ASTNode, functypeImports: FunctypeImports | Set<string>): boolean {\n if (!node) return false\n\n // Handle both new and legacy API\n const types = functypeImports instanceof Set ? functypeImports : functypeImports.types || functypeImports.all\n\n // Check direct type names\n if (node.type === \"TSTypeReference\" && node.typeName?.type === \"Identifier\") {\n const typeName = node.typeName.name\n return (\n types.has(typeName) ||\n [\"Option\", \"Either\", \"List\", \"LazyList\", \"Task\", \"Try\", \"Map\", \"Set\", \"Stack\"].includes(typeName)\n )\n }\n\n return false\n}\n\n/**\n * Check if a call expression is using functype methods\n */\nexport function isFunctypeCall(node: ASTNode, functypeImports: Set<string>): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for static method calls like Option.some(), Either.left(), List.of()\n if (callee.type === \"MemberExpression\" && callee.object.type === \"Identifier\") {\n const objectName = callee.object.name\n const methodName = callee.property?.name\n\n // Check if calling methods on imported functype types\n if (functypeImports.has(objectName)) return true\n\n // Check for common functype patterns\n if (\n (objectName === \"Option\" && [\"some\", \"none\", \"of\"].includes(methodName)) ||\n (objectName === \"Either\" && [\"left\", \"right\", \"of\"].includes(methodName)) ||\n (objectName === \"List\" && [\"of\", \"from\", \"empty\"].includes(methodName)) ||\n (objectName === \"Map\" && [\"of\", \"empty\"].includes(methodName)) ||\n (objectName === \"Set\" && [\"of\", \"empty\"].includes(methodName))\n ) {\n return true\n }\n }\n\n // Check for method calls on functype instances like someOption.map()\n if (callee.type === \"MemberExpression\") {\n const methodName = callee.property?.name\n\n // Common functype methods\n if (\n [\n \"map\",\n \"flatMap\",\n \"filter\",\n \"fold\",\n \"foldLeft\",\n \"foldRight\",\n \"getOrElse\",\n \"orElse\",\n \"isEmpty\",\n \"nonEmpty\",\n \"isDefined\",\n \"isSome\",\n \"isNone\",\n \"isLeft\",\n \"isRight\",\n \"toArray\",\n ].includes(methodName)\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** True iff any ancestor of `node` satisfies `pred`. Pure tail recursion. */\nfunction ancestorSatisfies(node: ASTNode | null | undefined, pred: (n: ASTNode) => boolean): boolean {\n const parent = node?.parent as ASTNode | undefined\n if (!parent) return false\n return pred(parent) || ancestorSatisfies(parent, pred)\n}\n\n/**\n * Check if current context is already using functype patterns appropriately\n */\nexport function isAlreadyUsingFunctype(node: ASTNode, functypeImports: Set<string>): boolean {\n return ancestorSatisfies(\n node,\n (parent) => isFunctypeCall(parent, functypeImports) || isFunctypeType(parent, functypeImports),\n )\n}\n\n/**\n * Check if a variable or parameter is typed with functype types\n */\nexport function hasFunctypeTypeAnnotation(node: ASTNode, functypeImports: FunctypeImports | Set<string>): boolean {\n // Check for type annotation\n if (node.typeAnnotation?.typeAnnotation) {\n return isFunctypeType(node.typeAnnotation.typeAnnotation, functypeImports)\n }\n\n return false\n}\n\n/**\n * Check if a call expression is a Do notation call\n */\nexport function isDoNotationCall(node: ASTNode, functypeImports: FunctypeImports): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for Do() or DoAsync() calls\n if (callee.type === \"Identifier\") {\n const name = callee.name\n return functypeImports.functions.has(name) && [\"Do\", \"DoAsync\"].includes(name)\n }\n\n return false\n}\n\n/**\n * Check if a call expression uses the $ helper function\n */\nexport function isDollarHelper(node: ASTNode, functypeImports: FunctypeImports): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for $() calls\n if (callee.type === \"Identifier\" && callee.name === \"$\") {\n return functypeImports.functions.has(\"$\")\n }\n\n return false\n}\n\n/**\n * Check if current expression is inside a Do notation block\n */\nexport function isInsideDoNotation(node: ASTNode, functypeImports: FunctypeImports): boolean {\n return ancestorSatisfies(node, (n) => n.type === \"CallExpression\" && isDoNotationCall(n, functypeImports))\n}\n\n/**\n * Check if a method call is a chained method call on functype types\n */\nexport function isChainedMethodCall(node: ASTNode, methodName: string): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n if (\n callee.type === \"MemberExpression\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === methodName\n ) {\n return true\n }\n\n return false\n}\n\n/**\n * Detect if code could benefit from Do notation\n */\nexport function shouldUseDoNotation(\n node: ASTNode,\n functypeImports: FunctypeImports,\n): {\n shouldUse: boolean\n reason: \"nested-checks\" | \"chained-flatmaps\" | \"mixed-monads\" | \"async-chains\" | null\n} {\n // Already using Do notation\n if (isInsideDoNotation(node, functypeImports)) {\n return { shouldUse: false, reason: null }\n }\n\n // Check for nested null checks (a && a.b && a.b.c pattern)\n if (node.type === \"LogicalExpression\" && node.operator === \"&&\") {\n const text = node.toString ? node.toString() : \"\"\n if (text.includes(\"&&\") && text.match(/\\w+(\\.\\w+){2,}/)) {\n return { shouldUse: true, reason: \"nested-checks\" }\n }\n }\n\n // Check for chained flatMap calls\n if (isChainedMethodCall(node, \"flatMap\") && flatMapChainDepth(node) >= 3) {\n return { shouldUse: true, reason: \"chained-flatmaps\" }\n }\n\n return { shouldUse: false, reason: null }\n}\n\n/** Length of an unbroken `.flatMap().flatMap()...` chain starting at `node`. */\nfunction flatMapChainDepth(node: ASTNode): number {\n if (!node || node.type !== \"CallExpression\" || !isChainedMethodCall(node, \"flatMap\")) return 0\n if (node.callee.type !== \"MemberExpression\") return 1\n return 1 + flatMapChainDepth(node.callee.object as ASTNode)\n}\n"],"mappings":"AAcA,MAAMA,kBAAkC,IAAI,IAAI,CAC9C,SACA,SACA,OACA,WACA,OACA,MACA,MACA,MACA,OACF,CAAC,EAGKC,EAAoB,GACxBC,EAAK,OAAS,qBAAuBA,EAAK,OAAO,OAAS,WAAaA,EAAK,OAAO,QAAU,WAK/F,SAAgBC,EAAkB,EAAoC,CACpE,OAAOC,EAAQ,WAAW,IAAI,KAAK,KAAKH,CAAgB,CAC1D,CAcA,SAASI,EAAoB,EAAwC,CACnE,GAAIC,EAAK,OAAS,mBAAqBA,EA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AAW,GAAM,OAAQ,eAAgB,CAEtD,CAOA,OAJIF,EAAoB9B,EAAM,SAAS,GAAKiC,EAAkBjC,CAAI,GAAK,EAC9D,CAAE,UAAW,GAAM,OAAQ,kBAAmB,EAGhD,CAAE,UAAW,GAAO,OAAQ,IAAK,CAC1C,CAGA,SAASiC,EAAkB,EAAuB,CAGhD,MAFI,CAACjC,GAAQA,EAAK,OAAS,kBAAoB,CAAC8B,EAAoB9B,EAAM,SAAS,EAAU,EACzFA,EAAK,OAAO,OAAS,mBAClB,EAAIiC,EAAkBjC,EAAK,OAAO,MAAiB,EADN,CAEtD,C"}
1
+ {"version":3,"file":"functype-detection.js","names":["TYPE_NAMES","isFunctypeImport","node","hasFunctypeImport","context","categorizeSpecifier","spec","name","pickPresent","buckets","v","b","key","getFunctypeImports","getFunctypeImportsLegacy","isFunctypeType","types","functypeImports","typeName","isFunctypeCall","callee","objectName","methodName","ancestorSatisfies","parent","pred","isAlreadyUsingFunctype","hasFunctypeTypeAnnotation","isDoNotationCall","isDollarHelper","isInsideDoNotation","n","isChainedMethodCall","shouldUseDoNotation","text","flatMapChainDepth"],"sources":["../../src/utils/functype-detection.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Utility functions for detecting functype library usage in ESLint rules.\n *\n * Implementation style: pure helpers operating over native immutable\n * primitives (Array.prototype methods + ReadonlySet). No mutable\n * accumulators, no `for-of` driving state changes. The plugin's domain\n * (AST traversal) is naturally tree-shaped; the helpers compose as\n * folds/filters/maps over those trees.\n */\n\nconst TYPE_NAMES: ReadonlySet<string> = new Set([\n \"Option\",\n \"Either\",\n \"List\",\n \"LazyList\",\n \"Task\",\n \"Try\",\n \"Map\",\n \"Set\",\n \"Stack\",\n])\n\n/** `import ... from \"functype\"` — including `functype/<subpath>` */\nconst isFunctypeImport = (node: ASTNode): boolean =>\n node.type === \"ImportDeclaration\" && node.source.type === \"Literal\" && node.source.value === \"functype\"\n\n/**\n * Check if functype library is imported in the current file\n */\nexport function hasFunctypeImport(context: Rule.RuleContext): boolean {\n return context.sourceCode.ast.body.some(isFunctypeImport)\n}\n\n/**\n * Enhanced functype imports tracking\n */\nexport interface FunctypeImports {\n types: Set<string> // Option, Either, List, etc.\n functions: Set<string> // Do, DoAsync, $, etc.\n all: Set<string> // Combined for compatibility\n}\n\ntype SpecifierBuckets = { readonly type: string | null; readonly fn: string | null; readonly all: string }\n\n/** Sort a single import specifier into the three buckets (or none). */\nfunction categorizeSpecifier(spec: ASTNode): SpecifierBuckets | null {\n if (spec.type === \"ImportSpecifier\" && spec.imported.type === \"Identifier\") {\n const name = spec.imported.name\n // Named imports split by whether they're a functype TYPE or anything else.\n // (Do/DoAsync/$ + any other named import bucket as `functions`, matching\n // the original behavior — the explicit Do/DoAsync/$ branch was redundant.)\n return TYPE_NAMES.has(name) ? { type: name, fn: null, all: name } : { type: null, fn: name, all: name }\n }\n if (spec.type === \"ImportDefaultSpecifier\") return { type: null, fn: \"default\", all: \"default\" }\n if (spec.type === \"ImportNamespaceSpecifier\") return { type: \"*\", fn: \"*\", all: \"*\" }\n return null\n}\n\nconst pickPresent = <K extends keyof SpecifierBuckets>(buckets: readonly SpecifierBuckets[], key: K): string[] =>\n buckets.flatMap((b) => {\n const v = b[key]\n return v === null ? [] : [v as string]\n })\n\n/**\n * Get imported functype symbols from the current file\n */\nexport function getFunctypeImports(context: Rule.RuleContext): FunctypeImports {\n const buckets = context.sourceCode.ast.body\n .filter(isFunctypeImport)\n .flatMap((node: ASTNode) => (node.specifiers ?? []) as ASTNode[])\n .map(categorizeSpecifier)\n .filter((b): b is SpecifierBuckets => b !== null)\n\n return {\n types: new Set(pickPresent(buckets, \"type\")),\n functions: new Set(pickPresent(buckets, \"fn\")),\n all: new Set(buckets.map((b) => b.all)),\n }\n}\n\n/**\n * Legacy compatibility - returns the 'all' set\n */\nexport function getFunctypeImportsLegacy(context: Rule.RuleContext): Set<string> {\n return getFunctypeImports(context).all\n}\n\n/**\n * Check if a type reference is using functype types\n */\nexport function isFunctypeType(node: ASTNode, functypeImports: FunctypeImports | Set<string>): boolean {\n if (!node) return false\n\n // Handle both new and legacy API\n const types = functypeImports instanceof Set ? functypeImports : functypeImports.types || functypeImports.all\n\n // Check direct type names\n if (node.type === \"TSTypeReference\" && node.typeName?.type === \"Identifier\") {\n const typeName = node.typeName.name\n return (\n types.has(typeName) ||\n [\"Option\", \"Either\", \"List\", \"LazyList\", \"Task\", \"Try\", \"Map\", \"Set\", \"Stack\"].includes(typeName)\n )\n }\n\n return false\n}\n\n/**\n * Check if a call expression is using functype methods\n */\nexport function isFunctypeCall(node: ASTNode, functypeImports: Set<string>): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for static method calls like Option.some(), Either.left(), List.of()\n if (callee.type === \"MemberExpression\" && callee.object.type === \"Identifier\") {\n const objectName = callee.object.name\n const methodName = callee.property?.name\n\n // Check if calling methods on imported functype types\n if (functypeImports.has(objectName)) return true\n\n // Check for common functype patterns\n if (\n (objectName === \"Option\" && [\"some\", \"none\", \"of\"].includes(methodName)) ||\n (objectName === \"Either\" && [\"left\", \"right\", \"of\"].includes(methodName)) ||\n (objectName === \"List\" && [\"of\", \"from\", \"empty\"].includes(methodName)) ||\n (objectName === \"Map\" && [\"of\", \"empty\"].includes(methodName)) ||\n (objectName === \"Set\" && [\"of\", \"empty\"].includes(methodName))\n ) {\n return true\n }\n }\n\n // Check for method calls on functype instances like someOption.map()\n if (callee.type === \"MemberExpression\") {\n const methodName = callee.property?.name\n\n // Common functype methods\n if (\n [\n \"map\",\n \"flatMap\",\n \"filter\",\n \"fold\",\n \"foldLeft\",\n \"foldRight\",\n \"getOrElse\",\n \"orElse\",\n \"isEmpty\",\n \"nonEmpty\",\n \"isDefined\",\n \"isSome\",\n \"isNone\",\n \"isLeft\",\n \"isRight\",\n \"toArray\",\n ].includes(methodName)\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** True iff any ancestor of `node` satisfies `pred`. Pure tail recursion. */\nfunction ancestorSatisfies(node: ASTNode | null | undefined, pred: (n: ASTNode) => boolean): boolean {\n const parent = node?.parent as ASTNode | undefined\n if (!parent) return false\n return pred(parent) || ancestorSatisfies(parent, pred)\n}\n\n/**\n * Check if current context is already using functype patterns appropriately\n */\nexport function isAlreadyUsingFunctype(node: ASTNode, functypeImports: Set<string>): boolean {\n return ancestorSatisfies(\n node,\n (parent) => isFunctypeCall(parent, functypeImports) || isFunctypeType(parent, functypeImports),\n )\n}\n\n/**\n * Check if a variable or parameter is typed with functype types\n */\nexport function hasFunctypeTypeAnnotation(node: ASTNode, functypeImports: FunctypeImports | Set<string>): boolean {\n // Check for type annotation\n if (node.typeAnnotation?.typeAnnotation) {\n return isFunctypeType(node.typeAnnotation.typeAnnotation, functypeImports)\n }\n\n return false\n}\n\n/**\n * Check if a call expression is a Do notation call\n */\nexport function isDoNotationCall(node: ASTNode, functypeImports: FunctypeImports): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for Do() or DoAsync() calls\n if (callee.type === \"Identifier\") {\n const name = callee.name\n return functypeImports.functions.has(name) && [\"Do\", \"DoAsync\"].includes(name)\n }\n\n return false\n}\n\n/**\n * Check if a call expression uses the $ helper function\n */\nexport function isDollarHelper(node: ASTNode, functypeImports: FunctypeImports): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n // Check for $() calls\n if (callee.type === \"Identifier\" && callee.name === \"$\") {\n return functypeImports.functions.has(\"$\")\n }\n\n return false\n}\n\n/**\n * Check if current expression is inside a Do notation block\n */\nexport function isInsideDoNotation(node: ASTNode, functypeImports: FunctypeImports): boolean {\n return ancestorSatisfies(node, (n) => n.type === \"CallExpression\" && isDoNotationCall(n, functypeImports))\n}\n\n/**\n * Check if a method call is a chained method call on functype types\n */\nexport function isChainedMethodCall(node: ASTNode, methodName: string): boolean {\n if (!node || node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n\n if (\n callee.type === \"MemberExpression\" &&\n callee.property.type === \"Identifier\" &&\n callee.property.name === methodName\n ) {\n return true\n }\n\n return false\n}\n\n/**\n * Detect if code could benefit from Do notation\n */\nexport function shouldUseDoNotation(\n node: ASTNode,\n functypeImports: FunctypeImports,\n): {\n shouldUse: boolean\n reason: \"nested-checks\" | \"chained-flatmaps\" | \"mixed-monads\" | \"async-chains\" | null\n} {\n // Already using Do notation\n if (isInsideDoNotation(node, functypeImports)) {\n return { shouldUse: false, reason: null }\n }\n\n // Check for nested null checks (a && a.b && a.b.c pattern)\n if (node.type === \"LogicalExpression\" && node.operator === \"&&\") {\n const text = node.toString ? node.toString() : \"\"\n if (text.includes(\"&&\") && text.match(/\\w+(\\.\\w+){2,}/)) {\n return { shouldUse: true, reason: \"nested-checks\" }\n }\n }\n\n // Check for chained flatMap calls\n if (isChainedMethodCall(node, \"flatMap\") && flatMapChainDepth(node) >= 3) {\n return { shouldUse: true, reason: \"chained-flatmaps\" }\n }\n\n return { shouldUse: false, reason: null }\n}\n\n/** Length of an unbroken `.flatMap().flatMap()...` chain starting at `node`. */\nfunction flatMapChainDepth(node: ASTNode): number {\n if (!node || node.type !== \"CallExpression\" || !isChainedMethodCall(node, \"flatMap\")) return 0\n if (node.callee.type !== \"MemberExpression\") return 1\n return 1 + flatMapChainDepth(node.callee.object as ASTNode)\n}\n"],"mappings":"AAcA,MAAMA,kBAAkC,IAAI,IAAI,CAC9C,SACA,SACA,OACA,WACA,OACA,MACA,MACA,MACA,OACF,CAAC,EAGKC,EAAoB,GACxBC,EAAK,OAAS,qBAAuBA,EAAK,OAAO,OAAS,WAAaA,EAAK,OAAO,QAAU,WAK/F,SAAgBC,EAAkB,EAAoC,CACpE,OAAOC,EAAQ,WAAW,IAAI,KAAK,KAAKH,CAAgB,CAC1D,CAcA,SAASI,EAAoB,EAAwC,CACnE,GAAIC,EAAK,OAAS,mBAAqBA,EAAK,SAAS,OAAS,aAAc,CAC1E,IAAMC,EAAOD,EAAK,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oB9B,EAAM,SAAS,GAAKiC,EAAkBjC,CAAI,GAAK,EAC9D,CAAE,UAAW,GAAM,OAAQ,kBAAmB,EAGhD,CAAE,UAAW,GAAO,OAAQ,IAAK,CAC1C,CAGA,SAASiC,EAAkB,EAAuB,CAGhD,MAFI,CAACjC,GAAQA,EAAK,OAAS,kBAAoB,CAAC8B,EAAoB9B,EAAM,SAAS,EAAU,EACzFA,EAAK,OAAO,OAAS,mBAClB,EAAIiC,EAAkBjC,EAAK,OAAO,MAAiB,EADN,CAEtD"}
@@ -1,5 +1,6 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
2
  import { SourceCode } from "eslint";
3
+ //#region src/utils/functype-predicates.d.ts
3
4
  /** Methods on a monadic value that mean "this is the Some/Right/Success path." */
4
5
  export declare const POSITIVE_PREDICATES: ReadonlySet<string>;
5
6
  /** Methods that mean "this is the None/Left/Failure path." */
@@ -35,4 +36,5 @@ export type Presence = "present" | "absent" | null;
35
36
  export declare const provesWhen: (test: ASTNode, outcome: boolean, receiverText: string, sourceCode: SourceCode) => Presence;
36
37
  /** The functype-react component that renders both cases of the container a predicate belongs to. */
37
38
  export declare const MATCH_COMPONENT: Readonly<Record<string, string>>;
39
+ //#endregion
38
40
  //# sourceMappingURL=functype-predicates.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functype-predicates.js","names":["POSITIVE_PREDICATES","NEGATIVE_PREDICATES","compact","text","predicateCall","node","callee","method","isNegated","sourceCode","testedPredicate","test","inner","isEmptyRead","receiverText","provesWhen","self","value","outcome","left","right","predicate","isAbsenceTest","MATCH_COMPONENT"],"sources":["../../src/utils/functype-predicates.ts"],"sourcesContent":["import type { SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/** Methods on a monadic value that mean \"this is the Some/Right/Success path.\" */\nexport const POSITIVE_PREDICATES: ReadonlySet<string> = new Set([\"isSome\", \"isRight\", \"isSuccess\"])\n/** Methods that mean \"this is the None/Left/Failure path.\" */\n// `isEmpty` is deliberately absent: it is a property on every functype container, never a method, so\n// `x.isEmpty()` is not functype code (and on a List, `.fold` is a reduce, not a branch).\nexport const NEGATIVE_PREDICATES: ReadonlySet<string> = new Set([\"isNone\", \"isLeft\", \"isFailure\"])\n\n/** Source text with all whitespace removed — receivers match however they are line-broken. */\nexport const compact = (text: string): string => text.replace(/\\s+/g, \"\")\n\n/** A functype predicate call such as `o.isSome()`, split into its receiver and method. */\nexport type PredicateCall = {\n readonly receiver: ASTNode\n /** The receiver's source text, whitespace removed, for matching against other reads of it. */\n readonly receiverText: string\n readonly method: string\n readonly isNegated: boolean\n}\n\n/**\n * `o.isSome()`, `e.isLeft()`, `t.isFailure()` — a zero-argument call of a functype predicate method.\n * A property read (`state.isPending`, `items.isEmpty`) is not a call, so it never matches.\n */\nexport const predicateCall = (node: ASTNode, sourceCode: SourceCode): PredicateCall | null => {\n if (node?.type !== \"CallExpression\" || node.arguments.length !== 0) return null\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return null\n const method = callee.property.name as string\n const isNegated = NEGATIVE_PREDICATES.has(method)\n if (!isNegated && !POSITIVE_PREDICATES.has(method)) return null\n return { receiver: callee.object, receiverText: compact(sourceCode.getText(callee.object)), method, isNegated }\n}\n\n/**\n * The first predicate call a test branches on, looking through `!` (which flips it) and `&&` / `||`:\n * `o.isSome()`, `!o.isSome()`, `loading || o.isNone()`. `isNegated` is the predicate's own meaning\n * with any `!` applied, so `!o.isSome()` reads like `o.isNone()`.\n */\nexport const testedPredicate = (test: ASTNode, sourceCode: SourceCode): PredicateCall | null => {\n if (test?.type === \"UnaryExpression\" && test.operator === \"!\") {\n const inner = testedPredicate(test.argument, sourceCode)\n return inner === null ? null : { ...inner, isNegated: !inner.isNegated }\n }\n if (test?.type === \"LogicalExpression\" && (test.operator === \"&&\" || test.operator === \"||\")) {\n return testedPredicate(test.left, sourceCode) ?? testedPredicate(test.right, sourceCode)\n }\n return predicateCall(test, sourceCode)\n}\n\n/** What a test proves about a receiver's value: there, missing, or nothing. */\nexport type Presence = \"present\" | \"absent\" | null\n\n/** `o.isEmpty` read (not called): Option's narrowing property, true when the value is missing. */\nconst isEmptyRead = (node: ASTNode, receiverText: string, sourceCode: SourceCode): boolean =>\n node?.type === \"MemberExpression\" &&\n !node.computed &&\n node.property.type === \"Identifier\" &&\n node.property.name === \"isEmpty\" &&\n !(node.parent?.type === \"CallExpression\" && node.parent.callee === node) &&\n compact(sourceCode.getText(node.object)) === receiverText\n\n/**\n * What `test` evaluating to `outcome` proves about `receiverText`. Looks through `!`, `&&` and `||`:\n * `a && b` being true proves whatever either side proves, `a || b` being false likewise, and the other\n * two cases prove something only when both sides agree. `o.isEmpty` counts as a test for absence.\n */\nexport const provesWhen = (test: ASTNode, outcome: boolean, receiverText: string, sourceCode: SourceCode): Presence => {\n const self = (node: ASTNode, value: boolean): Presence => provesWhen(node, value, receiverText, sourceCode)\n if (test?.type === \"UnaryExpression\" && test.operator === \"!\") return self(test.argument, !outcome)\n if (test?.type === \"LogicalExpression\" && (test.operator === \"&&\" || test.operator === \"||\")) {\n const left = self(test.left, outcome)\n const right = self(test.right, outcome)\n // `a && b` true, or `a || b` false: both sides hold that outcome, so either one's proof counts.\n if ((test.operator === \"&&\") === outcome) return left ?? right\n return left === right ? left : null\n }\n const predicate = predicateCall(test, sourceCode)\n const isAbsenceTest =\n predicate !== null && predicate.receiverText === receiverText\n ? predicate.isNegated\n : isEmptyRead(test, receiverText, sourceCode)\n ? true\n : null\n if (isAbsenceTest === null) return null\n return isAbsenceTest === outcome ? \"absent\" : \"present\"\n}\n\n/** The functype-react component that renders both cases of the container a predicate belongs to. */\nexport const MATCH_COMPONENT: Readonly<Record<string, string>> = {\n isSome: \"MatchOption\",\n isNone: \"MatchOption\",\n isLeft: \"MatchEither\",\n isRight: \"MatchEither\",\n isSuccess: \"MatchTry\",\n isFailure: \"MatchTry\",\n}\n"],"mappings":"AAKA,MAAaA,kBAA2C,IA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MC,GAAQ,EAAe,IAA6BD,EAAWV,EAAMY,EAAOH,EAAcL,CAAU,EAC1G,GAAIE,GAAM,OAAS,mBAAqBA,EAAK,WAAa,IAAK,OAAOK,EAAKL,EAAK,SAAU,CAACO,CAAO,EAClG,GAAIP,GAAM,OAAS,sBAAwBA,EAAK,WAAa,MAAQA,EAAK,WAAa,MAAO,CAC5F,IAAMQ,EAAOH,EAAKL,EAAK,KAAMO,CAAO,EAC9BE,EAAQJ,EAAKL,EAAK,MAAOO,CAAO,EAGtC,OADKP,EAAK,WAAa,OAAUO,EAAgBC,GAAQC,EAClDD,IAASC,EAAQD,EAAO,IACjC,CACA,IAAME,EAAYjB,EAAcO,EAAMF,CAAU,EAC1Ca,EACJD,IAAc,MAAQA,EAAU,eAAiBP,EAC7CO,EAAU,UACVR,EAAYF,EAAMG,EAAcL,CAAU,EACxC,GACA,KAER,OADIa,IAAkB,KAAa,KAC5BA,IAAkBJ,EAAU,SAAW,SAChD,EAGaK,EAAoD,CAC/D,OAAQ,cACR,OAAQ,cACR,OAAQ,cACR,QAAS,cACT,UAAW,WACX,UAAW,UACb,E"}
1
+ {"version":3,"file":"functype-predicates.js","names":["POSITIVE_PREDICATES","NEGATIVE_PREDICATES","compact","text","predicateCall","node","callee","method","isNegated","sourceCode","testedPredicate","test","inner","isEmptyRead","receiverText","provesWhen","self","value","outcome","left","right","predicate","isAbsenceTest","MATCH_COMPONENT"],"sources":["../../src/utils/functype-predicates.ts"],"sourcesContent":["import type { SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/** Methods on a monadic value that mean \"this is the Some/Right/Success path.\" */\nexport const POSITIVE_PREDICATES: ReadonlySet<string> = new Set([\"isSome\", \"isRight\", \"isSuccess\"])\n/** Methods that mean \"this is the None/Left/Failure path.\" */\n// `isEmpty` is deliberately absent: it is a property on every functype container, never a method, so\n// `x.isEmpty()` is not functype code (and on a List, `.fold` is a reduce, not a branch).\nexport const NEGATIVE_PREDICATES: ReadonlySet<string> = new Set([\"isNone\", \"isLeft\", \"isFailure\"])\n\n/** Source text with all whitespace removed — receivers match however they are line-broken. */\nexport const compact = (text: string): string => text.replace(/\\s+/g, \"\")\n\n/** A functype predicate call such as `o.isSome()`, split into its receiver and method. */\nexport type PredicateCall = {\n readonly receiver: ASTNode\n /** The receiver's source text, whitespace removed, for matching against other reads of it. */\n readonly receiverText: string\n readonly method: string\n readonly isNegated: boolean\n}\n\n/**\n * `o.isSome()`, `e.isLeft()`, `t.isFailure()` — a zero-argument call of a functype predicate method.\n * A property read (`state.isPending`, `items.isEmpty`) is not a call, so it never matches.\n */\nexport const predicateCall = (node: ASTNode, sourceCode: SourceCode): PredicateCall | null => {\n if (node?.type !== \"CallExpression\" || node.arguments.length !== 0) return null\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return null\n const method = callee.property.name as string\n const isNegated = NEGATIVE_PREDICATES.has(method)\n if (!isNegated && !POSITIVE_PREDICATES.has(method)) return null\n return { receiver: callee.object, receiverText: compact(sourceCode.getText(callee.object)), method, isNegated }\n}\n\n/**\n * The first predicate call a test branches on, looking through `!` (which flips it) and `&&` / `||`:\n * `o.isSome()`, `!o.isSome()`, `loading || o.isNone()`. `isNegated` is the predicate's own meaning\n * with any `!` applied, so `!o.isSome()` reads like `o.isNone()`.\n */\nexport const testedPredicate = (test: ASTNode, sourceCode: SourceCode): PredicateCall | null => {\n if (test?.type === \"UnaryExpression\" && test.operator === \"!\") {\n const inner = testedPredicate(test.argument, sourceCode)\n return inner === null ? null : { ...inner, isNegated: !inner.isNegated }\n }\n if (test?.type === \"LogicalExpression\" && (test.operator === \"&&\" || test.operator === \"||\")) {\n return testedPredicate(test.left, sourceCode) ?? testedPredicate(test.right, sourceCode)\n }\n return predicateCall(test, sourceCode)\n}\n\n/** What a test proves about a receiver's value: there, missing, or nothing. */\nexport type Presence = \"present\" | \"absent\" | null\n\n/** `o.isEmpty` read (not called): Option's narrowing property, true when the value is missing. */\nconst isEmptyRead = (node: ASTNode, receiverText: string, sourceCode: SourceCode): boolean =>\n node?.type === \"MemberExpression\" &&\n !node.computed &&\n node.property.type === \"Identifier\" &&\n node.property.name === \"isEmpty\" &&\n !(node.parent?.type === \"CallExpression\" && node.parent.callee === node) &&\n compact(sourceCode.getText(node.object)) === receiverText\n\n/**\n * What `test` evaluating to `outcome` proves about `receiverText`. Looks through `!`, `&&` and `||`:\n * `a && b` being true proves whatever either side proves, `a || b` being false likewise, and the other\n * two cases prove something only when both sides agree. `o.isEmpty` counts as a test for absence.\n */\nexport const provesWhen = (test: ASTNode, outcome: boolean, receiverText: string, sourceCode: SourceCode): Presence => {\n const self = (node: ASTNode, value: boolean): Presence => provesWhen(node, value, receiverText, sourceCode)\n if (test?.type === \"UnaryExpression\" && test.operator === \"!\") return self(test.argument, !outcome)\n if (test?.type === \"LogicalExpression\" && (test.operator === \"&&\" || test.operator === \"||\")) {\n const left = self(test.left, outcome)\n const right = self(test.right, outcome)\n // `a && b` true, or `a || b` false: both sides hold that outcome, so either one's proof counts.\n if ((test.operator === \"&&\") === outcome) return left ?? right\n return left === right ? left : null\n }\n const predicate = predicateCall(test, sourceCode)\n const isAbsenceTest =\n predicate !== null && predicate.receiverText === receiverText\n ? predicate.isNegated\n : isEmptyRead(test, receiverText, sourceCode)\n ? true\n : null\n if (isAbsenceTest === null) return null\n return isAbsenceTest === outcome ? \"absent\" : \"present\"\n}\n\n/** The functype-react component that renders both cases of the container a predicate belongs to. */\nexport const MATCH_COMPONENT: Readonly<Record<string, string>> = {\n isSome: \"MatchOption\",\n isNone: \"MatchOption\",\n isLeft: \"MatchEither\",\n isRight: \"MatchEither\",\n isSuccess: \"MatchTry\",\n isFailure: \"MatchTry\",\n}\n"],"mappings":"AAKA,MAAaA,kBAA2C,IAAI,IAAI,CAAC,SAAU,UAAW,WAAW,CAAC,EAIrFC,kBAA2C,IAAI,IAAI,CAAC,SAAU,SAAU,WAAW,CAAC,EAGpFC,EA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AAK,OAAOK,EAAKL,EAAK,SAAU,CAACO,CAAO,EAClG,GAAIP,GAAM,OAAS,sBAAwBA,EAAK,WAAa,MAAQA,EAAK,WAAa,MAAO,CAC5F,IAAMQ,EAAOH,EAAKL,EAAK,KAAMO,CAAO,EAC9BE,EAAQJ,EAAKL,EAAK,MAAOO,CAAO,EAGtC,OADKP,EAAK,WAAa,OAAUO,EAAgBC,GAAQC,EAClDD,IAASC,EAAQD,EAAO,IACjC,CACA,IAAME,EAAYjB,EAAcO,EAAMF,CAAU,EAC1Ca,EACJD,IAAc,MAAQA,EAAU,eAAiBP,EAC7CO,EAAU,UACVR,EAAYF,EAAMG,EAAcL,CAAU,EACxC,GACA,KAER,OADIa,IAAkB,KAAa,KAC5BA,IAAkBJ,EAAU,SAAW,SAChD,EAGaK,EAAoD,CAC/D,OAAQ,cACR,OAAQ,cACR,OAAQ,cACR,QAAS,cACT,UAAW,WACX,UAAW,UACb"}
@@ -1,4 +1,5 @@
1
1
  import { Rule, SourceCode } from "eslint";
2
+ //#region src/utils/import-fixer.d.ts
2
3
  /**
3
4
  * Check if a given symbol is already imported from functype
4
5
  */
@@ -8,4 +9,5 @@ export declare function hasFunctypeSymbol(sourceCode: SourceCode, symbolName: st
8
9
  * Returns a factory compatible with ESLint suggest[].fix signature.
9
10
  */
10
11
  export declare function createImportFixer(sourceCode: SourceCode, symbolName: string): (fixer: Rule.RuleFixer) => Rule.Fix | null;
12
+ //#endregion
11
13
  //# sourceMappingURL=import-fixer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"import-fixer.js","names":["isImportDecl","node","isFunctypeImportDecl","specifierMatches","spec","symbolName","hasFunctypeSymbol","sourceCode","n","createImportFixer","program","imports","lastImportNode","existingFunctypeImport","s","lastSpecifier","fixer","importText","newImport","firstNode"],"sources":["../../src/utils/import-fixer.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\nimport type { SourceCode } from \"eslint\"\n\ntype ImportSpec = {\n type: string\n imported?: { type: string; name: string }\n}\ntype ImportNode = {\n type: \"ImportDeclaration\"\n source: { type: string; value: string }\n specifiers?: readonly ImportSpec[]\n}\n\nconst isImportDecl = (node: { type: string }): node is ImportNode => node.type === \"ImportDeclaration\"\n\nconst isFunctypeImportDecl = (node: { type: string }): node is ImportNode =>\n isImportDecl(node) && node.source?.type === \"Literal\" && node.source.value === \"functype\"\n\nconst specifierMatches = (spec: ImportSpec, symbolName: string): boolean =>\n spec.type === \"ImportNamespaceSpecifier\" ||\n (spec.type === \"ImportSpecifier\" && spec.imported?.type === \"Identifier\" && spec.imported.name === symbolName)\n\n/**\n * Check if a given symbol is already imported from functype\n */\nexport function hasFunctypeSymbol(sourceCode: SourceCode, symbolName: string): boolean {\n return (sourceCode.ast.body as readonly unknown[])\n .filter((n): n is ImportNode => isFunctypeImportDecl(n as { type: string }))\n .flatMap((node) => node.specifiers ?? [])\n .some((spec) => specifierMatches(spec, symbolName))\n}\n\n/**\n * Create a fixer function that adds a symbol to the functype import.\n * Returns a factory compatible with ESLint suggest[].fix signature.\n */\nexport function createImportFixer(\n sourceCode: SourceCode,\n symbolName: string,\n): (fixer: Rule.RuleFixer) => Rule.Fix | null {\n return (fixer: Rule.RuleFixer): Rule.Fix | null => {\n // Already imported — nothing to do.\n if (hasFunctypeSymbol(sourceCode, symbolName)) return null\n\n const program = sourceCode.ast\n const imports = (program.body as readonly unknown[]).filter((n): n is ImportNode =>\n isImportDecl(n as { type: string }),\n )\n const lastImportNode = imports.at(-1) ?? null\n const existingFunctypeImport = imports.find((n) => isFunctypeImportDecl(n)) ?? null\n\n if (existingFunctypeImport) {\n // Namespace import (`import * as F from \"functype\"`) — can't add named.\n const hasNamespace =\n existingFunctypeImport.specifiers?.some((s) => s.type === \"ImportNamespaceSpecifier\") ?? false\n if (hasNamespace) return null\n\n // Append after the last named specifier if one exists.\n const namedSpecifiers = (existingFunctypeImport.specifiers ?? []).filter((s) => s.type === \"ImportSpecifier\")\n const lastSpecifier = namedSpecifiers.at(-1)\n if (lastSpecifier) return fixer.insertTextAfter(lastSpecifier as never, `, ${symbolName}`)\n\n // No named specifiers — fill the empty braces.\n const importText = sourceCode.getText(existingFunctypeImport as never)\n return fixer.replaceText(existingFunctypeImport as never, importText.replace(/\\{(\\s*)\\}/, `{ ${symbolName} }`))\n }\n\n // No existing functype import — insert a new one.\n const newImport = `import { ${symbolName} } from \"functype\"`\n if (lastImportNode) return fixer.insertTextAfter(lastImportNode as never, `\\n${newImport}`)\n\n const firstNode = program.body[0]\n if (firstNode) return fixer.insertTextBefore(firstNode, `${newImport}\\n`)\n return fixer.insertTextBeforeRange([0, 0], `${newImport}\\n`)\n }\n}\n"],"mappings":"AAaA,MAAMA,EAAgB,GAA+CC,EAAK,OAAS,oBAE7EC,EAAwB,GAC5BF,EAAaC,CAAI,GAAKA,EAAK,QAAQ,OAAS,WAAaA,EAAK,OAAO,QAAU,WAE3EE,GAAoB,EAAkB,IAC1CC,EAAK,OAAS,4BACbA,EAAK,OAAS,mBAAqBA,EAAK,UAAU,OAAS,cAAgBA,EAAK,SAAS,OAASC,EAKrG,SAAgBC,EAAkB,EAAwB,EAA6B,CACrF,OAAQC,EAAW,IAAI,KACpB,OAAQ,GAAuBL,EAAqBM,CAAqB,CAAC,CAAC,CAC3E,QAAS,GAASP,EAAK,YAAc,CAAC,CAAC,CAAC,CACxC,KAAM,GAASE,EAAiBC,EAAMC,CAAU,CAAC,CACtD,CAMA,SAAgBI,EACd,EACA,EAC4C,CAC5C,MAAQ,IAA2C,CAEjD,GAAIH,EAAkBC,EAAYF,CAAU,EAAG,OAAO,KAEtD,IAAMK,EAAUH,EAAW,IACrBI,EAAWD,EAAQ,KAA4B,OAAQ,GAC3DV,EAAaQ,CAAqB,CACpC,EACMI,EAAiBD,EAAQ,GAAG,EAAE,GAAK,KACnCE,EAAyBF,EAAQ,KAAM,GAAMT,EAAqBM,CAAC,CAAC,GAAK,KAE/E,GAAIK,EAAwB,CAI1B,GADEA,EAAuB,YAAY,KAAM,GAAMC,EAAE,OAAS,0BAA0B,GAAK,GACzE,OAAO,KAIzB,IAAMC,GADmBF,EAAuB,YAAc,CAAC,EAAA,CAAG,OAAQ,GAAMC,EAAE,OAAS,iBACvD,CAAC,CAAC,GAAG,EAAE,EAC3C,GAAIC,EAAe,OAAOC,EAAM,gBAAgBD,EAAwB,KAAKV,GAAY,EAGzF,IAAMY,EAAaV,EAAW,QAAQM,CAA+B,EACrE,OAAOG,EAAM,YAAYH,EAAiCI,EAAW,QAAQ,YAAa,KAAKZ,EAAW,GAAG,CAAC,CAChH,CAGA,IAAMa,EAAY,YAAYb,EAAW,oBACzC,GAAIO,EAAgB,OAAOI,EAAM,gBAAgBJ,EAAyB,KAAKM,GAAW,EAE1F,IAAMC,EAAYT,EAAQ,KAAK,GAE/B,OADIS,EAAkBH,EAAM,iBAAiBG,EAAW,GAAGD,EAAU,GAAG,EACjEF,EAAM,sBAAsB,CAAC,EAAG,CAAC,EAAG,GAAGE,EAAU,GAAG,CAC7D,CACF,C"}
1
+ {"version":3,"file":"import-fixer.js","names":["isImportDecl","node","isFunctypeImportDecl","specifierMatches","spec","symbolName","hasFunctypeSymbol","sourceCode","n","createImportFixer","program","imports","lastImportNode","existingFunctypeImport","s","lastSpecifier","fixer","importText","newImport","firstNode"],"sources":["../../src/utils/import-fixer.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\nimport type { SourceCode } from \"eslint\"\n\ntype ImportSpec = {\n type: string\n imported?: { type: string; name: string }\n}\ntype ImportNode = {\n type: \"ImportDeclaration\"\n source: { type: string; value: string }\n specifiers?: readonly ImportSpec[]\n}\n\nconst isImportDecl = (node: { type: string }): node is ImportNode => node.type === \"ImportDeclaration\"\n\nconst isFunctypeImportDecl = (node: { type: string }): node is ImportNode =>\n isImportDecl(node) && node.source?.type === \"Literal\" && node.source.value === \"functype\"\n\nconst specifierMatches = (spec: ImportSpec, symbolName: string): boolean =>\n spec.type === \"ImportNamespaceSpecifier\" ||\n (spec.type === \"ImportSpecifier\" && spec.imported?.type === \"Identifier\" && spec.imported.name === symbolName)\n\n/**\n * Check if a given symbol is already imported from functype\n */\nexport function hasFunctypeSymbol(sourceCode: SourceCode, symbolName: string): boolean {\n return (sourceCode.ast.body as readonly unknown[])\n .filter((n): n is ImportNode => isFunctypeImportDecl(n as { type: string }))\n .flatMap((node) => node.specifiers ?? [])\n .some((spec) => specifierMatches(spec, symbolName))\n}\n\n/**\n * Create a fixer function that adds a symbol to the functype import.\n * Returns a factory compatible with ESLint suggest[].fix signature.\n */\nexport function createImportFixer(\n sourceCode: SourceCode,\n symbolName: string,\n): (fixer: Rule.RuleFixer) => Rule.Fix | null {\n return (fixer: Rule.RuleFixer): Rule.Fix | null => {\n // Already imported — nothing to do.\n if (hasFunctypeSymbol(sourceCode, symbolName)) return null\n\n const program = sourceCode.ast\n const imports = (program.body as readonly unknown[]).filter((n): n is ImportNode =>\n isImportDecl(n as { type: string }),\n )\n const lastImportNode = imports.at(-1) ?? null\n const existingFunctypeImport = imports.find((n) => isFunctypeImportDecl(n)) ?? null\n\n if (existingFunctypeImport) {\n // Namespace import (`import * as F from \"functype\"`) — can't add named.\n const hasNamespace =\n existingFunctypeImport.specifiers?.some((s) => s.type === \"ImportNamespaceSpecifier\") ?? false\n if (hasNamespace) return null\n\n // Append after the last named specifier if one exists.\n const namedSpecifiers = (existingFunctypeImport.specifiers ?? []).filter((s) => s.type === \"ImportSpecifier\")\n const lastSpecifier = namedSpecifiers.at(-1)\n if (lastSpecifier) return fixer.insertTextAfter(lastSpecifier as never, `, ${symbolName}`)\n\n // No named specifiers — fill the empty braces.\n const importText = sourceCode.getText(existingFunctypeImport as never)\n return fixer.replaceText(existingFunctypeImport as never, importText.replace(/\\{(\\s*)\\}/, `{ ${symbolName} }`))\n }\n\n // No existing functype import — insert a new one.\n const newImport = `import { ${symbolName} } from \"functype\"`\n if (lastImportNode) return fixer.insertTextAfter(lastImportNode as never, `\\n${newImport}`)\n\n const firstNode = program.body[0]\n if (firstNode) return fixer.insertTextBefore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AC,CAChH,CAGA,IAAMa,EAAY,YAAYb,EAAW,oBACzC,GAAIO,EAAgB,OAAOI,EAAM,gBAAgBJ,EAAyB,KAAKM,GAAW,EAE1F,IAAMC,EAAYT,EAAQ,KAAK,GAE/B,OADIS,EAAkBH,EAAM,iBAAiBG,EAAW,GAAGD,EAAU,GAAG,EACjEF,EAAM,sBAAsB,CAAC,EAAG,CAAC,EAAG,GAAGE,EAAU,GAAG,CAC7D,CACF"}
@@ -1,5 +1,6 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
2
  import { SourceCode } from "eslint";
3
+ //#region src/utils/mutable-collection.d.ts
3
4
  /**
4
5
  * Detects a native Set/Map that the code mutates on purpose — a cache, a registry, an in-place
5
6
  * accumulator, a React copy-then-add. functype's collections are immutable, so they cannot express
@@ -25,4 +26,5 @@ export declare const isMutatedCollection: (newExpr: ASTNode, mutators: ReadonlyA
25
26
  * constructor parameter property (`constructor(private s: Set<T>)`).
26
27
  */
27
28
  export declare const annotatesMutatedBinding: (typeRef: ASTNode, mutators: ReadonlyArray<string>, sourceCode: SourceCode) => boolean;
29
+ //#endregion
28
30
  //# sourceMappingURL=mutable-collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutable-collection.js","names":["SET_MUTATORS","MAP_MUTATORS","isMutatorCallOn","parent","expr","mutators","fieldName","key","enclosingClassBody","node","isFieldMutated","body","descendants","n","name","resolveVariable","lookup","scope","sourceCode","isNameMutated","identifier","ref","isIdentifierBindingMutated","owner","isBindingMutated","target","binding","value","isMutatedCollection","newExpr","annotatesMutatedBinding","annotation","typeRef"],"sources":["../../src/utils/mutable-collection.ts"],"sourcesContent":["import type { Scope, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"./ast-walk\"\n\n/**\n * Detects a native Set/Map that the code mutates on purpose — a cache, a registry, an in-place\n * accumulator, a React copy-then-add. functype's collections are immutable, so they cannot express\n * these, and a rule that suggests them there is noise (#324).\n *\n * Mutation means a call of one of `mutators` on the collection itself:\n * - directly on a `new` expression that copies something (`new Set(prev).add(id)`) — an empty\n * `new Map().set(a, 1).set(b, 2)` is a builder, a `Map.of` candidate, and is NOT exempt;\n * - through the variable, parameter or later-assigned `let` it is bound to;\n * - through `this.<field>` in the owning class (field initializer, constructor assignment, or\n * constructor parameter property).\n *\n * Not followed: aliases (`const t = s; t.add(x)`), `useRef(new Set()).current.add(x)`, a mutator\n * passed as a callback (`xs.forEach(seen.add, seen)`), and a collection passed into another function.\n */\n\nexport const SET_MUTATORS: ReadonlyArray<string> = [\"add\", \"delete\", \"clear\"]\nexport const MAP_MUTATORS: ReadonlyArray<string> = [\"set\", \"delete\", \"clear\"]\n\n/** `expr.add(...)` / `expr!.add(...)` — `expr` is the object of a called mutator member. */\nconst isMutatorCallOn = (expr: ASTNode, mutators: ReadonlyArray<string>): boolean => {\n const parent = expr.parent\n if (parent?.type === \"TSNonNullExpression\" && parent.expression === expr) return isMutatorCallOn(parent, mutators)\n return (\n parent?.type === \"MemberExpression\" &&\n parent.object === expr &&\n !parent.computed &&\n parent.property.type === \"Identifier\" &&\n mutators.includes(parent.property.name) &&\n parent.parent?.type === \"CallExpression\" &&\n parent.parent.callee === parent\n )\n}\n\n/** The field name for `foo` / `#foo` keys, matching how `this.foo` / `this.#foo` spell it. */\nconst fieldName = (key: ASTNode): string | null =>\n key?.type === \"Identifier\" ? key.name : key?.type === \"PrivateIdentifier\" ? `#${key.name}` : null\n\nconst enclosingClassBody = (node: ASTNode): ASTNode | null =>\n node === null || node === undefined ? null : node.type === \"ClassBody\" ? node : enclosingClassBody(node.parent)\n\n/** Is `this.<name>` mutated anywhere in the class that contains `node`? */\nconst isFieldMutated = (node: ASTNode, name: string, mutators: ReadonlyArray<string>): boolean => {\n const body = enclosingClassBody(node)\n if (body === null) return false\n return descendants(body).some(\n (n) =>\n n.type === \"MemberExpression\" &&\n n.object.type === \"ThisExpression\" &&\n !n.computed &&\n fieldName(n.property) === name &&\n isMutatorCallOn(n, mutators),\n )\n}\n\n/** Lexical lookup of `name` from the scope that contains `node`. */\nconst resolveVariable = (node: ASTNode, name: string, sourceCode: SourceCode): Scope.Variable | null => {\n const lookup = (scope: Scope.Scope | null): Scope.Variable | null =>\n scope === null ? null : (scope.set.get(name) ?? lookup(scope.upper))\n return lookup(sourceCode.getScope(node))\n}\n\n/** Is any reference to the variable named by `identifier` the object of a mutator call? */\nconst isNameMutated = (identifier: ASTNode, mutators: ReadonlyArray<string>, sourceCode: SourceCode): boolean =>\n resolveVariable(identifier, identifier.name, sourceCode)?.references.some((ref) =>\n isMutatorCallOn(ref.identifier, mutators),\n ) ?? false\n\n/**\n * Is the binding identified by `identifier` mutated? A constructor parameter property is a class\n * field; any other identifier is a variable or parameter.\n */\nconst isIdentifierBindingMutated = (\n identifier: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n const owner = identifier.parent?.type === \"AssignmentPattern\" ? identifier.parent.parent : identifier.parent\n return owner?.type === \"TSParameterProperty\"\n ? isFieldMutated(owner, identifier.name, mutators)\n : isNameMutated(identifier, mutators, sourceCode)\n}\n\n/** Is the binding that `value` initializes or is assigned to mutated? */\nconst isBindingMutated = (\n binding: ASTNode,\n value: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n // `const s = new Set()` / `s = new Set()` / `(s = new Set()) =>` / `constructor(private s = new Set())`\n const target =\n binding?.type === \"VariableDeclarator\"\n ? binding.id\n : binding?.type === \"AssignmentExpression\" || binding?.type === \"AssignmentPattern\"\n ? binding.right === value\n ? binding.left\n : null\n : null\n if (target?.type === \"Identifier\") return isIdentifierBindingMutated(target, mutators, sourceCode)\n if (target?.type === \"MemberExpression\" && target.object.type === \"ThisExpression\") {\n const name = fieldName(target.property)\n return name !== null && isFieldMutated(binding, name, mutators)\n }\n if (binding?.type === \"PropertyDefinition\" && binding.value === value) {\n const name = fieldName(binding.key)\n return name !== null && isFieldMutated(binding, name, mutators)\n }\n return false\n}\n\n/** `new Set(...)` / `new Map(...)` that is mutated, directly or through what it is bound to. */\nexport const isMutatedCollection = (\n newExpr: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean =>\n (newExpr.arguments.length > 0 && isMutatorCallOn(newExpr, mutators)) ||\n isBindingMutated(newExpr.parent, newExpr, mutators, sourceCode)\n\n/**\n * A `Set<T>` / `Map<K, V>` type reference annotating a binding that is mutated — a variable\n * (`let s: Set<T>`), a parameter (`(s: Set<T>) =>`), a class field (`private s: Set<T>`), or a\n * constructor parameter property (`constructor(private s: Set<T>)`).\n */\nexport const annotatesMutatedBinding = (\n typeRef: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n const annotation = typeRef.parent\n if (annotation?.type !== \"TSTypeAnnotation\" || annotation.typeAnnotation !== typeRef) return false\n const owner = annotation.parent\n if (owner?.type === \"Identifier\") return isIdentifierBindingMutated(owner, mutators, sourceCode)\n if (owner?.type === \"PropertyDefinition\") {\n const name = fieldName(owner.key)\n return name !== null && isFieldMutated(owner, name, mutators)\n }\n return false\n}\n"],"mappings":"A,4CAqBA,MAAaA,EAAsC,CAAC,MAAO,SAAU,OAAO,EAC/DC,EAAsC,CAAC,MAAO,SAAU,OAAO,EAGtEC,GAAmB,EAAe,IAA6C,CACnF,IAAMC,EAASC,EAAK,OAEpB,OADID,GAAQ,OAAS,uBAAyBA,EAAO,aAAeC,EAAaF,EAAgBC,EAAQE,CAAQ,EAE/GF,GAAQ,OAAS,oBACjBA,EAAO,SAAWC,GAClB,CAACD,EAAO,UACRA,EAAO,SAAS,OAAS,cACzBE,EAAS,SAASF,EAAO,SAAS,IAAI,GACtCA,EAAO,QAAQ,OAAS,kBACxBA,EAAO,OAAO,SAAWA,CAE7B,EAGMG,EAAa,GACjBC,GAAK,OAAS,aAAeA,EAAI,KAAOA,GAAK,OAAS,oBAAsB,IAAIA,EAAI,OAAS,KAEzFC,EAAsB,GAC1BC,GAA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AQJ,EAAegB,EAASZ,EAAMT,CAAQ,CAChE,CACA,GAAIqB,GAAS,OAAS,sBAAwBA,EAAQ,QAAUC,EAAO,CACrE,IAAMb,EAAOR,EAAUoB,EAAQ,GAAG,EAClC,OAAOZ,IAAS,MAAQJ,EAAegB,EAASZ,EAAMT,CAAQ,CAChE,CACA,MAAO,EACT,EAGauB,GACX,EACA,EACA,IAECC,EAAQ,UAAU,OAAS,GAAK3B,EAAgB2B,EAASxB,CAAQ,GAClEmB,EAAiBK,EAAQ,OAAQA,EAASxB,EAAUa,CAAU,EAOnDY,GACX,EACA,EACA,IACY,CACZ,IAAMC,EAAaC,EAAQ,OAC3B,GAAID,GAAY,OAAS,oBAAsBA,EAAW,iBAAmBC,EAAS,MAAO,GAC7F,IAAMT,EAAQQ,EAAW,OACzB,GAAIR,GAAO,OAAS,aAAc,OAAOD,EAA2BC,EAAOlB,EAAUa,CAAU,EAC/F,GAAIK,GAAO,OAAS,qBAAsB,CACxC,IAAMT,EAAOR,EAAUiB,EAAM,GAAG,EAChC,OAAOT,IAAS,MAAQJ,EAAea,EAAOT,EAAMT,CAAQ,CAC9D,CACA,MAAO,EACT,E"}
1
+ {"version":3,"file":"mutable-collection.js","names":["SET_MUTATORS","MAP_MUTATORS","isMutatorCallOn","parent","expr","mutators","fieldName","key","enclosingClassBody","node","isFieldMutated","body","descendants","n","name","resolveVariable","lookup","scope","sourceCode","isNameMutated","identifier","ref","isIdentifierBindingMutated","owner","isBindingMutated","target","binding","value","isMutatedCollection","newExpr","annotatesMutatedBinding","annotation","typeRef"],"sources":["../../src/utils/mutable-collection.ts"],"sourcesContent":["import type { Scope, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"./ast-walk\"\n\n/**\n * Detects a native Set/Map that the code mutates on purpose — a cache, a registry, an in-place\n * accumulator, a React copy-then-add. functype's collections are immutable, so they cannot express\n * these, and a rule that suggests them there is noise (#324).\n *\n * Mutation means a call of one of `mutators` on the collection itself:\n * - directly on a `new` expression that copies something (`new Set(prev).add(id)`) — an empty\n * `new Map().set(a, 1).set(b, 2)` is a builder, a `Map.of` candidate, and is NOT exempt;\n * - through the variable, parameter or later-assigned `let` it is bound to;\n * - through `this.<field>` in the owning class (field initializer, constructor assignment, or\n * constructor parameter property).\n *\n * Not followed: aliases (`const t = s; t.add(x)`), `useRef(new Set()).current.add(x)`, a mutator\n * passed as a callback (`xs.forEach(seen.add, seen)`), and a collection passed into another function.\n */\n\nexport const SET_MUTATORS: ReadonlyArray<string> = [\"add\", \"delete\", \"clear\"]\nexport const MAP_MUTATORS: ReadonlyArray<string> = [\"set\", \"delete\", \"clear\"]\n\n/** `expr.add(...)` / `expr!.add(...)` — `expr` is the object of a called mutator member. */\nconst isMutatorCallOn = (expr: ASTNode, mutators: ReadonlyArray<string>): boolean => {\n const parent = expr.parent\n if (parent?.type === \"TSNonNullExpression\" && parent.expression === expr) return isMutatorCallOn(parent, mutators)\n return (\n parent?.type === \"MemberExpression\" &&\n parent.object === expr &&\n !parent.computed &&\n parent.property.type === \"Identifier\" &&\n mutators.includes(parent.property.name) &&\n parent.parent?.type === \"CallExpression\" &&\n parent.parent.callee === parent\n )\n}\n\n/** The field name for `foo` / `#foo` keys, matching how `this.foo` / `this.#foo` spell it. */\nconst fieldName = (key: ASTNode): string | null =>\n key?.type === \"Identifier\" ? key.name : key?.type === \"PrivateIdentifier\" ? `#${key.name}` : null\n\nconst enclosingClassBody = (node: ASTNode): ASTNode | null =>\n node === null || node === undefined ? null : node.type === \"ClassBody\" ? node : enclosingClassBody(node.parent)\n\n/** Is `this.<name>` mutated anywhere in the class that contains `node`? */\nconst isFieldMutated = (node: ASTNode, name: string, mutators: ReadonlyArray<string>): boolean => {\n const body = enclosingClassBody(node)\n if (body === null) return false\n return descendants(body).some(\n (n) =>\n n.type === \"MemberExpression\" &&\n n.object.type === \"ThisExpression\" &&\n !n.computed &&\n fieldName(n.property) === name &&\n isMutatorCallOn(n, mutators),\n )\n}\n\n/** Lexical lookup of `name` from the scope that contains `node`. */\nconst resolveVariable = (node: ASTNode, name: string, sourceCode: SourceCode): Scope.Variable | null => {\n const lookup = (scope: Scope.Scope | null): Scope.Variable | null =>\n scope === null ? null : (scope.set.get(name) ?? lookup(scope.upper))\n return lookup(sourceCode.getScope(node))\n}\n\n/** Is any reference to the variable named by `identifier` the object of a mutator call? */\nconst isNameMutated = (identifier: ASTNode, mutators: ReadonlyArray<string>, sourceCode: SourceCode): boolean =>\n resolveVariable(identifier, identifier.name, sourceCode)?.references.some((ref) =>\n isMutatorCallOn(ref.identifier, mutators),\n ) ?? false\n\n/**\n * Is the binding identified by `identifier` mutated? A constructor parameter property is a class\n * field; any other identifier is a variable or parameter.\n */\nconst isIdentifierBindingMutated = (\n identifier: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n const owner = identifier.parent?.type === \"AssignmentPattern\" ? identifier.parent.parent : identifier.parent\n return owner?.type === \"TSParameterProperty\"\n ? isFieldMutated(owner, identifier.name, mutators)\n : isNameMutated(identifier, mutators, sourceCode)\n}\n\n/** Is the binding that `value` initializes or is assigned to mutated? */\nconst isBindingMutated = (\n binding: ASTNode,\n value: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n // `const s = new Set()` / `s = new Set()` / `(s = new Set()) =>` / `constructor(private s = new Set())`\n const target =\n binding?.type === \"VariableDeclarator\"\n ? binding.id\n : binding?.type === \"AssignmentExpression\" || binding?.type === \"AssignmentPattern\"\n ? binding.right === value\n ? binding.left\n : null\n : null\n if (target?.type === \"Identifier\") return isIdentifierBindingMutated(target, mutators, sourceCode)\n if (target?.type === \"MemberExpression\" && target.object.type === \"ThisExpression\") {\n const name = fieldName(target.property)\n return name !== null && isFieldMutated(binding, name, mutators)\n }\n if (binding?.type === \"PropertyDefinition\" && binding.value === value) {\n const name = fieldName(binding.key)\n return name !== null && isFieldMutated(binding, name, mutators)\n }\n return false\n}\n\n/** `new Set(...)` / `new Map(...)` that is mutated, directly or through what it is bound to. */\nexport const isMutatedCollection = (\n newExpr: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean =>\n (newExpr.arguments.length > 0 && isMutatorCallOn(newExpr, mutators)) ||\n isBindingMutated(newExpr.parent, newExpr, mutators, sourceCode)\n\n/**\n * A `Set<T>` / `Map<K, V>` type reference annotating a binding that is mutated — a variable\n * (`let s: Set<T>`), a parameter (`(s: Set<T>) =>`), a class field (`private s: Set<T>`), or a\n * constructor parameter property (`constructor(private s: Set<T>)`).\n */\nexport const annotatesMutatedBinding = (\n typeRef: ASTNode,\n mutators: ReadonlyArray<string>,\n sourceCode: SourceCode,\n): boolean => {\n const annotation = typeRef.parent\n if (annotation?.type !== \"TSTypeAnnotation\" || annotation.typeAnnotation !== typeRef) return false\n const owner = annotation.parent\n if (owner?.type === \"Identifier\") return isIdentifierBindingMutated(owner, mutators, sourceCode)\n if (owner?.type === \"PropertyDefinition\") {\n const name = fieldName(owner.key)\n return name !== null && isFieldMutated(owner, name, mutators)\n }\n return false\n}\n"],"mappings":"4CAqBA,MAAaA,EAAsC,CAAC,MAAO,SAAU,OAAO,EAC/DC,EAAsC,CAAC,MAAO,SAAU,OAAO,EAGtEC,GAAmB,EAAe,IAA6C,CACnF,IAAMC,EAASC,EAAK,OAEpB,OADID,GAAQ,OAAS,uBAAyBA,EAAO,aAAeC,EAAaF,EAAgBC,EAAQE,CAAQ,EAE/GF,GAAQ,OAAS,oBACjBA,EAAO,SAAWC,GAClB,CAACD,EAAO,UACRA,EAAO,SAAS,OAAS,cACzBE,EAAS,SAASF,EAAO,SAAS,IAAI,GACtCA,EAAO,QAAQ,OAAS,kBACxBA,EAAO,OAAO,SAAWA,CAE7B,EAGMG,EAAa,GACjBC,GAAK,OAAS,aAAeA,EAAI,KAAOA,GAAK,OAAS,oBAAsB,IAAIA,EAAI,OAAS,KAEzFC,EAAsB,GAC1BC,GAAS,KAA6B,KAAOA,EA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,EAAMT,CAAQ,CAChE,CACA,GAAIqB,GAAS,OAAS,sBAAwBA,EAAQ,QAAUC,EAAO,CACrE,IAAMb,EAAOR,EAAUoB,EAAQ,GAAG,EAClC,OAAOZ,IAAS,MAAQJ,EAAegB,EAASZ,EAAMT,CAAQ,CAChE,CACA,MAAO,EACT,EAGauB,GACX,EACA,EACA,IAECC,EAAQ,UAAU,OAAS,GAAK3B,EAAgB2B,EAASxB,CAAQ,GAClEmB,EAAiBK,EAAQ,OAAQA,EAASxB,EAAUa,CAAU,EAOnDY,GACX,EACA,EACA,IACY,CACZ,IAAMC,EAAaC,EAAQ,OAC3B,GAAID,GAAY,OAAS,oBAAsBA,EAAW,iBAAmBC,EAAS,MAAO,GAC7F,IAAMT,EAAQQ,EAAW,OACzB,GAAIR,GAAO,OAAS,aAAc,OAAOD,EAA2BC,EAAOlB,EAAUa,CAAU,EAC/F,GAAIK,GAAO,OAAS,qBAAsB,CACxC,IAAMT,EAAOR,EAAUiB,EAAM,GAAG,EAChC,OAAOT,IAAS,MAAQJ,EAAea,EAAOT,EAAMT,CAAQ,CAC9D,CACA,MAAO,EACT"}
@@ -1,4 +1,5 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
+ //#region src/utils/react-render.d.ts
2
3
  /** The nearest function enclosing `node`, or null at the top level. */
3
4
  export declare const enclosingFunction: (node: ASTNode) => ASTNode | null;
4
5
  export declare const isJSX: (node: ASTNode) => boolean;
@@ -10,4 +11,5 @@ export type RenderKind = "component" | "hook";
10
11
  * candidate node (an unwrap, a predicate call), so the JSX scan over the body stays rare.
11
12
  */
12
13
  export declare const renderKind: (fn: ASTNode) => RenderKind | null;
14
+ //#endregion
13
15
  //# sourceMappingURL=react-render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-render.js","names":["FUNCTION_TYPES","WRAPPERS","isWrapperCall","node","fn","callee","name","enclosingFunction","parent","functionName","holder","isJSX","producesJSX","HOOK_NAME","COMPONENT_NAME","renderKind","descendants"],"sources":["../../src/utils/react-render.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"./ast-walk\"\n\n/**\n * Finds the function a node renders in: a React function component or a hook. Syntactic, by the\n * conventions React's own tooling uses (`eslint-plugin-react-hooks`):\n *\n * - a **component** is a function named in PascalCase whose body contains JSX — declared\n * (`function Card() {}`), assigned (`const Card = () => …`) or wrapped (`memo(…)`, `forwardRef(…)`);\n * - a **hook** is a function named `use` + an uppercase letter or digit (`useThing`, `use2D`).\n *\n * Only the function's own body is its render path. A function nested inside it (an event handler, a\n * `useEffect` callback, a `.map` callback) is a separate function: the rules that use this ask for the\n * *nearest* enclosing function, so code in a nested callback is never attributed to the render.\n */\n\nconst FUNCTION_TYPES: ReadonlySet<string> = new Set([\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n])\n\n/** `memo(fn)`, `forwardRef(fn)`, `React.memo(fn)`: the wrapped function keeps the variable's name. */\nconst WRAPPERS: ReadonlySet<string> = new Set([\"memo\", \"forwardRef\"])\n\nconst isWrapperCall = (node: ASTNode, fn: ASTNode): boolean => {\n if (node?.type !== \"CallExpression\" || node.arguments[0] !== fn) return false\n const callee = node.callee as ASTNode\n const name =\n callee.type === \"Identifier\"\n ? callee.name\n : callee.type === \"MemberExpression\" && callee.property.type === \"Identifier\"\n ? callee.property.name\n : null\n return name !== null && WRAPPERS.has(name)\n}\n\n/** The nearest function enclosing `node`, or null at the top level. */\nexport const enclosingFunction = (node: ASTNode): ASTNode | null => {\n const parent = node.parent as ASTNode | undefined\n if (!parent) return null\n return FUNCTION_TYPES.has(parent.type) ? parent : enclosingFunction(parent)\n}\n\n/** The name a function is known by: its own id, or the variable it (or its `memo` wrapper) is assigned to. */\nconst functionName = (fn: ASTNode): string | null => {\n if (fn.id?.type === \"Identifier\") return fn.id.name\n const parent = fn.parent as ASTNode | undefined\n const holder = isWrapperCall(parent, fn) ? (parent?.parent as ASTNode | undefined) : parent\n return holder?.type === \"VariableDeclarator\" && holder.id.type === \"Identifier\" ? holder.id.name : null\n}\n\nexport const isJSX = (node: ASTNode): boolean => node?.type === \"JSXElement\" || node?.type === \"JSXFragment\"\n\n/** JSX, or a conditional / logical expression with JSX in a branch: `<A />`, `ok ? <A /> : null`, `ok && <A />`. */\nexport const producesJSX = (node: ASTNode): boolean => {\n if (isJSX(node)) return true\n if (node?.type === \"ConditionalExpression\") return producesJSX(node.consequent) || producesJSX(node.alternate)\n if (node?.type === \"LogicalExpression\") return producesJSX(node.right)\n return false\n}\n\nexport type RenderKind = \"component\" | \"hook\"\n\nconst HOOK_NAME = /^use[A-Z0-9]/\nconst COMPONENT_NAME = /^[A-Z]/\n\n/**\n * Is `fn` a component or a hook, and which? Null for any other function. Rules call this only for a\n * candidate node (an unwrap, a predicate call), so the JSX scan over the body stays rare.\n */\nexport const renderKind = (fn: ASTNode): RenderKind | null => {\n const name = functionName(fn)\n if (name === null) return null\n if (HOOK_NAME.test(name)) return \"hook\"\n return COMPONENT_NAME.test(name) && descendants(fn.body).some(isJSX) ? \"component\" : null\n}\n"],"mappings":"A,4CAgBA,MAAMA,kBAAsC,IAAI,IAAI,CAClD,sBACA,qBACA,yBACF,CAAC,EAGKC,kBAAgC,IAAI,IAAI,CAAC,OAAQ,YAAY,CAAC,EAE9DC,GAAiB,EAAe,IAAyB,CAC7D,GAAIC,GAAM,OAAS,kBAAoBA,EAAK,UAAU,KAAOC,EAAI,MAAO,GACxE,IAAMC,EAASF,EAAK,OACdG,EACJD,EAAO,OAAS,aACZA,EAAO,KACPA,EAAO,OAAS,oBAAsBA,EAAO,SAAS,OAAS,aAC7DA,EAAO,SAAS,KAChB,KACR,OAAOC,IAAS,MAAQL,EAAS,IAAIK,CAAI,CAC3C,EAGaC,EAAqB,GAAkC,CAClE,IAAMC,EAASL,EAAK,OAEpB,OADKK,EACER,EAAe,IAAIQ,EAAO,IAAI,EAAIA,EAASD,EAAkBC,CAAM,EADtD,IAEtB,EAGMC,EAAgB,GAA+B,CACnD,GAAIL,EAAG,IAAI,OAAS,aAAc,OAAOA,EAAG,GAAG,KAC/C,IAAMI,EAASJ,EAAG,OACZM,EAASR,EAAcM,EAAQJ,CAAE,EAAKI,GAAQ,OAAiCA,EACrF,OAAOE,GAAQ,OAAS,sBAAwBA,EAAO,GAAG,OAAS,aAAeA,EAAO,GAAG,KAAO,IACrG,EAEaC,EAAS,GAA2BR,GAAM,OAAS,cAAgBA,GAAM,OAAS,cAGlFS,EAAe,GACtBD,EAAMR,CAAI,EAAU,GACpBA,GAAM,OAAS,wBAAgCS,EAAYT,EAAK,UAAU,GAAKS,EAAYT,EAAK,SAAS,EACzGA,GAAM,OAAS,qBAA4BS,EAAYT,EAAK,KAAK,EAMjEU,EAAY,eACZC,EAAiB,SAMVC,EAAc,GAAmC,CAC5D,IAAMT,EAAOG,EAAaL,CAAE,EAG5B,OAFIE,IAAS,KAAa,KACtBO,EAAU,KAAKP,CAAI,EAAU,OAC1BQ,EAAe,KAAKR,CAAI,GAAKU,EAAYZ,EAAG,IAAI,CAAC,CAAC,KAAKO,CAAK,EAAI,YAAc,IACvF,E"}
1
+ {"version":3,"file":"react-render.js","names":["FUNCTION_TYPES","WRAPPERS","isWrapperCall","node","fn","callee","name","enclosingFunction","parent","functionName","holder","isJSX","producesJSX","HOOK_NAME","COMPONENT_NAME","renderKind","descendants"],"sources":["../../src/utils/react-render.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"./ast-walk\"\n\n/**\n * Finds the function a node renders in: a React function component or a hook. Syntactic, by the\n * conventions React's own tooling uses (`eslint-plugin-react-hooks`):\n *\n * - a **component** is a function named in PascalCase whose body contains JSX — declared\n * (`function Card() {}`), assigned (`const Card = () => …`) or wrapped (`memo(…)`, `forwardRef(…)`);\n * - a **hook** is a function named `use` + an uppercase letter or digit (`useThing`, `use2D`).\n *\n * Only the function's own body is its render path. A function nested inside it (an event handler, a\n * `useEffect` callback, a `.map` callback) is a separate function: the rules that use this ask for the\n * *nearest* enclosing function, so code in a nested callback is never attributed to the render.\n */\n\nconst FUNCTION_TYPES: ReadonlySet<string> = new Set([\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n])\n\n/** `memo(fn)`, `forwardRef(fn)`, `React.memo(fn)`: the wrapped function keeps the variable's name. */\nconst WRAPPERS: ReadonlySet<string> = new Set([\"memo\", \"forwardRef\"])\n\nconst isWrapperCall = (node: ASTNode, fn: ASTNode): boolean => {\n if (node?.type !== \"CallExpression\" || node.arguments[0] !== fn) return false\n const callee = node.callee as ASTNode\n const name =\n callee.type === \"Identifier\"\n ? callee.name\n : callee.type === \"MemberExpression\" && callee.property.type === \"Identifier\"\n ? callee.property.name\n : null\n return name !== null && WRAPPERS.has(name)\n}\n\n/** The nearest function enclosing `node`, or null at the top level. */\nexport const enclosingFunction = (node: ASTNode): ASTNode | null => {\n const parent = node.parent as ASTNode | undefined\n if (!parent) return null\n return FUNCTION_TYPES.has(parent.type) ? parent : enclosingFunction(parent)\n}\n\n/** The name a function is known by: its own id, or the variable it (or its `memo` wrapper) is assigned to. */\nconst functionName = (fn: ASTNode): string | null => {\n if (fn.id?.type === \"Identifier\") return fn.id.name\n const parent = fn.parent as ASTNode | undefined\n const holder = isWrapperCall(parent, fn) ? (parent?.parent as ASTNode | undefined) : parent\n return holder?.type === \"VariableDeclarator\" && holder.id.type === \"Identifier\" ? holder.id.name : null\n}\n\nexport const isJSX = (node: ASTNode): boolean => node?.type === \"JSXElement\" || node?.type === \"JSXFragment\"\n\n/** JSX, or a conditional / logical expression with JSX in a branch: `<A />`, `ok ? <A /> : null`, `ok && <A />`. */\nexport const producesJSX = (node: ASTNode): boolean => {\n if (isJSX(node)) return true\n if (node?.type === \"ConditionalExpression\") return producesJSX(node.consequent) || producesJSX(node.alternate)\n if (node?.type === \"LogicalExpression\") return producesJSX(node.right)\n return false\n}\n\nexport type RenderKind = \"component\" | \"hook\"\n\nconst HOOK_NAME = /^use[A-Z0-9]/\nconst COMPONENT_NAME = /^[A-Z]/\n\n/**\n * Is `fn` a component or a hook, and which? Null for any other function. Rules call this only for a\n * candidate node (an unwrap, a predicate call), so the JSX scan over the body stays rare.\n */\nexport const renderKind = (fn: ASTNode): RenderKind | null => {\n const name = functionName(fn)\n if (name === null) return null\n if (HOOK_NAME.test(name)) return \"hook\"\n return COMPONENT_NAME.test(name) && descendants(fn.body).some(isJSX) ? \"component\" : null\n}\n"],"mappings":"4CAgBA,MAAMA,kBAAsC,IAAI,IAAI,CAClD,sBACA,qBACA,yBACF,CAAC,EAGKC,kBAAgC,IAAI,IAAI,CAAC,OAAQ,YAAY,CAAC,EAE9DC,GAAiB,EAAe,IAAyB,CAC7D,GAAIC,GAAM,OAAS,kBAAoBA,EAAK,UAAU,KAAOC,EAAI,MAAO,GACxE,IAAMC,EAASF,EAAK,OACdG,EACJD,EAAO,OAAS,aACZA,EAAO,KACPA,EAAO,OAAS,oBAAsBA,EAAO,SAAS,OAAS,aAC7DA,EAAO,SAAS,KAChB,KACR,OAAOC,IAAS,MAAQL,EAAS,IAAIK,CAAI,CAC3C,EAGaC,EAAqB,GAAkC,CAClE,IAAMC,EAASL,EAAK,OAEpB,OADKK,EACER,EAAe,IAAIQ,EAAO,IAAI,EAAIA,EAASD,EAAkBC,CAAM,EADtD,IAEtB,EAGMC,EAAgB,GAA+B,CACnD,GAAIL,EAAG,IAAI,OAAS,aAAc,OAAOA,EAAG,GAAG,KAC/C,IAAMI,EAASJ,EAAG,OACZM,EAASR,EAAcM,EAAQJ,CAAE,EAAKI,GAAQ,OAAiCA,EACrF,OAAOE,GAAQ,OAAS,sBAAwBA,EAAO,GAAG,OAAS,aAAeA,EAAO,GAAG,KAAO,IACrG,EAEaC,EAAS,GAA2BR,GAAM,OAAS,cAAgBA,GAAM,OAAS,cAGlFS,EAAe,GACtBD,EAAMR,CAAI,EAAU,GACpBA,GAAM,OAAS,wBAAgCS,EAAYT,EAAK,UAAU,GAAKS,EAAYT,EAAK,SAAS,EACzGA,GAAM,OAAS,qBAA4BS,EAAYT,EAAK,KAAK,EAMjEU,EAAY,eACZC,EAAiB,SAMVC,EAAc,GAAmC,CAC5D,IAAMT,EAAOG,EAAaL,CAAE,EAG5B,OAFIE,IAAS,KAAa,KACtBO,EAAU,KAAKP,CAAI,EAAU,OAC1BQ,EAAe,KAAKR,CAAI,GAAKU,EAAYZ,EAAG,IAAI,CAAC,CAAC,KAAKO,CAAK,EAAI,YAAc,IACvF"}
@@ -1,3 +1,5 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
+ //#region src/utils/readonly-contract.d.ts
2
3
  export declare const flowsIntoReadonlyContract: (node: ASTNode, readonlyName: string) => boolean;
4
+ //#endregion
3
5
  //# sourceMappingURL=readonly-contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readonly-contract.js","names":["FUNCTIONS","isNamed","type","name","typeArgs","isReadonlyContract","readonlyName","annotationOf","node","nearestFunction","flowsIntoReadonlyContract","parent"],"sources":["../../src/utils/readonly-contract.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\n\n/**\n * Does this expression flow straight into a declared native read-only contract (#350)?\n *\n * `prefer-functype-map` / `-set` never report a `ReadonlyMap` / `ReadonlySet` annotation, so they must not\n * report the constructor that annotation requires: when a function is declared to return\n * `ReadonlyMap<K, V>` — typically because a callee's interface takes one — the native `new Map(...)` it\n * returns is the contract, not an oversight. Recognized positions:\n *\n * - `return` in the nearest enclosing function whose declared return type is `R` or `Promise<R>`\n * (a callback nested inside such a function does not inherit its signature);\n * - the expression body of an arrow function with that return type;\n * - the initializer of a variable, class field, or parameter default annotated `R`;\n * - an `as R` / `satisfies R` assertion;\n * and through ternary branches and `??` / `||` / `&&` operands on the way there.\n */\n\nconst FUNCTIONS: ReadonlySet<string> = new Set([\"FunctionDeclaration\", \"FunctionExpression\", \"ArrowFunctionExpression\"])\n\nconst isNamed = (type: ASTNode | undefined, name: string): boolean =>\n type?.type === \"TSTypeReference\" && type.typeName?.type === \"Identifier\" && type.typeName.name === name\n\nconst typeArgs = (type: ASTNode): ReadonlyArray<ASTNode> =>\n (type.typeArguments?.params ?? type.typeParameters?.params ?? []) as ReadonlyArray<ASTNode>\n\n/** `R<…>` or `Promise<R<…>>`. */\nconst isReadonlyContract = (type: ASTNode | undefined, readonlyName: string): boolean =>\n isNamed(type, readonlyName) || (isNamed(type, \"Promise\") && isReadonlyContract(typeArgs(type!)[0], readonlyName))\n\nconst annotationOf = (node: ASTNode | undefined): ASTNode | undefined => node?.typeAnnotation?.typeAnnotation\n\nconst nearestFunction = (node: ASTNode | undefined): ASTNode | undefined =>\n node === undefined || node === null ? undefined : FUNCTIONS.has(node.type) ? node : nearestFunction(node.parent)\n\nexport const flowsIntoReadonlyContract = (node: ASTNode, readonlyName: string): boolean => {\n const parent = node.parent\n if (!parent) return false\n switch (parent.type) {\n case \"ConditionalExpression\":\n return parent.test !== node && flowsIntoReadonlyContract(parent, readonlyName)\n case \"LogicalExpression\":\n return flowsIntoReadonlyContract(parent, readonlyName)\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n return isReadonlyContract(parent.typeAnnotation, readonlyName) || flowsIntoReadonlyContract(parent, readonlyName)\n case \"ReturnStatement\":\n return isReadonlyContract(nearestFunction(parent)?.returnType?.typeAnnotation, readonlyName)\n case \"ArrowFunctionExpression\":\n return parent.body === node && isReadonlyContract(parent.returnType?.typeAnnotation, readonlyName)\n case \"VariableDeclarator\":\n return parent.init === node && isReadonlyContract(annotationOf(parent.id), readonlyName)\n case \"PropertyDefinition\":\n return parent.value === node && isReadonlyContract(annotationOf(parent), readonlyName)\n case \"AssignmentPattern\":\n return parent.right === node && isReadonlyContract(annotationOf(parent.left), readonlyName)\n default:\n return false\n }\n}\n"],"mappings":"AAkBA,MAAMA,kBAAiC,IAAI,IAAI,CAAC,sBAAuB,qBAAsB,yBAAyB,CAAC,EAEjHC,GAAW,EAA2B,IAC1CC,GAAM,OAAS,mBAAqBA,EAAK,UAAU,OAAS,cAAgBA,EAAK,SAAS,OAASC,EAE/FC,EAAY,GACfF,EAAK,eAAe,QAAUA,EAAK,gBAAgB,QAAU,CAAC,EAG3DG,GAAsB,EAA2B,IACrDJ,EAAQC,EAAMI,CAAY,GAAML,EAAQC,EAAM,SAAS,GAAKG,EAAmBD,EAASF,CAAK,CAAC,CAAC,GAAII,CAAY,EAE3GC,EAAgB,GAAmDC,GAAM,gBAAgB,eAEzFC,EAAmB,GACvBD,GAA+B,KAAO,IAAA,GAAYR,EAAU,IAAIQ,EAAK,IAAI,EAAIA,EAAOC,EAAgBD,EAAK,MAAM,EAEpGE,GAA6B,EAAe,IAAkC,CACzF,IAAMC,EAASH,EAAK,OACpB,GAAI,CAACG,EAAQ,MAAO,GACpB,OAAQA,EAAO,KAAf,CACE,IAAK,wBACH,OAAOA,EAAO,OAASH,GAAQE,EAA0BC,EAAQL,CAAY,EAC/E,IAAK,oBACH,OAAOI,EAA0BC,EAAQL,CAAY,EACvD,IAAK,iBACL,IAAK,wBACH,OAAOD,EAAmBM,EAAO,eAAgBL,CAAY,GAAKI,EAA0BC,EAAQL,CAAY,EAClH,IAAK,kBACH,OAAOD,EAAmBI,EAAgBE,CAAM,CAAC,EAAE,YAAY,eAAgBL,CAAY,EAC7F,IAAK,0BACH,OAAOK,EAAO,OAASH,GAAQH,EAAmBM,EAAO,YAAY,eAAgBL,CAAY,EACnG,IAAK,qBACH,OAAOK,EAAO,OAASH,GAAQH,EAAmBE,EAAaI,EAAO,EAAE,EAAGL,CAAY,EACzF,IAAK,qBACH,OAAOK,EAAO,QAAUH,GAAQH,EAAmBE,EAAaI,CAAM,EAAGL,CAAY,EACvF,IAAK,oBACH,OAAOK,EAAO,QAAUH,GAAQH,EAAmBE,EAAaI,EAAO,IAAI,EAAGL,CAAY,EAC5F,QACE,MAAO,EACX,CACF,E"}
1
+ {"version":3,"file":"readonly-contract.js","names":["FUNCTIONS","isNamed","type","name","typeArgs","isReadonlyContract","readonlyName","annotationOf","node","nearestFunction","flowsIntoReadonlyContract","parent"],"sources":["../../src/utils/readonly-contract.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\n\n/**\n * Does this expression flow straight into a declared native read-only contract (#350)?\n *\n * `prefer-functype-map` / `-set` never report a `ReadonlyMap` / `ReadonlySet` annotation, so they must not\n * report the constructor that annotation requires: when a function is declared to return\n * `ReadonlyMap<K, V>` — typically because a callee's interface takes one — the native `new Map(...)` it\n * returns is the contract, not an oversight. Recognized positions:\n *\n * - `return` in the nearest enclosing function whose declared return type is `R` or `Promise<R>`\n * (a callback nested inside such a function does not inherit its signature);\n * - the expression body of an arrow function with that return type;\n * - the initializer of a variable, class field, or parameter default annotated `R`;\n * - an `as R` / `satisfies R` assertion;\n * and through ternary branches and `??` / `||` / `&&` operands on the way there.\n */\n\nconst FUNCTIONS: ReadonlySet<string> = new Set([\"FunctionDeclaration\", \"FunctionExpression\", \"ArrowFunctionExpression\"])\n\nconst isNamed = (type: ASTNode | undefined, name: string): boolean =>\n type?.type === \"TSTypeReference\" && type.typeName?.type === \"Identifier\" && type.typeName.name === name\n\nconst typeArgs = (type: ASTNode): ReadonlyArray<ASTNode> =>\n (type.typeArguments?.params ?? type.typeParameters?.params ?? []) as ReadonlyArray<ASTNode>\n\n/** `R<…>` or `Promise<R<…>>`. */\nconst isReadonlyContract = (type: ASTNode | undefined, readonlyName: string): boolean =>\n isNamed(type, readonlyName) || (isNamed(type, \"Promise\") && isReadonlyContract(typeArgs(type!)[0], readonlyName))\n\nconst annotationOf = (node: ASTNode | undefined): ASTNode | undefined => node?.typeAnnotation?.typeAnnotation\n\nconst nearestFunction = (node: ASTNode | undefined): ASTNode | undefined =>\n node === undefined || node === null ? undefined : FUNCTIONS.has(node.type) ? node : nearestFunction(node.parent)\n\nexport const flowsIntoReadonlyContract = (node: ASTNode, readonlyName: string): boolean => {\n const parent = node.parent\n if (!parent) return false\n switch (parent.type) {\n case \"ConditionalExpression\":\n return parent.test !== node && flowsIntoReadonlyContract(parent, readonlyName)\n case \"LogicalExpression\":\n return flowsIntoReadonlyContract(parent, readonlyName)\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n return isReadonlyContract(parent.typeAnnotation, readonlyName) || flowsIntoReadonlyContract(parent, readonlyName)\n case \"ReturnStatement\":\n return isReadonlyContract(nearestFunction(parent)?.returnType?.typeAnnotation, readonlyName)\n case \"ArrowFunctionExpression\":\n return parent.body === node && isReadonlyContract(parent.returnType?.typeAnnotation, readonlyName)\n case \"VariableDeclarator\":\n return parent.init === node && isReadonlyContract(annotationOf(parent.id), readonlyName)\n case \"PropertyDefinition\":\n return parent.value === node && isReadonlyContract(annotationOf(parent), readonlyName)\n case \"AssignmentPattern\":\n return parent.right === node && isReadonlyContract(annotationOf(parent.left), readonlyName)\n default:\n return false\n }\n}\n"],"mappings":"AAkBA,MAAMA,kBAAiC,IAAI,IAAI,CAAC,sBAAuB,qBAAsB,yBAAyB,CAAC,EAEjHC,GAAW,EAA2B,IAC1CC,GAAM,OAAS,mBAAqBA,EAAK,UAAU,OAAS,cAAgBA,EAAK,SAAS,OAASC,EAE/FC,EAAY,GACfF,EAAK,eAAe,QAAUA,EAAK,gBAAgB,QAAU,CAAC,EAG3DG,GAAsB,EAA2B,IACrDJ,EAAQC,EAAMI,CAAY,GAAML,EAAQC,EAAM,SAAS,GAAKG,EAAmBD,EAASF,CAAK,CAAC,CAAC,GAAII,CAAY,EAE3GC,EAAgB,GAAmDC,GAAM,gBAAgB,eAEzFC,EAAmB,GACvBD,GAA+B,KAAO,IAAA,GAAYR,EAAU,IAAIQ,EAAK,IAAI,EAAIA,EAAOC,EAAgBD,EAAK,MAAM,EAEpGE,GAA6B,EAAe,IAAkC,CACzF,IAAMC,EAASH,EAAK,OACpB,GAAI,CAACG,EAAQ,MAAO,GACpB,OAAQA,EAAO,KAAf,CACE,IAAK,wBACH,OAAOA,EAAO,OAASH,GAAQE,EAA0BC,EAAQL,CAAY,EAC/E,IAAK,oBACH,OAAOI,EAA0BC,EAAQL,CAAY,EACvD,IAAK,iBACL,IAAK,wBACH,OAAOD,EAAmBM,EAAO,eAAgBL,CAAY,GAAKI,EAA0BC,EAAQL,CAAY,EAClH,IAAK,kBACH,OAAOD,EAAmBI,EAAgBE,CAAM,CAAC,EAAE,YAAY,eAAgBL,CAAY,EAC7F,IAAK,0BACH,OAAOK,EAAO,OAASH,GAAQH,EAAmBM,EAAO,YAAY,eAAgBL,CAAY,EACnG,IAAK,qBACH,OAAOK,EAAO,OAASH,GAAQH,EAAmBE,EAAaI,EAAO,EAAE,EAAGL,CAAY,EACzF,IAAK,qBACH,OAAOK,EAAO,QAAUH,GAAQH,EAAmBE,EAAaI,CAAM,EAAGL,CAAY,EACvF,IAAK,oBACH,OAAOK,EAAO,QAAUH,GAAQH,EAAmBE,EAAaI,EAAO,IAAI,EAAGL,CAAY,EAC5F,QACE,MAAO,EACX,CACF"}
@@ -1,5 +1,6 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
2
  import { Rule } from "eslint";
3
+ //#region src/utils/type-aware.d.ts
3
4
  /**
4
5
  * Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:
5
6
  * the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every
@@ -44,4 +45,5 @@ export declare const flowsIntoMutableArraySlot: (node: ASTNode, context: Rule.Ru
44
45
  export declare const isUntypedExpression: (node: ASTNode, context: Rule.RuleContext) => boolean | undefined;
45
46
  /** Is type-aware linting on for this file (`parserOptions.projectService` or `project`)? */
46
47
  export declare const hasTypeInformation: (context: Rule.RuleContext) => boolean;
48
+ //#endregion
47
49
  //# sourceMappingURL=type-aware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","services","context","isExtractableByType","tsNode","node","checker","type","isIOByType","isTypeParameter","enclosingCall","parent","at","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","depth","types","member","target","element","awaited","isOpaqueSink","isUntyped","slot","isArrayLikeOrUntyped","symbol","flags","isMutableArrayType","propertyKey","property","expectedSlot","own","declarator","ref","call","parameter","objectLiteral","outerSlot","outer","key","keyNode","keyTs","keyType","literal","named","flowsIntoArraySlot","flowsIntoMutableArraySlot","isUntypedExpression","hasTypeInformation"],"sources":["../../src/utils/type-aware.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Type-aware helpers that work only when the consumer turns on type-aware linting\n * (`parserOptions.projectService` or `project`). Without it they report \"unknown\", and a rule\n * falls back to its syntactic heuristic.\n *\n * The checker is reached through `parserServices` and typed structurally here, so the plugin\n * takes no runtime dependency on `typescript`.\n */\n\ntype TypeLike = object\n\ntype CheckerLike = {\n getTypeAtLocation(node: unknown): TypeLike\n getNonNullableType(type: TypeLike): TypeLike\n getPropertyOfType(type: TypeLike, name: string): unknown\n getContextualType(node: unknown): TypeLike | undefined\n isArrayLikeType(type: TypeLike): boolean\n getTypeOfSymbolAtLocation(symbol: unknown, node: unknown): TypeLike\n getTypeArguments(type: TypeLike): ReadonlyArray<TypeLike>\n getResolvedSignature(node: unknown): SignatureLike | undefined\n getIndexInfoOfType(type: TypeLike, kind: number): { readonly type: TypeLike } | undefined\n getReturnTypeOfSignature(signature: unknown): TypeLike\n getAwaitedType(type: TypeLike): TypeLike | undefined\n isTupleType(type: TypeLike): boolean\n isTypeAssignableTo(source: TypeLike, target: TypeLike): boolean\n}\n\ntype SignatureLike = {\n readonly parameters: ReadonlyArray<unknown>\n getDeclaration(): { readonly parameters?: ReadonlyArray<unknown> } | undefined\n}\n\n/** `ts.TypeFlags.Any` / `Unknown`, inlined so the plugin needs no runtime `typescript` import. */\nconst ANY_OR_UNKNOWN_FLAGS = 1 | 2\n\n/** Interfaces a consumer reads through rather than keeps: `importKey(…, usages: Iterable<KeyUsage>)`, `new Set(values)`. */\nconst CONSUMED_COLLECTION_TYPES: ReadonlySet<string> = new Set([\n \"Iterable\",\n \"AsyncIterable\",\n \"IterableIterator\",\n \"ArrayLike\",\n])\n\ntype TypedServices = {\n readonly program: { getTypeChecker(): CheckerLike }\n readonly esTreeNodeToTSNodeMap: { get(node: unknown): unknown }\n}\n\nconst typedServices = (context: Rule.RuleContext): TypedServices | undefined => {\n const services = context.sourceCode.parserServices as Partial<TypedServices> | undefined\n return services?.program && services.esTreeNodeToTSNodeMap ? (services as TypedServices) : undefined\n}\n\n/**\n * Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:\n * the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every\n * functype container, including union types like `Either` (each member has both). Native\n * collections (`Map#get`) and arbitrary objects don't.\n *\n * `undefined` when type information isn't available, so the caller can fall back.\n */\nexport const isExtractableByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"orThrow\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n )\n}\n\n/**\n * Is `node`'s type a functype `IO`? Structural: the type has both `runExit` and `provideLayer`, which\n * only `IO` carries — `Task`, `Lazy` and the other containers have neither — and has carried since\n * well before 1.9, so older functype versions are recognized too. A union of IOs counts.\n * `any` and `unknown` have no properties, so they don't.\n *\n * `undefined` when type information isn't available.\n */\nexport const isIOByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"runExit\") !== undefined &&\n checker.getPropertyOfType(type, \"provideLayer\") !== undefined\n )\n}\n\n/** A slot's expected type and the expression TypeScript computed it for. */\ntype Slot = { readonly type: TypeLike; readonly at: ASTNode }\n\n/**\n * Uses the `Type` object's own predicate rather than a `TypeFlags` bit: TypeScript renumbers its flags\n * between majors (TypeParameter is `1 << 19` in TS 6, `1 << 18` before), and the plugin has no runtime\n * `typescript` import to read them from.\n */\nconst isTypeParameter = (type: TypeLike): boolean =>\n (type as { isTypeParameter?: () => boolean }).isTypeParameter?.() === true\n\n/**\n * `f(…, arg, …)` where `at` is `arg` or sits inside it (an object property, an array element, a spread,\n * a conditional branch, an `as`): the call, the whole argument, and its index.\n */\nconst enclosingCall = (\n at: ASTNode,\n): { readonly call: ASTNode; readonly argument: ASTNode; readonly index: number } | null => {\n const parent = at.parent as ASTNode | undefined\n if (!parent) return null\n if ((parent.type === \"CallExpression\" || parent.type === \"NewExpression\") && parent.callee !== at) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(at)\n return index < 0 ? null : { call: parent, argument: at, index }\n }\n const passesThrough =\n parent.type === \"TSAsExpression\" ||\n parent.type === \"TSSatisfiesExpression\" ||\n (parent.type === \"ConditionalExpression\" && parent.test !== at) ||\n parent.type === \"LogicalExpression\" ||\n parent.type === \"Property\" ||\n parent.type === \"ObjectExpression\" ||\n parent.type === \"ArrayExpression\" ||\n parent.type === \"SpreadElement\"\n return passesThrough ? enclosingCall(parent) : null\n}\n\n/**\n * Is the parameter that `at` is passed to (directly or nested) declared as a type parameter, or a union\n * containing one — `json<T>(data: T)`, `useState<S>(init: S | (() => S))`? Then TypeScript's expected type for `at` is only an echo of what it inferred from\n * `at` itself (`[1, 2]` → `number[]`), not a shape the library demands.\n */\nconst isGenericParameterArgument = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const parameters = callTs ? checker.getResolvedSignature(callTs)?.getDeclaration()?.parameters : undefined\n if (!found || !parameters || parameters.length === 0) return false\n const declared = parameters[Math.min(found.index, parameters.length - 1)] as { readonly type?: unknown } | undefined\n // The parameter's type annotation node (`T` in `value: T`); asking for the declaration node's type gives `any`.\n if (declared?.type === undefined) return false\n const annotated = checker.getTypeAtLocation(declared.type)\n // React's `useState<S>(init: S | (() => S))`: a union that contains the type parameter is generic too.\n const members = (annotated as { types?: ReadonlyArray<TypeLike> }).types ?? [annotated]\n return members.some(isTypeParameter)\n}\n\n/**\n * Does the generic call around `at` hand the argument straight back to the caller — `useState(init)`\n * returning `[init, set]`, `identity(x)`, a `Promise` of it? Then the shape stays the caller's, and a\n * type parameter isn't a sink. Looks only at the return type itself, union / intersection members,\n * tuple and array elements, and an awaited Promise, not object properties: Hono's `c.json<T>` returns a\n * `Response` that carries a *parsed* copy of `T` for its RPC client, which the caller doesn't get back.\n */\nconst handsArgumentBack = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const signature = callTs ? checker.getResolvedSignature(callTs) : undefined\n const argTs = found ? services.esTreeNodeToTSNodeMap.get(found.argument) : undefined\n if (!signature || !argTs) return false\n const argType = checker.getTypeAtLocation(argTs)\n const sameAsArgument = (candidate: TypeLike): boolean =>\n candidate === argType ||\n (checker.isTypeAssignableTo(argType, candidate) && checker.isTypeAssignableTo(candidate, argType))\n const search = (type: TypeLike, depth: number): boolean => {\n if (depth > 3) return false\n if (sameAsArgument(type)) return true\n const { types, target } = type as { types?: ReadonlyArray<TypeLike>; target?: unknown }\n if (types) return types.some((member) => search(member, depth + 1))\n if (target !== undefined && (checker.isTupleType(type) || checker.isArrayLikeType(type))) {\n return checker.getTypeArguments(type).some((element) => search(element, depth + 1))\n }\n const awaited = checker.getAwaitedType(type)\n return awaited !== undefined && awaited !== type && search(awaited, depth + 1)\n }\n return search(checker.getReturnTypeOfSignature(signature), 0)\n}\n\n/**\n * Untyped, or a type parameter of a call that doesn't hand the argument back: an object handed to\n * `c.json<T>(data: T)` or `JSON.stringify` goes to a sink. `useState<T>(init: T)` is not one.\n */\nconst isOpaqueSink = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean =>\n isUntyped(slot.type) || (isTypeParameter(slot.type) && !handsArgumentBack(checker, services, slot.at))\n\nconst isArrayLikeOrUntyped = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean => {\n if (isOpaqueSink(checker, services, slot)) return true\n const { types, symbol } = slot.type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isArrayLikeOrUntyped(checker, services, { type: member, at: slot.at }))\n if (symbol?.name !== undefined && CONSUMED_COLLECTION_TYPES.has(symbol.name)) return true\n return !isTypeParameter(slot.type) && checker.isArrayLikeType(slot.type)\n}\n\nconst isUntyped = (type: TypeLike): boolean => {\n const { flags } = type as { flags?: number }\n return flags !== undefined && (flags & ANY_OR_UNKNOWN_FLAGS) !== 0\n}\n\n/** The mutable `Array` type, as opposed to `ReadonlyArray`: the one a `ReadonlyArray` can't be passed to. */\nconst isMutableArrayType = (checker: CheckerLike, type: TypeLike): boolean => {\n const { types, symbol } = type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isMutableArrayType(checker, member))\n return symbol?.name === \"Array\" && checker.isArrayLikeType(type)\n}\n\n/** The name a property is written under: `params` in `{ params }`, `parts` in `{ parts: … }` or `{ \"parts\": … }`. */\nconst propertyKey = (property: ASTNode): string | null => {\n if (property.computed) return null\n if (property.key?.type === \"Identifier\") return property.key.name\n return property.key?.type === \"Literal\" && typeof property.key.value === \"string\" ? property.key.value : null\n}\n\n/**\n * The expected type of `node`, looking through object literals when TypeScript gives the value none of\n * its own. Two cases: a shorthand `{ params }` passed to a function, where the expected type is that\n * property's type on the parameter; and `[…]` in `JSON.stringify({ parts: [...] })`, where the object is\n * passed to an `any` parameter, so the whole object is going to an untyped host.\n */\nconst expectedSlot = (\n checker: CheckerLike,\n services: TypedServices,\n node: ASTNode,\n context: Rule.RuleContext,\n depth = 0,\n): Slot | undefined => {\n if (depth > 4) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n const own = tsNode ? checker.getContextualType(tsNode) : undefined\n if (own !== undefined) return { type: own, at: node }\n const parent = node.parent as ASTNode | undefined\n // `const metadata = (url) => ({ … })` with no declared return type: the object goes wherever the\n // calls' results go (`c.json(metadata(url))`), so take the expected type at the first call site.\n if (parent?.type === \"ArrowFunctionExpression\" && parent.body === node) {\n const declarator = parent.parent as ASTNode | undefined\n if (\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === parent &&\n declarator.id?.type === \"Identifier\"\n ) {\n const variable = context.sourceCode.getDeclaredVariables(declarator)[0]\n const calls = (variable?.references ?? [])\n .map((ref) => (ref.identifier as unknown as ASTNode).parent as ASTNode | undefined)\n .filter((call): call is ASTNode => call?.type === \"CallExpression\")\n return calls\n .map((call) => expectedSlot(checker, services, call, context, depth + 1))\n .find((slot) => slot !== undefined)\n }\n }\n // An argument to an overloaded function (`crypto.subtle.importKey(…, [\"decrypt\"])`) gets no contextual\n // type; the parameter of the overload TypeScript picked is the expected type.\n if ((parent?.type === \"CallExpression\" || parent?.type === \"NewExpression\") && parent.callee !== node) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(node)\n const call = services.esTreeNodeToTSNodeMap.get(parent)\n const parameter = index >= 0 && call ? checker.getResolvedSignature(call)?.parameters[index] : undefined\n return parameter === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(parameter, call), at: node }\n }\n const objectLiteral = parent?.type === \"Property\" && parent.value === node ? (parent.parent as ASTNode) : undefined\n if (objectLiteral?.type !== \"ObjectExpression\") return undefined\n const outerSlot = expectedSlot(checker, services, objectLiteral, context, depth + 1)\n if (outerSlot === undefined || isOpaqueSink(checker, services, outerSlot)) return outerSlot\n const outer = outerSlot.type\n const key = propertyKey(parent as ASTNode)\n // `{ [k]: [...] }` (a reduce accumulator keyed by category): the property named by the key's literal\n // type, else the string index signature's type.\n if (key === null) {\n const keyNode = (parent as ASTNode).key\n const keyTs = keyNode ? services.esTreeNodeToTSNodeMap.get(keyNode) : undefined\n const keyType = keyTs\n ? (checker.getTypeAtLocation(keyTs) as { value?: unknown; types?: ReadonlyArray<{ value?: unknown }> })\n : undefined\n const literal = keyType?.value ?? keyType?.types?.[0]?.value\n const named = typeof literal === \"string\" ? checker.getPropertyOfType(outer, literal) : undefined\n const type =\n named !== undefined\n ? checker.getTypeOfSymbolAtLocation(named, tsNode)\n : checker.getIndexInfoOfType(outer, 0)?.type\n return type === undefined ? undefined : { type, at: node }\n }\n const member = checker.getPropertyOfType(outer, key)\n return member === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(member, tsNode), at: node }\n}\n\n/**\n * Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?\n * That's the expected type TypeScript checks it against: the parameter it is passed to, the property\n * it initialises, the declared return type. A literal in such a slot is handed to code that requires an\n * array, such as drizzle's `.values([...])` or an index definition, so `List` can't go there. A literal\n * inside an object passed to an `any` parameter (a `JSON.stringify` request body) counts too.\n *\n * `undefined` when type information isn't available, or when there is no expected type (a free-standing\n * literal), so the caller can fall back.\n */\nexport const flowsIntoArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined) return undefined\n // A bare `T` parameter: a sink unless the call hands the argument straight back (`useState`, `identity`).\n if (isGenericParameterArgument(checker, services, slot.at)) return !handsArgumentBack(checker, services, slot.at)\n return isArrayLikeOrUntyped(checker, services, slot)\n}\n\n/**\n * Does `node` flow into a slot that requires a *mutable* array — a parameter typed `T[]`, such as pg's\n * `query(text, values: unknown[])`, drizzle's `inArray(col, values)` or ReactFlow's `nodes`? There a\n * `ReadonlyArray` won't type-check, so a mutable annotation is what the library demands.\n *\n * `undefined` when type information isn't available.\n */\nexport const flowsIntoMutableArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined || isGenericParameterArgument(checker, services, slot.at)) return false\n return isMutableArrayType(checker, slot.type)\n}\n\n/**\n * Is `node`'s own type `any` / `unknown`, or an array of them — `JSON.parse(raw)`, `await res.json()`,\n * `raw` after `Array.isArray(raw)` (narrowed to `any[]`)? `undefined` when type information isn't available.\n */\nexport const isUntypedExpression = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getTypeAtLocation(tsNode)\n if (isUntyped(type)) return true\n if (!checker.isArrayLikeType(type)) return false\n const element = checker.getTypeArguments(type)[0]\n return element !== undefined && isUntyped(element)\n}\n\n/** Is type-aware linting on for this file (`parserOptions.projectService` or `project`)? */\nexport const hasTypeInformation = (context: Rule.RuleContext): boolean => typedServices(context) !== undefined\n"],"mappings":"AAqCA,MAGMA,kBAAiD,IAAI,IAAI,CAC7D,WACA,gBACA,mBACA,WACF,CAAC,EAOKC,EAAiB,GAAyD,CAC9E,IAAMC,EAAWC,EAAQ,WAAW,eACpC,OAAOD,GAAU,SAAWA,EAAS,sBAAyBA,EAA6B,IAAA,EAC7F,EAUaE,GAAuB,EAAe,IAAmD,CACpG,IAAMF,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,mBAAmBA,EAAQ,kBAAkBF,CAAM,CAAC,EACzE,OACEE,EAAQ,kBAAkBC,EAAM,SAAS,IAAM,IAAA,IAAaD,EAAQ,kBAAkBC,EAAM,MAAM,IAAM,IAAA,EAE5G,EAUaC,GAAc,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S6B,EAAK,IAAI,CAC9C,EAMawB,GAAuB,EAAe,IAAmD,CACpG,IAAM1D,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,kBAAkBF,CAAM,EAC7C,GAAI8B,EAAU3B,CAAI,EAAG,MAAO,GAC5B,GAAI,CAACD,EAAQ,gBAAgBC,CAAI,EAAG,MAAO,GAC3C,IAAMwB,EAAUzB,EAAQ,iBAAiBC,CAAI,CAAC,CAAC,GAC/C,OAAOwB,IAAY,IAAA,IAAaG,EAAUH,CAAO,CACnD,EAGa6B,EAAsB,GAAuC5D,EAAcE,CAAO,IAAM,IAAA,G"}
1
+ {"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","services","context","isExtractableByType","tsNode","node","checker","type","isIOByType","isTypeParameter","enclosingCall","parent","at","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","depth","types","member","target","element","awaited","isOpaqueSink","isUntyped","slot","isArrayLikeOrUntyped","symbol","flags","isMutableArrayType","propertyKey","property","expectedSlot","own","declarator","ref","call","parameter","objectLiteral","outerSlot","outer","key","keyNode","keyTs","keyType","literal","named","flowsIntoArraySlot","flowsIntoMutableArraySlot","isUntypedExpression","hasTypeInformation"],"sources":["../../src/utils/type-aware.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Type-aware helpers that work only when the consumer turns on type-aware linting\n * (`parserOptions.projectService` or `project`). Without it they report \"unknown\", and a rule\n * falls back to its syntactic heuristic.\n *\n * The checker is reached through `parserServices` and typed structurally here, so the plugin\n * takes no runtime dependency on `typescript`.\n */\n\ntype TypeLike = object\n\ntype CheckerLike = {\n getTypeAtLocation(node: unknown): TypeLike\n getNonNullableType(type: TypeLike): TypeLike\n getPropertyOfType(type: TypeLike, name: string): unknown\n getContextualType(node: unknown): TypeLike | undefined\n isArrayLikeType(type: TypeLike): boolean\n getTypeOfSymbolAtLocation(symbol: unknown, node: unknown): TypeLike\n getTypeArguments(type: TypeLike): ReadonlyArray<TypeLike>\n getResolvedSignature(node: unknown): SignatureLike | undefined\n getIndexInfoOfType(type: TypeLike, kind: number): { readonly type: TypeLike } | undefined\n getReturnTypeOfSignature(signature: unknown): TypeLike\n getAwaitedType(type: TypeLike): TypeLike | undefined\n isTupleType(type: TypeLike): boolean\n isTypeAssignableTo(source: TypeLike, target: TypeLike): boolean\n}\n\ntype SignatureLike = {\n readonly parameters: ReadonlyArray<unknown>\n getDeclaration(): { readonly parameters?: ReadonlyArray<unknown> } | undefined\n}\n\n/** `ts.TypeFlags.Any` / `Unknown`, inlined so the plugin needs no runtime `typescript` import. */\nconst ANY_OR_UNKNOWN_FLAGS = 1 | 2\n\n/** Interfaces a consumer reads through rather than keeps: `importKey(…, usages: Iterable<KeyUsage>)`, `new Set(values)`. */\nconst CONSUMED_COLLECTION_TYPES: ReadonlySet<string> = new Set([\n \"Iterable\",\n \"AsyncIterable\",\n \"IterableIterator\",\n \"ArrayLike\",\n])\n\ntype TypedServices = {\n readonly program: { getTypeChecker(): CheckerLike }\n readonly esTreeNodeToTSNodeMap: { get(node: unknown): unknown }\n}\n\nconst typedServices = (context: Rule.RuleContext): TypedServices | undefined => {\n const services = context.sourceCode.parserServices as Partial<TypedServices> | undefined\n return services?.program && services.esTreeNodeToTSNodeMap ? (services as TypedServices) : undefined\n}\n\n/**\n * Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:\n * the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every\n * functype container, including union types like `Either` (each member has both). Native\n * collections (`Map#get`) and arbitrary objects don't.\n *\n * `undefined` when type information isn't available, so the caller can fall back.\n */\nexport const isExtractableByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"orThrow\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n )\n}\n\n/**\n * Is `node`'s type a functype `IO`? Structural: the type has both `runExit` and `provideLayer`, which\n * only `IO` carries — `Task`, `Lazy` and the other containers have neither — and has carried since\n * well before 1.9, so older functype versions are recognized too. A union of IOs counts.\n * `any` and `unknown` have no properties, so they don't.\n *\n * `undefined` when type information isn't available.\n */\nexport const isIOByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"runExit\") !== undefined &&\n checker.getPropertyOfType(type, \"provideLayer\") !== undefined\n )\n}\n\n/** A slot's expected type and the expression TypeScript computed it for. */\ntype Slot = { readonly type: TypeLike; readonly at: ASTNode }\n\n/**\n * Uses the `Type` object's own predicate rather than a `TypeFlags` bit: TypeScript renumbers its flags\n * between majors (TypeParameter is `1 << 19` in TS 6, `1 << 18` before), and the plugin has no runtime\n * `typescript` import to read them from.\n */\nconst isTypeParameter = (type: TypeLike): boolean =>\n (type as { isTypeParameter?: () => boolean }).isTypeParameter?.() === true\n\n/**\n * `f(…, arg, …)` where `at` is `arg` or sits inside it (an object property, an array element, a spread,\n * a conditional branch, an `as`): the call, the whole argument, and its index.\n */\nconst enclosingCall = (\n at: ASTNode,\n): { readonly call: ASTNode; readonly argument: ASTNode; readonly index: number } | null => {\n const parent = at.parent as ASTNode | undefined\n if (!parent) return null\n if ((parent.type === \"CallExpression\" || parent.type === \"NewExpression\") && parent.callee !== at) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(at)\n return index < 0 ? null : { call: parent, argument: at, index }\n }\n const passesThrough =\n parent.type === \"TSAsExpression\" ||\n parent.type === \"TSSatisfiesExpression\" ||\n (parent.type === \"ConditionalExpression\" && parent.test !== at) ||\n parent.type === \"LogicalExpression\" ||\n parent.type === \"Property\" ||\n parent.type === \"ObjectExpression\" ||\n parent.type === \"ArrayExpression\" ||\n parent.type === \"SpreadElement\"\n return passesThrough ? enclosingCall(parent) : null\n}\n\n/**\n * Is the parameter that `at` is passed to (directly or nested) declared as a type parameter, or a union\n * containing one — `json<T>(data: T)`, `useState<S>(init: S | (() => S))`? Then TypeScript's expected type for `at` is only an echo of what it inferred from\n * `at` itself (`[1, 2]` → `number[]`), not a shape the library demands.\n */\nconst isGenericParameterArgument = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const parameters = callTs ? checker.getResolvedSignature(callTs)?.getDeclaration()?.parameters : undefined\n if (!found || !parameters || parameters.length === 0) return false\n const declared = parameters[Math.min(found.index, parameters.length - 1)] as { readonly type?: unknown } | undefined\n // The parameter's type annotation node (`T` in `value: T`); asking for the declaration node's type gives `any`.\n if (declared?.type === undefined) return false\n const annotated = checker.getTypeAtLocation(declared.type)\n // React's `useState<S>(init: S | (() => S))`: a union that contains the type parameter is generic too.\n const members = (annotated as { types?: ReadonlyArray<TypeLike> }).types ?? [annotated]\n return members.some(isTypeParameter)\n}\n\n/**\n * Does the generic call around `at` hand the argument straight back to the caller — `useState(init)`\n * returning `[init, set]`, `identity(x)`, a `Promise` of it? Then the shape stays the caller's, and a\n * type parameter isn't a sink. Looks only at the return type itself, union / intersection members,\n * tuple and array elements, and an awaited Promise, not object properties: Hono's `c.json<T>` returns a\n * `Response` that carries a *parsed* copy of `T` for its RPC client, which the caller doesn't get back.\n */\nconst handsArgumentBack = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const signature = callTs ? checker.getResolvedSignature(callTs) : undefined\n const argTs = found ? services.esTreeNodeToTSNodeMap.get(found.argument) : undefined\n if (!signature || !argTs) return false\n const argType = checker.getTypeAtLocation(argTs)\n const sameAsArgument = (candidate: TypeLike): boolean =>\n candidate === argType ||\n (checker.isTypeAssignableTo(argType, candidate) && checker.isTypeAssignableTo(candidate, argType))\n const search = (type: TypeLike, depth: number): boolean => {\n if (depth > 3) return false\n if (sameAsArgument(type)) return true\n const { types, target } = type as { types?: ReadonlyArray<TypeLike>; target?: unknown }\n if (types) return types.some((member) => search(member, depth + 1))\n if (target !== undefined && (checker.isTupleType(type) || checker.isArrayLikeType(type))) {\n return checker.getTypeArguments(type).some((element) => search(element, depth + 1))\n }\n const awaited = checker.getAwaitedType(type)\n return awaited !== undefined && awaited !== type && search(awaited, depth + 1)\n }\n return search(checker.getReturnTypeOfSignature(signature), 0)\n}\n\n/**\n * Untyped, or a type parameter of a call that doesn't hand the argument back: an object handed to\n * `c.json<T>(data: T)` or `JSON.stringify` goes to a sink. `useState<T>(init: T)` is not one.\n */\nconst isOpaqueSink = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean =>\n isUntyped(slot.type) || (isTypeParameter(slot.type) && !handsArgumentBack(checker, services, slot.at))\n\nconst isArrayLikeOrUntyped = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean => {\n if (isOpaqueSink(checker, services, slot)) return true\n const { types, symbol } = slot.type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isArrayLikeOrUntyped(checker, services, { type: member, at: slot.at }))\n if (symbol?.name !== undefined && CONSUMED_COLLECTION_TYPES.has(symbol.name)) return true\n return !isTypeParameter(slot.type) && checker.isArrayLikeType(slot.type)\n}\n\nconst isUntyped = (type: TypeLike): boolean => {\n const { flags } = type as { flags?: number }\n return flags !== undefined && (flags & ANY_OR_UNKNOWN_FLAGS) !== 0\n}\n\n/** The mutable `Array` type, as opposed to `ReadonlyArray`: the one a `ReadonlyArray` can't be passed to. */\nconst isMutableArrayType = (checker: CheckerLike, type: TypeLike): boolean => {\n const { types, symbol } = type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isMutableArrayType(checker, member))\n return symbol?.name === \"Array\" && checker.isArrayLikeType(type)\n}\n\n/** The name a property is written under: `params` in `{ params }`, `parts` in `{ parts: … }` or `{ \"parts\": … }`. */\nconst propertyKey = (property: ASTNode): string | null => {\n if (property.computed) return null\n if (property.key?.type === \"Identifier\") return property.key.name\n return property.key?.type === \"Literal\" && typeof property.key.value === \"string\" ? property.key.value : null\n}\n\n/**\n * The expected type of `node`, looking through object literals when TypeScript gives the value none of\n * its own. Two cases: a shorthand `{ params }` passed to a function, where the expected type is that\n * property's type on the parameter; and `[…]` in `JSON.stringify({ parts: [...] })`, where the object is\n * passed to an `any` parameter, so the whole object is going to an untyped host.\n */\nconst expectedSlot = (\n checker: CheckerLike,\n services: TypedServices,\n node: ASTNode,\n context: Rule.RuleContext,\n depth = 0,\n): Slot | undefined => {\n if (depth > 4) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n const own = tsNode ? checker.getContextualType(tsNode) : undefined\n if (own !== undefined) return { type: own, at: node }\n const parent = node.parent as ASTNode | undefined\n // `const metadata = (url) => ({ … })` with no declared return type: the object goes wherever the\n // calls' results go (`c.json(metadata(url))`), so take the expected type at the first call site.\n if (parent?.type === \"ArrowFunctionExpression\" && parent.body === node) {\n const declarator = parent.parent as ASTNode | undefined\n if (\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === parent &&\n declarator.id?.type === \"Identifier\"\n ) {\n const variable = context.sourceCode.getDeclaredVariables(declarator)[0]\n const calls = (variable?.references ?? [])\n .map((ref) => (ref.identifier as unknown as ASTNode).parent as ASTNode | undefined)\n .filter((call): call is ASTNode => call?.type === \"CallExpression\")\n return calls\n .map((call) => expectedSlot(checker, services, call, context, depth + 1))\n .find((slot) => slot !== undefined)\n }\n }\n // An argument to an overloaded function (`crypto.subtle.importKey(…, [\"decrypt\"])`) gets no contextual\n // type; the parameter of the overload TypeScript picked is the expected type.\n if ((parent?.type === \"CallExpression\" || parent?.type === \"NewExpression\") && parent.callee !== node) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(node)\n const call = services.esTreeNodeToTSNodeMap.get(parent)\n const parameter = index >= 0 && call ? checker.getResolvedSignature(call)?.parameters[index] : undefined\n return parameter === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(parameter, call), at: node }\n }\n const objectLiteral = parent?.type === \"Property\" && parent.value === node ? (parent.parent as ASTNode) : undefined\n if (objectLiteral?.type !== \"ObjectExpression\") return undefined\n const outerSlot = expectedSlot(checker, services, objectLiteral, context, depth + 1)\n if (outerSlot === undefined || isOpaqueSink(checker, services, outerSlot)) return outerSlot\n const outer = outerSlot.type\n const key = propertyKey(parent as ASTNode)\n // `{ [k]: [...] }` (a reduce accumulator keyed by category): the property named by the key's literal\n // type, else the string index signature's type.\n if (key === null) {\n const keyNode = (parent as ASTNode).key\n const keyTs = keyNode ? services.esTreeNodeToTSNodeMap.get(keyNode) : undefined\n const keyType = keyTs\n ? (checker.getTypeAtLocation(keyTs) as { value?: unknown; types?: ReadonlyArray<{ value?: unknown }> })\n : undefined\n const literal = keyType?.value ?? keyType?.types?.[0]?.value\n const named = typeof literal === \"string\" ? checker.getPropertyOfType(outer, literal) : undefined\n const type =\n named !== undefined\n ? checker.getTypeOfSymbolAtLocation(named, tsNode)\n : checker.getIndexInfoOfType(outer, 0)?.type\n return type === undefined ? undefined : { type, at: node }\n }\n const member = checker.getPropertyOfType(outer, key)\n return member === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(member, tsNode), at: node }\n}\n\n/**\n * Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?\n * That's the expected type TypeScript checks it against: the parameter it is passed to, the property\n * it initialises, the declared return type. A literal in such a slot is handed to code that requires an\n * array, such as drizzle's `.values([...])` or an index definition, so `List` can't go there. A literal\n * inside an object passed to an `any` parameter (a `JSON.stringify` request body) counts too.\n *\n * `undefined` when type information isn't available, or when there is no expected type (a free-standing\n * literal), so the caller can fall back.\n */\nexport const flowsIntoArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined) return undefined\n // A bare `T` parameter: a sink unless the call hands the argument straight back (`useState`, `identity`).\n if (isGenericParameterArgument(checker, services, slot.at)) return !handsArgumentBack(checker, services, slot.at)\n return isArrayLikeOrUntyped(checker, services, slot)\n}\n\n/**\n * Does `node` flow into a slot that requires a *mutable* array — a parameter typed `T[]`, such as pg's\n * `query(text, values: unknown[])`, drizzle's `inArray(col, values)` or ReactFlow's `nodes`? There a\n * `ReadonlyArray` won't type-check, so a mutable annotation is what the library demands.\n *\n * `undefined` when type information isn't available.\n */\nexport const flowsIntoMutableArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined || isGenericParameterArgument(checker, services, slot.at)) return false\n return isMutableArrayType(checker, slot.type)\n}\n\n/**\n * Is `node`'s own type `any` / `unknown`, or an array of them — `JSON.parse(raw)`, `await res.json()`,\n * `raw` after `Array.isArray(raw)` (narrowed to `any[]`)? `undefined` when type information isn't available.\n */\nexport const isUntypedExpression = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getTypeAtLocation(tsNode)\n if (isUntyped(type)) return true\n if (!checker.isArrayLikeType(type)) return false\n const element = checker.getTypeArguments(type)[0]\n return element !== undefined && isUntyped(element)\n}\n\n/** Is type-aware linting on for this file (`parserOptions.projectService` or `project`)? */\nexport const hasTypeInformation = (context: Rule.RuleContext): boolean => typedServices(context) !== undefined\n"],"mappings":"AAqCA,MAGMA,kBAAiD,IAAI,IAAI,CAC7D,WACA,gBACA,mBACA,WACF,CAAC,EAOKC,EAAiB,GAAyD,CAC9E,IAAMC,EAAWC,EAAQ,WAAW,eACpC,OAAOD,GAAU,SAAWA,EAAS,sBAAyBA,EAA6B,IAAA,EAC7F,EAUaE,GAAuB,EAAe,IAAmD,CACpG,IAAMF,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,mBAAmBA,EAAQ,kBAAkBF,CAAM,CAAC,EACzE,OACEE,EAAQ,kBAAkBC,EAAM,SAAS,IAAM,IAAA,IAAaD,EAAQ,kBAAkBC,EAAM,MAAM,IAAM,IAAA,EAE5G,EAUaC,GAAc,EAAe,IAAmD,CAC3F,IAAMP,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,mBAAmBA,EAAQ,kBAAkBF,CAAM,CAAC,EACzE,OACEE,EAAQ,kBAAkBC,EAAM,SAAS,IAAM,IAAA,IAC/CD,EAAQ,kBAAkBC,EAAM,cAAc,IAAM,IAAA,EAExD,EAUME,EAAmB,GACtBF,EAA6C,kBAAkB,IAAM,GAMlEG,EACJ,GAC0F,CAC1F,IAAMC,EAASC,EAAG,OAClB,GAAI,CAACD,EAAQ,OAAO,KACpB,IAAKA,EAAO,OAAS,kB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CAAO,IAAM,IAAA"}
@@ -1,4 +1,5 @@
1
1
  import { ASTNode } from "../types/ast.js";
2
+ //#region src/utils/wire-types.d.ts
2
3
  /**
3
4
  * `Wire<T>` declares a value in its serialization-safe shape — a DB row, an HTTP body,
4
5
  * a JSONB payload (#325 B). Everything inside its type argument is the wire shape by declaration: a
@@ -16,4 +17,5 @@ export declare const WIRE_TYPES_SCHEMA: {
16
17
  };
17
18
  /** Is `node` inside the type argument of a `Wire<…>` (or other configured wire type) reference? */
18
19
  export declare const isInsideWireType: (node: ASTNode, wireTypes: ReadonlyArray<string>) => boolean;
20
+ //#endregion
19
21
  //# sourceMappingURL=wire-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wire-types.js","names":["DEFAULT_WIRE_TYPES","WIRE_TYPES_SCHEMA","entityName","name","referenceName","typeRef","isInsideWireType","wireTypes","walk","parent","current","node"],"sources":["../../src/utils/wire-types.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\n\n/**\n * `Wire<T>` declares a value in its serialization-safe shape — a DB row, an HTTP body,\n * a JSONB payload (#325 B). Everything inside its type argument is the wire shape by declaration: a\n * `ReadonlyArray` there is not a missed `List`, and a `T | null` there is not a missed `Option`. Rules\n * that prefer the functype shape skip it, so the boundary is stated once instead of suppressed at every\n * field. Names are configurable (`wireTypes`) for consumers with their own boundary alias.\n */\n\nexport const DEFAULT_WIRE_TYPES: ReadonlyArray<string> = [\"Wire\"]\n\nexport const WIRE_TYPES_SCHEMA = {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_WIRE_TYPES],\n} as const\n\n/** The last segment of an entity name: `Wire` from `Wire` or `functype.Wire`. */\nconst entityName = (name: ASTNode): string | null => {\n if (name?.type === \"Identifier\") return name.name\n if (name?.type === \"TSQualifiedName\" && name.right?.type === \"Identifier\") return name.right.name\n return null\n}\n\n/** `Wire` from `Wire<…>`, `functype.Wire<…>` or `import(\"functype\").Wire<…>`; null otherwise. */\nconst referenceName = (typeRef: ASTNode): string | null => {\n if (typeRef.type === \"TSTypeReference\") return entityName(typeRef.typeName)\n if (typeRef.type === \"TSImportType\") return entityName(typeRef.qualifier)\n return null\n}\n\n/** Is `node` inside the type argument of a `Wire<…>` (or other configured wire type) reference? */\nexport const isInsideWireType = (node: ASTNode, wireTypes: ReadonlyArray<string>): boolean => {\n if (wireTypes.length === 0) return false\n const walk = (current: ASTNode | null | undefined): boolean => {\n const parent = current?.parent\n if (!parent) return false\n if (parent.type === \"TSTypeParameterInstantiation\" && parent.parent) {\n const name = referenceName(parent.parent)\n if (name !== null && wireTypes.includes(name)) return true\n }\n return walk(parent)\n }\n return walk(node)\n}\n"],"mappings":"AAUA,MAAaA,EAA4C,CAAC,MAAM,EAEnDC,EAAoB,CAC/B,KAAM,QACN,MAAO,CAAE,KAAM,QAAS,EACxB,QAAS,CAAC,GAAGD,CAAkB,CACjC,EAGME,EAAc,GACdC,GAAM,OAAS,aAAqBA,EAAK,KACzCA,GAAM,OAAS,mBAAqBA,EAAK,OAAO,OAAS,aAAqBA,EAAK,MAAM,KACtF,KAIHC,EAAiB,GACjBC,EAAQ,OAAS,kBAA0BH,EAAWG,EAAQ,QAAQ,EACtEA,EAAQ,OAAS,eAAuBH,EAAWG,EAAQ,SAAS,EACjE,KAIIC,GAAoB,EAAe,IAA8C,CAC5F,GAAIC,EAAU,SAAW,EAAG,MAAO,GACnC,IAAMC,EAAQ,GAAiD,CAC7D,IAAMC,EAASC,GAAS,OACxB,GAAI,CAACD,EAAQ,MAAO,GACpB,GAAIA,EAAO,OAAS,gCAAkCA,EAAO,OAAQ,CACnE,IAAMN,EAAOC,EAAcK,EAAO,MAAM,EACxC,GAAIN,IAAS,MAAQI,EAAU,SAASJ,CAAI,EAAG,MAAO,EACxD,CACA,OAAOK,EAAKC,CAAM,CACpB,EACA,OAAOD,EAAKG,CAAI,CAClB,E"}
1
+ {"version":3,"file":"wire-types.js","names":["DEFAULT_WIRE_TYPES","WIRE_TYPES_SCHEMA","entityName","name","referenceName","typeRef","isInsideWireType","wireTypes","walk","parent","current","node"],"sources":["../../src/utils/wire-types.ts"],"sourcesContent":["import type { ASTNode } from \"../types/ast\"\n\n/**\n * `Wire<T>` declares a value in its serialization-safe shape — a DB row, an HTTP body,\n * a JSONB payload (#325 B). Everything inside its type argument is the wire shape by declaration: a\n * `ReadonlyArray` there is not a missed `List`, and a `T | null` there is not a missed `Option`. Rules\n * that prefer the functype shape skip it, so the boundary is stated once instead of suppressed at every\n * field. Names are configurable (`wireTypes`) for consumers with their own boundary alias.\n */\n\nexport const DEFAULT_WIRE_TYPES: ReadonlyArray<string> = [\"Wire\"]\n\nexport const WIRE_TYPES_SCHEMA = {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_WIRE_TYPES],\n} as const\n\n/** The last segment of an entity name: `Wire` from `Wire` or `functype.Wire`. */\nconst entityName = (name: ASTNode): string | null => {\n if (name?.type === \"Identifier\") return name.name\n if (name?.type === \"TSQualifiedName\" && name.right?.type === \"Identifier\") return name.right.name\n return null\n}\n\n/** `Wire` from `Wire<…>`, `functype.Wire<…>` or `import(\"functype\").Wire<…>`; null otherwise. */\nconst referenceName = (typeRef: ASTNode): string | null => {\n if (typeRef.type === \"TSTypeReference\") return entityName(typeRef.typeName)\n if (typeRef.type === \"TSImportType\") return entityName(typeRef.qualifier)\n return null\n}\n\n/** Is `node` inside the type argument of a `Wire<…>` (or other configured wire type) reference? */\nexport const isInsideWireType = (node: ASTNode, wireTypes: ReadonlyArray<string>): boolean => {\n if (wireTypes.length === 0) return false\n const walk = (current: ASTNode | null | undefined): boolean => {\n const parent = current?.parent\n if (!parent) return false\n if (parent.type === \"TSTypeParameterInstantiation\" && parent.parent) {\n const name = referenceName(parent.parent)\n if (name !== null && wireTypes.includes(name)) return true\n }\n return walk(parent)\n }\n return walk(node)\n}\n"],"mappings":"AAUA,MAAaA,EAA4C,CAAC,MAAM,EAEnDC,EAAoB,CAC/B,KAAM,QACN,MAAO,CAAE,KAAM,QAAS,EACxB,QAAS,CAAC,GAAGD,CAAkB,CACjC,EAGME,EAAc,GACdC,GAAM,OAAS,aAAqBA,EAAK,KACzCA,GAAM,OAAS,mBAAqBA,EAAK,OAAO,OAAS,aAAqBA,EAAK,MAAM,KACtF,KAIHC,EAAiB,GACjBC,EAAQ,OAAS,kBAA0BH,EAAWG,EAAQ,QAAQ,EACtEA,EAAQ,OAAS,eAAuBH,EAAWG,EAAQ,SAAS,EACjE,KAIIC,GAAoB,EAAe,IAA8C,CAC5F,GAAIC,EAAU,SAAW,EAAG,MAAO,GACnC,IAAMC,EAAQ,GAAiD,CAC7D,IAAMC,EAASC,GAAS,OACxB,GAAI,CAACD,EAAQ,MAAO,GACpB,GAAIA,EAAO,OAAS,gCAAkCA,EAAO,OAAQ,CACnE,IAAMN,EAAOC,EAAcK,EAAO,MAAM,EACxC,GAAIN,IAAS,MAAQI,EAAU,SAASJ,CAAI,EAAG,MAAO,EACxD,CACA,OAAOK,EAAKC,CAAM,CACpB,EACA,OAAOD,EAAKG,CAAI,CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-functype",
3
- "version": "2.121.0",
3
+ "version": "2.122.0",
4
4
  "description": "Custom ESLint rules for functional TypeScript programming with functype library patterns including Do notation (ESLint 10+)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,12 +39,12 @@
39
39
  "eslint": "^10.2.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "^24.19.2",
43
- "@typescript-eslint/rule-tester": "^8.72.0",
42
+ "@types/node": "^24.19.1",
43
+ "@typescript-eslint/rule-tester": "^8.71.0",
44
44
  "eslint-config-prettier": "^10.1.8",
45
- "functype": "^1.21.0",
46
- "ts-builds": "^4.0.0",
47
- "tsdown": "^0.23.2"
45
+ "functype": "^1.22.0",
46
+ "ts-builds": "^3.4.3",
47
+ "tsdown": "^0.23.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public",