@antelopejs/tooling-configs 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -25
- package/dist/bin/api-diff.mjs +22 -1
- package/dist/bin/checks.mjs +1 -1
- package/dist/bin/comment-proof.mjs +1 -1
- package/dist/bin/sync.mjs +121 -44
- package/dist/bin/verify.mjs +21 -21
- package/dist/{checks-DJ_CFEZH.mjs → checks-CSlWvky1.mjs} +408 -94
- package/dist/{docs-compat-CSljVi3O.mjs → docs-compat-BAZiPLZt.mjs} +5 -7
- package/dist/eslint.mjs +2 -2
- package/dist/{guardrails-6i82vsUi.mjs → guardrails-nj7NTglr.mjs} +426 -83
- package/dist/oxc/guardrails/index.mjs +1 -1
- package/dist/oxc/lint.d.mts +1 -0
- package/dist/oxc/lint.mjs +1 -1
- package/dist/pack-tarball-Cn4zGKn7.mjs +40 -0
- package/dist/{type-aware-rules-Da3769fI.mjs → type-aware-rules-BxhHbizU.mjs} +15 -2
- package/dist/{typescript-CxfNxyr2.mjs → typescript-QfxkJYzd.mjs} +1 -1
- package/package.json +1 -1
|
@@ -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$
|
|
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$
|
|
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$
|
|
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
|
|
@@ -1871,6 +1876,13 @@ function declaresTypeParameters(sfc) {
|
|
|
1871
1876
|
const programs = /* @__PURE__ */ new Map();
|
|
1872
1877
|
/** The source files every program of the lint run shares, parsed once per text and per set of compiler options that change a parse. */
|
|
1873
1878
|
const documents = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames);
|
|
1879
|
+
/** `options` without `pathsBasePath`, the directory of the config that declares `paths`, which TypeScript adds to the key of a parse in {@link documents} though it changes no parse. The programs of configs that keep `paths` in different directories, as the tsconfig Nuxt generates for each site does, then share the files they all read. */
|
|
1880
|
+
function registrySettings(options) {
|
|
1881
|
+
return {
|
|
1882
|
+
...options,
|
|
1883
|
+
pathsBasePath: void 0
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1874
1886
|
function normalize(file) {
|
|
1875
1887
|
return resolve(file).replaceAll("\\", "/");
|
|
1876
1888
|
}
|
|
@@ -1879,12 +1891,33 @@ function isVue(path) {
|
|
|
1879
1891
|
}
|
|
1880
1892
|
/** 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
1893
|
function viewOf(path, text) {
|
|
1882
|
-
|
|
1894
|
+
if (!isVue(path)) return {
|
|
1895
|
+
text,
|
|
1896
|
+
tsx: false
|
|
1897
|
+
};
|
|
1898
|
+
const view = scriptView(text);
|
|
1899
|
+
return view === void 0 ? void 0 : {
|
|
1900
|
+
text: view,
|
|
1901
|
+
tsx: isTsx(text)
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
/** 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"`. */
|
|
1905
|
+
const tsxViews = /* @__PURE__ */ new Map();
|
|
1906
|
+
function tsxView(name, text, language) {
|
|
1907
|
+
const cached = tsxViews.get(name);
|
|
1908
|
+
if (cached?.text === text) return cached;
|
|
1909
|
+
const parsed = ts.createSourceFile(name, text, language, true, ts.ScriptKind.TSX);
|
|
1910
|
+
tsxViews.set(name, parsed);
|
|
1911
|
+
return parsed;
|
|
1883
1912
|
}
|
|
1884
1913
|
function readView(host, name) {
|
|
1885
1914
|
const text = host.readFile(name);
|
|
1886
1915
|
return text === void 0 ? void 0 : viewOf(name, text);
|
|
1887
1916
|
}
|
|
1917
|
+
/** Whether `sourceFile` is `view` parsed as its kind, JSX read as JSX. */
|
|
1918
|
+
function parses(sourceFile, view) {
|
|
1919
|
+
return sourceFile?.text === view.text && sourceFile.languageVariant === ts.LanguageVariant.JSX === view.tsx;
|
|
1920
|
+
}
|
|
1888
1921
|
function build(config, path, view) {
|
|
1889
1922
|
const parsed = project(config);
|
|
1890
1923
|
if (parsed === void 0) return void 0;
|
|
@@ -1894,9 +1927,11 @@ function build(config, path, view) {
|
|
|
1894
1927
|
allowNonTsExtensions: true
|
|
1895
1928
|
} : parsed.options;
|
|
1896
1929
|
const host = ts.createCompilerHost(options, true);
|
|
1930
|
+
const settings = registrySettings(options);
|
|
1897
1931
|
host.getSourceFile = (name, language) => {
|
|
1898
1932
|
const content = normalize(name) === path ? view : readView(host, name);
|
|
1899
|
-
|
|
1933
|
+
if (content === void 0) return void 0;
|
|
1934
|
+
return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name, settings, ts.ScriptSnapshot.fromString(content.text), content.text, void 0, language);
|
|
1900
1935
|
};
|
|
1901
1936
|
const program = ts.createProgram({
|
|
1902
1937
|
rootNames,
|
|
@@ -1920,7 +1955,7 @@ function typedFile(file, text) {
|
|
|
1920
1955
|
const view = viewOf(path, text);
|
|
1921
1956
|
if (view === void 0) return void 0;
|
|
1922
1957
|
const cached = programs.get(config);
|
|
1923
|
-
const program = cached?.getSourceFile(path)
|
|
1958
|
+
const program = parses(cached?.getSourceFile(path), view) ? cached : build(config, path, view);
|
|
1924
1959
|
const sourceFile = program?.getSourceFile(path);
|
|
1925
1960
|
return program && sourceFile ? {
|
|
1926
1961
|
checker: program.getTypeChecker(),
|
|
@@ -2148,53 +2183,348 @@ const noUnrunQueryRule = defineRule({
|
|
|
2148
2183
|
}
|
|
2149
2184
|
});
|
|
2150
2185
|
//#endregion
|
|
2151
|
-
//#region src/oxc/guardrails/
|
|
2186
|
+
//#region src/oxc/guardrails/any-leaks.ts
|
|
2152
2187
|
const UNTYPED$1 = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
|
|
2153
|
-
const MAX_DEPTH$2 = 4;
|
|
2154
2188
|
/** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
|
|
2155
2189
|
function isAnyType(checker, type) {
|
|
2156
2190
|
return type === checker.getAnyType();
|
|
2157
2191
|
}
|
|
2158
|
-
|
|
2159
|
-
|
|
2192
|
+
/** Whether `type` is `unknown`. */
|
|
2193
|
+
function isUnknown(type) {
|
|
2194
|
+
return type !== void 0 && (type.flags & ts.TypeFlags.Unknown) !== 0;
|
|
2195
|
+
}
|
|
2196
|
+
/** The element type of an array or a readonly array, whether or not an alias names it, `undefined` for another type. */
|
|
2197
|
+
function arrayElement(checker, type) {
|
|
2198
|
+
return checker.isArrayType(type) ? checker.getIndexTypeOfType(type, ts.IndexKind.Number) : void 0;
|
|
2160
2199
|
}
|
|
2200
|
+
/** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
|
|
2161
2201
|
function takesAnything(type) {
|
|
2162
2202
|
return type === void 0 || (type.flags & UNTYPED$1) !== 0;
|
|
2163
2203
|
}
|
|
2204
|
+
/** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
|
|
2164
2205
|
function isObjectType(type) {
|
|
2165
2206
|
return (type.flags & ts.TypeFlags.Object) !== 0;
|
|
2166
2207
|
}
|
|
2167
|
-
|
|
2208
|
+
/** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
|
|
2209
|
+
function isReference$1(type) {
|
|
2168
2210
|
return (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
|
2169
2211
|
}
|
|
2170
|
-
/**
|
|
2171
|
-
|
|
2172
|
-
|
|
2212
|
+
/**
|
|
2213
|
+
* The generic reference `type` is, such as `Set<any>`, `any[]` or a tuple,
|
|
2214
|
+
* for comparing by its generic target as tsgolint does. A deferred reference,
|
|
2215
|
+
* such as one a type alias names as in `type AA = any[]` or `G<any>`, is not
|
|
2216
|
+
* compared, as tsgolint compares only references that are not deferred.
|
|
2217
|
+
*/
|
|
2218
|
+
function reference(type) {
|
|
2219
|
+
return isObjectType(type) && isReference$1(type) && type.node === void 0 ? type : void 0;
|
|
2220
|
+
}
|
|
2221
|
+
/** Whether `node` is `new Map()`, which the lib types `Map<any, any>` and tsgolint lets into any `Map`. */
|
|
2222
|
+
function isEmptyMap(node) {
|
|
2223
|
+
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
2224
|
}
|
|
2174
2225
|
/**
|
|
2175
2226
|
* Whether a `sender` value lets `any` into a `receiver` slot as an argument,
|
|
2176
|
-
*
|
|
2177
|
-
* neither `any` nor `unknown`, or
|
|
2178
|
-
* `any[]
|
|
2179
|
-
* another type in that position. `readonly`
|
|
2180
|
-
* of their own
|
|
2227
|
+
* an assignment or a type argument: `any` into a slot that is undeclared or
|
|
2228
|
+
* typed neither `any` nor `unknown`, or a generic reference holding `any`, as
|
|
2229
|
+
* in `any[]` or `Set<any>`, into one of the same generic target, such as
|
|
2230
|
+
* `string[]` or `Set<string>`, with another type in that position. `readonly`
|
|
2231
|
+
* and labelled tuples have targets of their own, and `node`, the expression
|
|
2232
|
+
* that sends the value, lets `new Map()` in. A pair of types is compared once,
|
|
2233
|
+
* however deep, as tsgolint compares it.
|
|
2234
|
+
*/
|
|
2235
|
+
function leaks(checker, sender, receiver, node) {
|
|
2236
|
+
if (isEmptyMap(node)) return false;
|
|
2237
|
+
const compared = /* @__PURE__ */ new Map();
|
|
2238
|
+
function compare(from, to) {
|
|
2239
|
+
if (isAnyType(checker, from)) return to === void 0 || !takesAnything(to);
|
|
2240
|
+
if (to === void 0) return false;
|
|
2241
|
+
const seen = compared.get(from) ?? /* @__PURE__ */ new Set();
|
|
2242
|
+
if (seen.has(to)) return false;
|
|
2243
|
+
compared.set(from, seen.add(to));
|
|
2244
|
+
const sent = reference(from);
|
|
2245
|
+
const slot = reference(to);
|
|
2246
|
+
if (sent === void 0 || slot === void 0 || sent.target !== slot.target) return false;
|
|
2247
|
+
const slots = checker.getTypeArguments(slot);
|
|
2248
|
+
return checker.getTypeArguments(sent).some((argument, index) => compare(argument, slots[index]));
|
|
2249
|
+
}
|
|
2250
|
+
return compare(sender, receiver);
|
|
2251
|
+
}
|
|
2252
|
+
/** Whether `type` is `any` or an array of `any`, as a spread or rest holds it. */
|
|
2253
|
+
function isAnyOrAnyArray(checker, type) {
|
|
2254
|
+
const element = arrayElement(checker, type);
|
|
2255
|
+
return isAnyType(checker, type) || element !== void 0 && isAnyType(checker, element);
|
|
2256
|
+
}
|
|
2257
|
+
//#endregion
|
|
2258
|
+
//#region src/oxc/guardrails/any-arguments.ts
|
|
2259
|
+
function isTupleTarget(target) {
|
|
2260
|
+
return (target.objectFlags & ts.ObjectFlags.Tuple) !== 0;
|
|
2261
|
+
}
|
|
2262
|
+
function tupleOf(type) {
|
|
2263
|
+
if (!isObjectType(type) || !isReference$1(type)) return void 0;
|
|
2264
|
+
const { target } = type;
|
|
2265
|
+
return isTupleTarget(target) ? {
|
|
2266
|
+
reference: type,
|
|
2267
|
+
target
|
|
2268
|
+
} : void 0;
|
|
2269
|
+
}
|
|
2270
|
+
function restOf(checker, type, index) {
|
|
2271
|
+
const element = arrayElement(checker, type);
|
|
2272
|
+
if (element !== void 0) return {
|
|
2273
|
+
kind: "element",
|
|
2274
|
+
type: element
|
|
2275
|
+
};
|
|
2276
|
+
const tuple = tupleOf(type);
|
|
2277
|
+
return tuple === void 0 ? {
|
|
2278
|
+
kind: "element",
|
|
2279
|
+
type
|
|
2280
|
+
} : {
|
|
2281
|
+
kind: "tuple",
|
|
2282
|
+
types: checker.getTypeArguments(tuple.reference),
|
|
2283
|
+
index
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
function calleeOf(call) {
|
|
2287
|
+
return ts.isTaggedTemplateExpression(call) ? call.tag : call.expression;
|
|
2288
|
+
}
|
|
2289
|
+
function argumentsOf(call) {
|
|
2290
|
+
if (!ts.isTaggedTemplateExpression(call)) return call.arguments ?? [];
|
|
2291
|
+
return ts.isTemplateExpression(call.template) ? call.template.templateSpans.map((span) => span.expression) : [];
|
|
2292
|
+
}
|
|
2293
|
+
function parameterCursor(checker, call, signature) {
|
|
2294
|
+
const fixed = [];
|
|
2295
|
+
let rest;
|
|
2296
|
+
for (const [index, parameter] of signature.getParameters().entries()) {
|
|
2297
|
+
const type = checker.getTypeOfSymbolAtLocation(parameter, call);
|
|
2298
|
+
const declaration = parameter.getDeclarations()?.[0];
|
|
2299
|
+
if (declaration !== void 0 && ts.isParameter(declaration) && declaration.dotDotDotToken !== void 0) {
|
|
2300
|
+
rest = restOf(checker, type, index);
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
fixed.push(type);
|
|
2304
|
+
}
|
|
2305
|
+
let position = 0;
|
|
2306
|
+
let consumed = false;
|
|
2307
|
+
return {
|
|
2308
|
+
next() {
|
|
2309
|
+
const index = position;
|
|
2310
|
+
position += 1;
|
|
2311
|
+
if (index < fixed.length && !consumed) return fixed[index];
|
|
2312
|
+
if (rest === void 0) return void 0;
|
|
2313
|
+
if (rest.kind === "element") return rest.type;
|
|
2314
|
+
const last = rest.types.at(-1);
|
|
2315
|
+
return consumed ? last : rest.types[index - rest.index] ?? last;
|
|
2316
|
+
},
|
|
2317
|
+
consumeRest() {
|
|
2318
|
+
consumed = true;
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* The arguments of `call` that pass `any` to a typed parameter, as
|
|
2324
|
+
* `typescript/no-unsafe-argument` reports them: each argument against the
|
|
2325
|
+
* parameter it fills, a spread `any` or `any[]` once, and each element of a
|
|
2326
|
+
* spread tuple against the parameter that element fills, so one spread can be
|
|
2327
|
+
* reported once per element. The substitutions of a tagged template fill the
|
|
2328
|
+
* parameters after the one its template strings fill. A call whose callee is
|
|
2329
|
+
* `any` is left alone.
|
|
2330
|
+
*/
|
|
2331
|
+
function unsafeArguments(checker, call) {
|
|
2332
|
+
const args = argumentsOf(call);
|
|
2333
|
+
if (args.length === 0 || isAnyType(checker, checker.getTypeAtLocation(calleeOf(call)))) return [];
|
|
2334
|
+
const signature = checker.getResolvedSignature(call);
|
|
2335
|
+
if (signature === void 0) return [];
|
|
2336
|
+
const cursor = parameterCursor(checker, call, signature);
|
|
2337
|
+
if (ts.isTaggedTemplateExpression(call)) cursor.next();
|
|
2338
|
+
return args.flatMap((argument) => {
|
|
2339
|
+
if (!ts.isSpreadElement(argument)) {
|
|
2340
|
+
const parameter = cursor.next();
|
|
2341
|
+
return parameter !== void 0 && leaks(checker, checker.getTypeAtLocation(argument), parameter, argument) ? [argument] : [];
|
|
2342
|
+
}
|
|
2343
|
+
const spread = checker.getTypeAtLocation(argument.expression);
|
|
2344
|
+
if (isAnyOrAnyArray(checker, spread)) return [argument];
|
|
2345
|
+
const tuple = tupleOf(spread);
|
|
2346
|
+
if (tuple === void 0) return [];
|
|
2347
|
+
const unsafe = checker.getTypeArguments(tuple.reference).flatMap((element) => {
|
|
2348
|
+
const parameter = cursor.next();
|
|
2349
|
+
return parameter !== void 0 && leaks(checker, element, parameter) ? [argument] : [];
|
|
2350
|
+
});
|
|
2351
|
+
if ((tuple.target.combinedFlags & ts.ElementFlags.Variable) !== 0) cursor.consumeRest();
|
|
2352
|
+
return unsafe;
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
//#endregion
|
|
2356
|
+
//#region src/oxc/guardrails/type-order.ts
|
|
2357
|
+
function isObject(type) {
|
|
2358
|
+
return (type.flags & ts.TypeFlags.Object) !== 0;
|
|
2359
|
+
}
|
|
2360
|
+
function isReference(type) {
|
|
2361
|
+
return isObject(type) && (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
|
2362
|
+
}
|
|
2363
|
+
function compareText(a, b) {
|
|
2364
|
+
if (a === b) return 0;
|
|
2365
|
+
return a < b ? -1 : 1;
|
|
2366
|
+
}
|
|
2367
|
+
/** 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. */
|
|
2368
|
+
function nameSymbol(type) {
|
|
2369
|
+
if (type.aliasSymbol !== void 0) return type.aliasSymbol;
|
|
2370
|
+
return (type.flags & ts.TypeFlags.TypeParameter) !== 0 || isObject(type) && (type.objectFlags & (ts.ObjectFlags.ClassOrInterface | ts.ObjectFlags.Reference)) !== 0 ? type.getSymbol() : void 0;
|
|
2371
|
+
}
|
|
2372
|
+
/** 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. */
|
|
2373
|
+
function compareNodes(a, b) {
|
|
2374
|
+
if (a === b) return 0;
|
|
2375
|
+
if (a === void 0) return 1;
|
|
2376
|
+
if (b === void 0) return -1;
|
|
2377
|
+
return a.getSourceFile() === b.getSourceFile() ? a.pos - b.pos : 0;
|
|
2378
|
+
}
|
|
2379
|
+
function compareSymbols(a, b) {
|
|
2380
|
+
if (a === b) return 0;
|
|
2381
|
+
if (a === void 0) return 1;
|
|
2382
|
+
if (b === void 0) return -1;
|
|
2383
|
+
const first = a.declarations?.[0];
|
|
2384
|
+
const second = b.declarations?.[0];
|
|
2385
|
+
if (first !== void 0 && second !== void 0) {
|
|
2386
|
+
const byNode = compareNodes(first, second);
|
|
2387
|
+
if (byNode !== 0) return byNode;
|
|
2388
|
+
} else if (first !== void 0) return -1;
|
|
2389
|
+
else if (second !== void 0) return 1;
|
|
2390
|
+
return compareText(a.name, b.name);
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* The order tsgo, the checker tsgolint runs, gives the members of a union:
|
|
2394
|
+
* by type flags, then named types by name, unnamed ones after them, then
|
|
2395
|
+
* object types by their symbol's declaration, references first, and
|
|
2396
|
+
* intersections by their members. Where tsgo falls back to type creation
|
|
2397
|
+
* order this keeps the order the types already have, as a TypeScript 6 union
|
|
2398
|
+
* lists its members in creation order. So does a tie tsgo breaks with data
|
|
2399
|
+
* TypeScript 6 keeps internal: the type mappers of two instantiations of one
|
|
2400
|
+
* anonymous type, and the file order of tsgo's program.
|
|
2401
|
+
*/
|
|
2402
|
+
function typeOrder(checker) {
|
|
2403
|
+
function compareLists(a, b) {
|
|
2404
|
+
const first = a ?? [];
|
|
2405
|
+
const second = b ?? [];
|
|
2406
|
+
if (first.length !== second.length) return first.length - second.length;
|
|
2407
|
+
for (const [index, type] of first.entries()) {
|
|
2408
|
+
const other = second[index];
|
|
2409
|
+
const order = other === void 0 ? 0 : compare(type, other);
|
|
2410
|
+
if (order !== 0) return order;
|
|
2411
|
+
}
|
|
2412
|
+
return 0;
|
|
2413
|
+
}
|
|
2414
|
+
function compareNames(a, b) {
|
|
2415
|
+
const first = nameSymbol(a);
|
|
2416
|
+
const second = nameSymbol(b);
|
|
2417
|
+
if (first === second) return a.aliasSymbol === void 0 ? 0 : compareLists(a.aliasTypeArguments, b.aliasTypeArguments);
|
|
2418
|
+
if (first === void 0) return 1;
|
|
2419
|
+
if (second === void 0) return -1;
|
|
2420
|
+
return compareText(first.name, second.name);
|
|
2421
|
+
}
|
|
2422
|
+
function compareObjects(a, b) {
|
|
2423
|
+
const bySymbol = compareSymbols(a.getSymbol(), b.getSymbol());
|
|
2424
|
+
if (bySymbol !== 0) return bySymbol;
|
|
2425
|
+
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);
|
|
2426
|
+
if (isReference(a)) return -1;
|
|
2427
|
+
return isReference(b) ? 1 : 0;
|
|
2428
|
+
}
|
|
2429
|
+
function compare(a, b) {
|
|
2430
|
+
if (a === b) return 0;
|
|
2431
|
+
if (a.flags !== b.flags) return a.flags - b.flags;
|
|
2432
|
+
const byName = compareNames(a, b);
|
|
2433
|
+
if (byName !== 0) return byName;
|
|
2434
|
+
if (isObject(a) && isObject(b)) return compareObjects(a, b);
|
|
2435
|
+
if (a.isUnionOrIntersection() && b.isUnionOrIntersection()) return compareLists(a.types, b.types);
|
|
2436
|
+
if (a.isStringLiteral() && b.isStringLiteral()) return compareText(a.value, b.value);
|
|
2437
|
+
return a.isNumberLiteral() && b.isNumberLiteral() ? a.value - b.value : 0;
|
|
2438
|
+
}
|
|
2439
|
+
return compare;
|
|
2440
|
+
}
|
|
2441
|
+
//#endregion
|
|
2442
|
+
//#region src/oxc/guardrails/any-returns.ts
|
|
2443
|
+
function anyKind(checker, type) {
|
|
2444
|
+
if (isAnyType(checker, type)) return "any";
|
|
2445
|
+
const element = arrayElement(checker, type);
|
|
2446
|
+
if (element !== void 0 && isAnyType(checker, element)) return "any[]";
|
|
2447
|
+
return (type.isUnionOrIntersection() ? type.types : [type]).some((part) => {
|
|
2448
|
+
const awaited = checker.getAwaitedType(part);
|
|
2449
|
+
return awaited !== void 0 && isAnyType(checker, awaited);
|
|
2450
|
+
}) ? "Promise<any>" : "safe";
|
|
2451
|
+
}
|
|
2452
|
+
/** The function a returned `value` leaves. */
|
|
2453
|
+
function ownerOf(value) {
|
|
2454
|
+
let owner = value.parent;
|
|
2455
|
+
while (!ts.isFunctionLike(owner)) {
|
|
2456
|
+
if (ts.isSourceFile(owner)) return void 0;
|
|
2457
|
+
owner = owner.parent;
|
|
2458
|
+
}
|
|
2459
|
+
return owner;
|
|
2460
|
+
}
|
|
2461
|
+
/** 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. */
|
|
2462
|
+
function contextOf(checker, node) {
|
|
2463
|
+
const { parent } = node;
|
|
2464
|
+
if (ts.isCallExpression(parent) || ts.isNewExpression(parent)) return parent.expression === node ? void 0 : checker.getContextualType(node);
|
|
2465
|
+
if (ts.isVariableDeclaration(parent) || ts.isPropertyDeclaration(parent) || ts.isParameter(parent)) return parent.type && checker.getTypeFromTypeNode(parent.type);
|
|
2466
|
+
if (ts.isJsxExpression(parent)) return checker.getContextualType(parent);
|
|
2467
|
+
if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.right === node) return checker.getTypeAtLocation(parent.left);
|
|
2468
|
+
return ts.isTemplateSpan(parent) ? checker.getContextualType(node) : void 0;
|
|
2469
|
+
}
|
|
2470
|
+
/** 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. */
|
|
2471
|
+
function declaringType(checker, owner) {
|
|
2472
|
+
return (ts.isArrowFunction(owner) || ts.isFunctionExpression(owner) ? contextOf(checker, owner) : void 0) ?? checker.getTypeAtLocation(owner);
|
|
2473
|
+
}
|
|
2474
|
+
/** 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. */
|
|
2475
|
+
function callSignatures(checker, type) {
|
|
2476
|
+
if (type.isUnion()) return type.types.toSorted(typeOrder(checker)).flatMap((member) => callSignatures(checker, member));
|
|
2477
|
+
if (!type.isIntersection()) return type.getCallSignatures();
|
|
2478
|
+
const callable = type.types.map((member) => callSignatures(checker, member)).filter((signatures) => signatures.length > 0);
|
|
2479
|
+
return callable.length === 1 ? callable[0] ?? [] : [];
|
|
2480
|
+
}
|
|
2481
|
+
/** 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`. */
|
|
2482
|
+
function annotationExcuses(checker, sender, returns, isAsync) {
|
|
2483
|
+
return returns.some((declared) => {
|
|
2484
|
+
if (declared === sender || takesAnything(declared)) return true;
|
|
2485
|
+
if (!isAsync) return false;
|
|
2486
|
+
const awaited = checker.getAwaitedType(declared);
|
|
2487
|
+
return awaited === checker.getAwaitedType(sender) || awaited !== void 0 && takesAnything(awaited);
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
/** 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. */
|
|
2491
|
+
function anyExcuses(checker, kind, returns, isAsync) {
|
|
2492
|
+
if (kind === "Promise<any>" && !isAsync) return true;
|
|
2493
|
+
return returns.some((declared) => {
|
|
2494
|
+
if (kind === "any") return isUnknown(declared);
|
|
2495
|
+
if (kind === "any[]") return isUnknown(arrayElement(checker, declared));
|
|
2496
|
+
return isUnknown(checker.getAwaitedType(declared));
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Whether returning `value` lets `any` out, as `typescript/no-unsafe-return`
|
|
2501
|
+
* judges it: by the call signatures of the type that declares the function's
|
|
2502
|
+
* return, a function expression's context or the function's own type. An own
|
|
2503
|
+
* annotation is excused when a signature returns that type, `any` or
|
|
2504
|
+
* `unknown`. An `any`, `any[]` or `Promise<any>` is reported unless a
|
|
2505
|
+
* signature returns `unknown`, `unknown[]` or `Promise<unknown>`, and another
|
|
2506
|
+
* type is compared with the first signature by {@link leaks}.
|
|
2181
2507
|
*/
|
|
2182
|
-
function
|
|
2183
|
-
|
|
2184
|
-
if (
|
|
2185
|
-
const
|
|
2186
|
-
const
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2508
|
+
function returnLeaks(checker, value) {
|
|
2509
|
+
const owner = ownerOf(value);
|
|
2510
|
+
if (owner === void 0) return false;
|
|
2511
|
+
const sender = checker.getTypeAtLocation(value);
|
|
2512
|
+
const returns = callSignatures(checker, declaringType(checker, owner)).map((signature) => signature.getReturnType());
|
|
2513
|
+
const isAsync = ts.canHaveModifiers(owner) && (ts.getModifiers(owner)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) ?? false);
|
|
2514
|
+
if (owner.type !== void 0 && annotationExcuses(checker, sender, returns, isAsync)) return false;
|
|
2515
|
+
const kind = anyKind(checker, sender);
|
|
2516
|
+
return kind === "safe" ? leaks(checker, sender, returns[0], value) : !anyExcuses(checker, kind, returns, isAsync);
|
|
2517
|
+
}
|
|
2518
|
+
//#endregion
|
|
2519
|
+
//#region src/oxc/guardrails/rules/no-unsafe-any-in-vue.ts
|
|
2520
|
+
/** Whether `value` lets `any` into an assigned `receiver`: `any` into anything but `unknown`, a slot declared `any` included, or what {@link leaks} finds. */
|
|
2521
|
+
function assignmentLeaks(checker, value, receiver) {
|
|
2522
|
+
const sender = checker.getTypeAtLocation(value);
|
|
2523
|
+
return isAnyType(checker, sender) ? !isUnknown(receiver) : leaks(checker, sender, receiver, value);
|
|
2194
2524
|
}
|
|
2195
2525
|
/** Whether `value`, flowing into the slot its context declares, lets `any` in. */
|
|
2196
2526
|
function leaksIntoContext(checker, value) {
|
|
2197
|
-
return assignmentLeaks(checker,
|
|
2527
|
+
return assignmentLeaks(checker, value, checker.getContextualType(value));
|
|
2198
2528
|
}
|
|
2199
2529
|
/** Whether `literal` is the target of a destructuring assignment, as in `({ a } = value)`, whose elements name targets, not values. */
|
|
2200
2530
|
function isDestructuringTarget(literal) {
|
|
@@ -2206,48 +2536,23 @@ function isDestructuringTarget(literal) {
|
|
|
2206
2536
|
}
|
|
2207
2537
|
return ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === child || (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === child;
|
|
2208
2538
|
}
|
|
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
2539
|
function returned(checker, value) {
|
|
2230
|
-
return
|
|
2540
|
+
return returnLeaks(checker, value) ? [{
|
|
2231
2541
|
kind: "return",
|
|
2232
2542
|
node: value
|
|
2233
2543
|
}] : [];
|
|
2234
2544
|
}
|
|
2235
|
-
/**
|
|
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
|
-
}
|
|
2545
|
+
/** 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
2546
|
function spreadFindings(checker, spread) {
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
kind: ts.isArrayLiteralExpression(spread.parent) ? "assignment" : "argument",
|
|
2547
|
+
return ts.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
|
|
2548
|
+
kind: "assignment",
|
|
2244
2549
|
node: spread
|
|
2245
2550
|
}] : [];
|
|
2246
2551
|
}
|
|
2247
2552
|
function propertyFindings(checker, property) {
|
|
2248
2553
|
if (isDestructuringTarget(property.parent)) {
|
|
2249
2554
|
const fallback = ts.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
|
|
2250
|
-
return fallback !== void 0 && assignmentLeaks(checker,
|
|
2555
|
+
return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
|
|
2251
2556
|
kind: "assignment",
|
|
2252
2557
|
node: property
|
|
2253
2558
|
}] : [];
|
|
@@ -2325,13 +2630,13 @@ function arrayElements(pattern) {
|
|
|
2325
2630
|
}];
|
|
2326
2631
|
});
|
|
2327
2632
|
}
|
|
2328
|
-
/** An element that takes an `any` its source declares,
|
|
2633
|
+
/** 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
2634
|
function elementFindings(checker, element, source) {
|
|
2330
|
-
if (isAnyType(checker, source)) return
|
|
2635
|
+
if (isAnyType(checker, source)) return [{
|
|
2331
2636
|
kind: "assignment",
|
|
2332
2637
|
node: element.node
|
|
2333
2638
|
}];
|
|
2334
|
-
return isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
|
|
2639
|
+
return element.initializer === void 0 && isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
|
|
2335
2640
|
}
|
|
2336
2641
|
/** The property or tuple slot named `key` that `source` declares, not one an index signature stands for. */
|
|
2337
2642
|
function declaredSlot(checker, source, key, at) {
|
|
@@ -2358,33 +2663,60 @@ function destructuredFindings(checker, pattern, source) {
|
|
|
2358
2663
|
}];
|
|
2359
2664
|
return checker.isTupleType(source) ? arrayElements(pattern).flatMap((element) => slotFindings(checker, element, source)) : [];
|
|
2360
2665
|
}
|
|
2666
|
+
/** The elements a pattern `name`, annotated or not, takes `any` into from `initializer`. */
|
|
2667
|
+
function bindingFindings(checker, name, initializer) {
|
|
2668
|
+
const source = checker.getTypeAtLocation(initializer);
|
|
2669
|
+
return ts.isIdentifier(name) ? [] : destructuredFindings(checker, name, source);
|
|
2670
|
+
}
|
|
2361
2671
|
function declarationFindings(checker, node, initializer) {
|
|
2362
|
-
|
|
2672
|
+
return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
|
|
2363
2673
|
kind: "assignment",
|
|
2364
2674
|
node
|
|
2365
|
-
}];
|
|
2366
|
-
|
|
2675
|
+
}] : bindingFindings(checker, node.name, initializer);
|
|
2676
|
+
}
|
|
2677
|
+
/** A JSX attribute whose value lets `any` into the prop it fills. */
|
|
2678
|
+
function attributeFindings(checker, attribute) {
|
|
2679
|
+
const value = attribute.initializer !== void 0 && ts.isJsxExpression(attribute.initializer) ? attribute.initializer.expression : void 0;
|
|
2680
|
+
return value !== void 0 && leaksIntoContext(checker, value) ? [{
|
|
2681
|
+
kind: "assignment",
|
|
2682
|
+
node: value
|
|
2683
|
+
}] : [];
|
|
2684
|
+
}
|
|
2685
|
+
/** A class field whose initializer lets `any` in: against its annotation, or whatever its type when it has none. */
|
|
2686
|
+
function fieldFindings(checker, field) {
|
|
2687
|
+
return field.initializer !== void 0 && assignmentLeaks(checker, field.initializer, field.type && checker.getTypeAtLocation(field.name)) ? [{
|
|
2688
|
+
kind: "assignment",
|
|
2689
|
+
node: field
|
|
2690
|
+
}] : [];
|
|
2367
2691
|
}
|
|
2368
2692
|
function assignmentFindings(checker, node) {
|
|
2369
2693
|
if (ts.isVariableDeclaration(node) && node.initializer !== void 0) return declarationFindings(checker, node, node.initializer);
|
|
2370
2694
|
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2371
|
-
|
|
2372
|
-
if (assignmentLeaks(checker, source, checker.getTypeAtLocation(node.left))) return [{
|
|
2695
|
+
if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
|
|
2373
2696
|
kind: "assignment",
|
|
2374
2697
|
node
|
|
2375
2698
|
}];
|
|
2376
|
-
return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left,
|
|
2699
|
+
return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
|
|
2377
2700
|
}
|
|
2378
|
-
if (
|
|
2701
|
+
if (ts.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
|
|
2379
2702
|
kind: "assignment",
|
|
2380
2703
|
node
|
|
2381
|
-
}] :
|
|
2704
|
+
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2705
|
+
if (ts.isBindingElement(node) && node.initializer !== void 0) return assignmentLeaks(checker, node.initializer, checker.getTypeAtLocation(node.name)) ? [{
|
|
2706
|
+
kind: "assignment",
|
|
2707
|
+
node
|
|
2708
|
+
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2709
|
+
if (ts.isJsxAttribute(node)) return attributeFindings(checker, node);
|
|
2710
|
+
if (ts.isPropertyDeclaration(node)) return fieldFindings(checker, node);
|
|
2382
2711
|
if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) return propertyFindings(checker, node);
|
|
2383
2712
|
return [];
|
|
2384
2713
|
}
|
|
2385
2714
|
function nodeFindings(checker, node) {
|
|
2386
2715
|
if (ts.isSpreadElement(node)) return spreadFindings(checker, node);
|
|
2387
|
-
if (ts.isCallExpression(node) || ts.isNewExpression(node)) return
|
|
2716
|
+
if (ts.isCallExpression(node) || ts.isNewExpression(node) || ts.isTaggedTemplateExpression(node)) return unsafeArguments(checker, node).map((argument) => ({
|
|
2717
|
+
kind: "argument",
|
|
2718
|
+
node: argument
|
|
2719
|
+
}));
|
|
2388
2720
|
if (ts.isReturnStatement(node) && node.expression !== void 0) return returned(checker, node.expression);
|
|
2389
2721
|
if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) return returned(checker, node.body);
|
|
2390
2722
|
return assignmentFindings(checker, node);
|
|
@@ -2401,14 +2733,25 @@ function findings({ checker, sourceFile }) {
|
|
|
2401
2733
|
/**
|
|
2402
2734
|
* `typescript/no-unsafe-assignment`, `no-unsafe-argument` and
|
|
2403
2735
|
* `no-unsafe-return` for the script blocks of a `.vue` file, which
|
|
2404
|
-
* oxlint-tsgolint cannot read: an `any
|
|
2405
|
-
*
|
|
2406
|
-
*
|
|
2407
|
-
*
|
|
2736
|
+
* oxlint-tsgolint cannot read: an `any`, or a generic such as `any[]` or
|
|
2737
|
+
* `Set<any>` holding one, reaching a declared type
|
|
2738
|
+
* through a declaration, an assignment, an object literal property, a class
|
|
2739
|
+
* field, a JSX attribute in a `lang="tsx"` script, a default value, an
|
|
2740
|
+
* argument, a tagged template substitution, a spread, a tuple spread into
|
|
2741
|
+
* parameters, a destructured binding,
|
|
2742
|
+
* a destructuring assignment such as `({ a } = value)` or a return. An `any`
|
|
2408
2743
|
* assigned to a slot declared `any` is reported too, as tsgolint reports it.
|
|
2409
2744
|
* TypeScript files stay with tsgolint, and a
|
|
2410
2745
|
* component with `generic` type parameters is skipped, as only Vue's compiler
|
|
2411
2746
|
* brings them into scope.
|
|
2747
|
+
*
|
|
2748
|
+
* A tuple or generic returned into a union of callables is compared with the
|
|
2749
|
+
* member tsgo, which tsgolint runs, orders first. Two ties stay in TypeScript
|
|
2750
|
+
* 6's creation order, so the rule can compare another member than tsgolint
|
|
2751
|
+
* does: two instantiations of one anonymous generic, as in
|
|
2752
|
+
* `H<string>["m"] | H<unknown>["m"]`, which tsgo orders by their type
|
|
2753
|
+
* mappers, and two same-named types declared in different files, which tsgo
|
|
2754
|
+
* orders by its program's file order. TypeScript 6 exposes neither.
|
|
2412
2755
|
*/
|
|
2413
2756
|
const noUnsafeAnyInVueRule = defineRule({
|
|
2414
2757
|
meta: {
|
|
@@ -2417,7 +2760,7 @@ const noUnsafeAnyInVueRule = defineRule({
|
|
|
2417
2760
|
messages: {
|
|
2418
2761
|
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
2762
|
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
|
|
2763
|
+
return: "Unsafe return of an `any` value, which `typescript/no-unsafe-return` reports in a TypeScript file. Return a typed value."
|
|
2421
2764
|
}
|
|
2422
2765
|
},
|
|
2423
2766
|
createOnce(context) {
|