@antelopejs/tooling-configs 0.7.3 → 0.7.5-next.356.g0d472b3
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 +63 -80
- package/dist/bin/api-diff.mjs +29 -49
- package/dist/bin/capture.mjs +4 -4
- package/dist/bin/check-size.mjs +12 -3
- package/dist/bin/checks.mjs +2 -2
- package/dist/bin/comment-proof.mjs +3 -4
- package/dist/bin/garden.mjs +45 -170
- package/dist/bin/readme-strip.mjs +2 -2
- package/dist/bin/suppressions.mjs +212 -9
- package/dist/bin/sync.mjs +318 -210
- package/dist/bin/tsc.mjs +24 -0
- package/dist/bin/verify.mjs +91 -671
- package/dist/{checks-CSlWvky1.mjs → checks-C60vMFin.mjs} +155 -310
- package/dist/{docs-compat-BAZiPLZt.mjs → docs-compat-CdgBviGf.mjs} +2 -2
- package/dist/eslint.mjs +1 -1
- package/dist/{files-C-JJhExM.mjs → files-BbzJEk-L.mjs} +5 -4
- package/dist/formal/index.mjs +1 -1
- package/dist/{guardrails-nj7NTglr.mjs → guardrails-Dron1AbR.mjs} +67 -673
- package/dist/{installed-typescript-6MtIWlE4.mjs → installed-typescript-CF_FR9DV.mjs} +17 -17
- package/dist/{map-BYkmnvNw.mjs → map-CbNbypUa.mjs} +2 -2
- package/dist/oxc/anti-slop/index.mjs +22 -964
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +1 -1
- package/dist/oxc/lint.d.mts +2 -14
- package/dist/oxc/lint.mjs +3 -20
- package/dist/{package-DDG3YH7W.mjs → package-7oylgBeT.mjs} +6 -19
- package/dist/{workflow-C-oBwL2H.mjs → renovate-D0su_v9p.mjs} +191 -91
- package/dist/{suppression-budget-CPDSFg4X.mjs → suppression-budget-De9nUzlD.mjs} +33 -13
- package/dist/{suppressions-CxPnh4sC.mjs → suppressions-CfJwL0fN.mjs} +6 -2
- package/dist/{templates-HG0fel2S.mjs → templates-DLW0Ubfk.mjs} +26 -29
- package/dist/typescript-C7eU-cig.mjs +581 -0
- package/dist/typescript-version-CptQKjGz.mjs +18 -0
- package/dist/typescript6-BWqCcXGY.mjs +2 -0
- package/dist/typescript6-HdyOMBv3.mjs +8 -0
- package/dist/verify/index.d.mts +5 -24
- package/package.json +27 -7
- package/dist/bin/body-check.mjs +0 -350
- package/dist/bin/ratchet.d.mts +0 -1
- package/dist/bin/ratchet.mjs +0 -375
- package/dist/ceilings-B7KayYIG.mjs +0 -76
- package/dist/oxlint-CIeonWMB.mjs +0 -133
- package/dist/proof-stamp-BFV7JTZT.mjs +0 -342
- package/dist/ratchet-DLCfeaPY.mjs +0 -453
- package/dist/renames-L2owF5GD.mjs +0 -59
- package/dist/size-CCGLY4Ke.mjs +0 -18
- package/dist/suppression-base-CYaLZAq7.mjs +0 -120
- package/dist/typescript-QfxkJYzd.mjs +0 -292
- /package/dist/bin/{body-check.d.mts → tsc.d.mts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { a as matcherChain, i as isAssertion, o as memberName, r as callName, s as testCallback } from "./shared-WC0z3y9F.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { t as typescript6_default } from "./typescript6-HdyOMBv3.mjs";
|
|
3
|
+
import { r as installedTypeScriptMajor, t as asInstalledCompilerReads } from "./installed-typescript-CF_FR9DV.mjs";
|
|
3
4
|
import { isBuiltin } from "node:module";
|
|
4
5
|
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
5
6
|
import { dirname, join, relative, resolve } from "node:path";
|
|
6
7
|
import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
7
|
-
import ts from "@typescript/typescript6";
|
|
8
8
|
//#region src/oxc/guardrails/rules/no-comments.ts
|
|
9
9
|
const allowedCommentForms = [
|
|
10
10
|
{
|
|
@@ -1518,7 +1518,7 @@ const noReadThenInsertRule = defineRule({
|
|
|
1518
1518
|
});
|
|
1519
1519
|
//#endregion
|
|
1520
1520
|
//#region src/oxc/guardrails/self-package.ts
|
|
1521
|
-
function isObject
|
|
1521
|
+
function isObject(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
|
|
1534
|
+
if (!isObject(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
|
|
1539
|
+
testedByAjs: isObject(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
|
|
1562
|
+
if (!isObject(exportsField)) return ["."];
|
|
1563
1563
|
const keys = Object.keys(exportsField);
|
|
1564
1564
|
return keys.some((key) => key.startsWith(".")) ? keys : ["."];
|
|
1565
1565
|
}
|
|
@@ -1720,14 +1720,14 @@ const noTypeofFunctionOnlyTestRule = defineRule({
|
|
|
1720
1720
|
//#region src/oxc/guardrails/tsconfig-program.ts
|
|
1721
1721
|
const CONFIG_NAMES = ["tsconfig.json", "jsconfig.json"];
|
|
1722
1722
|
const HOST = {
|
|
1723
|
-
...
|
|
1723
|
+
...typescript6_default.sys,
|
|
1724
1724
|
onUnRecoverableConfigFileDiagnostic: () => void 0
|
|
1725
1725
|
};
|
|
1726
1726
|
/** The extension a config's `include` globs match besides TypeScript's own, so a Vue component is a root file of its program. */
|
|
1727
1727
|
const VUE_EXTENSION = [{
|
|
1728
1728
|
extension: ".vue",
|
|
1729
1729
|
isMixedContent: true,
|
|
1730
|
-
scriptKind:
|
|
1730
|
+
scriptKind: typescript6_default.ScriptKind.Deferred
|
|
1731
1731
|
}];
|
|
1732
1732
|
const projects = /* @__PURE__ */ new Map();
|
|
1733
1733
|
const resolutionCaches = /* @__PURE__ */ new Map();
|
|
@@ -1741,7 +1741,7 @@ function configAbove(directory) {
|
|
|
1741
1741
|
/** The files `config` lists, its compiler options as the TypeScript its directory installs reads them, and the configs it references, parsed once per lint run. */
|
|
1742
1742
|
function project(config) {
|
|
1743
1743
|
if (projects.has(config)) return projects.get(config);
|
|
1744
|
-
const parsed =
|
|
1744
|
+
const parsed = typescript6_default.getParsedCommandLineOfConfigFile(config, void 0, HOST, void 0, void 0, VUE_EXTENSION);
|
|
1745
1745
|
const result = parsed && read(parsed, dirname(config));
|
|
1746
1746
|
projects.set(config, result);
|
|
1747
1747
|
return result;
|
|
@@ -1752,9 +1752,9 @@ function read(parsed, directory) {
|
|
|
1752
1752
|
return {
|
|
1753
1753
|
files: new Set(parsed.fileNames),
|
|
1754
1754
|
options,
|
|
1755
|
-
references: (parsed.projectReferences ?? []).map((reference) =>
|
|
1756
|
-
automaticTypes: parsed.options.types === void 0 ?
|
|
1757
|
-
nodeTypes:
|
|
1755
|
+
references: (parsed.projectReferences ?? []).map((reference) => typescript6_default.resolveProjectReferencePath(reference)),
|
|
1756
|
+
automaticTypes: parsed.options.types === void 0 ? typescript6_default.getAutomaticTypeDirectiveNames(options, typescript6_default.sys) : [],
|
|
1757
|
+
nodeTypes: typescript6_default.getAutomaticTypeDirectiveNames(options, typescript6_default.sys).includes("node")
|
|
1758
1758
|
};
|
|
1759
1759
|
}
|
|
1760
1760
|
/** The first config the nearest one or its references reach that lists `file`, skipping configs already visited. */
|
|
@@ -1799,10 +1799,10 @@ function resolves(config, specifier, file) {
|
|
|
1799
1799
|
if (parsed === void 0 || parsed.nodeTypes && isBuiltin(specifier)) return true;
|
|
1800
1800
|
let cache = resolutionCaches.get(config);
|
|
1801
1801
|
if (cache === void 0) {
|
|
1802
|
-
cache =
|
|
1802
|
+
cache = typescript6_default.createModuleResolutionCache(dirname(config), (name) => typescript6_default.sys.useCaseSensitiveFileNames ? name : name.toLowerCase(), parsed.options);
|
|
1803
1803
|
resolutionCaches.set(config, cache);
|
|
1804
1804
|
}
|
|
1805
|
-
return
|
|
1805
|
+
return typescript6_default.resolveModuleName(specifier, file, parsed.options, typescript6_default.sys, cache).resolvedModule !== void 0;
|
|
1806
1806
|
}
|
|
1807
1807
|
/**
|
|
1808
1808
|
* The `@types` packages tsc loads into `config`'s program only because it lists no
|
|
@@ -1875,7 +1875,7 @@ function declaresTypeParameters(sfc) {
|
|
|
1875
1875
|
//#region src/oxc/guardrails/type-checker.ts
|
|
1876
1876
|
const programs = /* @__PURE__ */ new Map();
|
|
1877
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. */
|
|
1878
|
-
const documents =
|
|
1878
|
+
const documents = typescript6_default.createDocumentRegistry(typescript6_default.sys.useCaseSensitiveFileNames);
|
|
1879
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
1880
|
function registrySettings(options) {
|
|
1881
1881
|
return {
|
|
@@ -1906,7 +1906,7 @@ const tsxViews = /* @__PURE__ */ new Map();
|
|
|
1906
1906
|
function tsxView(name, text, language) {
|
|
1907
1907
|
const cached = tsxViews.get(name);
|
|
1908
1908
|
if (cached?.text === text) return cached;
|
|
1909
|
-
const parsed =
|
|
1909
|
+
const parsed = typescript6_default.createSourceFile(name, text, language, true, typescript6_default.ScriptKind.TSX);
|
|
1910
1910
|
tsxViews.set(name, parsed);
|
|
1911
1911
|
return parsed;
|
|
1912
1912
|
}
|
|
@@ -1916,7 +1916,7 @@ function readView(host, name) {
|
|
|
1916
1916
|
}
|
|
1917
1917
|
/** Whether `sourceFile` is `view` parsed as its kind, JSX read as JSX. */
|
|
1918
1918
|
function parses(sourceFile, view) {
|
|
1919
|
-
return sourceFile?.text === view.text && sourceFile.languageVariant ===
|
|
1919
|
+
return sourceFile?.text === view.text && sourceFile.languageVariant === typescript6_default.LanguageVariant.JSX === view.tsx;
|
|
1920
1920
|
}
|
|
1921
1921
|
function build(config, path, view) {
|
|
1922
1922
|
const parsed = project(config);
|
|
@@ -1926,14 +1926,14 @@ function build(config, path, view) {
|
|
|
1926
1926
|
...parsed.options,
|
|
1927
1927
|
allowNonTsExtensions: true
|
|
1928
1928
|
} : parsed.options;
|
|
1929
|
-
const host =
|
|
1929
|
+
const host = typescript6_default.createCompilerHost(options, true);
|
|
1930
1930
|
const settings = registrySettings(options);
|
|
1931
1931
|
host.getSourceFile = (name, language) => {
|
|
1932
1932
|
const content = normalize(name) === path ? view : readView(host, name);
|
|
1933
1933
|
if (content === void 0) return void 0;
|
|
1934
|
-
return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name, settings,
|
|
1934
|
+
return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name, settings, typescript6_default.ScriptSnapshot.fromString(content.text), content.text, void 0, language);
|
|
1935
1935
|
};
|
|
1936
|
-
const program =
|
|
1936
|
+
const program = typescript6_default.createProgram({
|
|
1937
1937
|
rootNames,
|
|
1938
1938
|
options,
|
|
1939
1939
|
host,
|
|
@@ -1969,7 +1969,7 @@ function nodeAt(sourceFile, { range: [start, end] }, test) {
|
|
|
1969
1969
|
function visit(node) {
|
|
1970
1970
|
if (found !== void 0 || node.pos > start || node.end < end) return;
|
|
1971
1971
|
if (test(node) && node.getStart(sourceFile) === start && node.end === end) found = node;
|
|
1972
|
-
else
|
|
1972
|
+
else typescript6_default.forEachChild(node, visit);
|
|
1973
1973
|
}
|
|
1974
1974
|
visit(sourceFile);
|
|
1975
1975
|
return found;
|
|
@@ -2032,7 +2032,7 @@ function callsFirstParameter(call) {
|
|
|
2032
2032
|
}
|
|
2033
2033
|
return false;
|
|
2034
2034
|
}
|
|
2035
|
-
const HOLDERS =
|
|
2035
|
+
const HOLDERS = typescript6_default.SymbolFlags.ObjectLiteral | typescript6_default.SymbolFlags.Interface | typescript6_default.SymbolFlags.TypeLiteral;
|
|
2036
2036
|
function declaredIn(symbol, path) {
|
|
2037
2037
|
return symbol?.declarations?.some((declaration) => declaration.getSourceFile().fileName.includes(path)) === true;
|
|
2038
2038
|
}
|
|
@@ -2048,8 +2048,8 @@ function isTable(checker, type) {
|
|
|
2048
2048
|
function isHolder(type) {
|
|
2049
2049
|
if (type.isIntersection()) return type.types.every(isHolder);
|
|
2050
2050
|
const symbol = type.getSymbol();
|
|
2051
|
-
if (symbol?.declarations?.some(
|
|
2052
|
-
return symbol !== void 0 && (symbol.flags & HOLDERS) !== 0 && (symbol.flags &
|
|
2051
|
+
if (symbol?.declarations?.some(typescript6_default.isMappedTypeNode) === true) return true;
|
|
2052
|
+
return symbol !== void 0 && (symbol.flags & HOLDERS) !== 0 && (symbol.flags & typescript6_default.SymbolFlags.Class) === 0 && !declaredIn(symbol, "/node_modules/");
|
|
2053
2053
|
}
|
|
2054
2054
|
function members$1(type) {
|
|
2055
2055
|
return type.isUnion() ? type.types : [type];
|
|
@@ -2057,7 +2057,7 @@ function members$1(type) {
|
|
|
2057
2057
|
/** The values an array, a tuple or a holder keeps in its properties and index signatures, which awaiting it leaves as they are. */
|
|
2058
2058
|
function heldValues(checker, type) {
|
|
2059
2059
|
if (checker.isArrayType(type) || checker.isTupleType(type)) {
|
|
2060
|
-
const element = checker.getIndexTypeOfType(type,
|
|
2060
|
+
const element = checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number);
|
|
2061
2061
|
return element === void 0 ? [] : [element];
|
|
2062
2062
|
}
|
|
2063
2063
|
if (!isHolder(type)) return [];
|
|
@@ -2079,26 +2079,26 @@ function holdsQuery(checker, type) {
|
|
|
2079
2079
|
}
|
|
2080
2080
|
/** What a function value handed to `then`, `catch` or `finally` resolves the promise to: the return types of its non-async call signatures, since an async one reports its own returns. */
|
|
2081
2081
|
function callbackResult(checker, callback) {
|
|
2082
|
-
return checker.getTypeAtLocation(callback).getCallSignatures().filter(({ declaration }) => declaration === void 0 || (
|
|
2082
|
+
return checker.getTypeAtLocation(callback).getCallSignatures().filter(({ declaration }) => declaration === void 0 || (typescript6_default.getCombinedModifierFlags(declaration) & typescript6_default.ModifierFlags.Async) === 0).map((signature) => checker.getReturnTypeOfSignature(signature));
|
|
2083
2083
|
}
|
|
2084
2084
|
const executorsByFile = /* @__PURE__ */ new WeakMap();
|
|
2085
2085
|
/** `expression` without the parentheses, `as`, `<T>`, `satisfies` and `!` around it. */
|
|
2086
2086
|
function unwrapped(expression) {
|
|
2087
|
-
return
|
|
2087
|
+
return typescript6_default.isParenthesizedExpression(expression) || typescript6_default.isAsExpression(expression) || typescript6_default.isTypeAssertionExpression(expression) || typescript6_default.isSatisfiesExpression(expression) || typescript6_default.isNonNullExpression(expression) ? unwrapped(expression.expression) : expression;
|
|
2088
2088
|
}
|
|
2089
2089
|
/** The function a declaration holds: the initialiser of a variable or property, the value a shorthand property names, or the declaration itself. */
|
|
2090
2090
|
function declaredFunctions(checker, declaration) {
|
|
2091
|
-
if (
|
|
2092
|
-
return (
|
|
2091
|
+
if (typescript6_default.isShorthandPropertyAssignment(declaration)) return (checker.getShorthandAssignmentValueSymbol(declaration)?.declarations ?? []).flatMap((value) => declaredFunctions(checker, value));
|
|
2092
|
+
return (typescript6_default.isVariableDeclaration(declaration) || typescript6_default.isPropertyDeclaration(declaration) || typescript6_default.isPropertyAssignment(declaration)) && declaration.initializer !== void 0 ? [unwrapped(declaration.initializer)] : [declaration];
|
|
2093
2093
|
}
|
|
2094
2094
|
/** `value` as a member access the source names, or `undefined` for any other expression. */
|
|
2095
2095
|
function namedMember(value) {
|
|
2096
|
-
if (
|
|
2096
|
+
if (typescript6_default.isPropertyAccessExpression(value)) return {
|
|
2097
2097
|
receiver: value.expression,
|
|
2098
2098
|
key: value,
|
|
2099
2099
|
name: value.name.text
|
|
2100
2100
|
};
|
|
2101
|
-
return
|
|
2101
|
+
return typescript6_default.isElementAccessExpression(value) && typescript6_default.isStringLiteralLike(value.argumentExpression) ? {
|
|
2102
2102
|
receiver: value.expression,
|
|
2103
2103
|
key: value.argumentExpression,
|
|
2104
2104
|
name: value.argumentExpression.text
|
|
@@ -2106,15 +2106,15 @@ function namedMember(value) {
|
|
|
2106
2106
|
}
|
|
2107
2107
|
/** The declarations of `member` on the value its receiver variable is initialised with, past any type annotation that names only a signature. */
|
|
2108
2108
|
function initialisedMember(checker, member) {
|
|
2109
|
-
const receiver =
|
|
2110
|
-
return receiver !== void 0 &&
|
|
2109
|
+
const receiver = typescript6_default.isIdentifier(member.receiver) ? checker.getSymbolAtLocation(member.receiver)?.valueDeclaration : void 0;
|
|
2110
|
+
return receiver !== void 0 && typescript6_default.isVariableDeclaration(receiver) && receiver.initializer !== void 0 ? checker.getTypeAtLocation(unwrapped(receiver.initializer)).getProperty(member.name)?.declarations ?? [] : [];
|
|
2111
2111
|
}
|
|
2112
2112
|
/** 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. */
|
|
2113
2113
|
function namedFunctions(checker, argument) {
|
|
2114
2114
|
const value = unwrapped(argument);
|
|
2115
|
-
if (
|
|
2115
|
+
if (typescript6_default.isFunctionExpression(value) || typescript6_default.isArrowFunction(value)) return [value];
|
|
2116
2116
|
const member = namedMember(value);
|
|
2117
|
-
if (!
|
|
2117
|
+
if (!typescript6_default.isIdentifier(value) && member === void 0) return [];
|
|
2118
2118
|
return [...checker.getSymbolAtLocation(member?.key ?? value)?.declarations ?? [], ...member === void 0 ? [] : initialisedMember(checker, member)].flatMap((declaration) => declaredFunctions(checker, declaration));
|
|
2119
2119
|
}
|
|
2120
2120
|
/** The functions `sourceFile` hands to `new Promise` as its executor, inline or by name. */
|
|
@@ -2123,9 +2123,9 @@ function promiseExecutors(checker, sourceFile) {
|
|
|
2123
2123
|
if (known !== void 0) return known;
|
|
2124
2124
|
const executors = /* @__PURE__ */ new Set();
|
|
2125
2125
|
const visit = (node) => {
|
|
2126
|
-
const argument =
|
|
2126
|
+
const argument = typescript6_default.isNewExpression(node) && typescript6_default.isIdentifier(node.expression) && node.expression.text === "Promise" ? node.arguments?.[0] : void 0;
|
|
2127
2127
|
for (const executor of argument ? namedFunctions(checker, argument) : []) executors.add(executor);
|
|
2128
|
-
|
|
2128
|
+
typescript6_default.forEachChild(node, visit);
|
|
2129
2129
|
};
|
|
2130
2130
|
visit(sourceFile);
|
|
2131
2131
|
executorsByFile.set(sourceFile, executors);
|
|
@@ -2135,7 +2135,7 @@ function promiseExecutors(checker, sourceFile) {
|
|
|
2135
2135
|
function resolvedValue(checker, call) {
|
|
2136
2136
|
const parameter = checker.getSymbolAtLocation(call.expression)?.valueDeclaration;
|
|
2137
2137
|
const executor = parameter?.parent;
|
|
2138
|
-
return parameter !== void 0 &&
|
|
2138
|
+
return parameter !== void 0 && typescript6_default.isParameter(parameter) && executor !== void 0 && typescript6_default.isFunctionLike(executor) && executor.parameters.find(({ name }) => !typescript6_default.isIdentifier(name) || name.text !== "this") === parameter && promiseExecutors(checker, call.getSourceFile()).has(executor) ? call.arguments[0] : void 0;
|
|
2139
2139
|
}
|
|
2140
2140
|
/** 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. */
|
|
2141
2141
|
const noUnrunQueryRule = defineRule({
|
|
@@ -2160,22 +2160,22 @@ const noUnrunQueryRule = defineRule({
|
|
|
2160
2160
|
ReturnStatement(node) {
|
|
2161
2161
|
const fn = enclosingFunction(node);
|
|
2162
2162
|
if (fn === null || node.argument === null || !resultIsAwaited(fn)) return;
|
|
2163
|
-
check(node.argument, (typed) => typeOf(nodeAt(typed.sourceFile, node,
|
|
2163
|
+
check(node.argument, (typed) => typeOf(nodeAt(typed.sourceFile, node, typescript6_default.isReturnStatement)?.expression, typed));
|
|
2164
2164
|
},
|
|
2165
2165
|
ArrowFunctionExpression(node) {
|
|
2166
2166
|
if (node.body.type === "BlockStatement" || !resultIsAwaited(node)) return;
|
|
2167
|
-
check(node.body, (typed) => typeOf(nodeAt(typed.sourceFile, node,
|
|
2167
|
+
check(node.body, (typed) => typeOf(nodeAt(typed.sourceFile, node, typescript6_default.isArrowFunction)?.body, typed));
|
|
2168
2168
|
},
|
|
2169
2169
|
CallExpression(node) {
|
|
2170
2170
|
if (isPromiseCallback(node)) {
|
|
2171
2171
|
for (const argument of node.arguments) if (!isFunction(argument)) check(argument, (typed) => {
|
|
2172
|
-
const callback = nodeAt(typed.sourceFile, argument,
|
|
2172
|
+
const callback = nodeAt(typed.sourceFile, argument, typescript6_default.isExpression);
|
|
2173
2173
|
return callback === void 0 ? [] : callbackResult(typed.checker, callback);
|
|
2174
2174
|
});
|
|
2175
2175
|
}
|
|
2176
2176
|
const [value] = node.arguments;
|
|
2177
2177
|
if (value !== void 0 && callsFirstParameter(node)) check(value, (typed) => {
|
|
2178
|
-
const call = nodeAt(typed.sourceFile, node,
|
|
2178
|
+
const call = nodeAt(typed.sourceFile, node, typescript6_default.isCallExpression);
|
|
2179
2179
|
return typeOf(call && resolvedValue(typed.checker, call), typed);
|
|
2180
2180
|
});
|
|
2181
2181
|
}
|
|
@@ -2183,624 +2183,19 @@ const noUnrunQueryRule = defineRule({
|
|
|
2183
2183
|
}
|
|
2184
2184
|
});
|
|
2185
2185
|
//#endregion
|
|
2186
|
-
//#region src/oxc/guardrails/any-leaks.ts
|
|
2187
|
-
const UNTYPED$1 = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
|
|
2188
|
-
/** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
|
|
2189
|
-
function isAnyType(checker, type) {
|
|
2190
|
-
return type === checker.getAnyType();
|
|
2191
|
-
}
|
|
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;
|
|
2199
|
-
}
|
|
2200
|
-
/** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
|
|
2201
|
-
function takesAnything(type) {
|
|
2202
|
-
return type === void 0 || (type.flags & UNTYPED$1) !== 0;
|
|
2203
|
-
}
|
|
2204
|
-
/** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
|
|
2205
|
-
function isObjectType(type) {
|
|
2206
|
-
return (type.flags & ts.TypeFlags.Object) !== 0;
|
|
2207
|
-
}
|
|
2208
|
-
/** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
|
|
2209
|
-
function isReference$1(type) {
|
|
2210
|
-
return (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
|
2211
|
-
}
|
|
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);
|
|
2224
|
-
}
|
|
2225
|
-
/**
|
|
2226
|
-
* Whether a `sender` value lets `any` into a `receiver` slot as an argument,
|
|
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}.
|
|
2507
|
-
*/
|
|
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);
|
|
2524
|
-
}
|
|
2525
|
-
/** Whether `value`, flowing into the slot its context declares, lets `any` in. */
|
|
2526
|
-
function leaksIntoContext(checker, value) {
|
|
2527
|
-
return assignmentLeaks(checker, value, checker.getContextualType(value));
|
|
2528
|
-
}
|
|
2529
|
-
/** Whether `literal` is the target of a destructuring assignment, as in `({ a } = value)`, whose elements name targets, not values. */
|
|
2530
|
-
function isDestructuringTarget(literal) {
|
|
2531
|
-
let child = literal;
|
|
2532
|
-
let parent = literal.parent;
|
|
2533
|
-
while (ts.isParenthesizedExpression(parent) || ts.isArrayLiteralExpression(parent) || ts.isObjectLiteralExpression(parent) || ts.isPropertyAssignment(parent) || ts.isShorthandPropertyAssignment(parent) || ts.isSpreadElement(parent) || ts.isSpreadAssignment(parent)) {
|
|
2534
|
-
child = parent;
|
|
2535
|
-
parent = parent.parent;
|
|
2536
|
-
}
|
|
2537
|
-
return ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === child || (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === child;
|
|
2538
|
-
}
|
|
2539
|
-
function returned(checker, value) {
|
|
2540
|
-
return returnLeaks(checker, value) ? [{
|
|
2541
|
-
kind: "return",
|
|
2542
|
-
node: value
|
|
2543
|
-
}] : [];
|
|
2544
|
-
}
|
|
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. */
|
|
2546
|
-
function spreadFindings(checker, spread) {
|
|
2547
|
-
return ts.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
|
|
2548
|
-
kind: "assignment",
|
|
2549
|
-
node: spread
|
|
2550
|
-
}] : [];
|
|
2551
|
-
}
|
|
2552
|
-
function propertyFindings(checker, property) {
|
|
2553
|
-
if (isDestructuringTarget(property.parent)) {
|
|
2554
|
-
const fallback = ts.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
|
|
2555
|
-
return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
|
|
2556
|
-
kind: "assignment",
|
|
2557
|
-
node: property
|
|
2558
|
-
}] : [];
|
|
2559
|
-
}
|
|
2560
|
-
return leaksIntoContext(checker, ts.isPropertyAssignment(property) ? property.initializer : property.name) ? [{
|
|
2561
|
-
kind: "assignment",
|
|
2562
|
-
node: property
|
|
2563
|
-
}] : [];
|
|
2564
|
-
}
|
|
2565
|
-
function isPattern(node) {
|
|
2566
|
-
return ts.isObjectBindingPattern(node) || ts.isArrayBindingPattern(node) || ts.isObjectLiteralExpression(node) || ts.isArrayLiteralExpression(node);
|
|
2567
|
-
}
|
|
2568
|
-
/** The key a property name spells, a computed literal such as `['a']` included. */
|
|
2569
|
-
function literalKey(name) {
|
|
2570
|
-
if (ts.isIdentifier(name)) return name.text;
|
|
2571
|
-
const key = ts.isComputedPropertyName(name) ? name.expression : name;
|
|
2572
|
-
return ts.isStringLiteral(key) || ts.isNumericLiteral(key) || ts.isNoSubstitutionTemplateLiteral(key) ? key.text : void 0;
|
|
2573
|
-
}
|
|
2574
|
-
/** The target and default of an assignment pattern element, as in `a = fallback`. */
|
|
2575
|
-
function withDefault(element) {
|
|
2576
|
-
return ts.isBinaryExpression(element) && element.operatorToken.kind === ts.SyntaxKind.EqualsToken ? {
|
|
2577
|
-
target: element.left,
|
|
2578
|
-
initializer: element.right
|
|
2579
|
-
} : {
|
|
2580
|
-
target: element,
|
|
2581
|
-
initializer: void 0
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
function objectElements(pattern) {
|
|
2585
|
-
if (ts.isObjectBindingPattern(pattern)) return pattern.elements.map((element) => ({
|
|
2586
|
-
key: element.dotDotDotToken === void 0 ? literalKey(element.propertyName ?? element.name) : void 0,
|
|
2587
|
-
target: element.name,
|
|
2588
|
-
initializer: element.initializer,
|
|
2589
|
-
node: element
|
|
2590
|
-
}));
|
|
2591
|
-
return pattern.properties.map((property) => {
|
|
2592
|
-
if (ts.isPropertyAssignment(property)) return {
|
|
2593
|
-
key: literalKey(property.name),
|
|
2594
|
-
...withDefault(property.initializer),
|
|
2595
|
-
node: property
|
|
2596
|
-
};
|
|
2597
|
-
if (ts.isShorthandPropertyAssignment(property)) return {
|
|
2598
|
-
key: property.name.text,
|
|
2599
|
-
target: property.name,
|
|
2600
|
-
initializer: property.objectAssignmentInitializer,
|
|
2601
|
-
node: property
|
|
2602
|
-
};
|
|
2603
|
-
return {
|
|
2604
|
-
key: void 0,
|
|
2605
|
-
target: property,
|
|
2606
|
-
initializer: void 0,
|
|
2607
|
-
node: property
|
|
2608
|
-
};
|
|
2609
|
-
});
|
|
2610
|
-
}
|
|
2611
|
-
function arrayElements(pattern) {
|
|
2612
|
-
return pattern.elements.flatMap((element, index) => {
|
|
2613
|
-
if (ts.isOmittedExpression(element)) return [];
|
|
2614
|
-
if (ts.isBindingElement(element)) return [{
|
|
2615
|
-
key: element.dotDotDotToken === void 0 ? String(index) : void 0,
|
|
2616
|
-
target: element.name,
|
|
2617
|
-
initializer: element.initializer,
|
|
2618
|
-
node: element
|
|
2619
|
-
}];
|
|
2620
|
-
if (ts.isSpreadElement(element)) return [{
|
|
2621
|
-
key: void 0,
|
|
2622
|
-
target: element.expression,
|
|
2623
|
-
initializer: void 0,
|
|
2624
|
-
node: element
|
|
2625
|
-
}];
|
|
2626
|
-
return [{
|
|
2627
|
-
key: String(index),
|
|
2628
|
-
...withDefault(element),
|
|
2629
|
-
node: element
|
|
2630
|
-
}];
|
|
2631
|
-
});
|
|
2632
|
-
}
|
|
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. */
|
|
2634
|
-
function elementFindings(checker, element, source) {
|
|
2635
|
-
if (isAnyType(checker, source)) return [{
|
|
2636
|
-
kind: "assignment",
|
|
2637
|
-
node: element.node
|
|
2638
|
-
}];
|
|
2639
|
-
return element.initializer === void 0 && isPattern(element.target) ? destructuredFindings(checker, element.target, source) : [];
|
|
2640
|
-
}
|
|
2641
|
-
/** The property or tuple slot named `key` that `source` declares, not one an index signature stands for. */
|
|
2642
|
-
function declaredSlot(checker, source, key, at) {
|
|
2643
|
-
const slot = checker.getPropertyOfType(source, key);
|
|
2644
|
-
return slot === void 0 ? void 0 : checker.getTypeOfSymbolAtLocation(slot, at);
|
|
2645
|
-
}
|
|
2646
|
-
function slotFindings(checker, element, source) {
|
|
2647
|
-
const slot = element.key === void 0 ? void 0 : declaredSlot(checker, source, element.key, element.node);
|
|
2648
|
-
return slot === void 0 ? [] : elementFindings(checker, element, slot);
|
|
2649
|
-
}
|
|
2650
|
-
/**
|
|
2651
|
-
* The elements of an untyped destructuring declaration or of a destructuring
|
|
2652
|
-
* assignment that take `any` from what `source` declares: a property or
|
|
2653
|
-
* tuple slot typed `any`, whatever the target's own type, or the whole
|
|
2654
|
-
* pattern once when it reads an `any[]`. An index signature, another iterable
|
|
2655
|
-
* and a rest from an object or a tuple are left alone, as
|
|
2656
|
-
* `typescript/no-unsafe-assignment` leaves them.
|
|
2657
|
-
*/
|
|
2658
|
-
function destructuredFindings(checker, pattern, source) {
|
|
2659
|
-
if (ts.isObjectBindingPattern(pattern) || ts.isObjectLiteralExpression(pattern)) return objectElements(pattern).flatMap((element) => slotFindings(checker, element, source));
|
|
2660
|
-
if (isAnyOrAnyArray(checker, source)) return [{
|
|
2661
|
-
kind: "assignment",
|
|
2662
|
-
node: pattern
|
|
2663
|
-
}];
|
|
2664
|
-
return checker.isTupleType(source) ? arrayElements(pattern).flatMap((element) => slotFindings(checker, element, source)) : [];
|
|
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
|
-
}
|
|
2671
|
-
function declarationFindings(checker, node, initializer) {
|
|
2672
|
-
return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
|
|
2673
|
-
kind: "assignment",
|
|
2674
|
-
node
|
|
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
|
-
}] : [];
|
|
2691
|
-
}
|
|
2692
|
-
function assignmentFindings(checker, node) {
|
|
2693
|
-
if (ts.isVariableDeclaration(node) && node.initializer !== void 0) return declarationFindings(checker, node, node.initializer);
|
|
2694
|
-
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
2695
|
-
if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
|
|
2696
|
-
kind: "assignment",
|
|
2697
|
-
node
|
|
2698
|
-
}];
|
|
2699
|
-
return ts.isObjectLiteralExpression(node.left) || ts.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
|
|
2700
|
-
}
|
|
2701
|
-
if (ts.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
|
|
2702
|
-
kind: "assignment",
|
|
2703
|
-
node
|
|
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);
|
|
2711
|
-
if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) return propertyFindings(checker, node);
|
|
2712
|
-
return [];
|
|
2713
|
-
}
|
|
2714
|
-
function nodeFindings(checker, node) {
|
|
2715
|
-
if (ts.isSpreadElement(node)) return spreadFindings(checker, node);
|
|
2716
|
-
if (ts.isCallExpression(node) || ts.isNewExpression(node) || ts.isTaggedTemplateExpression(node)) return unsafeArguments(checker, node).map((argument) => ({
|
|
2717
|
-
kind: "argument",
|
|
2718
|
-
node: argument
|
|
2719
|
-
}));
|
|
2720
|
-
if (ts.isReturnStatement(node) && node.expression !== void 0) return returned(checker, node.expression);
|
|
2721
|
-
if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) return returned(checker, node.body);
|
|
2722
|
-
return assignmentFindings(checker, node);
|
|
2723
|
-
}
|
|
2724
|
-
function findings({ checker, sourceFile }) {
|
|
2725
|
-
const found = [];
|
|
2726
|
-
function visit(node) {
|
|
2727
|
-
found.push(...nodeFindings(checker, node));
|
|
2728
|
-
ts.forEachChild(node, visit);
|
|
2729
|
-
}
|
|
2730
|
-
visit(sourceFile);
|
|
2731
|
-
return found;
|
|
2732
|
-
}
|
|
2733
|
-
/**
|
|
2734
|
-
* `typescript/no-unsafe-assignment`, `no-unsafe-argument` and
|
|
2735
|
-
* `no-unsafe-return` for the script blocks of a `.vue` file, which
|
|
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`
|
|
2743
|
-
* assigned to a slot declared `any` is reported too, as tsgolint reports it.
|
|
2744
|
-
* TypeScript files stay with tsgolint, and a
|
|
2745
|
-
* component with `generic` type parameters is skipped, as only Vue's compiler
|
|
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.
|
|
2755
|
-
*/
|
|
2756
|
-
const noUnsafeAnyInVueRule = defineRule({
|
|
2757
|
-
meta: {
|
|
2758
|
-
type: "problem",
|
|
2759
|
-
docs: { description: "A Vue component's script assigns, passes and returns no `any` where a type is declared." },
|
|
2760
|
-
messages: {
|
|
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.",
|
|
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.",
|
|
2763
|
-
return: "Unsafe return of an `any` value, which `typescript/no-unsafe-return` reports in a TypeScript file. Return a typed value."
|
|
2764
|
-
}
|
|
2765
|
-
},
|
|
2766
|
-
createOnce(context) {
|
|
2767
|
-
return { Program() {
|
|
2768
|
-
const { filename, sourceCode } = context;
|
|
2769
|
-
if (!filename.endsWith(".vue")) return;
|
|
2770
|
-
const { text } = sourceCode;
|
|
2771
|
-
const linted = lintedSource(filename, text);
|
|
2772
|
-
if (linted === void 0) return;
|
|
2773
|
-
const { offset } = linted;
|
|
2774
|
-
const typed = typedFile(filename, linted.text);
|
|
2775
|
-
if (typed === void 0) return;
|
|
2776
|
-
for (const { kind, node } of findings(typed)) {
|
|
2777
|
-
const start = node.getStart(typed.sourceFile) - offset;
|
|
2778
|
-
const end = node.end - offset;
|
|
2779
|
-
if (start >= 0 && end <= text.length) context.report({
|
|
2780
|
-
messageId: kind,
|
|
2781
|
-
loc: {
|
|
2782
|
-
start: sourceCode.getLocFromIndex(start),
|
|
2783
|
-
end: sourceCode.getLocFromIndex(end)
|
|
2784
|
-
}
|
|
2785
|
-
});
|
|
2786
|
-
}
|
|
2787
|
-
} };
|
|
2788
|
-
}
|
|
2789
|
-
});
|
|
2790
|
-
//#endregion
|
|
2791
2186
|
//#region src/oxc/guardrails/literal-fit.ts
|
|
2792
2187
|
const MAX_DEPTH$1 = 8;
|
|
2793
2188
|
const INDEX = /^\d+$/u;
|
|
2794
2189
|
/** The type a written value has: a shorthand property reads its variable, as a direct assignment would. */
|
|
2795
2190
|
function valueType(checker, value) {
|
|
2796
|
-
const shorthand =
|
|
2191
|
+
const shorthand = typescript6_default.isShorthandPropertyAssignment(value.parent) && value.parent.name === value ? checker.getShorthandAssignmentValueSymbol(value.parent) : void 0;
|
|
2797
2192
|
return shorthand === void 0 ? checker.getTypeAtLocation(value) : checker.getTypeOfSymbolAtLocation(shorthand, value);
|
|
2798
2193
|
}
|
|
2799
2194
|
function propertyName(property) {
|
|
2800
|
-
if (!(
|
|
2195
|
+
if (!(typescript6_default.isPropertyAssignment(property) || typescript6_default.isShorthandPropertyAssignment(property)) || !(typescript6_default.isIdentifier(property.name) || typescript6_default.isStringLiteral(property.name) || typescript6_default.isNumericLiteral(property.name))) return void 0;
|
|
2801
2196
|
return {
|
|
2802
2197
|
name: property.name.text,
|
|
2803
|
-
value:
|
|
2198
|
+
value: typescript6_default.isPropertyAssignment(property) ? property.initializer : property.name
|
|
2804
2199
|
};
|
|
2805
2200
|
}
|
|
2806
2201
|
function objectFits(checker, literal, type, depth) {
|
|
@@ -2810,20 +2205,20 @@ function objectFits(checker, literal, type, depth) {
|
|
|
2810
2205
|
if (named === void 0) return false;
|
|
2811
2206
|
names.add(named.name);
|
|
2812
2207
|
const field = checker.getPropertyOfType(type, named.name);
|
|
2813
|
-
const fieldType = field === void 0 ? checker.getIndexTypeOfType(type,
|
|
2208
|
+
const fieldType = field === void 0 ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.String) : checker.getTypeOfSymbolAtLocation(field, literal);
|
|
2814
2209
|
if (fieldType === void 0 || !literalFits(checker, named.value, fieldType, depth + 1)) return false;
|
|
2815
2210
|
}
|
|
2816
|
-
return checker.getPropertiesOfType(type).every((field) => (field.flags &
|
|
2211
|
+
return checker.getPropertiesOfType(type).every((field) => (field.flags & typescript6_default.SymbolFlags.Optional) !== 0 || names.has(field.name));
|
|
2817
2212
|
}
|
|
2818
2213
|
function arrayFits(checker, literal, type, depth) {
|
|
2819
2214
|
const { elements } = literal;
|
|
2820
|
-
if (elements.some((element) =>
|
|
2215
|
+
if (elements.some((element) => typescript6_default.isSpreadElement(element) || typescript6_default.isOmittedExpression(element))) return false;
|
|
2821
2216
|
if (checker.isTupleType(type)) {
|
|
2822
2217
|
const slots = checker.getPropertiesOfType(type).filter((slot) => INDEX.test(slot.name));
|
|
2823
|
-
const required = slots.filter((slot) => (slot.flags &
|
|
2218
|
+
const required = slots.filter((slot) => (slot.flags & typescript6_default.SymbolFlags.Optional) === 0);
|
|
2824
2219
|
return elements.length >= required.length && elements.length <= slots.length && elements.every((element, index) => literalFits(checker, element, checker.getTypeOfSymbolAtLocation(slots[index], literal), depth + 1));
|
|
2825
2220
|
}
|
|
2826
|
-
const element = checker.getIndexTypeOfType(type,
|
|
2221
|
+
const element = checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number);
|
|
2827
2222
|
return element !== void 0 && elements.every((value) => literalFits(checker, value, element, depth + 1));
|
|
2828
2223
|
}
|
|
2829
2224
|
/**
|
|
@@ -2835,35 +2230,35 @@ function arrayFits(checker, literal, type, depth) {
|
|
|
2835
2230
|
*/
|
|
2836
2231
|
function literalFits(checker, expression, type, depth = 0) {
|
|
2837
2232
|
let value = expression;
|
|
2838
|
-
while (
|
|
2233
|
+
while (typescript6_default.isParenthesizedExpression(value)) value = value.expression;
|
|
2839
2234
|
if (checker.isTypeAssignableTo(valueType(checker, value), type)) return true;
|
|
2840
|
-
if (!
|
|
2235
|
+
if (!typescript6_default.isObjectLiteralExpression(value) && !typescript6_default.isArrayLiteralExpression(value)) return false;
|
|
2841
2236
|
if (depth === MAX_DEPTH$1) return true;
|
|
2842
2237
|
if (type.isUnion()) return type.types.some((member) => literalFits(checker, value, member, depth));
|
|
2843
|
-
return
|
|
2238
|
+
return typescript6_default.isObjectLiteralExpression(value) ? objectFits(checker, value, type, depth) : arrayFits(checker, value, type, depth);
|
|
2844
2239
|
}
|
|
2845
2240
|
//#endregion
|
|
2846
2241
|
//#region src/oxc/guardrails/rules/no-unsafe-object-assign.ts
|
|
2847
|
-
const UNTYPED =
|
|
2242
|
+
const UNTYPED = typescript6_default.TypeFlags.Any | typescript6_default.TypeFlags.Unknown;
|
|
2848
2243
|
const MAX_DEPTH = 4;
|
|
2849
2244
|
function members(type) {
|
|
2850
2245
|
return type.isUnion() ? type.types : [type];
|
|
2851
2246
|
}
|
|
2852
2247
|
/** Whether `type` is `any`, or holds `any` in a union, an intersection or the elements of an array or tuple, as in `any[]`. */
|
|
2853
2248
|
function holdsAny(checker, type, depth = 0) {
|
|
2854
|
-
if (type.flags &
|
|
2249
|
+
if (type.flags & typescript6_default.TypeFlags.Any) return true;
|
|
2855
2250
|
if (depth === MAX_DEPTH) return false;
|
|
2856
|
-
const element = checker.isArrayType(type) || checker.isTupleType(type) ? checker.getIndexTypeOfType(type,
|
|
2251
|
+
const element = checker.isArrayType(type) || checker.isTupleType(type) ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number) : void 0;
|
|
2857
2252
|
return (type.isUnionOrIntersection() ? type.types : element === void 0 ? [] : [element]).some((member) => holdsAny(checker, member, depth + 1));
|
|
2858
2253
|
}
|
|
2859
2254
|
/** Whether a declaration sits inside a generic class, interface or type alias, whose type parameters the public checker API cannot instantiate for a declaration. */
|
|
2860
2255
|
function insideGeneric(declaration) {
|
|
2861
|
-
for (let node = declaration.parent; !
|
|
2256
|
+
for (let node = declaration.parent; !typescript6_default.isSourceFile(node); node = node.parent) if ((typescript6_default.isClassLike(node) || typescript6_default.isInterfaceDeclaration(node) || typescript6_default.isTypeAliasDeclaration(node)) && node.typeParameters !== void 0) return true;
|
|
2862
2257
|
return false;
|
|
2863
2258
|
}
|
|
2864
2259
|
/** The types a field accepts: its read type, and its setter's parameter type. Undefined when the setter sits inside a generic declaration, whose parameter type this rule cannot instantiate. */
|
|
2865
2260
|
function acceptedTypes(checker, field, source) {
|
|
2866
|
-
const setter = field.declarations?.find(
|
|
2261
|
+
const setter = field.declarations?.find(typescript6_default.isSetAccessorDeclaration);
|
|
2867
2262
|
const parameter = setter?.parameters[0];
|
|
2868
2263
|
const read = checker.getTypeOfSymbolAtLocation(field, source);
|
|
2869
2264
|
if (setter === void 0 || parameter === void 0) return [read];
|
|
@@ -2875,15 +2270,15 @@ function untyped(type) {
|
|
|
2875
2270
|
function typeVerdict({ checker, exactOptional }, type, accepted, optional) {
|
|
2876
2271
|
if (accepted.length === 0 || accepted.some(untyped)) return void 0;
|
|
2877
2272
|
if (untyped(type) || holdsAny(checker, type) && !accepted.some((member) => holdsAny(checker, member))) return "untypedField";
|
|
2878
|
-
return (optional && !exactOptional ? members(type).filter((member) => !(member.flags &
|
|
2273
|
+
return (optional && !exactOptional ? members(type).filter((member) => !(member.flags & typescript6_default.TypeFlags.Undefined)) : [type]).every((member) => accepted.some((field) => checker.isTypeAssignableTo(member, field))) ? void 0 : "mistypedField";
|
|
2879
2274
|
}
|
|
2880
2275
|
function fieldWrite(check, property, field, source) {
|
|
2881
2276
|
const { checker } = check;
|
|
2882
2277
|
const accepted = acceptedTypes(checker, field, source);
|
|
2883
2278
|
if (accepted === void 0) return void 0;
|
|
2884
2279
|
const declaration = property.valueDeclaration;
|
|
2885
|
-
const written = declaration !== void 0 && declaration.getSourceFile() === source.getSourceFile() && declaration.pos >= source.pos && declaration.end <= source.end && (
|
|
2886
|
-
const kind = written === void 0 ? typeVerdict(check, checker.getTypeOfSymbolAtLocation(property, source), accepted, (property.flags &
|
|
2280
|
+
const written = declaration !== void 0 && declaration.getSourceFile() === source.getSourceFile() && declaration.pos >= source.pos && declaration.end <= source.end && (typescript6_default.isPropertyAssignment(declaration) || typescript6_default.isShorthandPropertyAssignment(declaration)) ? typescript6_default.isPropertyAssignment(declaration) ? declaration.initializer : declaration.name : void 0;
|
|
2281
|
+
const kind = written === void 0 ? typeVerdict(check, checker.getTypeOfSymbolAtLocation(property, source), accepted, (property.flags & typescript6_default.SymbolFlags.Optional) !== 0) : typeVerdict(check, valueType(checker, written), accepted, false);
|
|
2887
2282
|
if (kind === void 0 || kind === "mistypedField" && written !== void 0 && accepted.some((type) => literalFits(checker, written, type))) return void 0;
|
|
2888
2283
|
return {
|
|
2889
2284
|
kind,
|
|
@@ -2891,13 +2286,13 @@ function fieldWrite(check, property, field, source) {
|
|
|
2891
2286
|
};
|
|
2892
2287
|
}
|
|
2893
2288
|
/** A primitive source member, such as the `false` of `flag && { ... }`, whose apparent members (`valueOf`) `Object.assign` never copies. */
|
|
2894
|
-
const PRIMITIVE =
|
|
2289
|
+
const PRIMITIVE = typescript6_default.TypeFlags.BooleanLike | typescript6_default.TypeFlags.NumberLike | typescript6_default.TypeFlags.StringLike | typescript6_default.TypeFlags.BigIntLike | typescript6_default.TypeFlags.ESSymbolLike | typescript6_default.TypeFlags.Null | typescript6_default.TypeFlags.Undefined | typescript6_default.TypeFlags.Void | typescript6_default.TypeFlags.Never;
|
|
2895
2290
|
/** Whether the target declares a field that does not take `unknown`, which an untyped string-keyed source could overwrite. */
|
|
2896
2291
|
function hasTypedField(checker, target) {
|
|
2897
2292
|
return checker.getPropertiesOfType(target).some((field) => !untyped(checker.getTypeOfSymbol(field)));
|
|
2898
2293
|
}
|
|
2899
2294
|
function untypedKeys(checker, member) {
|
|
2900
|
-
return checker.getIndexInfosOfType(member).some((info) => (info.keyType.flags &
|
|
2295
|
+
return checker.getIndexInfosOfType(member).some((info) => (info.keyType.flags & typescript6_default.TypeFlags.String) !== 0 && untyped(info.type));
|
|
2901
2296
|
}
|
|
2902
2297
|
function sourceWrites(check, target, source) {
|
|
2903
2298
|
const { checker } = check;
|
|
@@ -2930,7 +2325,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2930
2325
|
const linted = lintedSource(context.filename, context.sourceCode.text);
|
|
2931
2326
|
const typed = linted && typedFile(context.filename, linted.text);
|
|
2932
2327
|
const [start, end] = node.range;
|
|
2933
|
-
const call = linted && typed && nodeAt(typed.sourceFile, { range: [start + linted.offset, end + linted.offset] },
|
|
2328
|
+
const call = linted && typed && nodeAt(typed.sourceFile, { range: [start + linted.offset, end + linted.offset] }, typescript6_default.isCallExpression);
|
|
2934
2329
|
if (typed === void 0 || call === void 0) return;
|
|
2935
2330
|
const declared = typed.checker.getTypeAtLocation(call.arguments[0]);
|
|
2936
2331
|
const target = declared.isTypeParameter() ? typed.checker.getBaseConstraintOfType(declared) ?? declared : declared;
|
|
@@ -2940,7 +2335,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2940
2335
|
exactOptional: typed.options.exactOptionalPropertyTypes === true
|
|
2941
2336
|
};
|
|
2942
2337
|
call.arguments.slice(1).forEach((source, index) => {
|
|
2943
|
-
if (
|
|
2338
|
+
if (typescript6_default.isSpreadElement(source)) return;
|
|
2944
2339
|
for (const write of sourceWrites(check, target, source)) context.report({
|
|
2945
2340
|
node: node.arguments[index + 1],
|
|
2946
2341
|
messageId: write.kind,
|
|
@@ -3009,7 +2404,7 @@ function isStringLiteral(node) {
|
|
|
3009
2404
|
function moduleResolves(config, filename, text, source) {
|
|
3010
2405
|
if (resolves(config, source.value, filename)) return true;
|
|
3011
2406
|
const typed = typedFile(filename, text);
|
|
3012
|
-
const literal = typed && nodeAt(typed.sourceFile, source,
|
|
2407
|
+
const literal = typed && nodeAt(typed.sourceFile, source, typescript6_default.isStringLiteral);
|
|
3013
2408
|
return typed === void 0 || literal === void 0 || typed.checker.getSymbolAtLocation(literal) !== void 0;
|
|
3014
2409
|
}
|
|
3015
2410
|
/** A file type-aware lint reads must be listed by a tsconfig, or tsgolint types it without the repository's compiler options and `types`; and that tsconfig must resolve its imports, or the program types everything imported through one as an error type. */
|
|
@@ -3086,7 +2481,7 @@ const requireTsconfigTypesRule = defineRule({
|
|
|
3086
2481
|
});
|
|
3087
2482
|
//#endregion
|
|
3088
2483
|
//#region src/oxc/guardrails/index.ts
|
|
3089
|
-
/** 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,
|
|
2484
|
+
/** 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`. */
|
|
3090
2485
|
const guardrailsPlugin = eslintCompatPlugin({
|
|
3091
2486
|
meta: { name: "antelopejs" },
|
|
3092
2487
|
rules: {
|
|
@@ -3099,7 +2494,6 @@ const guardrailsPlugin = eslintCompatPlugin({
|
|
|
3099
2494
|
"no-self-import-in-tests": noSelfImportInTestsRule,
|
|
3100
2495
|
"no-typeof-function-only-test": noTypeofFunctionOnlyTestRule,
|
|
3101
2496
|
"no-unrun-query": noUnrunQueryRule,
|
|
3102
|
-
"no-unsafe-any-in-vue": noUnsafeAnyInVueRule,
|
|
3103
2497
|
"no-unsafe-object-assign": noUnsafeObjectAssignRule,
|
|
3104
2498
|
"require-assertion": requireAssertionRule,
|
|
3105
2499
|
"require-tsconfig-include": requireTsconfigIncludeRule,
|