@antelopejs/tooling-configs 0.7.3 → 0.7.4
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 +31 -3
- package/dist/bin/api-diff.mjs +16 -16
- package/dist/bin/body-check.mjs +1 -1
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +1 -1
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/ratchet.mjs +3 -3
- package/dist/bin/readme-strip.mjs +1 -1
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +41 -28
- package/dist/bin/tsc.d.mts +1 -0
- package/dist/bin/tsc.mjs +24 -0
- package/dist/bin/verify.mjs +89 -89
- package/dist/{checks-CSlWvky1.mjs → checks-BTFf0Evy.mjs} +31 -33
- package/dist/{docs-compat-BAZiPLZt.mjs → docs-compat-BmczGA1d.mjs} +1 -1
- package/dist/eslint.mjs +1 -1
- package/dist/{guardrails-nj7NTglr.mjs → guardrails-CNmSFSxO.mjs} +120 -120
- package/dist/{installed-typescript-6MtIWlE4.mjs → installed-typescript-CF_FR9DV.mjs} +17 -17
- package/dist/oxc/guardrails/index.mjs +1 -1
- package/dist/oxc/lint.mjs +1 -1
- package/dist/{package-DDG3YH7W.mjs → package-1pH5I0TF.mjs} +3 -7
- package/dist/{proof-stamp-BFV7JTZT.mjs → proof-stamp-Bg4ULLvr.mjs} +2 -2
- package/dist/{ratchet-DLCfeaPY.mjs → ratchet-CPpvIU6Y.mjs} +2 -2
- package/dist/{suppression-base-CYaLZAq7.mjs → suppression-base-CDiFJse2.mjs} +2 -2
- package/dist/{suppression-budget-CPDSFg4X.mjs → suppression-budget-BeJIgSTO.mjs} +1 -1
- package/dist/{suppressions-CxPnh4sC.mjs → suppressions-BvWGA463.mjs} +5 -1
- package/dist/{templates-HG0fel2S.mjs → templates-Df6SlGLA.mjs} +1 -1
- package/dist/{typescript-QfxkJYzd.mjs → typescript-B0df00nl.mjs} +13 -13
- package/dist/typescript-version-CptQKjGz.mjs +18 -0
- package/dist/typescript6-BWqCcXGY.mjs +2 -0
- package/dist/typescript6-HdyOMBv3.mjs +8 -0
- package/package.json +27 -5
|
@@ -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
|
{
|
|
@@ -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
|
}
|
|
@@ -2184,18 +2184,18 @@ const noUnrunQueryRule = defineRule({
|
|
|
2184
2184
|
});
|
|
2185
2185
|
//#endregion
|
|
2186
2186
|
//#region src/oxc/guardrails/any-leaks.ts
|
|
2187
|
-
const UNTYPED$1 =
|
|
2187
|
+
const UNTYPED$1 = typescript6_default.TypeFlags.Any | typescript6_default.TypeFlags.Unknown;
|
|
2188
2188
|
/** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
|
|
2189
2189
|
function isAnyType(checker, type) {
|
|
2190
2190
|
return type === checker.getAnyType();
|
|
2191
2191
|
}
|
|
2192
2192
|
/** Whether `type` is `unknown`. */
|
|
2193
2193
|
function isUnknown(type) {
|
|
2194
|
-
return type !== void 0 && (type.flags &
|
|
2194
|
+
return type !== void 0 && (type.flags & typescript6_default.TypeFlags.Unknown) !== 0;
|
|
2195
2195
|
}
|
|
2196
2196
|
/** The element type of an array or a readonly array, whether or not an alias names it, `undefined` for another type. */
|
|
2197
2197
|
function arrayElement(checker, type) {
|
|
2198
|
-
return checker.isArrayType(type) ? checker.getIndexTypeOfType(type,
|
|
2198
|
+
return checker.isArrayType(type) ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number) : void 0;
|
|
2199
2199
|
}
|
|
2200
2200
|
/** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
|
|
2201
2201
|
function takesAnything(type) {
|
|
@@ -2203,11 +2203,11 @@ function takesAnything(type) {
|
|
|
2203
2203
|
}
|
|
2204
2204
|
/** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
|
|
2205
2205
|
function isObjectType(type) {
|
|
2206
|
-
return (type.flags &
|
|
2206
|
+
return (type.flags & typescript6_default.TypeFlags.Object) !== 0;
|
|
2207
2207
|
}
|
|
2208
2208
|
/** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
|
|
2209
2209
|
function isReference$1(type) {
|
|
2210
|
-
return (type.objectFlags &
|
|
2210
|
+
return (type.objectFlags & typescript6_default.ObjectFlags.Reference) !== 0;
|
|
2211
2211
|
}
|
|
2212
2212
|
/**
|
|
2213
2213
|
* The generic reference `type` is, such as `Set<any>`, `any[]` or a tuple,
|
|
@@ -2220,7 +2220,7 @@ function reference(type) {
|
|
|
2220
2220
|
}
|
|
2221
2221
|
/** Whether `node` is `new Map()`, which the lib types `Map<any, any>` and tsgolint lets into any `Map`. */
|
|
2222
2222
|
function isEmptyMap(node) {
|
|
2223
|
-
return node !== void 0 &&
|
|
2223
|
+
return node !== void 0 && typescript6_default.isNewExpression(node) && typescript6_default.isIdentifier(node.expression) && node.expression.text === "Map" && node.typeArguments === void 0 && (node.arguments === void 0 || node.arguments.length === 0);
|
|
2224
2224
|
}
|
|
2225
2225
|
/**
|
|
2226
2226
|
* Whether a `sender` value lets `any` into a `receiver` slot as an argument,
|
|
@@ -2257,7 +2257,7 @@ function isAnyOrAnyArray(checker, type) {
|
|
|
2257
2257
|
//#endregion
|
|
2258
2258
|
//#region src/oxc/guardrails/any-arguments.ts
|
|
2259
2259
|
function isTupleTarget(target) {
|
|
2260
|
-
return (target.objectFlags &
|
|
2260
|
+
return (target.objectFlags & typescript6_default.ObjectFlags.Tuple) !== 0;
|
|
2261
2261
|
}
|
|
2262
2262
|
function tupleOf(type) {
|
|
2263
2263
|
if (!isObjectType(type) || !isReference$1(type)) return void 0;
|
|
@@ -2284,11 +2284,11 @@ function restOf(checker, type, index) {
|
|
|
2284
2284
|
};
|
|
2285
2285
|
}
|
|
2286
2286
|
function calleeOf(call) {
|
|
2287
|
-
return
|
|
2287
|
+
return typescript6_default.isTaggedTemplateExpression(call) ? call.tag : call.expression;
|
|
2288
2288
|
}
|
|
2289
2289
|
function argumentsOf(call) {
|
|
2290
|
-
if (!
|
|
2291
|
-
return
|
|
2290
|
+
if (!typescript6_default.isTaggedTemplateExpression(call)) return call.arguments ?? [];
|
|
2291
|
+
return typescript6_default.isTemplateExpression(call.template) ? call.template.templateSpans.map((span) => span.expression) : [];
|
|
2292
2292
|
}
|
|
2293
2293
|
function parameterCursor(checker, call, signature) {
|
|
2294
2294
|
const fixed = [];
|
|
@@ -2296,7 +2296,7 @@ function parameterCursor(checker, call, signature) {
|
|
|
2296
2296
|
for (const [index, parameter] of signature.getParameters().entries()) {
|
|
2297
2297
|
const type = checker.getTypeOfSymbolAtLocation(parameter, call);
|
|
2298
2298
|
const declaration = parameter.getDeclarations()?.[0];
|
|
2299
|
-
if (declaration !== void 0 &&
|
|
2299
|
+
if (declaration !== void 0 && typescript6_default.isParameter(declaration) && declaration.dotDotDotToken !== void 0) {
|
|
2300
2300
|
rest = restOf(checker, type, index);
|
|
2301
2301
|
break;
|
|
2302
2302
|
}
|
|
@@ -2334,9 +2334,9 @@ function unsafeArguments(checker, call) {
|
|
|
2334
2334
|
const signature = checker.getResolvedSignature(call);
|
|
2335
2335
|
if (signature === void 0) return [];
|
|
2336
2336
|
const cursor = parameterCursor(checker, call, signature);
|
|
2337
|
-
if (
|
|
2337
|
+
if (typescript6_default.isTaggedTemplateExpression(call)) cursor.next();
|
|
2338
2338
|
return args.flatMap((argument) => {
|
|
2339
|
-
if (!
|
|
2339
|
+
if (!typescript6_default.isSpreadElement(argument)) {
|
|
2340
2340
|
const parameter = cursor.next();
|
|
2341
2341
|
return parameter !== void 0 && leaks(checker, checker.getTypeAtLocation(argument), parameter, argument) ? [argument] : [];
|
|
2342
2342
|
}
|
|
@@ -2348,17 +2348,17 @@ function unsafeArguments(checker, call) {
|
|
|
2348
2348
|
const parameter = cursor.next();
|
|
2349
2349
|
return parameter !== void 0 && leaks(checker, element, parameter) ? [argument] : [];
|
|
2350
2350
|
});
|
|
2351
|
-
if ((tuple.target.combinedFlags &
|
|
2351
|
+
if ((tuple.target.combinedFlags & typescript6_default.ElementFlags.Variable) !== 0) cursor.consumeRest();
|
|
2352
2352
|
return unsafe;
|
|
2353
2353
|
});
|
|
2354
2354
|
}
|
|
2355
2355
|
//#endregion
|
|
2356
2356
|
//#region src/oxc/guardrails/type-order.ts
|
|
2357
2357
|
function isObject(type) {
|
|
2358
|
-
return (type.flags &
|
|
2358
|
+
return (type.flags & typescript6_default.TypeFlags.Object) !== 0;
|
|
2359
2359
|
}
|
|
2360
2360
|
function isReference(type) {
|
|
2361
|
-
return isObject(type) && (type.objectFlags &
|
|
2361
|
+
return isObject(type) && (type.objectFlags & typescript6_default.ObjectFlags.Reference) !== 0;
|
|
2362
2362
|
}
|
|
2363
2363
|
function compareText(a, b) {
|
|
2364
2364
|
if (a === b) return 0;
|
|
@@ -2367,7 +2367,7 @@ function compareText(a, b) {
|
|
|
2367
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
2368
|
function nameSymbol(type) {
|
|
2369
2369
|
if (type.aliasSymbol !== void 0) return type.aliasSymbol;
|
|
2370
|
-
return (type.flags &
|
|
2370
|
+
return (type.flags & typescript6_default.TypeFlags.TypeParameter) !== 0 || isObject(type) && (type.objectFlags & (typescript6_default.ObjectFlags.ClassOrInterface | typescript6_default.ObjectFlags.Reference)) !== 0 ? type.getSymbol() : void 0;
|
|
2371
2371
|
}
|
|
2372
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
2373
|
function compareNodes(a, b) {
|
|
@@ -2452,8 +2452,8 @@ function anyKind(checker, type) {
|
|
|
2452
2452
|
/** The function a returned `value` leaves. */
|
|
2453
2453
|
function ownerOf(value) {
|
|
2454
2454
|
let owner = value.parent;
|
|
2455
|
-
while (!
|
|
2456
|
-
if (
|
|
2455
|
+
while (!typescript6_default.isFunctionLike(owner)) {
|
|
2456
|
+
if (typescript6_default.isSourceFile(owner)) return void 0;
|
|
2457
2457
|
owner = owner.parent;
|
|
2458
2458
|
}
|
|
2459
2459
|
return owner;
|
|
@@ -2461,15 +2461,15 @@ function ownerOf(value) {
|
|
|
2461
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
2462
|
function contextOf(checker, node) {
|
|
2463
2463
|
const { parent } = node;
|
|
2464
|
-
if (
|
|
2465
|
-
if (
|
|
2466
|
-
if (
|
|
2467
|
-
if (
|
|
2468
|
-
return
|
|
2464
|
+
if (typescript6_default.isCallExpression(parent) || typescript6_default.isNewExpression(parent)) return parent.expression === node ? void 0 : checker.getContextualType(node);
|
|
2465
|
+
if (typescript6_default.isVariableDeclaration(parent) || typescript6_default.isPropertyDeclaration(parent) || typescript6_default.isParameter(parent)) return parent.type && checker.getTypeFromTypeNode(parent.type);
|
|
2466
|
+
if (typescript6_default.isJsxExpression(parent)) return checker.getContextualType(parent);
|
|
2467
|
+
if (typescript6_default.isBinaryExpression(parent) && parent.operatorToken.kind === typescript6_default.SyntaxKind.EqualsToken && parent.right === node) return checker.getTypeAtLocation(parent.left);
|
|
2468
|
+
return typescript6_default.isTemplateSpan(parent) ? checker.getContextualType(node) : void 0;
|
|
2469
2469
|
}
|
|
2470
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
2471
|
function declaringType(checker, owner) {
|
|
2472
|
-
return (
|
|
2472
|
+
return (typescript6_default.isArrowFunction(owner) || typescript6_default.isFunctionExpression(owner) ? contextOf(checker, owner) : void 0) ?? checker.getTypeAtLocation(owner);
|
|
2473
2473
|
}
|
|
2474
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
2475
|
function callSignatures(checker, type) {
|
|
@@ -2510,7 +2510,7 @@ function returnLeaks(checker, value) {
|
|
|
2510
2510
|
if (owner === void 0) return false;
|
|
2511
2511
|
const sender = checker.getTypeAtLocation(value);
|
|
2512
2512
|
const returns = callSignatures(checker, declaringType(checker, owner)).map((signature) => signature.getReturnType());
|
|
2513
|
-
const isAsync =
|
|
2513
|
+
const isAsync = typescript6_default.canHaveModifiers(owner) && (typescript6_default.getModifiers(owner)?.some((modifier) => modifier.kind === typescript6_default.SyntaxKind.AsyncKeyword) ?? false);
|
|
2514
2514
|
if (owner.type !== void 0 && annotationExcuses(checker, sender, returns, isAsync)) return false;
|
|
2515
2515
|
const kind = anyKind(checker, sender);
|
|
2516
2516
|
return kind === "safe" ? leaks(checker, sender, returns[0], value) : !anyExcuses(checker, kind, returns, isAsync);
|
|
@@ -2530,11 +2530,11 @@ function leaksIntoContext(checker, value) {
|
|
|
2530
2530
|
function isDestructuringTarget(literal) {
|
|
2531
2531
|
let child = literal;
|
|
2532
2532
|
let parent = literal.parent;
|
|
2533
|
-
while (
|
|
2533
|
+
while (typescript6_default.isParenthesizedExpression(parent) || typescript6_default.isArrayLiteralExpression(parent) || typescript6_default.isObjectLiteralExpression(parent) || typescript6_default.isPropertyAssignment(parent) || typescript6_default.isShorthandPropertyAssignment(parent) || typescript6_default.isSpreadElement(parent) || typescript6_default.isSpreadAssignment(parent)) {
|
|
2534
2534
|
child = parent;
|
|
2535
2535
|
parent = parent.parent;
|
|
2536
2536
|
}
|
|
2537
|
-
return
|
|
2537
|
+
return typescript6_default.isBinaryExpression(parent) && parent.operatorToken.kind === typescript6_default.SyntaxKind.EqualsToken && parent.left === child || (typescript6_default.isForOfStatement(parent) || typescript6_default.isForInStatement(parent)) && parent.initializer === child;
|
|
2538
2538
|
}
|
|
2539
2539
|
function returned(checker, value) {
|
|
2540
2540
|
return returnLeaks(checker, value) ? [{
|
|
@@ -2544,36 +2544,36 @@ function returned(checker, value) {
|
|
|
2544
2544
|
}
|
|
2545
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
2546
|
function spreadFindings(checker, spread) {
|
|
2547
|
-
return
|
|
2547
|
+
return typescript6_default.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
|
|
2548
2548
|
kind: "assignment",
|
|
2549
2549
|
node: spread
|
|
2550
2550
|
}] : [];
|
|
2551
2551
|
}
|
|
2552
2552
|
function propertyFindings(checker, property) {
|
|
2553
2553
|
if (isDestructuringTarget(property.parent)) {
|
|
2554
|
-
const fallback =
|
|
2554
|
+
const fallback = typescript6_default.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
|
|
2555
2555
|
return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
|
|
2556
2556
|
kind: "assignment",
|
|
2557
2557
|
node: property
|
|
2558
2558
|
}] : [];
|
|
2559
2559
|
}
|
|
2560
|
-
return leaksIntoContext(checker,
|
|
2560
|
+
return leaksIntoContext(checker, typescript6_default.isPropertyAssignment(property) ? property.initializer : property.name) ? [{
|
|
2561
2561
|
kind: "assignment",
|
|
2562
2562
|
node: property
|
|
2563
2563
|
}] : [];
|
|
2564
2564
|
}
|
|
2565
2565
|
function isPattern(node) {
|
|
2566
|
-
return
|
|
2566
|
+
return typescript6_default.isObjectBindingPattern(node) || typescript6_default.isArrayBindingPattern(node) || typescript6_default.isObjectLiteralExpression(node) || typescript6_default.isArrayLiteralExpression(node);
|
|
2567
2567
|
}
|
|
2568
2568
|
/** The key a property name spells, a computed literal such as `['a']` included. */
|
|
2569
2569
|
function literalKey(name) {
|
|
2570
|
-
if (
|
|
2571
|
-
const key =
|
|
2572
|
-
return
|
|
2570
|
+
if (typescript6_default.isIdentifier(name)) return name.text;
|
|
2571
|
+
const key = typescript6_default.isComputedPropertyName(name) ? name.expression : name;
|
|
2572
|
+
return typescript6_default.isStringLiteral(key) || typescript6_default.isNumericLiteral(key) || typescript6_default.isNoSubstitutionTemplateLiteral(key) ? key.text : void 0;
|
|
2573
2573
|
}
|
|
2574
2574
|
/** The target and default of an assignment pattern element, as in `a = fallback`. */
|
|
2575
2575
|
function withDefault(element) {
|
|
2576
|
-
return
|
|
2576
|
+
return typescript6_default.isBinaryExpression(element) && element.operatorToken.kind === typescript6_default.SyntaxKind.EqualsToken ? {
|
|
2577
2577
|
target: element.left,
|
|
2578
2578
|
initializer: element.right
|
|
2579
2579
|
} : {
|
|
@@ -2582,19 +2582,19 @@ function withDefault(element) {
|
|
|
2582
2582
|
};
|
|
2583
2583
|
}
|
|
2584
2584
|
function objectElements(pattern) {
|
|
2585
|
-
if (
|
|
2585
|
+
if (typescript6_default.isObjectBindingPattern(pattern)) return pattern.elements.map((element) => ({
|
|
2586
2586
|
key: element.dotDotDotToken === void 0 ? literalKey(element.propertyName ?? element.name) : void 0,
|
|
2587
2587
|
target: element.name,
|
|
2588
2588
|
initializer: element.initializer,
|
|
2589
2589
|
node: element
|
|
2590
2590
|
}));
|
|
2591
2591
|
return pattern.properties.map((property) => {
|
|
2592
|
-
if (
|
|
2592
|
+
if (typescript6_default.isPropertyAssignment(property)) return {
|
|
2593
2593
|
key: literalKey(property.name),
|
|
2594
2594
|
...withDefault(property.initializer),
|
|
2595
2595
|
node: property
|
|
2596
2596
|
};
|
|
2597
|
-
if (
|
|
2597
|
+
if (typescript6_default.isShorthandPropertyAssignment(property)) return {
|
|
2598
2598
|
key: property.name.text,
|
|
2599
2599
|
target: property.name,
|
|
2600
2600
|
initializer: property.objectAssignmentInitializer,
|
|
@@ -2610,14 +2610,14 @@ function objectElements(pattern) {
|
|
|
2610
2610
|
}
|
|
2611
2611
|
function arrayElements(pattern) {
|
|
2612
2612
|
return pattern.elements.flatMap((element, index) => {
|
|
2613
|
-
if (
|
|
2614
|
-
if (
|
|
2613
|
+
if (typescript6_default.isOmittedExpression(element)) return [];
|
|
2614
|
+
if (typescript6_default.isBindingElement(element)) return [{
|
|
2615
2615
|
key: element.dotDotDotToken === void 0 ? String(index) : void 0,
|
|
2616
2616
|
target: element.name,
|
|
2617
2617
|
initializer: element.initializer,
|
|
2618
2618
|
node: element
|
|
2619
2619
|
}];
|
|
2620
|
-
if (
|
|
2620
|
+
if (typescript6_default.isSpreadElement(element)) return [{
|
|
2621
2621
|
key: void 0,
|
|
2622
2622
|
target: element.expression,
|
|
2623
2623
|
initializer: void 0,
|
|
@@ -2656,7 +2656,7 @@ function slotFindings(checker, element, source) {
|
|
|
2656
2656
|
* `typescript/no-unsafe-assignment` leaves them.
|
|
2657
2657
|
*/
|
|
2658
2658
|
function destructuredFindings(checker, pattern, source) {
|
|
2659
|
-
if (
|
|
2659
|
+
if (typescript6_default.isObjectBindingPattern(pattern) || typescript6_default.isObjectLiteralExpression(pattern)) return objectElements(pattern).flatMap((element) => slotFindings(checker, element, source));
|
|
2660
2660
|
if (isAnyOrAnyArray(checker, source)) return [{
|
|
2661
2661
|
kind: "assignment",
|
|
2662
2662
|
node: pattern
|
|
@@ -2666,7 +2666,7 @@ function destructuredFindings(checker, pattern, source) {
|
|
|
2666
2666
|
/** The elements a pattern `name`, annotated or not, takes `any` into from `initializer`. */
|
|
2667
2667
|
function bindingFindings(checker, name, initializer) {
|
|
2668
2668
|
const source = checker.getTypeAtLocation(initializer);
|
|
2669
|
-
return
|
|
2669
|
+
return typescript6_default.isIdentifier(name) ? [] : destructuredFindings(checker, name, source);
|
|
2670
2670
|
}
|
|
2671
2671
|
function declarationFindings(checker, node, initializer) {
|
|
2672
2672
|
return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
|
|
@@ -2676,7 +2676,7 @@ function declarationFindings(checker, node, initializer) {
|
|
|
2676
2676
|
}
|
|
2677
2677
|
/** A JSX attribute whose value lets `any` into the prop it fills. */
|
|
2678
2678
|
function attributeFindings(checker, attribute) {
|
|
2679
|
-
const value = attribute.initializer !== void 0 &&
|
|
2679
|
+
const value = attribute.initializer !== void 0 && typescript6_default.isJsxExpression(attribute.initializer) ? attribute.initializer.expression : void 0;
|
|
2680
2680
|
return value !== void 0 && leaksIntoContext(checker, value) ? [{
|
|
2681
2681
|
kind: "assignment",
|
|
2682
2682
|
node: value
|
|
@@ -2690,42 +2690,42 @@ function fieldFindings(checker, field) {
|
|
|
2690
2690
|
}] : [];
|
|
2691
2691
|
}
|
|
2692
2692
|
function assignmentFindings(checker, node) {
|
|
2693
|
-
if (
|
|
2694
|
-
if (
|
|
2693
|
+
if (typescript6_default.isVariableDeclaration(node) && node.initializer !== void 0) return declarationFindings(checker, node, node.initializer);
|
|
2694
|
+
if (typescript6_default.isBinaryExpression(node) && node.operatorToken.kind === typescript6_default.SyntaxKind.EqualsToken) {
|
|
2695
2695
|
if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
|
|
2696
2696
|
kind: "assignment",
|
|
2697
2697
|
node
|
|
2698
2698
|
}];
|
|
2699
|
-
return
|
|
2699
|
+
return typescript6_default.isObjectLiteralExpression(node.left) || typescript6_default.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
|
|
2700
2700
|
}
|
|
2701
|
-
if (
|
|
2701
|
+
if (typescript6_default.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
|
|
2702
2702
|
kind: "assignment",
|
|
2703
2703
|
node
|
|
2704
2704
|
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2705
|
-
if (
|
|
2705
|
+
if (typescript6_default.isBindingElement(node) && node.initializer !== void 0) return assignmentLeaks(checker, node.initializer, checker.getTypeAtLocation(node.name)) ? [{
|
|
2706
2706
|
kind: "assignment",
|
|
2707
2707
|
node
|
|
2708
2708
|
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2709
|
-
if (
|
|
2710
|
-
if (
|
|
2711
|
-
if (
|
|
2709
|
+
if (typescript6_default.isJsxAttribute(node)) return attributeFindings(checker, node);
|
|
2710
|
+
if (typescript6_default.isPropertyDeclaration(node)) return fieldFindings(checker, node);
|
|
2711
|
+
if (typescript6_default.isPropertyAssignment(node) || typescript6_default.isShorthandPropertyAssignment(node)) return propertyFindings(checker, node);
|
|
2712
2712
|
return [];
|
|
2713
2713
|
}
|
|
2714
2714
|
function nodeFindings(checker, node) {
|
|
2715
|
-
if (
|
|
2716
|
-
if (
|
|
2715
|
+
if (typescript6_default.isSpreadElement(node)) return spreadFindings(checker, node);
|
|
2716
|
+
if (typescript6_default.isCallExpression(node) || typescript6_default.isNewExpression(node) || typescript6_default.isTaggedTemplateExpression(node)) return unsafeArguments(checker, node).map((argument) => ({
|
|
2717
2717
|
kind: "argument",
|
|
2718
2718
|
node: argument
|
|
2719
2719
|
}));
|
|
2720
|
-
if (
|
|
2721
|
-
if (
|
|
2720
|
+
if (typescript6_default.isReturnStatement(node) && node.expression !== void 0) return returned(checker, node.expression);
|
|
2721
|
+
if (typescript6_default.isArrowFunction(node) && !typescript6_default.isBlock(node.body)) return returned(checker, node.body);
|
|
2722
2722
|
return assignmentFindings(checker, node);
|
|
2723
2723
|
}
|
|
2724
2724
|
function findings({ checker, sourceFile }) {
|
|
2725
2725
|
const found = [];
|
|
2726
2726
|
function visit(node) {
|
|
2727
2727
|
found.push(...nodeFindings(checker, node));
|
|
2728
|
-
|
|
2728
|
+
typescript6_default.forEachChild(node, visit);
|
|
2729
2729
|
}
|
|
2730
2730
|
visit(sourceFile);
|
|
2731
2731
|
return found;
|
|
@@ -2793,14 +2793,14 @@ const MAX_DEPTH$1 = 8;
|
|
|
2793
2793
|
const INDEX = /^\d+$/u;
|
|
2794
2794
|
/** The type a written value has: a shorthand property reads its variable, as a direct assignment would. */
|
|
2795
2795
|
function valueType(checker, value) {
|
|
2796
|
-
const shorthand =
|
|
2796
|
+
const shorthand = typescript6_default.isShorthandPropertyAssignment(value.parent) && value.parent.name === value ? checker.getShorthandAssignmentValueSymbol(value.parent) : void 0;
|
|
2797
2797
|
return shorthand === void 0 ? checker.getTypeAtLocation(value) : checker.getTypeOfSymbolAtLocation(shorthand, value);
|
|
2798
2798
|
}
|
|
2799
2799
|
function propertyName(property) {
|
|
2800
|
-
if (!(
|
|
2800
|
+
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
2801
|
return {
|
|
2802
2802
|
name: property.name.text,
|
|
2803
|
-
value:
|
|
2803
|
+
value: typescript6_default.isPropertyAssignment(property) ? property.initializer : property.name
|
|
2804
2804
|
};
|
|
2805
2805
|
}
|
|
2806
2806
|
function objectFits(checker, literal, type, depth) {
|
|
@@ -2810,20 +2810,20 @@ function objectFits(checker, literal, type, depth) {
|
|
|
2810
2810
|
if (named === void 0) return false;
|
|
2811
2811
|
names.add(named.name);
|
|
2812
2812
|
const field = checker.getPropertyOfType(type, named.name);
|
|
2813
|
-
const fieldType = field === void 0 ? checker.getIndexTypeOfType(type,
|
|
2813
|
+
const fieldType = field === void 0 ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.String) : checker.getTypeOfSymbolAtLocation(field, literal);
|
|
2814
2814
|
if (fieldType === void 0 || !literalFits(checker, named.value, fieldType, depth + 1)) return false;
|
|
2815
2815
|
}
|
|
2816
|
-
return checker.getPropertiesOfType(type).every((field) => (field.flags &
|
|
2816
|
+
return checker.getPropertiesOfType(type).every((field) => (field.flags & typescript6_default.SymbolFlags.Optional) !== 0 || names.has(field.name));
|
|
2817
2817
|
}
|
|
2818
2818
|
function arrayFits(checker, literal, type, depth) {
|
|
2819
2819
|
const { elements } = literal;
|
|
2820
|
-
if (elements.some((element) =>
|
|
2820
|
+
if (elements.some((element) => typescript6_default.isSpreadElement(element) || typescript6_default.isOmittedExpression(element))) return false;
|
|
2821
2821
|
if (checker.isTupleType(type)) {
|
|
2822
2822
|
const slots = checker.getPropertiesOfType(type).filter((slot) => INDEX.test(slot.name));
|
|
2823
|
-
const required = slots.filter((slot) => (slot.flags &
|
|
2823
|
+
const required = slots.filter((slot) => (slot.flags & typescript6_default.SymbolFlags.Optional) === 0);
|
|
2824
2824
|
return elements.length >= required.length && elements.length <= slots.length && elements.every((element, index) => literalFits(checker, element, checker.getTypeOfSymbolAtLocation(slots[index], literal), depth + 1));
|
|
2825
2825
|
}
|
|
2826
|
-
const element = checker.getIndexTypeOfType(type,
|
|
2826
|
+
const element = checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number);
|
|
2827
2827
|
return element !== void 0 && elements.every((value) => literalFits(checker, value, element, depth + 1));
|
|
2828
2828
|
}
|
|
2829
2829
|
/**
|
|
@@ -2835,35 +2835,35 @@ function arrayFits(checker, literal, type, depth) {
|
|
|
2835
2835
|
*/
|
|
2836
2836
|
function literalFits(checker, expression, type, depth = 0) {
|
|
2837
2837
|
let value = expression;
|
|
2838
|
-
while (
|
|
2838
|
+
while (typescript6_default.isParenthesizedExpression(value)) value = value.expression;
|
|
2839
2839
|
if (checker.isTypeAssignableTo(valueType(checker, value), type)) return true;
|
|
2840
|
-
if (!
|
|
2840
|
+
if (!typescript6_default.isObjectLiteralExpression(value) && !typescript6_default.isArrayLiteralExpression(value)) return false;
|
|
2841
2841
|
if (depth === MAX_DEPTH$1) return true;
|
|
2842
2842
|
if (type.isUnion()) return type.types.some((member) => literalFits(checker, value, member, depth));
|
|
2843
|
-
return
|
|
2843
|
+
return typescript6_default.isObjectLiteralExpression(value) ? objectFits(checker, value, type, depth) : arrayFits(checker, value, type, depth);
|
|
2844
2844
|
}
|
|
2845
2845
|
//#endregion
|
|
2846
2846
|
//#region src/oxc/guardrails/rules/no-unsafe-object-assign.ts
|
|
2847
|
-
const UNTYPED =
|
|
2847
|
+
const UNTYPED = typescript6_default.TypeFlags.Any | typescript6_default.TypeFlags.Unknown;
|
|
2848
2848
|
const MAX_DEPTH = 4;
|
|
2849
2849
|
function members(type) {
|
|
2850
2850
|
return type.isUnion() ? type.types : [type];
|
|
2851
2851
|
}
|
|
2852
2852
|
/** Whether `type` is `any`, or holds `any` in a union, an intersection or the elements of an array or tuple, as in `any[]`. */
|
|
2853
2853
|
function holdsAny(checker, type, depth = 0) {
|
|
2854
|
-
if (type.flags &
|
|
2854
|
+
if (type.flags & typescript6_default.TypeFlags.Any) return true;
|
|
2855
2855
|
if (depth === MAX_DEPTH) return false;
|
|
2856
|
-
const element = checker.isArrayType(type) || checker.isTupleType(type) ? checker.getIndexTypeOfType(type,
|
|
2856
|
+
const element = checker.isArrayType(type) || checker.isTupleType(type) ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number) : void 0;
|
|
2857
2857
|
return (type.isUnionOrIntersection() ? type.types : element === void 0 ? [] : [element]).some((member) => holdsAny(checker, member, depth + 1));
|
|
2858
2858
|
}
|
|
2859
2859
|
/** 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
2860
|
function insideGeneric(declaration) {
|
|
2861
|
-
for (let node = declaration.parent; !
|
|
2861
|
+
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
2862
|
return false;
|
|
2863
2863
|
}
|
|
2864
2864
|
/** 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
2865
|
function acceptedTypes(checker, field, source) {
|
|
2866
|
-
const setter = field.declarations?.find(
|
|
2866
|
+
const setter = field.declarations?.find(typescript6_default.isSetAccessorDeclaration);
|
|
2867
2867
|
const parameter = setter?.parameters[0];
|
|
2868
2868
|
const read = checker.getTypeOfSymbolAtLocation(field, source);
|
|
2869
2869
|
if (setter === void 0 || parameter === void 0) return [read];
|
|
@@ -2875,15 +2875,15 @@ function untyped(type) {
|
|
|
2875
2875
|
function typeVerdict({ checker, exactOptional }, type, accepted, optional) {
|
|
2876
2876
|
if (accepted.length === 0 || accepted.some(untyped)) return void 0;
|
|
2877
2877
|
if (untyped(type) || holdsAny(checker, type) && !accepted.some((member) => holdsAny(checker, member))) return "untypedField";
|
|
2878
|
-
return (optional && !exactOptional ? members(type).filter((member) => !(member.flags &
|
|
2878
|
+
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
2879
|
}
|
|
2880
2880
|
function fieldWrite(check, property, field, source) {
|
|
2881
2881
|
const { checker } = check;
|
|
2882
2882
|
const accepted = acceptedTypes(checker, field, source);
|
|
2883
2883
|
if (accepted === void 0) return void 0;
|
|
2884
2884
|
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 &
|
|
2885
|
+
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;
|
|
2886
|
+
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
2887
|
if (kind === void 0 || kind === "mistypedField" && written !== void 0 && accepted.some((type) => literalFits(checker, written, type))) return void 0;
|
|
2888
2888
|
return {
|
|
2889
2889
|
kind,
|
|
@@ -2891,13 +2891,13 @@ function fieldWrite(check, property, field, source) {
|
|
|
2891
2891
|
};
|
|
2892
2892
|
}
|
|
2893
2893
|
/** A primitive source member, such as the `false` of `flag && { ... }`, whose apparent members (`valueOf`) `Object.assign` never copies. */
|
|
2894
|
-
const PRIMITIVE =
|
|
2894
|
+
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
2895
|
/** Whether the target declares a field that does not take `unknown`, which an untyped string-keyed source could overwrite. */
|
|
2896
2896
|
function hasTypedField(checker, target) {
|
|
2897
2897
|
return checker.getPropertiesOfType(target).some((field) => !untyped(checker.getTypeOfSymbol(field)));
|
|
2898
2898
|
}
|
|
2899
2899
|
function untypedKeys(checker, member) {
|
|
2900
|
-
return checker.getIndexInfosOfType(member).some((info) => (info.keyType.flags &
|
|
2900
|
+
return checker.getIndexInfosOfType(member).some((info) => (info.keyType.flags & typescript6_default.TypeFlags.String) !== 0 && untyped(info.type));
|
|
2901
2901
|
}
|
|
2902
2902
|
function sourceWrites(check, target, source) {
|
|
2903
2903
|
const { checker } = check;
|
|
@@ -2930,7 +2930,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2930
2930
|
const linted = lintedSource(context.filename, context.sourceCode.text);
|
|
2931
2931
|
const typed = linted && typedFile(context.filename, linted.text);
|
|
2932
2932
|
const [start, end] = node.range;
|
|
2933
|
-
const call = linted && typed && nodeAt(typed.sourceFile, { range: [start + linted.offset, end + linted.offset] },
|
|
2933
|
+
const call = linted && typed && nodeAt(typed.sourceFile, { range: [start + linted.offset, end + linted.offset] }, typescript6_default.isCallExpression);
|
|
2934
2934
|
if (typed === void 0 || call === void 0) return;
|
|
2935
2935
|
const declared = typed.checker.getTypeAtLocation(call.arguments[0]);
|
|
2936
2936
|
const target = declared.isTypeParameter() ? typed.checker.getBaseConstraintOfType(declared) ?? declared : declared;
|
|
@@ -2940,7 +2940,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2940
2940
|
exactOptional: typed.options.exactOptionalPropertyTypes === true
|
|
2941
2941
|
};
|
|
2942
2942
|
call.arguments.slice(1).forEach((source, index) => {
|
|
2943
|
-
if (
|
|
2943
|
+
if (typescript6_default.isSpreadElement(source)) return;
|
|
2944
2944
|
for (const write of sourceWrites(check, target, source)) context.report({
|
|
2945
2945
|
node: node.arguments[index + 1],
|
|
2946
2946
|
messageId: write.kind,
|
|
@@ -3009,7 +3009,7 @@ function isStringLiteral(node) {
|
|
|
3009
3009
|
function moduleResolves(config, filename, text, source) {
|
|
3010
3010
|
if (resolves(config, source.value, filename)) return true;
|
|
3011
3011
|
const typed = typedFile(filename, text);
|
|
3012
|
-
const literal = typed && nodeAt(typed.sourceFile, source,
|
|
3012
|
+
const literal = typed && nodeAt(typed.sourceFile, source, typescript6_default.isStringLiteral);
|
|
3013
3013
|
return typed === void 0 || literal === void 0 || typed.checker.getSymbolAtLocation(literal) !== void 0;
|
|
3014
3014
|
}
|
|
3015
3015
|
/** 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. */
|