@antelopejs/tooling-configs 0.7.0 → 0.7.2

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.
@@ -1518,7 +1518,7 @@ const noReadThenInsertRule = defineRule({
1518
1518
  });
1519
1519
  //#endregion
1520
1520
  //#region src/oxc/guardrails/self-package.ts
1521
- function isObject(value) {
1521
+ function isObject$1(value) {
1522
1522
  return typeof value === "object" && value !== null && !Array.isArray(value);
1523
1523
  }
1524
1524
  function isText(value) {
@@ -1531,12 +1531,12 @@ function readManifest(directory) {
1531
1531
  } catch {
1532
1532
  return;
1533
1533
  }
1534
- if (!isObject(parsed) || !isText(parsed.name)) return void 0;
1534
+ if (!isObject$1(parsed) || !isText(parsed.name)) return void 0;
1535
1535
  const { antelopeJs } = parsed;
1536
1536
  return {
1537
1537
  name: parsed.name,
1538
1538
  exports: parsed.exports,
1539
- testedByAjs: isObject(antelopeJs) && isText(antelopeJs.test)
1539
+ testedByAjs: isObject$1(antelopeJs) && isText(antelopeJs.test)
1540
1540
  };
1541
1541
  }
1542
1542
  /** The nearest enclosing package that has a name, with the directory holding its manifest. */
@@ -1559,7 +1559,7 @@ function selfSubpath(name, specifier) {
1559
1559
  return specifier.startsWith(`${name}/`) ? `./${specifier.slice(name.length + 1)}` : void 0;
1560
1560
  }
1561
1561
  function exportKeys(exportsField) {
1562
- if (!isObject(exportsField)) return ["."];
1562
+ if (!isObject$1(exportsField)) return ["."];
1563
1563
  const keys = Object.keys(exportsField);
1564
1564
  return keys.some((key) => key.startsWith(".")) ? keys : ["."];
1565
1565
  }
@@ -1816,6 +1816,7 @@ function automaticTypes(config) {
1816
1816
  //#region src/oxc/guardrails/vue-script.ts
1817
1817
  const BLOCK = /<!--[\s\S]*?-->|(<script\b(?:"[^"]*"|'[^']*'|[^>"'])*>)([\s\S]*?)(?=<\/script\s*>)/giu;
1818
1818
  const GENERIC = /\sgeneric\s*=/iu;
1819
+ const TSX = /\slang\s*=\s*["']?tsx["'\s>]/iu;
1819
1820
  const MODULE = "\nexport {};\n";
1820
1821
  function blank(text) {
1821
1822
  return Array.from(text, (character) => character === "\n" || character === "\r" ? character : " ".repeat(character.length)).join("");
@@ -1839,6 +1840,33 @@ function scriptView(sfc) {
1839
1840
  }
1840
1841
  return end === 0 ? void 0 : `${view}${blank(sfc.slice(end))}${MODULE}`;
1841
1842
  }
1843
+ /** Whether a script block of the component declares `lang="tsx"`, which Vue then requires of each of its script blocks, so its script view holds JSX. */
1844
+ function isTsx(sfc) {
1845
+ return Array.from(sfc.matchAll(BLOCK)).some(({ 1: open }) => open !== void 0 && TSX.test(open));
1846
+ }
1847
+ /**
1848
+ * The text to type for a linted file. A component whose linted text holds no
1849
+ * script block, as oxlint passes a component's script alone, is read whole
1850
+ * from disk, and `offset` is where that script starts inside the block whose
1851
+ * contents it is, which oxlint passes trimmed. Undefined for a component with no such block, or that
1852
+ * declares `generic` type parameters.
1853
+ */
1854
+ function lintedSource(filename, text) {
1855
+ if (!filename.endsWith(".vue")) return {
1856
+ text,
1857
+ offset: 0
1858
+ };
1859
+ if (scriptView(text) !== void 0) return declaresTypeParameters(text) ? void 0 : {
1860
+ text,
1861
+ offset: 0
1862
+ };
1863
+ const component = readFileSync(filename, "utf8");
1864
+ const block = Array.from(component.matchAll(BLOCK)).find(({ 1: open, 2: content }) => open !== void 0 && content?.trim() === text.trim());
1865
+ return block?.[1] === void 0 || block[2] === void 0 || declaresTypeParameters(component) ? void 0 : {
1866
+ text: component,
1867
+ offset: block.index + block[1].length + block[2].indexOf(text)
1868
+ };
1869
+ }
1842
1870
  /** Whether a script block of the component declares type parameters with `generic`, which only Vue's compiler brings into scope, so the view types them as error types. */
1843
1871
  function declaresTypeParameters(sfc) {
1844
1872
  return Array.from(sfc.matchAll(BLOCK)).some(({ 1: open }) => open !== void 0 && GENERIC.test(open));
@@ -1856,12 +1884,33 @@ function isVue(path) {
1856
1884
  }
1857
1885
  /** A file as the program reads it: a component as its script view, undefined when it has none, and any other file as written. */
1858
1886
  function viewOf(path, text) {
1859
- return isVue(path) ? scriptView(text) : text;
1887
+ if (!isVue(path)) return {
1888
+ text,
1889
+ tsx: false
1890
+ };
1891
+ const view = scriptView(text);
1892
+ return view === void 0 ? void 0 : {
1893
+ text: view,
1894
+ tsx: isTsx(text)
1895
+ };
1896
+ }
1897
+ /** The TSX component views, parsed outside {@link documents}, which keeps one parse kind per path and fails on a path whose script changes between `lang="ts"` and `lang="tsx"`. */
1898
+ const tsxViews = /* @__PURE__ */ new Map();
1899
+ function tsxView(name, text, language) {
1900
+ const cached = tsxViews.get(name);
1901
+ if (cached?.text === text) return cached;
1902
+ const parsed = ts.createSourceFile(name, text, language, true, ts.ScriptKind.TSX);
1903
+ tsxViews.set(name, parsed);
1904
+ return parsed;
1860
1905
  }
1861
1906
  function readView(host, name) {
1862
1907
  const text = host.readFile(name);
1863
1908
  return text === void 0 ? void 0 : viewOf(name, text);
1864
1909
  }
1910
+ /** Whether `sourceFile` is `view` parsed as its kind, JSX read as JSX. */
1911
+ function parses(sourceFile, view) {
1912
+ return sourceFile?.text === view.text && sourceFile.languageVariant === ts.LanguageVariant.JSX === view.tsx;
1913
+ }
1865
1914
  function build(config, path, view) {
1866
1915
  const parsed = project(config);
1867
1916
  if (parsed === void 0) return void 0;
@@ -1873,7 +1922,8 @@ function build(config, path, view) {
1873
1922
  const host = ts.createCompilerHost(options, true);
1874
1923
  host.getSourceFile = (name, language) => {
1875
1924
  const content = normalize(name) === path ? view : readView(host, name);
1876
- return content === void 0 ? void 0 : documents.acquireDocument(name, options, ts.ScriptSnapshot.fromString(content), content, void 0, language);
1925
+ if (content === void 0) return void 0;
1926
+ return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name, options, ts.ScriptSnapshot.fromString(content.text), content.text, void 0, language);
1877
1927
  };
1878
1928
  const program = ts.createProgram({
1879
1929
  rootNames,
@@ -1897,7 +1947,7 @@ function typedFile(file, text) {
1897
1947
  const view = viewOf(path, text);
1898
1948
  if (view === void 0) return void 0;
1899
1949
  const cached = programs.get(config);
1900
- const program = cached?.getSourceFile(path)?.text === view ? cached : build(config, path, view);
1950
+ const program = parses(cached?.getSourceFile(path), view) ? cached : build(config, path, view);
1901
1951
  const sourceFile = program?.getSourceFile(path);
1902
1952
  return program && sourceFile ? {
1903
1953
  checker: program.getTypeChecker(),
@@ -1963,12 +2013,12 @@ function resultIsAwaited(fn) {
1963
2013
  const call = fn.parent;
1964
2014
  return call?.type === "CallExpression" && call.arguments.some((argument) => argument === fn) && isPromiseCallback(call);
1965
2015
  }
1966
- /** Whether `call` calls the first parameter of a function it sits in, as a `new Promise` executor calls its `resolve`. */
2016
+ /** Whether `call` calls the first parameter after any `this` parameter of a function it sits in, as a `new Promise` executor calls its `resolve`. */
1967
2017
  function callsFirstParameter(call) {
1968
2018
  const { callee } = call;
1969
2019
  if (callee.type !== "Identifier") return false;
1970
2020
  for (let fn = enclosingFunction(call); fn !== null; fn = enclosingFunction(fn)) {
1971
- const [first] = fn.params;
2021
+ const first = fn.params.find((param) => param.type !== "Identifier" || param.name !== "this");
1972
2022
  const name = first?.type === "AssignmentPattern" ? first.left : first;
1973
2023
  if (name?.type === "Identifier" && name.name === callee.name) return true;
1974
2024
  }
@@ -1986,21 +2036,24 @@ function isQuery(checker, type) {
1986
2036
  function isTable(checker, type) {
1987
2037
  return declaredIn(checker.getPropertyOfType(type, "insert"), INTERFACE_DATABASE);
1988
2038
  }
1989
- /** Whether `type` is an object literal, or an interface or object type the project declares, as opposed to a class instance or a library type. */
2039
+ /** Whether `type` is an object literal, an interface or object type the project declares, a mapped type such as `Readonly<T>` or `Record<K, V>`, or an intersection of those, as opposed to a class instance or a library type. */
1990
2040
  function isHolder(type) {
2041
+ if (type.isIntersection()) return type.types.every(isHolder);
1991
2042
  const symbol = type.getSymbol();
2043
+ if (symbol?.declarations?.some(ts.isMappedTypeNode) === true) return true;
1992
2044
  return symbol !== void 0 && (symbol.flags & HOLDERS) !== 0 && (symbol.flags & ts.SymbolFlags.Class) === 0 && !declaredIn(symbol, "/node_modules/");
1993
2045
  }
1994
2046
  function members$1(type) {
1995
2047
  return type.isUnion() ? type.types : [type];
1996
2048
  }
1997
- /** The values an array, a tuple or a holder keeps, which awaiting it leaves as they are. */
2049
+ /** The values an array, a tuple or a holder keeps in its properties and index signatures, which awaiting it leaves as they are. */
1998
2050
  function heldValues(checker, type) {
1999
2051
  if (checker.isArrayType(type) || checker.isTupleType(type)) {
2000
2052
  const element = checker.getIndexTypeOfType(type, ts.IndexKind.Number);
2001
2053
  return element === void 0 ? [] : [element];
2002
2054
  }
2003
- return isHolder(type) ? checker.getPropertiesOfType(type).map((property) => checker.getTypeOfSymbol(property)) : [];
2055
+ if (!isHolder(type)) return [];
2056
+ return [...checker.getPropertiesOfType(type).map((property) => checker.getTypeOfSymbol(property)), ...checker.getIndexInfosOfType(type).map((info) => info.type)];
2004
2057
  }
2005
2058
  /** Whether an array, a tuple or a holder of `type` keeps a query other than a table at any depth. */
2006
2059
  function holdsHeldQuery(checker, type, visited) {
@@ -2021,12 +2074,40 @@ function callbackResult(checker, callback) {
2021
2074
  return checker.getTypeAtLocation(callback).getCallSignatures().filter(({ declaration }) => declaration === void 0 || (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Async) === 0).map((signature) => checker.getReturnTypeOfSignature(signature));
2022
2075
  }
2023
2076
  const executorsByFile = /* @__PURE__ */ new WeakMap();
2024
- /** The function a `new Promise` argument names: the function written there, or the function declaration or initialised variable its identifier resolves to. */
2025
- function namedFunction(checker, argument) {
2026
- if (ts.isFunctionExpression(argument) || ts.isArrowFunction(argument)) return argument;
2027
- if (!ts.isIdentifier(argument)) return void 0;
2028
- const declaration = checker.getSymbolAtLocation(argument)?.valueDeclaration;
2029
- return declaration !== void 0 && ts.isVariableDeclaration(declaration) && declaration.initializer !== void 0 ? declaration.initializer : declaration;
2077
+ /** `expression` without the parentheses, `as`, `<T>`, `satisfies` and `!` around it. */
2078
+ function unwrapped(expression) {
2079
+ return ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isNonNullExpression(expression) ? unwrapped(expression.expression) : expression;
2080
+ }
2081
+ /** The function a declaration holds: the initialiser of a variable or property, the value a shorthand property names, or the declaration itself. */
2082
+ function declaredFunctions(checker, declaration) {
2083
+ if (ts.isShorthandPropertyAssignment(declaration)) return (checker.getShorthandAssignmentValueSymbol(declaration)?.declarations ?? []).flatMap((value) => declaredFunctions(checker, value));
2084
+ return (ts.isVariableDeclaration(declaration) || ts.isPropertyDeclaration(declaration) || ts.isPropertyAssignment(declaration)) && declaration.initializer !== void 0 ? [unwrapped(declaration.initializer)] : [declaration];
2085
+ }
2086
+ /** `value` as a member access the source names, or `undefined` for any other expression. */
2087
+ function namedMember(value) {
2088
+ if (ts.isPropertyAccessExpression(value)) return {
2089
+ receiver: value.expression,
2090
+ key: value,
2091
+ name: value.name.text
2092
+ };
2093
+ return ts.isElementAccessExpression(value) && ts.isStringLiteralLike(value.argumentExpression) ? {
2094
+ receiver: value.expression,
2095
+ key: value.argumentExpression,
2096
+ name: value.argumentExpression.text
2097
+ } : void 0;
2098
+ }
2099
+ /** The declarations of `member` on the value its receiver variable is initialised with, past any type annotation that names only a signature. */
2100
+ function initialisedMember(checker, member) {
2101
+ const receiver = ts.isIdentifier(member.receiver) ? checker.getSymbolAtLocation(member.receiver)?.valueDeclaration : void 0;
2102
+ return receiver !== void 0 && ts.isVariableDeclaration(receiver) && receiver.initializer !== void 0 ? checker.getTypeAtLocation(unwrapped(receiver.initializer)).getProperty(member.name)?.declarations ?? [] : [];
2103
+ }
2104
+ /** The functions a `new Promise` argument names: the function written there, or each declaration, overloads included, or initialiser of the variable, property or method its identifier, member access or literal-keyed element access resolves to. */
2105
+ function namedFunctions(checker, argument) {
2106
+ const value = unwrapped(argument);
2107
+ if (ts.isFunctionExpression(value) || ts.isArrowFunction(value)) return [value];
2108
+ const member = namedMember(value);
2109
+ if (!ts.isIdentifier(value) && member === void 0) return [];
2110
+ return [...checker.getSymbolAtLocation(member?.key ?? value)?.declarations ?? [], ...member === void 0 ? [] : initialisedMember(checker, member)].flatMap((declaration) => declaredFunctions(checker, declaration));
2030
2111
  }
2031
2112
  /** The functions `sourceFile` hands to `new Promise` as its executor, inline or by name. */
2032
2113
  function promiseExecutors(checker, sourceFile) {
@@ -2035,19 +2116,18 @@ function promiseExecutors(checker, sourceFile) {
2035
2116
  const executors = /* @__PURE__ */ new Set();
2036
2117
  const visit = (node) => {
2037
2118
  const argument = ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Promise" ? node.arguments?.[0] : void 0;
2038
- const executor = argument && namedFunction(checker, argument);
2039
- if (executor !== void 0) executors.add(executor);
2119
+ for (const executor of argument ? namedFunctions(checker, argument) : []) executors.add(executor);
2040
2120
  ts.forEachChild(node, visit);
2041
2121
  };
2042
2122
  visit(sourceFile);
2043
2123
  executorsByFile.set(sourceFile, executors);
2044
2124
  return executors;
2045
2125
  }
2046
- /** The value `call` resolves its promise with, when its callee is the first parameter of a function the file hands to `new Promise` as its executor. */
2126
+ /** The value `call` resolves its promise with, when its callee is the first parameter after any `this` parameter of a function the file hands to `new Promise` as its executor. */
2047
2127
  function resolvedValue(checker, call) {
2048
2128
  const parameter = checker.getSymbolAtLocation(call.expression)?.valueDeclaration;
2049
2129
  const executor = parameter?.parent;
2050
- return parameter !== void 0 && ts.isParameter(parameter) && executor !== void 0 && ts.isFunctionLike(executor) && executor.parameters[0] === parameter && promiseExecutors(checker, call.getSourceFile()).has(executor) ? call.arguments[0] : void 0;
2130
+ return parameter !== void 0 && ts.isParameter(parameter) && executor !== void 0 && ts.isFunctionLike(executor) && executor.parameters.find(({ name }) => !ts.isIdentifier(name) || name.text !== "this") === parameter && promiseExecutors(checker, call.getSourceFile()).has(executor) ? call.arguments[0] : void 0;
2051
2131
  }
2052
2132
  /** Since interface-database 0.4.0 a query is no longer thenable, so an awaited function that returns one, alone or wrapped, resolves to the unrun query and sends nothing. */
2053
2133
  const noUnrunQueryRule = defineRule({
@@ -2095,6 +2175,611 @@ const noUnrunQueryRule = defineRule({
2095
2175
  }
2096
2176
  });
2097
2177
  //#endregion
2178
+ //#region src/oxc/guardrails/any-leaks.ts
2179
+ const UNTYPED$1 = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
2180
+ /** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
2181
+ function isAnyType(checker, type) {
2182
+ return type === checker.getAnyType();
2183
+ }
2184
+ /** Whether `type` is `unknown`. */
2185
+ function isUnknown(type) {
2186
+ return type !== void 0 && (type.flags & ts.TypeFlags.Unknown) !== 0;
2187
+ }
2188
+ /** The element type of an array or a readonly array, whether or not an alias names it, `undefined` for another type. */
2189
+ function arrayElement(checker, type) {
2190
+ return checker.isArrayType(type) ? checker.getIndexTypeOfType(type, ts.IndexKind.Number) : void 0;
2191
+ }
2192
+ /** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
2193
+ function takesAnything(type) {
2194
+ return type === void 0 || (type.flags & UNTYPED$1) !== 0;
2195
+ }
2196
+ /** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
2197
+ function isObjectType(type) {
2198
+ return (type.flags & ts.TypeFlags.Object) !== 0;
2199
+ }
2200
+ /** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
2201
+ function isReference$1(type) {
2202
+ return (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
2203
+ }
2204
+ /**
2205
+ * The generic reference `type` is, such as `Set<any>`, `any[]` or a tuple,
2206
+ * for comparing by its generic target as tsgolint does. A deferred reference,
2207
+ * such as one a type alias names as in `type AA = any[]` or `G<any>`, is not
2208
+ * compared, as tsgolint compares only references that are not deferred.
2209
+ */
2210
+ function reference(type) {
2211
+ return isObjectType(type) && isReference$1(type) && type.node === void 0 ? type : void 0;
2212
+ }
2213
+ /** Whether `node` is `new Map()`, which the lib types `Map<any, any>` and tsgolint lets into any `Map`. */
2214
+ function isEmptyMap(node) {
2215
+ return node !== void 0 && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Map" && node.typeArguments === void 0 && (node.arguments === void 0 || node.arguments.length === 0);
2216
+ }
2217
+ /**
2218
+ * Whether a `sender` value lets `any` into a `receiver` slot as an argument,
2219
+ * an assignment or a type argument: `any` into a slot that is undeclared or
2220
+ * typed neither `any` nor `unknown`, or a generic reference holding `any`, as
2221
+ * in `any[]` or `Set<any>`, into one of the same generic target, such as
2222
+ * `string[]` or `Set<string>`, with another type in that position. `readonly`
2223
+ * and labelled tuples have targets of their own, and `node`, the expression
2224
+ * that sends the value, lets `new Map()` in. A pair of types is compared once,
2225
+ * however deep, as tsgolint compares it.
2226
+ */
2227
+ function leaks(checker, sender, receiver, node) {
2228
+ if (isEmptyMap(node)) return false;
2229
+ const compared = /* @__PURE__ */ new Map();
2230
+ function compare(from, to) {
2231
+ if (isAnyType(checker, from)) return to === void 0 || !takesAnything(to);
2232
+ if (to === void 0) return false;
2233
+ const seen = compared.get(from) ?? /* @__PURE__ */ new Set();
2234
+ if (seen.has(to)) return false;
2235
+ compared.set(from, seen.add(to));
2236
+ const sent = reference(from);
2237
+ const slot = reference(to);
2238
+ if (sent === void 0 || slot === void 0 || sent.target !== slot.target) return false;
2239
+ const slots = checker.getTypeArguments(slot);
2240
+ return checker.getTypeArguments(sent).some((argument, index) => compare(argument, slots[index]));
2241
+ }
2242
+ return compare(sender, receiver);
2243
+ }
2244
+ /** Whether `type` is `any` or an array of `any`, as a spread or rest holds it. */
2245
+ function isAnyOrAnyArray(checker, type) {
2246
+ const element = arrayElement(checker, type);
2247
+ return isAnyType(checker, type) || element !== void 0 && isAnyType(checker, element);
2248
+ }
2249
+ //#endregion
2250
+ //#region src/oxc/guardrails/any-arguments.ts
2251
+ function isTupleTarget(target) {
2252
+ return (target.objectFlags & ts.ObjectFlags.Tuple) !== 0;
2253
+ }
2254
+ function tupleOf(type) {
2255
+ if (!isObjectType(type) || !isReference$1(type)) return void 0;
2256
+ const { target } = type;
2257
+ return isTupleTarget(target) ? {
2258
+ reference: type,
2259
+ target
2260
+ } : void 0;
2261
+ }
2262
+ function restOf(checker, type, index) {
2263
+ const element = arrayElement(checker, type);
2264
+ if (element !== void 0) return {
2265
+ kind: "element",
2266
+ type: element
2267
+ };
2268
+ const tuple = tupleOf(type);
2269
+ return tuple === void 0 ? {
2270
+ kind: "element",
2271
+ type
2272
+ } : {
2273
+ kind: "tuple",
2274
+ types: checker.getTypeArguments(tuple.reference),
2275
+ index
2276
+ };
2277
+ }
2278
+ function calleeOf(call) {
2279
+ return ts.isTaggedTemplateExpression(call) ? call.tag : call.expression;
2280
+ }
2281
+ function argumentsOf(call) {
2282
+ if (!ts.isTaggedTemplateExpression(call)) return call.arguments ?? [];
2283
+ return ts.isTemplateExpression(call.template) ? call.template.templateSpans.map((span) => span.expression) : [];
2284
+ }
2285
+ function parameterCursor(checker, call, signature) {
2286
+ const fixed = [];
2287
+ let rest;
2288
+ for (const [index, parameter] of signature.getParameters().entries()) {
2289
+ const type = checker.getTypeOfSymbolAtLocation(parameter, call);
2290
+ const declaration = parameter.getDeclarations()?.[0];
2291
+ if (declaration !== void 0 && ts.isParameter(declaration) && declaration.dotDotDotToken !== void 0) {
2292
+ rest = restOf(checker, type, index);
2293
+ break;
2294
+ }
2295
+ fixed.push(type);
2296
+ }
2297
+ let position = 0;
2298
+ let consumed = false;
2299
+ return {
2300
+ next() {
2301
+ const index = position;
2302
+ position += 1;
2303
+ if (index < fixed.length && !consumed) return fixed[index];
2304
+ if (rest === void 0) return void 0;
2305
+ if (rest.kind === "element") return rest.type;
2306
+ const last = rest.types.at(-1);
2307
+ return consumed ? last : rest.types[index - rest.index] ?? last;
2308
+ },
2309
+ consumeRest() {
2310
+ consumed = true;
2311
+ }
2312
+ };
2313
+ }
2314
+ /**
2315
+ * The arguments of `call` that pass `any` to a typed parameter, as
2316
+ * `typescript/no-unsafe-argument` reports them: each argument against the
2317
+ * parameter it fills, a spread `any` or `any[]` once, and each element of a
2318
+ * spread tuple against the parameter that element fills, so one spread can be
2319
+ * reported once per element. The substitutions of a tagged template fill the
2320
+ * parameters after the one its template strings fill. A call whose callee is
2321
+ * `any` is left alone.
2322
+ */
2323
+ function unsafeArguments(checker, call) {
2324
+ const args = argumentsOf(call);
2325
+ if (args.length === 0 || isAnyType(checker, checker.getTypeAtLocation(calleeOf(call)))) return [];
2326
+ const signature = checker.getResolvedSignature(call);
2327
+ if (signature === void 0) return [];
2328
+ const cursor = parameterCursor(checker, call, signature);
2329
+ if (ts.isTaggedTemplateExpression(call)) cursor.next();
2330
+ return args.flatMap((argument) => {
2331
+ if (!ts.isSpreadElement(argument)) {
2332
+ const parameter = cursor.next();
2333
+ return parameter !== void 0 && leaks(checker, checker.getTypeAtLocation(argument), parameter, argument) ? [argument] : [];
2334
+ }
2335
+ const spread = checker.getTypeAtLocation(argument.expression);
2336
+ if (isAnyOrAnyArray(checker, spread)) return [argument];
2337
+ const tuple = tupleOf(spread);
2338
+ if (tuple === void 0) return [];
2339
+ const unsafe = checker.getTypeArguments(tuple.reference).flatMap((element) => {
2340
+ const parameter = cursor.next();
2341
+ return parameter !== void 0 && leaks(checker, element, parameter) ? [argument] : [];
2342
+ });
2343
+ if ((tuple.target.combinedFlags & ts.ElementFlags.Variable) !== 0) cursor.consumeRest();
2344
+ return unsafe;
2345
+ });
2346
+ }
2347
+ //#endregion
2348
+ //#region src/oxc/guardrails/type-order.ts
2349
+ function isObject(type) {
2350
+ return (type.flags & ts.TypeFlags.Object) !== 0;
2351
+ }
2352
+ function isReference(type) {
2353
+ return isObject(type) && (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
2354
+ }
2355
+ function compareText(a, b) {
2356
+ if (a === b) return 0;
2357
+ return a < b ? -1 : 1;
2358
+ }
2359
+ /** The symbol tsgo orders a type by name: its alias's, or its own for a type parameter, a class, an interface or a reference. */
2360
+ function nameSymbol(type) {
2361
+ if (type.aliasSymbol !== void 0) return type.aliasSymbol;
2362
+ return (type.flags & ts.TypeFlags.TypeParameter) !== 0 || isObject(type) && (type.objectFlags & (ts.ObjectFlags.ClassOrInterface | ts.ObjectFlags.Reference)) !== 0 ? type.getSymbol() : void 0;
2363
+ }
2364
+ /** Nodes by position in one file. Nodes in different files compare equal, as the order tsgo gives its program's files is not this program's. */
2365
+ function compareNodes(a, b) {
2366
+ if (a === b) return 0;
2367
+ if (a === void 0) return 1;
2368
+ if (b === void 0) return -1;
2369
+ return a.getSourceFile() === b.getSourceFile() ? a.pos - b.pos : 0;
2370
+ }
2371
+ function compareSymbols(a, b) {
2372
+ if (a === b) return 0;
2373
+ if (a === void 0) return 1;
2374
+ if (b === void 0) return -1;
2375
+ const first = a.declarations?.[0];
2376
+ const second = b.declarations?.[0];
2377
+ if (first !== void 0 && second !== void 0) {
2378
+ const byNode = compareNodes(first, second);
2379
+ if (byNode !== 0) return byNode;
2380
+ } else if (first !== void 0) return -1;
2381
+ else if (second !== void 0) return 1;
2382
+ return compareText(a.name, b.name);
2383
+ }
2384
+ /**
2385
+ * The order tsgo, the checker tsgolint runs, gives the members of a union:
2386
+ * by type flags, then named types by name, unnamed ones after them, then
2387
+ * object types by their symbol's declaration, references first, and
2388
+ * intersections by their members. Where tsgo falls back to type creation
2389
+ * order this keeps the order the types already have, as a TypeScript 6 union
2390
+ * lists its members in creation order. So does a tie tsgo breaks with data
2391
+ * TypeScript 6 keeps internal: the type mappers of two instantiations of one
2392
+ * anonymous type, and the file order of tsgo's program.
2393
+ */
2394
+ function typeOrder(checker) {
2395
+ function compareLists(a, b) {
2396
+ const first = a ?? [];
2397
+ const second = b ?? [];
2398
+ if (first.length !== second.length) return first.length - second.length;
2399
+ for (const [index, type] of first.entries()) {
2400
+ const other = second[index];
2401
+ const order = other === void 0 ? 0 : compare(type, other);
2402
+ if (order !== 0) return order;
2403
+ }
2404
+ return 0;
2405
+ }
2406
+ function compareNames(a, b) {
2407
+ const first = nameSymbol(a);
2408
+ const second = nameSymbol(b);
2409
+ if (first === second) return a.aliasSymbol === void 0 ? 0 : compareLists(a.aliasTypeArguments, b.aliasTypeArguments);
2410
+ if (first === void 0) return 1;
2411
+ if (second === void 0) return -1;
2412
+ return compareText(first.name, second.name);
2413
+ }
2414
+ function compareObjects(a, b) {
2415
+ const bySymbol = compareSymbols(a.getSymbol(), b.getSymbol());
2416
+ if (bySymbol !== 0) return bySymbol;
2417
+ if (isReference(a) && isReference(b)) return a.node === void 0 && b.node === void 0 ? compareLists(checker.getTypeArguments(a), checker.getTypeArguments(b)) : compareNodes(a.node, b.node);
2418
+ if (isReference(a)) return -1;
2419
+ return isReference(b) ? 1 : 0;
2420
+ }
2421
+ function compare(a, b) {
2422
+ if (a === b) return 0;
2423
+ if (a.flags !== b.flags) return a.flags - b.flags;
2424
+ const byName = compareNames(a, b);
2425
+ if (byName !== 0) return byName;
2426
+ if (isObject(a) && isObject(b)) return compareObjects(a, b);
2427
+ if (a.isUnionOrIntersection() && b.isUnionOrIntersection()) return compareLists(a.types, b.types);
2428
+ if (a.isStringLiteral() && b.isStringLiteral()) return compareText(a.value, b.value);
2429
+ return a.isNumberLiteral() && b.isNumberLiteral() ? a.value - b.value : 0;
2430
+ }
2431
+ return compare;
2432
+ }
2433
+ //#endregion
2434
+ //#region src/oxc/guardrails/any-returns.ts
2435
+ function anyKind(checker, type) {
2436
+ if (isAnyType(checker, type)) return "any";
2437
+ const element = arrayElement(checker, type);
2438
+ if (element !== void 0 && isAnyType(checker, element)) return "any[]";
2439
+ return (type.isUnionOrIntersection() ? type.types : [type]).some((part) => {
2440
+ const awaited = checker.getAwaitedType(part);
2441
+ return awaited !== void 0 && isAnyType(checker, awaited);
2442
+ }) ? "Promise<any>" : "safe";
2443
+ }
2444
+ /** The function a returned `value` leaves. */
2445
+ function ownerOf(value) {
2446
+ let owner = value.parent;
2447
+ while (!ts.isFunctionLike(owner)) {
2448
+ if (ts.isSourceFile(owner)) return void 0;
2449
+ owner = owner.parent;
2450
+ }
2451
+ return owner;
2452
+ }
2453
+ /** The type typescript-eslint's `getContextualType` gives a function expression: the parameter's at an argument, the annotation's in an annotated declaration, the target's at the right of an assignment, and none elsewhere, as in an object literal, an array, `as`, `satisfies`, a conditional, parentheses or a return. */
2454
+ function contextOf(checker, node) {
2455
+ const { parent } = node;
2456
+ if (ts.isCallExpression(parent) || ts.isNewExpression(parent)) return parent.expression === node ? void 0 : checker.getContextualType(node);
2457
+ if (ts.isVariableDeclaration(parent) || ts.isPropertyDeclaration(parent) || ts.isParameter(parent)) return parent.type && checker.getTypeFromTypeNode(parent.type);
2458
+ if (ts.isJsxExpression(parent)) return checker.getContextualType(parent);
2459
+ if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.right === node) return checker.getTypeAtLocation(parent.left);
2460
+ return ts.isTemplateSpan(parent) ? checker.getContextualType(node) : void 0;
2461
+ }
2462
+ /** The type whose call signatures declare what `owner` returns: a function expression's context, else its own type, as for a declaration, whose overloads leave its implementation out, or a getter, whose type is its property's and has no signature. */
2463
+ function declaringType(checker, owner) {
2464
+ return (ts.isArrowFunction(owner) || ts.isFunctionExpression(owner) ? contextOf(checker, owner) : void 0) ?? checker.getTypeAtLocation(owner);
2465
+ }
2466
+ /** The call signatures of `type` as tsgolint lists them: each union member's in turn, in the order {@link typeOrder} gives them, and an intersection's only when one member alone is callable. */
2467
+ function callSignatures(checker, type) {
2468
+ if (type.isUnion()) return type.types.toSorted(typeOrder(checker)).flatMap((member) => callSignatures(checker, member));
2469
+ if (!type.isIntersection()) return type.getCallSignatures();
2470
+ const callable = type.types.map((member) => callSignatures(checker, member)).filter((signatures) => signatures.length > 0);
2471
+ return callable.length === 1 ? callable[0] ?? [] : [];
2472
+ }
2473
+ /** Whether a declared return in `returns` excuses an annotated function returning `sender`: the type itself, `any` or `unknown`, or, for an async function, one whose awaited type is the awaited `sender`, `any` or `unknown`. */
2474
+ function annotationExcuses(checker, sender, returns, isAsync) {
2475
+ return returns.some((declared) => {
2476
+ if (declared === sender || takesAnything(declared)) return true;
2477
+ if (!isAsync) return false;
2478
+ const awaited = checker.getAwaitedType(declared);
2479
+ return awaited === checker.getAwaitedType(sender) || awaited !== void 0 && takesAnything(awaited);
2480
+ });
2481
+ }
2482
+ /** Whether a declared return in `returns` excuses a returned `any`, `any[]` or `Promise<any>`: `unknown`, `unknown[]` or a promise of `unknown`, each read without awaiting the declared return, or a `Promise<any>` that a function not async returns. */
2483
+ function anyExcuses(checker, kind, returns, isAsync) {
2484
+ if (kind === "Promise<any>" && !isAsync) return true;
2485
+ return returns.some((declared) => {
2486
+ if (kind === "any") return isUnknown(declared);
2487
+ if (kind === "any[]") return isUnknown(arrayElement(checker, declared));
2488
+ return isUnknown(checker.getAwaitedType(declared));
2489
+ });
2490
+ }
2491
+ /**
2492
+ * Whether returning `value` lets `any` out, as `typescript/no-unsafe-return`
2493
+ * judges it: by the call signatures of the type that declares the function's
2494
+ * return, a function expression's context or the function's own type. An own
2495
+ * annotation is excused when a signature returns that type, `any` or
2496
+ * `unknown`. An `any`, `any[]` or `Promise<any>` is reported unless a
2497
+ * signature returns `unknown`, `unknown[]` or `Promise<unknown>`, and another
2498
+ * type is compared with the first signature by {@link leaks}.
2499
+ */
2500
+ function returnLeaks(checker, value) {
2501
+ const owner = ownerOf(value);
2502
+ if (owner === void 0) return false;
2503
+ const sender = checker.getTypeAtLocation(value);
2504
+ const returns = callSignatures(checker, declaringType(checker, owner)).map((signature) => signature.getReturnType());
2505
+ const isAsync = ts.canHaveModifiers(owner) && (ts.getModifiers(owner)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) ?? false);
2506
+ if (owner.type !== void 0 && annotationExcuses(checker, sender, returns, isAsync)) return false;
2507
+ const kind = anyKind(checker, sender);
2508
+ return kind === "safe" ? leaks(checker, sender, returns[0], value) : !anyExcuses(checker, kind, returns, isAsync);
2509
+ }
2510
+ //#endregion
2511
+ //#region src/oxc/guardrails/rules/no-unsafe-any-in-vue.ts
2512
+ /** Whether `value` lets `any` into an assigned `receiver`: `any` into anything but `unknown`, a slot declared `any` included, or what {@link leaks} finds. */
2513
+ function assignmentLeaks(checker, value, receiver) {
2514
+ const sender = checker.getTypeAtLocation(value);
2515
+ return isAnyType(checker, sender) ? !isUnknown(receiver) : leaks(checker, sender, receiver, value);
2516
+ }
2517
+ /** Whether `value`, flowing into the slot its context declares, lets `any` in. */
2518
+ function leaksIntoContext(checker, value) {
2519
+ return assignmentLeaks(checker, value, checker.getContextualType(value));
2520
+ }
2521
+ /** Whether `literal` is the target of a destructuring assignment, as in `({ a } = value)`, whose elements name targets, not values. */
2522
+ function isDestructuringTarget(literal) {
2523
+ let child = literal;
2524
+ let parent = literal.parent;
2525
+ while (ts.isParenthesizedExpression(parent) || ts.isArrayLiteralExpression(parent) || ts.isObjectLiteralExpression(parent) || ts.isPropertyAssignment(parent) || ts.isShorthandPropertyAssignment(parent) || ts.isSpreadElement(parent) || ts.isSpreadAssignment(parent)) {
2526
+ child = parent;
2527
+ parent = parent.parent;
2528
+ }
2529
+ return ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === child || (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === child;
2530
+ }
2531
+ function returned(checker, value) {
2532
+ return returnLeaks(checker, value) ? [{
2533
+ kind: "return",
2534
+ node: value
2535
+ }] : [];
2536
+ }
2537
+ /** An `any` or `any[]` spread into an array literal that is not a destructuring target. A spread into a call is an argument, which {@link unsafeArguments} judges. */
2538
+ function spreadFindings(checker, spread) {
2539
+ return ts.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
2540
+ kind: "assignment",
2541
+ node: spread
2542
+ }] : [];
2543
+ }
2544
+ function propertyFindings(checker, property) {
2545
+ if (isDestructuringTarget(property.parent)) {
2546
+ const fallback = ts.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
2547
+ return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
2548
+ kind: "assignment",
2549
+ node: property
2550
+ }] : [];
2551
+ }
2552
+ return leaksIntoContext(checker, ts.isPropertyAssignment(property) ? property.initializer : property.name) ? [{
2553
+ kind: "assignment",
2554
+ node: property
2555
+ }] : [];
2556
+ }
2557
+ function isPattern(node) {
2558
+ return ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node) || ts.isObjectLiteralExpression(node) || ts.isArrayLiteralExpression(node);
2559
+ }
2560
+ /** The key a property name spells, a computed literal such as `['a']` included. */
2561
+ function literalKey(name) {
2562
+ if (ts.isIdentifier(name)) return name.text;
2563
+ const key = ts.isComputedPropertyName(name) ? name.expression : name;
2564
+ return ts.isStringLiteral(key) || ts.isNumericLiteral(key) || ts.isNoSubstitutionTemplateLiteral(key) ? key.text : void 0;
2565
+ }
2566
+ /** The target and default of an assignment pattern element, as in `a = fallback`. */
2567
+ function withDefault(element) {
2568
+ return ts.isBinaryExpression(element) && element.operatorToken.kind === ts.SyntaxKind.EqualsToken ? {
2569
+ target: element.left,
2570
+ initializer: element.right
2571
+ } : {
2572
+ target: element,
2573
+ initializer: void 0
2574
+ };
2575
+ }
2576
+ function objectElements(pattern) {
2577
+ if (ts.isObjectBindingPattern(pattern)) return pattern.elements.map((element) => ({
2578
+ key: element.dotDotDotToken === void 0 ? literalKey(element.propertyName ?? element.name) : void 0,
2579
+ target: element.name,
2580
+ initializer: element.initializer,
2581
+ node: element
2582
+ }));
2583
+ return pattern.properties.map((property) => {
2584
+ if (ts.isPropertyAssignment(property)) return {
2585
+ key: literalKey(property.name),
2586
+ ...withDefault(property.initializer),
2587
+ node: property
2588
+ };
2589
+ if (ts.isShorthandPropertyAssignment(property)) return {
2590
+ key: property.name.text,
2591
+ target: property.name,
2592
+ initializer: property.objectAssignmentInitializer,
2593
+ node: property
2594
+ };
2595
+ return {
2596
+ key: void 0,
2597
+ target: property,
2598
+ initializer: void 0,
2599
+ node: property
2600
+ };
2601
+ });
2602
+ }
2603
+ function arrayElements(pattern) {
2604
+ return pattern.elements.flatMap((element, index) => {
2605
+ if (ts.isOmittedExpression(element)) return [];
2606
+ if (ts.isBindingElement(element)) return [{
2607
+ key: element.dotDotDotToken === void 0 ? String(index) : void 0,
2608
+ target: element.name,
2609
+ initializer: element.initializer,
2610
+ node: element
2611
+ }];
2612
+ if (ts.isSpreadElement(element)) return [{
2613
+ key: void 0,
2614
+ target: element.expression,
2615
+ initializer: void 0,
2616
+ node: element
2617
+ }];
2618
+ return [{
2619
+ key: String(index),
2620
+ ...withDefault(element),
2621
+ node: element
2622
+ }];
2623
+ });
2624
+ }
2625
+ /** An element that takes an `any` its source declares, and the elements nested under one with no default, as a nested pattern with a default reads that default. */
2626
+ function elementFindings(checker, element, source) {
2627
+ if (isAnyType(checker, source)) return [{
2628
+ kind: "assignment",
2629
+ node: element.node
2630
+ }];
2631
+ return element.initializer === void 0 && isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
2632
+ }
2633
+ /** The property or tuple slot named `key` that `source` declares, not one an index signature stands for. */
2634
+ function declaredSlot(checker, source, key, at) {
2635
+ const slot = checker.getPropertyOfType(source, key);
2636
+ return slot === void 0 ? void 0 : checker.getTypeOfSymbolAtLocation(slot, at);
2637
+ }
2638
+ function slotFindings(checker, element, source) {
2639
+ const slot = element.key === void 0 ? void 0 : declaredSlot(checker, source, element.key, element.node);
2640
+ return slot === void 0 ? [] : elementFindings(checker, element, slot);
2641
+ }
2642
+ /**
2643
+ * The elements of an untyped destructuring declaration or of a destructuring
2644
+ * assignment that take `any` from what `source` declares: a property or
2645
+ * tuple slot typed `any`, whatever the target's own type, or the whole
2646
+ * pattern once when it reads an `any[]`. An index signature, another iterable
2647
+ * and a rest from an object or a tuple are left alone, as
2648
+ * `typescript/no-unsafe-assignment` leaves them.
2649
+ */
2650
+ function destructuredFindings(checker, pattern, source) {
2651
+ if (ts.isObjectBindingPattern(pattern) || ts.isObjectLiteralExpression(pattern)) return objectElements(pattern).flatMap((element) => slotFindings(checker, element, source));
2652
+ if (isAnyOrAnyArray(checker, source)) return [{
2653
+ kind: "assignment",
2654
+ node: pattern
2655
+ }];
2656
+ return checker.isTupleType(source) ? arrayElements(pattern).flatMap((element) => slotFindings(checker, element, source)) : [];
2657
+ }
2658
+ /** The elements a pattern `name`, annotated or not, takes `any` into from `initializer`. */
2659
+ function bindingFindings(checker, name, initializer) {
2660
+ const source = checker.getTypeAtLocation(initializer);
2661
+ return ts.isIdentifier(name) ? [] : destructuredFindings(checker, name, source);
2662
+ }
2663
+ function declarationFindings(checker, node, initializer) {
2664
+ return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
2665
+ kind: "assignment",
2666
+ node
2667
+ }] : bindingFindings(checker, node.name, initializer);
2668
+ }
2669
+ /** A JSX attribute whose value lets `any` into the prop it fills. */
2670
+ function attributeFindings(checker, attribute) {
2671
+ const value = attribute.initializer !== void 0 && ts.isJsxExpression(attribute.initializer) ? attribute.initializer.expression : void 0;
2672
+ return value !== void 0 && leaksIntoContext(checker, value) ? [{
2673
+ kind: "assignment",
2674
+ node: value
2675
+ }] : [];
2676
+ }
2677
+ /** A class field whose initializer lets `any` in: against its annotation, or whatever its type when it has none. */
2678
+ function fieldFindings(checker, field) {
2679
+ return field.initializer !== void 0 && assignmentLeaks(checker, field.initializer, field.type && checker.getTypeAtLocation(field.name)) ? [{
2680
+ kind: "assignment",
2681
+ node: field
2682
+ }] : [];
2683
+ }
2684
+ function assignmentFindings(checker, node) {
2685
+ if (ts.isVariableDeclaration(node) && node.initializer !== void 0) return declarationFindings(checker, node, node.initializer);
2686
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2687
+ if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
2688
+ kind: "assignment",
2689
+ node
2690
+ }];
2691
+ return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
2692
+ }
2693
+ if (ts.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
2694
+ kind: "assignment",
2695
+ node
2696
+ }] : bindingFindings(checker, node.name, node.initializer);
2697
+ if (ts.isBindingElement(node) && node.initializer !== void 0) return assignmentLeaks(checker, node.initializer, checker.getTypeAtLocation(node.name)) ? [{
2698
+ kind: "assignment",
2699
+ node
2700
+ }] : bindingFindings(checker, node.name, node.initializer);
2701
+ if (ts.isJsxAttribute(node)) return attributeFindings(checker, node);
2702
+ if (ts.isPropertyDeclaration(node)) return fieldFindings(checker, node);
2703
+ if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) return propertyFindings(checker, node);
2704
+ return [];
2705
+ }
2706
+ function nodeFindings(checker, node) {
2707
+ if (ts.isSpreadElement(node)) return spreadFindings(checker, node);
2708
+ if (ts.isCallExpression(node) || ts.isNewExpression(node) || ts.isTaggedTemplateExpression(node)) return unsafeArguments(checker, node).map((argument) => ({
2709
+ kind: "argument",
2710
+ node: argument
2711
+ }));
2712
+ if (ts.isReturnStatement(node) && node.expression !== void 0) return returned(checker, node.expression);
2713
+ if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) return returned(checker, node.body);
2714
+ return assignmentFindings(checker, node);
2715
+ }
2716
+ function findings({ checker, sourceFile }) {
2717
+ const found = [];
2718
+ function visit(node) {
2719
+ found.push(...nodeFindings(checker, node));
2720
+ ts.forEachChild(node, visit);
2721
+ }
2722
+ visit(sourceFile);
2723
+ return found;
2724
+ }
2725
+ /**
2726
+ * `typescript/no-unsafe-assignment`, `no-unsafe-argument` and
2727
+ * `no-unsafe-return` for the script blocks of a `.vue` file, which
2728
+ * oxlint-tsgolint cannot read: an `any`, or a generic such as `any[]` or
2729
+ * `Set<any>` holding one, reaching a declared type
2730
+ * through a declaration, an assignment, an object literal property, a class
2731
+ * field, a JSX attribute in a `lang="tsx"` script, a default value, an
2732
+ * argument, a tagged template substitution, a spread, a tuple spread into
2733
+ * parameters, a destructured binding,
2734
+ * a destructuring assignment such as `({ a } = value)` or a return. An `any`
2735
+ * assigned to a slot declared `any` is reported too, as tsgolint reports it.
2736
+ * TypeScript files stay with tsgolint, and a
2737
+ * component with `generic` type parameters is skipped, as only Vue's compiler
2738
+ * brings them into scope.
2739
+ *
2740
+ * A tuple or generic returned into a union of callables is compared with the
2741
+ * member tsgo, which tsgolint runs, orders first. Two ties stay in TypeScript
2742
+ * 6's creation order, so the rule can compare another member than tsgolint
2743
+ * does: two instantiations of one anonymous generic, as in
2744
+ * `H<string>["m"] | H<unknown>["m"]`, which tsgo orders by their type
2745
+ * mappers, and two same-named types declared in different files, which tsgo
2746
+ * orders by its program's file order. TypeScript 6 exposes neither.
2747
+ */
2748
+ const noUnsafeAnyInVueRule = defineRule({
2749
+ meta: {
2750
+ type: "problem",
2751
+ docs: { description: "A Vue component's script assigns, passes and returns no `any` where a type is declared." },
2752
+ messages: {
2753
+ assignment: "Unsafe assignment of an `any` value, which `typescript/no-unsafe-assignment` reports in a TypeScript file. Use a typed value or `unknown`, and narrow it before use.",
2754
+ argument: "Unsafe argument of type `any` to a typed parameter, which `typescript/no-unsafe-argument` reports in a TypeScript file. Pass a typed value.",
2755
+ return: "Unsafe return of an `any` value, which `typescript/no-unsafe-return` reports in a TypeScript file. Return a typed value."
2756
+ }
2757
+ },
2758
+ createOnce(context) {
2759
+ return { Program() {
2760
+ const { filename, sourceCode } = context;
2761
+ if (!filename.endsWith(".vue")) return;
2762
+ const { text } = sourceCode;
2763
+ const linted = lintedSource(filename, text);
2764
+ if (linted === void 0) return;
2765
+ const { offset } = linted;
2766
+ const typed = typedFile(filename, linted.text);
2767
+ if (typed === void 0) return;
2768
+ for (const { kind, node } of findings(typed)) {
2769
+ const start = node.getStart(typed.sourceFile) - offset;
2770
+ const end = node.end - offset;
2771
+ if (start >= 0 && end <= text.length) context.report({
2772
+ messageId: kind,
2773
+ loc: {
2774
+ start: sourceCode.getLocFromIndex(start),
2775
+ end: sourceCode.getLocFromIndex(end)
2776
+ }
2777
+ });
2778
+ }
2779
+ } };
2780
+ }
2781
+ });
2782
+ //#endregion
2098
2783
  //#region src/oxc/guardrails/literal-fit.ts
2099
2784
  const MAX_DEPTH$1 = 8;
2100
2785
  const INDEX = /^\d+$/u;
@@ -2233,9 +2918,11 @@ const noUnsafeObjectAssignRule = defineRule({
2233
2918
  },
2234
2919
  createOnce(context) {
2235
2920
  return { CallExpression(node) {
2236
- if (callName(node.callee) !== "Object.assign" || node.arguments.length < 2 || context.filename.endsWith(".vue") && declaresTypeParameters(context.sourceCode.text)) return;
2237
- const typed = typedFile(context.filename, context.sourceCode.text);
2238
- const call = typed && nodeAt(typed.sourceFile, node, ts.isCallExpression);
2921
+ if (callName(node.callee) !== "Object.assign" || node.arguments.length < 2) return;
2922
+ const linted = lintedSource(context.filename, context.sourceCode.text);
2923
+ const typed = linted && typedFile(context.filename, linted.text);
2924
+ const [start, end] = node.range;
2925
+ const call = linted && typed && nodeAt(typed.sourceFile, { range: [start + linted.offset, end + linted.offset] }, ts.isCallExpression);
2239
2926
  if (typed === void 0 || call === void 0) return;
2240
2927
  const declared = typed.checker.getTypeAtLocation(call.arguments[0]);
2241
2928
  const target = declared.isTypeParameter() ? typed.checker.getBaseConstraintOfType(declared) ?? declared : declared;
@@ -2391,7 +3078,7 @@ const requireTsconfigTypesRule = defineRule({
2391
3078
  });
2392
3079
  //#endregion
2393
3080
  //#region src/oxc/guardrails/index.ts
2394
- /** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, inserts that follow a read of the same table or that a called function makes once an awaited read found nothing, unrun interface-database queries an awaited function returns, unchecked Object.assign writes, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
3081
+ /** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, inserts that follow a read of the same table or that a called function makes once an awaited read found nothing, unrun interface-database queries an awaited function returns, unchecked Object.assign writes, `any` assigned, passed or returned in a Vue script, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
2395
3082
  const guardrailsPlugin = eslintCompatPlugin({
2396
3083
  meta: { name: "antelopejs" },
2397
3084
  rules: {
@@ -2404,6 +3091,7 @@ const guardrailsPlugin = eslintCompatPlugin({
2404
3091
  "no-self-import-in-tests": noSelfImportInTestsRule,
2405
3092
  "no-typeof-function-only-test": noTypeofFunctionOnlyTestRule,
2406
3093
  "no-unrun-query": noUnrunQueryRule,
3094
+ "no-unsafe-any-in-vue": noUnsafeAnyInVueRule,
2407
3095
  "no-unsafe-object-assign": noUnsafeObjectAssignRule,
2408
3096
  "require-assertion": requireAssertionRule,
2409
3097
  "require-tsconfig-include": requireTsconfigIncludeRule,