eslint-plugin-functype 2.200.0 → 2.201.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 +30 -2
- package/dist/cli/list-rules.js.map +1 -1
- package/dist/configs/recommended.d.ts +5 -1
- package/dist/configs/recommended.js +1 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rules/collection-naming.js.map +1 -1
- package/dist/rules/index.d.ts +13 -11
- package/dist/rules/index.js +1 -1
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/must-fold-on-component-return.js.map +1 -1
- package/dist/rules/no-array-mutation.js.map +1 -1
- package/dist/rules/no-floating-io.js.map +1 -1
- package/dist/rules/no-floating-result.js.map +1 -1
- package/dist/rules/no-get-unsafe.js.map +1 -1
- package/dist/rules/no-getOrThrow-in-render.js.map +1 -1
- package/dist/rules/no-imperative-loops.js.map +1 -1
- package/dist/rules/no-let.js.map +1 -1
- package/dist/rules/no-serialize-container.js.map +1 -1
- package/dist/rules/no-uncalled-method.d.ts +16 -0
- package/dist/rules/no-uncalled-method.js +2 -0
- package/dist/rules/no-uncalled-method.js.map +1 -0
- 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.map +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.map +1 -1
- package/dist/rules/prefer-functype-set.js.map +1 -1
- package/dist/rules/prefer-list.js.map +1 -1
- package/dist/rules/prefer-map.js.map +1 -1
- package/dist/rules/prefer-option.js.map +1 -1
- package/dist/rules/prefer-try.js.map +1 -1
- package/dist/utils/array-mutation.d.ts +1 -1
- package/dist/utils/array-mutation.js.map +1 -1
- package/dist/utils/ast-walk.js.map +1 -1
- package/dist/utils/async-detection.js.map +1 -1
- package/dist/utils/boundary-tags.d.ts +1 -1
- package/dist/utils/boundary-tags.js.map +1 -1
- package/dist/utils/collection-binding.d.ts +1 -1
- package/dist/utils/collection-binding.js.map +1 -1
- package/dist/utils/dependency-validator.js.map +1 -1
- package/dist/utils/functype-detection.d.ts +1 -1
- package/dist/utils/functype-detection.js.map +1 -1
- package/dist/utils/functype-predicates.d.ts +1 -1
- package/dist/utils/functype-predicates.js.map +1 -1
- package/dist/utils/host-throws.d.ts +1 -1
- package/dist/utils/host-throws.js.map +1 -1
- package/dist/utils/import-fixer.js.map +1 -1
- package/dist/utils/mutable-collection.d.ts +1 -1
- package/dist/utils/mutable-collection.js.map +1 -1
- package/dist/utils/react-render.js.map +1 -1
- package/dist/utils/readonly-contract.js.map +1 -1
- package/dist/utils/type-aware.d.ts +13 -1
- package/dist/utils/type-aware.js +1 -1
- package/dist/utils/type-aware.js.map +1 -1
- package/dist/utils/wire-types.js.map +1 -1
- package/package.json +3 -3
|
@@ -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","
|
|
1
|
+
{"version":3,"file":"import-fixer.js","names":["isImportDecl","node","isFunctypeImportDecl","specifierMatches","spec","symbolName","hasFunctypeSymbol","sourceCode","n","createImportFixer","fixer","program","imports","lastImportNode","existingFunctypeImport","s","lastSpecifier","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,EAAgBC,GAA+CA,EAAK,OAAS,oBAE7EC,EAAwBD,GAC5BD,EAAaC,CAAI,GAAKA,EAAK,QAAQ,OAAS,WAAaA,EAAK,OAAO,QAAU,WAE3EE,GAAoBC,EAAkBC,IAC1CD,EAAK,OAAS,4BACbA,EAAK,OAAS,mBAAqBA,EAAK,UAAU,OAAS,cAAgBA,EAAK,SAAS,OAASC,EAKrG,SAAgBC,EAAkBC,EAAwBF,EAA6B,CACrF,OAAQE,EAAW,IAAI,KACpB,OAAQC,GAAuBN,EAAqBM,CAAqB,CAAC,CAAC,CAC3E,QAASP,GAASA,EAAK,YAAc,CAAC,CAAC,CAAC,CACxC,KAAMG,GAASD,EAAiBC,EAAMC,CAAU,CAAC,CACtD,CAMA,SAAgBI,EACdF,EACAF,EAC4C,CAC5C,MAAQK,IAA2C,CAEjD,GAAIJ,EAAkBC,EAAYF,CAAU,EAAG,OAAO,KAEtD,IAAMM,EAAUJ,EAAW,IACrBK,EAAWD,EAAQ,KAA4B,OAAQH,GAC3DR,EAAaQ,CAAqB,CACpC,EACMK,EAAiBD,EAAQ,GAAG,EAAE,GAAK,KACnCE,EAAyBF,EAAQ,KAAMJ,GAAMN,EAAqBM,CAAC,CAAC,GAAK,KAE/E,GAAIM,EAAwB,CAI1B,GADEA,EAAuB,YAAY,KAAMC,GAAMA,EAAE,OAAS,0BAA0B,GAAK,GACzE,OAAO,KAIzB,IAAMC,GADmBF,EAAuB,YAAc,CAAC,EAAA,CAAG,OAAQC,GAAMA,EAAE,OAAS,iBACvD,CAAC,CAAC,GAAG,EAAE,EAC3C,GAAIC,EAAe,OAAON,EAAM,gBAAgBM,EAAwB,KAAKX,GAAY,EAGzF,IAAMY,EAAaV,EAAW,QAAQO,CAA+B,EACrE,OAAOJ,EAAM,YAAYI,EAAiCG,EAAW,QAAQ,YAAa,KAAKZ,EAAW,GAAG,CAAC,CAChH,CAGA,IAAMa,EAAY,YAAYb,EAAW,oBACzC,GAAIQ,EAAgB,OAAOH,EAAM,gBAAgBG,EAAyB,KAAKK,GAAW,EAE1F,IAAMC,EAAYR,EAAQ,KAAK,GAE/B,OADIQ,EAAkBT,EAAM,iBAAiBS,EAAW,GAAGD,EAAU,GAAG,EACjER,EAAM,sBAAsB,CAAC,EAAG,CAAC,EAAG,GAAGQ,EAAU,GAAG,CAC7D,CACF,C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ASTNode } from "../types/ast.js";
|
|
2
1
|
import { SourceCode } from "eslint";
|
|
2
|
+
import { ASTNode } from "../types/ast.js";
|
|
3
3
|
/**
|
|
4
4
|
* Detects a native Set/Map that the code mutates on purpose — a cache, a registry, an in-place
|
|
5
5
|
* accumulator, a React copy-then-add. functype's collections are immutable, so they cannot express
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutable-collection.js","names":["SET_MUTATORS","MAP_MUTATORS","isMutatorCallOn","
|
|
1
|
+
{"version":3,"file":"mutable-collection.js","names":["descendants","SET_MUTATORS","MAP_MUTATORS","isMutatorCallOn","expr","mutators","parent","fieldName","key","enclosingClassBody","node","isFieldMutated","name","body","n","resolveVariable","sourceCode","lookup","scope","isNameMutated","identifier","ref","isIdentifierBindingMutated","owner","isBindingMutated","binding","value","target","isMutatedCollection","newExpr","annotatesMutatedBinding","typeRef","annotation"],"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,MAAaC,EAAsC,CAAC,MAAO,SAAU,OAAO,EAC/DC,EAAsC,CAAC,MAAO,SAAU,OAAO,EAGtEC,GAAmBC,EAAeC,IAA6C,CACnF,IAAMC,EAASF,EAAK,OAEpB,OADIE,GAAQ,OAAS,uBAAyBA,EAAO,aAAeF,EAAaD,EAAgBG,EAAQD,CAAQ,EAE/GC,GAAQ,OAAS,oBACjBA,EAAO,SAAWF,GAClB,CAACE,EAAO,UACRA,EAAO,SAAS,OAAS,cACzBD,EAAS,SAASC,EAAO,SAAS,IAAI,GACtCA,EAAO,QAAQ,OAAS,kBACxBA,EAAO,OAAO,SAAWA,CAE7B,EAGMC,EAAaC,GAC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AAU,EACjG,GAAIW,GAAQ,OAAS,oBAAsBA,EAAO,OAAO,OAAS,iBAAkB,CAClF,IAAMf,EAAOL,EAAUoB,EAAO,QAAQ,EACtC,OAAOf,IAAS,MAAQD,EAAec,EAASb,EAAMP,CAAQ,CAChE,CACA,GAAIoB,GAAS,OAAS,sBAAwBA,EAAQ,QAAUC,EAAO,CACrE,IAAMd,EAAOL,EAAUkB,EAAQ,GAAG,EAClC,OAAOb,IAAS,MAAQD,EAAec,EAASb,EAAMP,CAAQ,CAChE,CACA,MAAO,EACT,EAGauB,GACXC,EACAxB,EACAW,IAECa,EAAQ,UAAU,OAAS,GAAK1B,EAAgB0B,EAASxB,CAAQ,GAClEmB,EAAiBK,EAAQ,OAAQA,EAASxB,EAAUW,CAAU,EAOnDc,GACXC,EACA1B,EACAW,IACY,CACZ,IAAMgB,EAAaD,EAAQ,OAC3B,GAAIC,GAAY,OAAS,oBAAsBA,EAAW,iBAAmBD,EAAS,MAAO,GAC7F,IAAMR,EAAQS,EAAW,OACzB,GAAIT,GAAO,OAAS,aAAc,OAAOD,EAA2BC,EAAOlB,EAAUW,CAAU,EAC/F,GAAIO,GAAO,OAAS,qBAAsB,CACxC,IAAMX,EAAOL,EAAUgB,EAAM,GAAG,EAChC,OAAOX,IAAS,MAAQD,EAAeY,EAAOX,EAAMP,CAAQ,CAC9D,CACA,MAAO,EACT,E"}
|
|
@@ -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"
|
|
1
|
+
{"version":3,"file":"react-render.js","names":["descendants","FUNCTION_TYPES","WRAPPERS","isWrapperCall","node","fn","callee","name","enclosingFunction","parent","functionName","holder","isJSX","producesJSX","HOOK_NAME","COMPONENT_NAME","renderKind"],"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,MAAMC,kBAAsC,IAAI,IAAI,CAClD,sBACA,qBACA,yBACF,CAAC,EAGKC,kBAAgC,IAAI,IAAI,CAAC,OAAQ,YAAY,CAAC,EAE9DC,GAAiBC,EAAeC,IAAyB,CAC7D,GAAID,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,EAAqBJ,GAAkC,CAClE,IAAMK,EAASL,EAAK,OAEpB,OADKK,EACER,EAAe,IAAIQ,EAAO,IAAI,EAAIA,EAASD,EAAkBC,CAAM,EADtD,IAEtB,EAGMC,EAAgBL,GAA+B,CACnD,GAAIA,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,EAASR,GAA2BA,GAAM,OAAS,cAAgBA,GAAM,OAAS,cAGlFS,EAAeT,GACtBQ,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,EAAcX,GAAmC,CAC5D,IAAME,EAAOG,EAAaL,CAAE,EAG5B,OAFIE,IAAS,KAAa,KACtBO,EAAU,KAAKP,CAAI,EAAU,OAC1BQ,EAAe,KAAKR,CAAI,GAAKP,EAAYK,EAAG,IAAI,CAAC,CAAC,KAAKO,CAAK,EAAI,YAAc,IACvF,E"}
|
|
@@ -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,
|
|
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,GAAWC,EAA2BC,IAC1CD,GAAM,OAAS,mBAAqBA,EAAK,UAAU,OAAS,cAAgBA,EAAK,SAAS,OAASC,EAE/FC,EAAYF,GACfA,EAAK,eAAe,QAAUA,EAAK,gBAAgB,QAAU,CAAC,EAG3DG,GAAsBH,EAA2BI,IACrDL,EAAQC,EAAMI,CAAY,GAAML,EAAQC,EAAM,SAAS,GAAKG,EAAmBD,EAASF,CAAK,CAAC,CAAC,GAAII,CAAY,EAE3GC,EAAgBC,GAAmDA,GAAM,gBAAgB,eAEzFC,EAAmBD,GACvBA,GAA+B,KAAO,IAAA,GAAYR,EAAU,IAAIQ,EAAK,IAAI,EAAIA,EAAOC,EAAgBD,EAAK,MAAM,EAEpGE,GAA6BF,EAAeF,IAAkC,CACzF,IAAMK,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,5 +1,5 @@
|
|
|
1
|
-
import { ASTNode } from "../types/ast.js";
|
|
2
1
|
import { Rule } from "eslint";
|
|
2
|
+
import { ASTNode } from "../types/ast.js";
|
|
3
3
|
/**
|
|
4
4
|
* Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:
|
|
5
5
|
* the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every
|
|
@@ -42,6 +42,18 @@ export type ContainerAt = {
|
|
|
42
42
|
* `undefined` when there is none, or when type information isn't available.
|
|
43
43
|
*/
|
|
44
44
|
export declare const containerInsideByType: (node: ASTNode, context: Rule.RuleContext) => ContainerAt | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* If `object` is a functype container and `name` is one of its methods, the container's name
|
|
47
|
+
* (`List`, `Option`, `Either`); otherwise `undefined`. A container has `_tag` and `fold`. A method is
|
|
48
|
+
* declared in functype's own files, so a user type with the same shape (a union with `_tag` and a
|
|
49
|
+
* `fold`, or an interface extending `List` with methods of its own) never counts for those methods. It is a
|
|
50
|
+
* callable member whose declaration has parameters (`head(): A | undefined`, `fold<B>(…)`), so neither
|
|
51
|
+
* function-valued data (`readonly value: R` on a `Right` holding a callback) nor a getter (`size`) is one. A type parameter is read
|
|
52
|
+
* through its constraint.
|
|
53
|
+
*
|
|
54
|
+
* `undefined` when type information isn't available.
|
|
55
|
+
*/
|
|
56
|
+
export declare const functypeMethodByType: (object: ASTNode, name: string, context: Rule.RuleContext) => string | undefined;
|
|
45
57
|
/**
|
|
46
58
|
* Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?
|
|
47
59
|
* That's the expected type TypeScript checks it against: the parameter it is passed to, the property
|
package/dist/utils/type-aware.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=/* @__PURE__ */ new Set([`Iterable`,`AsyncIterable`,`IterableIterator`,`ArrayLike`]),t=e=>{let t=e.sourceCode.parserServices;return t?.program&&t.esTreeNodeToTSNodeMap?t:void 0},n=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`orThrow`)!==void 0&&a.getPropertyOfType(o,`fold`)!==void 0},r=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`runExit`)!==void 0&&a.getPropertyOfType(o,`provideLayer`)!==void 0},i=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i)),s=(e,t)=>a.getPropertyOfType(e,t)!==void 0;return(o.types??[o]).some(e=>s(e,`fold`)&&(s(e,`isLeft`)||s(e,`isFailure`))&&!s(e,`runExit`))},a={LeftOf:`Either`,RightOf:`Either`,SomeOf:`Option`,NoneOf:`Option`,SuccessOf:`Try`,FailureOf:`Try`,SuccessExitOf:`Exit`,FailureExitOf:`Exit`,DieExitOf:`Exit`,InterruptedExitOf:`Exit`},o=e=>{let t=(e.aliasSymbol?.name??e.getSymbol?.()?.name)?.replace(/\$\d+$/,``);return t===void 0||t.startsWith(`__`)?`functype container`:a[t]??t},s=e=>{let t=e.getSymbol?.();return t===void 0||t.name.startsWith(`__`)?!1:(t.getDeclarations?.()??[]).some(e=>e.getSourceFile().fileName.includes(`/node_modules/`))},c=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),c=/* @__PURE__ */ new Set,
|
|
1
|
+
const e=/* @__PURE__ */ new Set([`Iterable`,`AsyncIterable`,`IterableIterator`,`ArrayLike`]),t=e=>{let t=e.sourceCode.parserServices;return t?.program&&t.esTreeNodeToTSNodeMap?t:void 0},n=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`orThrow`)!==void 0&&a.getPropertyOfType(o,`fold`)!==void 0},r=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`runExit`)!==void 0&&a.getPropertyOfType(o,`provideLayer`)!==void 0},i=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i)),s=(e,t)=>a.getPropertyOfType(e,t)!==void 0;return(o.types??[o]).some(e=>s(e,`fold`)&&(s(e,`isLeft`)||s(e,`isFailure`))&&!s(e,`runExit`))},a={LeftOf:`Either`,RightOf:`Either`,SomeOf:`Option`,NoneOf:`Option`,SuccessOf:`Try`,FailureOf:`Try`,SuccessExitOf:`Exit`,FailureExitOf:`Exit`,DieExitOf:`Exit`,InterruptedExitOf:`Exit`},o=e=>{let t=(e.aliasSymbol?.name??e.getSymbol?.()?.name)?.replace(/\$\d+$/,``);return t===void 0||t.startsWith(`__`)?`functype container`:a[t]??t},s=e=>{let t=e.getSymbol?.();return t===void 0||t.name.startsWith(`__`)?!1:(t.getDeclarations?.()??[]).some(e=>e.getSourceFile().fileName.includes(`/node_modules/`))},c=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),c=/* @__PURE__ */ new Set,l=e=>a.getPropertyOfType(e,`_tag`)!==void 0&&a.getPropertyOfType(e,`fold`)!==void 0,u=(e,t)=>e===``?t:t.startsWith(`[`)?e+t:`${e}.${t}`,d=(e,t,n)=>{if(n>4||c.has(e)||f(e))return;c.add(e);let r=e;if(l(e))return{path:t,name:o(r)};if(r.isUnionOrIntersection?.()===!0)return(r.types??[]).map(e=>d(e,t,n)).find(e=>e!==void 0);if((r.getCallSignatures?.()??[]).length>0)return;if(a.isArrayLikeType(e)||a.isTupleType(e))return a.getTypeArguments(e).map(e=>d(e,t===``?`[]`:`${t}[]`,n+1)).find(e=>e!==void 0);let p=a.getIndexInfoOfType(e,0)?.type,m=p===void 0?void 0:d(p,u(t,`[key]`),n+1);if(m!==void 0)return m;if(!(r.getSymbol?.()===void 0||s(r)))return a.getPropertiesOfType(e).map(e=>d(a.getTypeOfSymbolAtLocation(e,i),u(t,e.name),n+1)).find(e=>e!==void 0)};return d(a.getTypeAtLocation(i),``,0)},l=/(?:^|[\\/])functype[\\/](?:dist|src)[\\/]/,u=e=>l.test(e.getSourceFile().fileName),d=(e,n,r)=>{let i=t(r);if(!i)return;let a=i.esTreeNodeToTSNodeMap.get(e);if(!a)return;let s=i.program.getTypeChecker(),c=s.getNonNullableType(s.getTypeAtLocation(a)),l=f(c)?s.getApparentType?.(c)??c:c;if(s.getPropertyOfType(l,`_tag`)===void 0||s.getPropertyOfType(l,`fold`)===void 0)return;let d=s.getPropertyOfType(l,n),p=d?.getDeclarations?.()??[];return p.length>0&&p.every(e=>Array.isArray(e.parameters)&&u(e))&&(s.getTypeOfSymbolAtLocation(d,a).getCallSignatures?.()??[]).length>0?o(l):void 0},f=e=>e.isTypeParameter?.()===!0,p=e=>{let t=e.parent;if(!t)return null;if((t.type===`CallExpression`||t.type===`NewExpression`)&&t.callee!==e){let n=t.arguments.indexOf(e);return n<0?null:{call:t,argument:e,index:n}}return t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`ConditionalExpression`&&t.test!==e||t.type===`LogicalExpression`||t.type===`Property`||t.type===`ObjectExpression`||t.type===`ArrayExpression`||t.type===`SpreadElement`?p(t):null},m=(e,t,n)=>{let r=p(n),i=r?t.esTreeNodeToTSNodeMap.get(r.call):void 0,a=i?e.getResolvedSignature(i)?.getDeclaration()?.parameters:void 0;if(!r||!a||a.length===0)return!1;let o=a[Math.min(r.index,a.length-1)];if(o?.type===void 0)return!1;let s=e.getTypeAtLocation(o.type);return(s.types??[s]).some(f)},h=(e,t,n)=>{let r=p(n),i=r?t.esTreeNodeToTSNodeMap.get(r.call):void 0,a=i?e.getResolvedSignature(i):void 0,o=r?t.esTreeNodeToTSNodeMap.get(r.argument):void 0;if(!a||!o)return!1;let s=e.getTypeAtLocation(o),c=t=>t===s||e.isTypeAssignableTo(s,t)&&e.isTypeAssignableTo(t,s),l=(t,n)=>{if(n>3)return!1;if(c(t))return!0;let{types:r,target:i}=t;if(r)return r.some(e=>l(e,n+1));if(i!==void 0&&(e.isTupleType(t)||e.isArrayLikeType(t)))return e.getTypeArguments(t).some(e=>l(e,n+1));let a=e.getAwaitedType(t);return a!==void 0&&a!==t&&l(a,n+1)};return l(e.getReturnTypeOfSignature(a),0)},g=(e,t,n)=>v(n.type)||f(n.type)&&!h(e,t,n.at),_=(t,n,r)=>{if(g(t,n,r))return!0;let{types:i,symbol:a}=r.type;return i?i.some(e=>_(t,n,{type:e,at:r.at})):a?.name!==void 0&&e.has(a.name)?!0:!f(r.type)&&t.isArrayLikeType(r.type)},v=e=>{let{flags:t}=e;return t!==void 0&&!!(t&3)},y=(e,t)=>{let{types:n,symbol:r}=t;return n?n.some(t=>y(e,t)):r?.name===`Array`&&e.isArrayLikeType(t)},b=e=>e.computed?null:e.key?.type===`Identifier`?e.key.name:e.key?.type===`Literal`&&typeof e.key.value==`string`?e.key.value:null,x=(e,t,n,r,i=0)=>{if(i>4)return;let a=t.esTreeNodeToTSNodeMap.get(n),o=a?e.getContextualType(a):void 0;if(o!==void 0)return{type:o,at:n};let s=n.parent;if(s?.type===`ArrowFunctionExpression`&&s.body===n){let n=s.parent;if(n?.type===`VariableDeclarator`&&n.init===s&&n.id?.type===`Identifier`)return(r.sourceCode.getDeclaredVariables(n)[0]?.references??[]).map(e=>e.identifier.parent).filter(e=>e?.type===`CallExpression`).map(n=>x(e,t,n,r,i+1)).find(e=>e!==void 0)}if((s?.type===`CallExpression`||s?.type===`NewExpression`)&&s.callee!==n){let r=s.arguments.indexOf(n),i=t.esTreeNodeToTSNodeMap.get(s),a=r>=0&&i?e.getResolvedSignature(i)?.parameters[r]:void 0;return a===void 0?void 0:{type:e.getTypeOfSymbolAtLocation(a,i),at:n}}let c=s?.type===`Property`&&s.value===n?s.parent:void 0;if(c?.type!==`ObjectExpression`)return;let l=x(e,t,c,r,i+1);if(l===void 0||g(e,t,l))return l;let u=l.type,d=b(s);if(d===null){let r=s.key,i=r?t.esTreeNodeToTSNodeMap.get(r):void 0,o=i?e.getTypeAtLocation(i):void 0,c=o?.value??o?.types?.[0]?.value,l=typeof c==`string`?e.getPropertyOfType(u,c):void 0,d=l===void 0?e.getIndexInfoOfType(u,0)?.type:e.getTypeOfSymbolAtLocation(l,a);return d===void 0?void 0:{type:d,at:n}}let f=e.getPropertyOfType(u,d);return f===void 0?void 0:{type:e.getTypeOfSymbolAtLocation(f,a),at:n}},S=(e,n)=>{let r=t(n);if(!r)return;let i=r.program.getTypeChecker(),a=x(i,r,e,n);if(a!==void 0)return m(i,r,a.at)?!h(i,r,a.at):_(i,r,a)},C=(e,n)=>{let r=t(n);if(!r)return;let i=r.program.getTypeChecker(),a=x(i,r,e,n);return a===void 0||m(i,r,a.at)?!1:y(i,a.type)},w=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getTypeAtLocation(i);if(v(o))return!0;if(!a.isArrayLikeType(o))return!1;let s=a.getTypeArguments(o)[0];return s!==void 0&&v(s)},T=e=>t(e)!==void 0;export{i as canCarryFailureByType,c as containerInsideByType,S as flowsIntoArraySlot,C as flowsIntoMutableArraySlot,d as functypeMethodByType,T as hasTypeInformation,n as isExtractableByType,r as isIOByType,w as isUntypedExpression};
|
|
2
2
|
//# sourceMappingURL=type-aware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","services","context","isExtractableByType","tsNode","node","checker","type","isIOByType","canCarryFailureByType","has","member","name","MEMBER_TO_CONTAINER","containerName","raw","isFromDependency","symbol","declaration","containerInsideByType","seen","isContainer","at","path","step","find","depth","isTypeParameter","shape","h","element","indexed","byIndex","property","enclosingCall","parent","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","types","target","awaited","isOpaqueSink","isUntyped","slot","isArrayLikeOrUntyped","flags","isMutableArrayType","propertyKey","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 getPropertiesOfType(type: TypeLike): ReadonlyArray<{ readonly name: string }>\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 — `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/**\n * Can `node`'s value carry a failure that dropping it would lose? Structural: the type, or a member of\n * its union, has `fold` and `isLeft` or `isFailure`. That covers Either, Try, Exit, Validation and\n * Either-shaped wrappers such as a `ServiceResult`, and leaves out Option and List, whose `None` or\n * empty value is no error. An `IO` is left to no-floating-io: it hasn't run, so it holds no failure yet.\n *\n * `undefined` when type information isn't available.\n */\nexport const canCarryFailureByType = (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 const has = (member: TypeLike, name: string): boolean => checker.getPropertyOfType(member, name) !== undefined\n const carries = (member: TypeLike): boolean =>\n has(member, \"fold\") && (has(member, \"isLeft\") || has(member, \"isFailure\")) && !has(member, \"runExit\")\n const members = (type as { readonly types?: ReadonlyArray<TypeLike> }).types ?? [type]\n return members.some(carries)\n}\n\n/** Where a functype container sits inside a value, and what it is called. */\nexport type ContainerAt = { readonly path: string; readonly name: string }\n\ntype TypeShape = {\n readonly types?: ReadonlyArray<TypeLike>\n readonly aliasSymbol?: SymbolShape\n isUnionOrIntersection?: () => boolean\n getSymbol?: () => SymbolShape | undefined\n getCallSignatures?: () => ReadonlyArray<unknown>\n}\ntype SymbolShape = {\n readonly name: string\n getDeclarations?: () => ReadonlyArray<{ getSourceFile(): { readonly fileName: string } }> | undefined\n}\n\nconst SERIALIZE_DEPTH = 4\n\n/** A name to show for a container type: `Either`, `Option`, `List`, or the generic fallback. */\n/** Member names TypeScript shows once a union loses its alias (`Either<E, A> | null`), mapped back. */\nconst MEMBER_TO_CONTAINER: Readonly<Record<string, string>> = {\n LeftOf: \"Either\",\n RightOf: \"Either\",\n SomeOf: \"Option\",\n NoneOf: \"Option\",\n SuccessOf: \"Try\",\n FailureOf: \"Try\",\n SuccessExitOf: \"Exit\",\n FailureExitOf: \"Exit\",\n DieExitOf: \"Exit\",\n InterruptedExitOf: \"Exit\",\n}\n\nconst containerName = (type: TypeShape): string => {\n // A bundled .d.ts renames a clashing declaration `Map$1`.\n const raw = (type.aliasSymbol?.name ?? type.getSymbol?.()?.name)?.replace(/\\$\\d+$/, \"\")\n if (raw === undefined || raw.startsWith(\"__\")) return \"functype container\"\n return MEMBER_TO_CONTAINER[raw] ?? raw\n}\n\n/** Declared in a dependency or the TypeScript lib: Stripe objects, Date, Request. Never descended into. */\nconst isFromDependency = (type: TypeShape): boolean => {\n // The type's own symbol, not its alias: `Partial<User>` and `Omit<Row, \"x\">` are anonymous mapped\n // types whose alias is declared in TypeScript's lib, and their properties are the caller's.\n const symbol = type.getSymbol?.()\n if (symbol === undefined || symbol.name.startsWith(\"__\")) return false\n return (symbol.getDeclarations?.() ?? []).some((declaration) =>\n declaration.getSourceFile().fileName.includes(\"/node_modules/\"),\n )\n}\n\n/**\n * The first functype container inside the value `node` evaluates to, and the path to it: `subscription`,\n * `items[]`, or empty for the whole value. A container is a type with `_tag` and `fold`, which every\n * functype container has and its `toJSON()` envelope doesn't. Walks unions, intersections, array and\n * tuple elements, object properties and string index signatures, up to 4 levels deep, and checks for a\n * container before skipping types declared in node_modules, where functype itself lives (#364).\n *\n * `undefined` when there is none, or when type information isn't available.\n */\nexport const containerInsideByType = (node: ASTNode, context: Rule.RuleContext): ContainerAt | 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 seen = new Set<TypeLike>()\n const isContainer = (type: TypeLike): boolean =>\n checker.getPropertyOfType(type, \"_tag\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n const at = (path: string, step: string): string =>\n path === \"\" ? step : step.startsWith(\"[\") ? path + step : `${path}.${step}`\n\n const find = (type: TypeLike, path: string, depth: number): ContainerAt | undefined => {\n if (depth > SERIALIZE_DEPTH || seen.has(type) || isTypeParameter(type)) return undefined\n seen.add(type)\n const shape = type as TypeShape\n // Before splitting: an Either union has `_tag` and `fold` on every member, and `Stack` is an\n // intersection whose `_tag` and `fold` come from different members.\n if (isContainer(type)) return { path, name: containerName(shape) }\n if (shape.isUnionOrIntersection?.() === true) {\n return (shape.types ?? []).map((member) => find(member, path, depth)).find((h) => h !== undefined)\n }\n if ((shape.getCallSignatures?.() ?? []).length > 0) return undefined\n if (checker.isArrayLikeType(type) || checker.isTupleType(type)) {\n return checker\n .getTypeArguments(type)\n .map((element) => find(element, path === \"\" ? \"[]\" : `${path}[]`, depth + 1))\n .find((h) => h !== undefined)\n }\n // Before the dependency skip: `Record<string, Option<T>>` is declared in TypeScript's lib.\n const indexed = checker.getIndexInfoOfType(type, 0)?.type\n const byIndex = indexed === undefined ? undefined : find(indexed, at(path, \"[key]\"), depth + 1)\n if (byIndex !== undefined) return byIndex\n if (shape.getSymbol?.() === undefined || isFromDependency(shape)) return undefined\n return checker\n .getPropertiesOfType(type)\n .map((property) => find(checker.getTypeOfSymbolAtLocation(property, tsNode), at(path, property.name), depth + 1))\n .find((h) => h !== undefined)\n }\n\n return find(checker.getTypeAtLocation(tsNode), \"\", 0)\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":"AAsCA,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,EAUaE,GAAyB,EAAe,IAAmD,CACtG,IAAMR,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,kBAA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eAAe,EAC1CM,EAAOD,EAAQ,kBAAkBF,CAAM,EAC7C,GAAIkD,EAAU/C,CAAI,EAAG,MAAO,GAC5B,GAAI,CAACD,EAAQ,gBAAgBC,CAAI,EAAG,MAAO,GAC3C,IAAMuB,EAAUxB,EAAQ,iBAAiBC,CAAI,CAAC,CAAC,GAC/C,OAAOuB,IAAY,IAAA,IAAawB,EAAUxB,CAAO,CACnD,EAGagD,EAAsB,GAAuC9E,EAAcE,CAAO,IAAM,IAAA,G"}
|
|
1
|
+
{"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","context","services","isExtractableByType","node","tsNode","checker","type","isIOByType","canCarryFailureByType","has","member","name","MEMBER_TO_CONTAINER","containerName","raw","isFromDependency","symbol","declaration","containerInsideByType","seen","isContainer","at","path","step","find","depth","isTypeParameter","shape","h","element","indexed","byIndex","property","FUNCTYPE_FILE","isDeclaredByFunctype","functypeMethodByType","object","read","declarations","d","enclosingCall","parent","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","types","target","awaited","isOpaqueSink","slot","isUntyped","isArrayLikeOrUntyped","flags","isMutableArrayType","propertyKey","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 getPropertiesOfType(type: TypeLike): ReadonlyArray<{ readonly name: string }>\n getApparentType?(type: TypeLike): TypeLike\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 — `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/**\n * Can `node`'s value carry a failure that dropping it would lose? Structural: the type, or a member of\n * its union, has `fold` and `isLeft` or `isFailure`. That covers Either, Try, Exit, Validation and\n * Either-shaped wrappers such as a `ServiceResult`, and leaves out Option and List, whose `None` or\n * empty value is no error. An `IO` is left to no-floating-io: it hasn't run, so it holds no failure yet.\n *\n * `undefined` when type information isn't available.\n */\nexport const canCarryFailureByType = (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 const has = (member: TypeLike, name: string): boolean => checker.getPropertyOfType(member, name) !== undefined\n const carries = (member: TypeLike): boolean =>\n has(member, \"fold\") && (has(member, \"isLeft\") || has(member, \"isFailure\")) && !has(member, \"runExit\")\n const members = (type as { readonly types?: ReadonlyArray<TypeLike> }).types ?? [type]\n return members.some(carries)\n}\n\n/** Where a functype container sits inside a value, and what it is called. */\nexport type ContainerAt = { readonly path: string; readonly name: string }\n\ntype TypeShape = {\n readonly types?: ReadonlyArray<TypeLike>\n readonly aliasSymbol?: SymbolShape\n isUnionOrIntersection?: () => boolean\n getSymbol?: () => SymbolShape | undefined\n getCallSignatures?: () => ReadonlyArray<unknown>\n}\ntype SymbolShape = {\n readonly name: string\n getDeclarations?: () => ReadonlyArray<{ getSourceFile(): { readonly fileName: string } }> | undefined\n}\n\nconst SERIALIZE_DEPTH = 4\n\n/** A name to show for a container type: `Either`, `Option`, `List`, or the generic fallback. */\n/** Member names TypeScript shows once a union loses its alias (`Either<E, A> | null`), mapped back. */\nconst MEMBER_TO_CONTAINER: Readonly<Record<string, string>> = {\n LeftOf: \"Either\",\n RightOf: \"Either\",\n SomeOf: \"Option\",\n NoneOf: \"Option\",\n SuccessOf: \"Try\",\n FailureOf: \"Try\",\n SuccessExitOf: \"Exit\",\n FailureExitOf: \"Exit\",\n DieExitOf: \"Exit\",\n InterruptedExitOf: \"Exit\",\n}\n\nconst containerName = (type: TypeShape): string => {\n // A bundled .d.ts renames a clashing declaration `Map$1`.\n const raw = (type.aliasSymbol?.name ?? type.getSymbol?.()?.name)?.replace(/\\$\\d+$/, \"\")\n if (raw === undefined || raw.startsWith(\"__\")) return \"functype container\"\n return MEMBER_TO_CONTAINER[raw] ?? raw\n}\n\n/** Declared in a dependency or the TypeScript lib: Stripe objects, Date, Request. Never descended into. */\nconst isFromDependency = (type: TypeShape): boolean => {\n // The type's own symbol, not its alias: `Partial<User>` and `Omit<Row, \"x\">` are anonymous mapped\n // types whose alias is declared in TypeScript's lib, and their properties are the caller's.\n const symbol = type.getSymbol?.()\n if (symbol === undefined || symbol.name.startsWith(\"__\")) return false\n return (symbol.getDeclarations?.() ?? []).some((declaration) =>\n declaration.getSourceFile().fileName.includes(\"/node_modules/\"),\n )\n}\n\n/**\n * The first functype container inside the value `node` evaluates to, and the path to it: `subscription`,\n * `items[]`, or empty for the whole value. A container is a type with `_tag` and `fold`, which every\n * functype container has and its `toJSON()` envelope doesn't. Walks unions, intersections, array and\n * tuple elements, object properties and string index signatures, up to 4 levels deep, and checks for a\n * container before skipping types declared in node_modules, where functype itself lives (#364).\n *\n * `undefined` when there is none, or when type information isn't available.\n */\nexport const containerInsideByType = (node: ASTNode, context: Rule.RuleContext): ContainerAt | 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 seen = new Set<TypeLike>()\n const isContainer = (type: TypeLike): boolean =>\n checker.getPropertyOfType(type, \"_tag\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n const at = (path: string, step: string): string =>\n path === \"\" ? step : step.startsWith(\"[\") ? path + step : `${path}.${step}`\n\n const find = (type: TypeLike, path: string, depth: number): ContainerAt | undefined => {\n if (depth > SERIALIZE_DEPTH || seen.has(type) || isTypeParameter(type)) return undefined\n seen.add(type)\n const shape = type as TypeShape\n // Before splitting: an Either union has `_tag` and `fold` on every member, and `Stack` is an\n // intersection whose `_tag` and `fold` come from different members.\n if (isContainer(type)) return { path, name: containerName(shape) }\n if (shape.isUnionOrIntersection?.() === true) {\n return (shape.types ?? []).map((member) => find(member, path, depth)).find((h) => h !== undefined)\n }\n if ((shape.getCallSignatures?.() ?? []).length > 0) return undefined\n if (checker.isArrayLikeType(type) || checker.isTupleType(type)) {\n return checker\n .getTypeArguments(type)\n .map((element) => find(element, path === \"\" ? \"[]\" : `${path}[]`, depth + 1))\n .find((h) => h !== undefined)\n }\n // Before the dependency skip: `Record<string, Option<T>>` is declared in TypeScript's lib.\n const indexed = checker.getIndexInfoOfType(type, 0)?.type\n const byIndex = indexed === undefined ? undefined : find(indexed, at(path, \"[key]\"), depth + 1)\n if (byIndex !== undefined) return byIndex\n if (shape.getSymbol?.() === undefined || isFromDependency(shape)) return undefined\n return checker\n .getPropertiesOfType(type)\n .map((property) => find(checker.getTypeOfSymbolAtLocation(property, tsNode), at(path, property.name), depth + 1))\n .find((h) => h !== undefined)\n }\n\n return find(checker.getTypeAtLocation(tsNode), \"\", 0)\n}\n\ntype MemberDeclaration = {\n readonly parameters?: unknown\n getSourceFile(): { readonly fileName: string }\n}\ntype MemberSymbol = { getDeclarations?: () => ReadonlyArray<MemberDeclaration> | undefined }\n\n/**\n * Declared by functype itself: its published `dist` (`node_modules/functype/dist/…`, pnpm's\n * `.pnpm/functype@x/node_modules/functype/dist/…`) or, inside this repo, `packages/functype/{src,dist}`.\n */\nconst FUNCTYPE_FILE = /(?:^|[\\\\/])functype[\\\\/](?:dist|src)[\\\\/]/\nconst isDeclaredByFunctype = (declaration: MemberDeclaration): boolean =>\n FUNCTYPE_FILE.test(declaration.getSourceFile().fileName)\n\n/**\n * If `object` is a functype container and `name` is one of its methods, the container's name\n * (`List`, `Option`, `Either`); otherwise `undefined`. A container has `_tag` and `fold`. A method is\n * declared in functype's own files, so a user type with the same shape (a union with `_tag` and a\n * `fold`, or an interface extending `List` with methods of its own) never counts for those methods. It is a\n * callable member whose declaration has parameters (`head(): A | undefined`, `fold<B>(…)`), so neither\n * function-valued data (`readonly value: R` on a `Right` holding a callback) nor a getter (`size`) is one. A type parameter is read\n * through its constraint.\n *\n * `undefined` when type information isn't available.\n */\nexport const functypeMethodByType = (object: ASTNode, name: string, context: Rule.RuleContext): string | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(object)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const read = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n const type = isTypeParameter(read) ? (checker.getApparentType?.(read) ?? read) : read\n const isContainer =\n checker.getPropertyOfType(type, \"_tag\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n if (!isContainer) return undefined\n const member = checker.getPropertyOfType(type, name) as MemberSymbol | undefined\n const declarations = member?.getDeclarations?.() ?? []\n // A getter (`get size(): number`) has parameters too, but reading it gives its value, not a function.\n const isCallable = (): boolean =>\n ((checker.getTypeOfSymbolAtLocation(member, tsNode) as TypeShape).getCallSignatures?.() ?? []).length > 0\n const isMethod =\n declarations.length > 0 &&\n declarations.every((d) => Array.isArray(d.parameters) && isDeclaredByFunctype(d)) &&\n isCallable()\n return isMethod ? containerName(type as TypeShape) : undefined\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":"AAuCA,MAGMA,kBAAiD,IAAI,IAAI,CAC7D,WACA,gBACA,mBACA,WACF,CAAC,EAOKC,EAAiBC,GAAyD,CAC9E,IAAMC,EAAWD,EAAQ,WAAW,eACpC,OAAOC,GAAU,SAAWA,EAAS,sBAAyBA,EAA6B,IAAA,EAC7F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","
|
|
1
|
+
{"version":3,"file":"wire-types.js","names":["DEFAULT_WIRE_TYPES","WIRE_TYPES_SCHEMA","entityName","name","referenceName","typeRef","isInsideWireType","node","wireTypes","walk","current","parent"],"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,EAAcC,GACdA,GAAM,OAAS,aAAqBA,EAAK,KACzCA,GAAM,OAAS,mBAAqBA,EAAK,OAAO,OAAS,aAAqBA,EAAK,MAAM,KACtF,KAIHC,EAAiBC,GACjBA,EAAQ,OAAS,kBAA0BH,EAAWG,EAAQ,QAAQ,EACtEA,EAAQ,OAAS,eAAuBH,EAAWG,EAAQ,SAAS,EACjE,KAIIC,GAAoBC,EAAeC,IAA8C,CAC5F,GAAIA,EAAU,SAAW,EAAG,MAAO,GACnC,IAAMC,EAAQC,GAAiD,CAC7D,IAAMC,EAASD,GAAS,OACxB,GAAI,CAACC,EAAQ,MAAO,GACpB,GAAIA,EAAO,OAAS,gCAAkCA,EAAO,OAAQ,CACnE,IAAMR,EAAOC,EAAcO,EAAO,MAAM,EACxC,GAAIR,IAAS,MAAQK,EAAU,SAASL,CAAI,EAAG,MAAO,EACxD,CACA,OAAOM,EAAKE,CAAM,CACpB,EACA,OAAOF,EAAKF,CAAI,CAClB,E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-functype",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.201.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",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@types/node": "^24.19.2",
|
|
43
43
|
"@typescript-eslint/rule-tester": "^8.72.2",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"functype": "^2.
|
|
46
|
-
"ts-builds": "^
|
|
45
|
+
"functype": "^2.1.0",
|
|
46
|
+
"ts-builds": "^5.0.0",
|
|
47
47
|
"tsdown": "^0.23.7"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|