@antelopejs/tooling-configs 0.7.1 → 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.
@@ -414,7 +414,7 @@ function checksOwnKey(node, read) {
414
414
  }
415
415
  const EQUALITY = /* @__PURE__ */ new Set(["==", "==="]);
416
416
  const INEQUALITY = /* @__PURE__ */ new Set(["!=", "!=="]);
417
- const MAX_DEPTH$3 = 8;
417
+ const MAX_DEPTH$2 = 8;
418
418
  const ASSERTS = /* @__PURE__ */ new Set([
419
419
  "assert",
420
420
  "assert.ok",
@@ -441,7 +441,7 @@ function comparedOutcome(node, outcome) {
441
441
  }
442
442
  /** A value that is `true` or `false`, so comparing it with a boolean literal tests its truth: a call, a `!`, or a `const` of one. */
443
443
  function isBooleanValued(node, read, depth) {
444
- if (depth > MAX_DEPTH$3) return false;
444
+ if (depth > MAX_DEPTH$2) return false;
445
445
  if (node.type === "ParenthesizedExpression") return isBooleanValued(node.expression, read, depth);
446
446
  if (node.type === "Identifier") {
447
447
  const value = constValue(node, read);
@@ -478,7 +478,7 @@ function combinedHolds(node, outcome, read, depth) {
478
478
  * `Object.prototype`'s own value.
479
479
  */
480
480
  function holds$1(node, outcome, read, depth = 0) {
481
- if (depth > MAX_DEPTH$3) return false;
481
+ if (depth > MAX_DEPTH$2) return false;
482
482
  switch (node.type) {
483
483
  case "ParenthesizedExpression": return holds$1(node.expression, outcome, read, depth);
484
484
  case "CallExpression": return outcome ? checksOwnKey(node, read) : checksOwnKey(node, {
@@ -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,10 @@ 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
+ }
1842
1847
  /**
1843
1848
  * The text to type for a linted file. A component whose linted text holds no
1844
1849
  * script block, as oxlint passes a component's script alone, is read whole
@@ -1879,12 +1884,33 @@ function isVue(path) {
1879
1884
  }
1880
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. */
1881
1886
  function viewOf(path, text) {
1882
- 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;
1883
1905
  }
1884
1906
  function readView(host, name) {
1885
1907
  const text = host.readFile(name);
1886
1908
  return text === void 0 ? void 0 : viewOf(name, text);
1887
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
+ }
1888
1914
  function build(config, path, view) {
1889
1915
  const parsed = project(config);
1890
1916
  if (parsed === void 0) return void 0;
@@ -1896,7 +1922,8 @@ function build(config, path, view) {
1896
1922
  const host = ts.createCompilerHost(options, true);
1897
1923
  host.getSourceFile = (name, language) => {
1898
1924
  const content = normalize(name) === path ? view : readView(host, name);
1899
- 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);
1900
1927
  };
1901
1928
  const program = ts.createProgram({
1902
1929
  rootNames,
@@ -1920,7 +1947,7 @@ function typedFile(file, text) {
1920
1947
  const view = viewOf(path, text);
1921
1948
  if (view === void 0) return void 0;
1922
1949
  const cached = programs.get(config);
1923
- 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);
1924
1951
  const sourceFile = program?.getSourceFile(path);
1925
1952
  return program && sourceFile ? {
1926
1953
  checker: program.getTypeChecker(),
@@ -2148,53 +2175,348 @@ const noUnrunQueryRule = defineRule({
2148
2175
  }
2149
2176
  });
2150
2177
  //#endregion
2151
- //#region src/oxc/guardrails/rules/no-unsafe-any-in-vue.ts
2178
+ //#region src/oxc/guardrails/any-leaks.ts
2152
2179
  const UNTYPED$1 = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
2153
- const MAX_DEPTH$2 = 4;
2154
2180
  /** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
2155
2181
  function isAnyType(checker, type) {
2156
2182
  return type === checker.getAnyType();
2157
2183
  }
2158
- function isAny(checker, node) {
2159
- return isAnyType(checker, checker.getTypeAtLocation(node));
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;
2160
2191
  }
2192
+ /** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
2161
2193
  function takesAnything(type) {
2162
2194
  return type === void 0 || (type.flags & UNTYPED$1) !== 0;
2163
2195
  }
2196
+ /** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
2164
2197
  function isObjectType(type) {
2165
2198
  return (type.flags & ts.TypeFlags.Object) !== 0;
2166
2199
  }
2167
- function isReference(type) {
2200
+ /** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
2201
+ function isReference$1(type) {
2168
2202
  return (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
2169
2203
  }
2170
- /** The array or tuple reference `type` is, for comparing by its generic target as tsgolint does. */
2171
- function arrayReference(checker, type) {
2172
- return (checker.isArrayType(type) || checker.isTupleType(type)) && isObjectType(type) && isReference(type) ? type : void 0;
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);
2173
2216
  }
2174
2217
  /**
2175
2218
  * Whether a `sender` value lets `any` into a `receiver` slot as an argument,
2176
- * a return or a type argument: `any` into a slot that is undeclared or typed
2177
- * neither `any` nor `unknown`, or an array or tuple holding `any`, as in
2178
- * `any[]`, into one of the same generic target, such as `string[]`, with
2179
- * another type in that position. `readonly` and labelled tuples have targets
2180
- * of their own.
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.
2181
2226
  */
2182
- function leaks(checker, sender, receiver, depth = 0) {
2183
- if (isAnyType(checker, sender)) return receiver === void 0 || !takesAnything(receiver);
2184
- if (receiver === void 0 || depth === MAX_DEPTH$2) return false;
2185
- const from = arrayReference(checker, sender);
2186
- const to = arrayReference(checker, receiver);
2187
- if (from === void 0 || to === void 0 || from.target !== to.target) return false;
2188
- const slots = checker.getTypeArguments(to);
2189
- return checker.getTypeArguments(from).some((argument, index) => leaks(checker, argument, slots[index], depth + 1));
2190
- }
2191
- /** Whether `sender` lets `any` into an assigned `receiver`: `any` into anything but `unknown`, a slot declared `any` included, or what {@link leaks} finds. */
2192
- function assignmentLeaks(checker, sender, receiver) {
2193
- return isAnyType(checker, sender) ? receiver === void 0 || (receiver.flags & ts.TypeFlags.Unknown) === 0 : leaks(checker, sender, receiver);
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);
2194
2516
  }
2195
2517
  /** Whether `value`, flowing into the slot its context declares, lets `any` in. */
2196
2518
  function leaksIntoContext(checker, value) {
2197
- return assignmentLeaks(checker, checker.getTypeAtLocation(value), checker.getContextualType(value));
2519
+ return assignmentLeaks(checker, value, checker.getContextualType(value));
2198
2520
  }
2199
2521
  /** Whether `literal` is the target of a destructuring assignment, as in `({ a } = value)`, whose elements name targets, not values. */
2200
2522
  function isDestructuringTarget(literal) {
@@ -2206,48 +2528,23 @@ function isDestructuringTarget(literal) {
2206
2528
  }
2207
2529
  return ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === child || (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === child;
2208
2530
  }
2209
- function declaredReturn(checker, node) {
2210
- let owner = node.parent;
2211
- while (!ts.isFunctionLike(owner)) {
2212
- if (ts.isSourceFile(owner)) return void 0;
2213
- owner = owner.parent;
2214
- }
2215
- const contextual = ts.isExpression(owner) ? checker.getContextualType(owner) : void 0;
2216
- const declared = owner.type === void 0 ? contextual && checker.getNonNullableType(contextual).getCallSignatures()[0]?.getReturnType() : checker.getTypeFromTypeNode(owner.type);
2217
- const isAsync = ts.canHaveModifiers(owner) && ts.getModifiers(owner)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
2218
- return declared && isAsync ? checker.getAwaitedType(declared) : declared;
2219
- }
2220
- function argumentFindings(checker, call) {
2221
- return (call.arguments ?? []).flatMap((argument) => {
2222
- const parameter = checker.getContextualType(argument);
2223
- return ts.isSpreadElement(argument) || parameter === void 0 || !leaks(checker, checker.getTypeAtLocation(argument), parameter) ? [] : [{
2224
- kind: "argument",
2225
- node: argument
2226
- }];
2227
- });
2228
- }
2229
2531
  function returned(checker, value) {
2230
- return leaks(checker, checker.getTypeAtLocation(value), declaredReturn(checker, value)) ? [{
2532
+ return returnLeaks(checker, value) ? [{
2231
2533
  kind: "return",
2232
2534
  node: value
2233
2535
  }] : [];
2234
2536
  }
2235
- /** Whether `type` is `any` or an array of `any`, as a spread or rest holds it. */
2236
- function isAnyOrAnyArray(checker, type) {
2237
- const element = checker.isArrayType(type) ? checker.getIndexTypeOfType(type, ts.IndexKind.Number) : void 0;
2238
- return isAnyType(checker, type) || element !== void 0 && isAnyType(checker, element);
2239
- }
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. */
2240
2538
  function spreadFindings(checker, spread) {
2241
- const { parent } = spread;
2242
- return !((ts.isCallExpression(parent) || ts.isNewExpression(parent)) && isAny(checker, parent.expression)) && !isDestructuringTarget(parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
2243
- kind: ts.isArrayLiteralExpression(spread.parent) ? "assignment" : "argument",
2539
+ return ts.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
2540
+ kind: "assignment",
2244
2541
  node: spread
2245
2542
  }] : [];
2246
2543
  }
2247
2544
  function propertyFindings(checker, property) {
2248
2545
  if (isDestructuringTarget(property.parent)) {
2249
2546
  const fallback = ts.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
2250
- return fallback !== void 0 && assignmentLeaks(checker, checker.getTypeAtLocation(fallback), checker.getTypeAtLocation(property.name)) ? [{
2547
+ return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
2251
2548
  kind: "assignment",
2252
2549
  node: property
2253
2550
  }] : [];
@@ -2325,13 +2622,13 @@ function arrayElements(pattern) {
2325
2622
  }];
2326
2623
  });
2327
2624
  }
2328
- /** An element that takes an `any` its source declares, but for one whose default is itself reported, and the elements nested under it. */
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. */
2329
2626
  function elementFindings(checker, element, source) {
2330
- if (isAnyType(checker, source)) return element.initializer !== void 0 && isAny(checker, element.initializer) ? [] : [{
2627
+ if (isAnyType(checker, source)) return [{
2331
2628
  kind: "assignment",
2332
2629
  node: element.node
2333
2630
  }];
2334
- return isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
2631
+ return element.initializer === void 0 && isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
2335
2632
  }
2336
2633
  /** The property or tuple slot named `key` that `source` declares, not one an index signature stands for. */
2337
2634
  function declaredSlot(checker, source, key, at) {
@@ -2358,33 +2655,60 @@ function destructuredFindings(checker, pattern, source) {
2358
2655
  }];
2359
2656
  return checker.isTupleType(source) ? arrayElements(pattern).flatMap((element) => slotFindings(checker, element, source)) : [];
2360
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
+ }
2361
2663
  function declarationFindings(checker, node, initializer) {
2362
- if (assignmentLeaks(checker, checker.getTypeAtLocation(initializer), node.type === void 0 ? void 0 : checker.getTypeAtLocation(node.name))) return [{
2664
+ return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
2363
2665
  kind: "assignment",
2364
2666
  node
2365
- }];
2366
- return node.type === void 0 && !ts.isIdentifier(node.name) ? destructuredFindings(checker, node.name, checker.getTypeAtLocation(initializer)) : [];
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
+ }] : [];
2367
2683
  }
2368
2684
  function assignmentFindings(checker, node) {
2369
2685
  if (ts.isVariableDeclaration(node) && node.initializer !== void 0) return declarationFindings(checker, node, node.initializer);
2370
2686
  if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
2371
- const source = checker.getTypeAtLocation(node.right);
2372
- if (assignmentLeaks(checker, source, checker.getTypeAtLocation(node.left))) return [{
2687
+ if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
2373
2688
  kind: "assignment",
2374
2689
  node
2375
2690
  }];
2376
- return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, source) : [];
2691
+ return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
2377
2692
  }
2378
- if ((ts.isParameter(node) || ts.isBindingElement(node)) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
2693
+ if (ts.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
2379
2694
  kind: "assignment",
2380
2695
  node
2381
- }] : [];
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);
2382
2703
  if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) return propertyFindings(checker, node);
2383
2704
  return [];
2384
2705
  }
2385
2706
  function nodeFindings(checker, node) {
2386
2707
  if (ts.isSpreadElement(node)) return spreadFindings(checker, node);
2387
- if (ts.isCallExpression(node) || ts.isNewExpression(node)) return argumentFindings(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
+ }));
2388
2712
  if (ts.isReturnStatement(node) && node.expression !== void 0) return returned(checker, node.expression);
2389
2713
  if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) return returned(checker, node.body);
2390
2714
  return assignmentFindings(checker, node);
@@ -2401,14 +2725,25 @@ function findings({ checker, sourceFile }) {
2401
2725
  /**
2402
2726
  * `typescript/no-unsafe-assignment`, `no-unsafe-argument` and
2403
2727
  * `no-unsafe-return` for the script blocks of a `.vue` file, which
2404
- * oxlint-tsgolint cannot read: an `any` or `any[]` reaching a declared type
2405
- * through a declaration, an assignment, an object literal property, a
2406
- * default value, an argument, a spread, a destructured binding, a
2407
- * destructuring assignment such as `({ a } = value)` or a return. An `any`
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`
2408
2735
  * assigned to a slot declared `any` is reported too, as tsgolint reports it.
2409
2736
  * TypeScript files stay with tsgolint, and a
2410
2737
  * component with `generic` type parameters is skipped, as only Vue's compiler
2411
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.
2412
2747
  */
2413
2748
  const noUnsafeAnyInVueRule = defineRule({
2414
2749
  meta: {
@@ -2417,7 +2752,7 @@ const noUnsafeAnyInVueRule = defineRule({
2417
2752
  messages: {
2418
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.",
2419
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.",
2420
- return: "Unsafe return of an `any` value from a function with a declared return type, which `typescript/no-unsafe-return` reports in a TypeScript file. Return 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."
2421
2756
  }
2422
2757
  },
2423
2758
  createOnce(context) {