eslint-plugin-functype 2.108.0 → 2.110.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.
- package/README.md +139 -12
- package/dist/cli/list-rules.js.map +1 -1
- package/dist/configs/recommended.d.ts +21 -5
- package/dist/configs/recommended.js +1 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict.d.ts +1 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-get-unsafe.js +1 -1
- package/dist/rules/no-get-unsafe.js.map +1 -1
- package/dist/rules/no-imperative-loops.js +1 -1
- package/dist/rules/no-imperative-loops.js.map +1 -1
- package/dist/rules/no-let.js.map +1 -1
- package/dist/rules/prefer-do-notation.js +1 -1
- package/dist/rules/prefer-do-notation.js.map +1 -1
- package/dist/rules/prefer-either.js +1 -1
- package/dist/rules/prefer-either.js.map +1 -1
- package/dist/rules/prefer-flatmap.js +1 -1
- package/dist/rules/prefer-flatmap.js.map +1 -1
- package/dist/rules/prefer-fold.js +1 -1
- package/dist/rules/prefer-fold.js.map +1 -1
- package/dist/rules/prefer-functype-map.js +1 -1
- package/dist/rules/prefer-functype-map.js.map +1 -1
- package/dist/rules/prefer-functype-set.js +1 -1
- package/dist/rules/prefer-functype-set.js.map +1 -1
- package/dist/rules/prefer-list.js +1 -1
- package/dist/rules/prefer-list.js.map +1 -1
- package/dist/rules/prefer-map.js +1 -1
- package/dist/rules/prefer-map.js.map +1 -1
- package/dist/rules/prefer-option.js +1 -1
- package/dist/rules/prefer-option.js.map +1 -1
- package/dist/rules/prefer-try.js +1 -1
- package/dist/rules/prefer-try.js.map +1 -1
- package/dist/types/ast.d.ts +1 -2
- package/dist/utils/ast-walk.d.ts +12 -0
- package/dist/utils/ast-walk.js +2 -0
- package/dist/utils/ast-walk.js.map +1 -0
- package/dist/utils/async-detection.d.ts +6 -0
- package/dist/utils/async-detection.js +2 -0
- package/dist/utils/async-detection.js.map +1 -0
- package/dist/utils/boundary-tags.d.ts +25 -0
- package/dist/utils/boundary-tags.js +2 -0
- package/dist/utils/boundary-tags.js.map +1 -0
- package/dist/utils/dependency-validator.d.ts +4 -5
- package/dist/utils/dependency-validator.js +1 -1
- package/dist/utils/dependency-validator.js.map +1 -1
- package/dist/utils/functype-detection.d.ts +13 -14
- package/dist/utils/functype-detection.js +1 -1
- package/dist/utils/functype-detection.js.map +1 -1
- package/dist/utils/import-fixer.d.ts +2 -3
- package/dist/utils/import-fixer.js.map +1 -1
- package/dist/utils/mutable-collection.d.ts +30 -0
- package/dist/utils/mutable-collection.js +2 -0
- package/dist/utils/mutable-collection.js.map +1 -0
- package/dist/utils/wire-types.d.ts +21 -0
- package/dist/utils/wire-types.js +2 -0
- package/dist/utils/wire-types.js.map +1 -0
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functype-detection.js","names":[],"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,MAAM,EAAkC,IAAI,IAAI,CAC9C,SACA,SACA,OACA,WACA,OACA,MACA,MACA,MACA,OACF,CAAC,EAGK,EAAoB,GACxB,EAAK,OAAS,qBAAuB,EAAK,OAAO,OAAS,WAAa,EAAK,OAAO,QAAU,WAK/F,SAAgB,EAAkB,EAAoC,CACpE,OAAO,EAAQ,WAAW,IAAI,KAAK,KAAK,CAAgB,CAC1D,CAcA,SAAS,EAAoB,EAAwC,CACnE,GAAI,EAAK,OAAS,mBAAqB,EAAK,SAAS,OAAS,aAAc,CAC1E,IAAM,EAAO,EAAK,SAAS,KAI3B,OAAO,EAAW,IAAI,CAAI,EAAI,CAAE,KAAM,EAAM,GAAI,KAAM,IAAK,CAAK,EAAI,CAAE,KAAM,KAAM,GAAI,EAAM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AAO,MAAiB,EADN,CAEtD"}
|
|
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,SAAS,KAI3B,OAAON,EAAW,IAAIO,CAAI,EAAI,CAAE,KAAMA,EAAM,GAAI,KAAM,IAAKA,CAAK,EAAI,CAAE,KAAM,KAAM,GAAIA,EAAM,IAAKA,CAAK,CACxG,CAGA,OAFID,EAAK,OAAS,yBAAiC,CAAE,KAAM,KAAM,GAAI,UAAW,IAAK,SAAU,EAC3FA,EAAK,OAAS,2BAAmC,CAAE,KAAM,IAAK,GAAI,IAAK,IAAK,GAAI,EAC7E,IACT,CAEA,MAAME,GAAiD,EAAsC,IAC3FC,EAAQ,QAA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11 @@ import { Rule, SourceCode } from "eslint";
|
|
|
3
3
|
/**
|
|
4
4
|
* Check if a given symbol is already imported from functype
|
|
5
5
|
*/
|
|
6
|
-
declare function hasFunctypeSymbol(sourceCode: SourceCode, symbolName: string): boolean;
|
|
6
|
+
export declare function hasFunctypeSymbol(sourceCode: SourceCode, symbolName: string): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Create a fixer function that adds a symbol to the functype import.
|
|
9
9
|
* Returns a factory compatible with ESLint suggest[].fix signature.
|
|
10
10
|
*/
|
|
11
|
-
declare function createImportFixer(sourceCode: SourceCode, symbolName: string): (fixer: Rule.RuleFixer) => Rule.Fix | null;
|
|
11
|
+
export declare function createImportFixer(sourceCode: SourceCode, symbolName: string): (fixer: Rule.RuleFixer) => Rule.Fix | null;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { createImportFixer, hasFunctypeSymbol };
|
|
14
13
|
//# sourceMappingURL=import-fixer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-fixer.js","names":[],"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,
|
|
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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ASTNode } from "../types/ast.js";
|
|
2
|
+
import { SourceCode } from "eslint";
|
|
3
|
+
//#region src/utils/mutable-collection.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects a native Set/Map that the code mutates on purpose — a cache, a registry, an in-place
|
|
6
|
+
* accumulator, a React copy-then-add. functype's collections are immutable, so they cannot express
|
|
7
|
+
* these, and a rule that suggests them there is noise (#324).
|
|
8
|
+
*
|
|
9
|
+
* Mutation means a call of one of `mutators` on the collection itself:
|
|
10
|
+
* - directly on a `new` expression that copies something (`new Set(prev).add(id)`) — an empty
|
|
11
|
+
* `new Map().set(a, 1).set(b, 2)` is a builder, a `Map.of` candidate, and is NOT exempt;
|
|
12
|
+
* - through the variable, parameter or later-assigned `let` it is bound to;
|
|
13
|
+
* - through `this.<field>` in the owning class (field initializer, constructor assignment, or
|
|
14
|
+
* constructor parameter property).
|
|
15
|
+
*
|
|
16
|
+
* Not followed: aliases (`const t = s; t.add(x)`), `useRef(new Set()).current.add(x)`, a mutator
|
|
17
|
+
* passed as a callback (`xs.forEach(seen.add, seen)`), and a collection passed into another function.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SET_MUTATORS: ReadonlyArray<string>;
|
|
20
|
+
export declare const MAP_MUTATORS: ReadonlyArray<string>;
|
|
21
|
+
/** `new Set(...)` / `new Map(...)` that is mutated, directly or through what it is bound to. */
|
|
22
|
+
export declare const isMutatedCollection: (newExpr: ASTNode, mutators: ReadonlyArray<string>, sourceCode: SourceCode) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A `Set<T>` / `Map<K, V>` type reference annotating a binding that is mutated — a variable
|
|
25
|
+
* (`let s: Set<T>`), a parameter (`(s: Set<T>) =>`), a class field (`private s: Set<T>`), or a
|
|
26
|
+
* constructor parameter property (`constructor(private s: Set<T>)`).
|
|
27
|
+
*/
|
|
28
|
+
export declare const annotatesMutatedBinding: (typeRef: ASTNode, mutators: ReadonlyArray<string>, sourceCode: SourceCode) => boolean;
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=mutable-collection.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{descendants as e}from"./ast-walk.js";const t=[`add`,`delete`,`clear`],n=[`set`,`delete`,`clear`],r=(e,t)=>{let n=e.parent;return n?.type===`TSNonNullExpression`&&n.expression===e?r(n,t):n?.type===`MemberExpression`&&n.object===e&&!n.computed&&n.property.type===`Identifier`&&t.includes(n.property.name)&&n.parent?.type===`CallExpression`&&n.parent.callee===n},i=e=>e?.type===`Identifier`?e.name:e?.type===`PrivateIdentifier`?`#${e.name}`:null,a=e=>e==null?null:e.type===`ClassBody`?e:a(e.parent),o=(t,n,o)=>{let s=a(t);return s!==null&&e(s).some(e=>e.type===`MemberExpression`&&e.object.type===`ThisExpression`&&!e.computed&&i(e.property)===n&&r(e,o))},s=(e,t,n)=>{let r=e=>e===null?null:e.set.get(t)??r(e.upper);return r(n.getScope(e))},c=(e,t,n)=>s(e,e.name,n)?.references.some(e=>r(e.identifier,t))??!1,l=(e,t,n)=>{let r=e.parent?.type===`AssignmentPattern`?e.parent.parent:e.parent;return r?.type===`TSParameterProperty`?o(r,e.name,t):c(e,t,n)},u=(e,t,n,r)=>{let a=e?.type===`VariableDeclarator`?e.id:(e?.type===`AssignmentExpression`||e?.type===`AssignmentPattern`)&&e.right===t?e.left:null;if(a?.type===`Identifier`)return l(a,n,r);if(a?.type===`MemberExpression`&&a.object.type===`ThisExpression`){let t=i(a.property);return t!==null&&o(e,t,n)}if(e?.type===`PropertyDefinition`&&e.value===t){let t=i(e.key);return t!==null&&o(e,t,n)}return!1},d=(e,t,n)=>e.arguments.length>0&&r(e,t)||u(e.parent,e,t,n),f=(e,t,n)=>{let r=e.parent;if(r?.type!==`TSTypeAnnotation`||r.typeAnnotation!==e)return!1;let a=r.parent;if(a?.type===`Identifier`)return l(a,t,n);if(a?.type===`PropertyDefinition`){let e=i(a.key);return e!==null&&o(a,e,t)}return!1};export{n as MAP_MUTATORS,t as SET_MUTATORS,f as annotatesMutatedBinding,d as isMutatedCollection};
|
|
2
|
+
//# sourceMappingURL=mutable-collection.js.map
|
|
@@ -0,0 +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":"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,SA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OAAS,wBAA0BA,GAAS,OAAS,sBAC5DA,EAAQ,QAAUC,EAChBD,EAAQ,KACR,KAEV,GAAID,GAAQ,OAAS,aAAc,OAAOH,EAA2BG,EAAQpB,EAAUa,CAAU,EACjG,GAAIO,GAAQ,OAAS,oBAAsBA,EAAO,OAAO,OAAS,iBAAkB,CAClF,IAAMX,EAAOR,EAAUmB,EAAO,QAAQ,EACtC,OAAOX,IAAS,MAAQJ,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ASTNode } from "../types/ast.js";
|
|
2
|
+
//#region src/utils/wire-types.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* `Wire<T>` declares a value in its serialization-safe shape — a DB row, an HTTP body,
|
|
5
|
+
* a JSONB payload (#325 B). Everything inside its type argument is the wire shape by declaration: a
|
|
6
|
+
* `ReadonlyArray` there is not a missed `List`, and a `T | null` there is not a missed `Option`. Rules
|
|
7
|
+
* that prefer the functype shape skip it, so the boundary is stated once instead of suppressed at every
|
|
8
|
+
* field. Names are configurable (`wireTypes`) for consumers with their own boundary alias.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_WIRE_TYPES: ReadonlyArray<string>;
|
|
11
|
+
export declare const WIRE_TYPES_SCHEMA: {
|
|
12
|
+
readonly type: "array";
|
|
13
|
+
readonly items: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
};
|
|
16
|
+
readonly default: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
/** Is `node` inside the type argument of a `Wire<…>` (or other configured wire type) reference? */
|
|
19
|
+
export declare const isInsideWireType: (node: ASTNode, wireTypes: ReadonlyArray<string>) => boolean;
|
|
20
|
+
//#endregion
|
|
21
|
+
//# sourceMappingURL=wire-types.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=[`Wire`],t={type:`array`,items:{type:`string`},default:[...e]},n=e=>e?.type===`Identifier`?e.name:e?.type===`TSQualifiedName`&&e.right?.type===`Identifier`?e.right.name:null,r=e=>e.type===`TSTypeReference`?n(e.typeName):e.type===`TSImportType`?n(e.qualifier):null,i=(e,t)=>{if(t.length===0)return!1;let n=e=>{let i=e?.parent;if(!i)return!1;if(i.type===`TSTypeParameterInstantiation`&&i.parent){let e=r(i.parent);if(e!==null&&t.includes(e))return!0}return n(i)};return n(e)};export{e as DEFAULT_WIRE_TYPES,t as WIRE_TYPES_SCHEMA,i as isInsideWireType};
|
|
2
|
+
//# sourceMappingURL=wire-types.js.map
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-functype",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.110.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.
|
|
43
|
-
"@typescript-eslint/rule-tester": "^8.
|
|
42
|
+
"@types/node": "^24.19.0",
|
|
43
|
+
"@typescript-eslint/rule-tester": "^8.71.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
45
|
+
"functype": "^1.10.0",
|
|
46
|
+
"ts-builds": "^3.4.3",
|
|
47
|
+
"tsdown": "^0.23.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public",
|