@antelopejs/tooling-configs 0.7.2 → 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 +68 -26
- 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-DvND3Ngb.mjs → checks-BTFf0Evy.mjs} +246 -65
- package/dist/{docs-compat-BAZiPLZt.mjs → docs-compat-BmczGA1d.mjs} +1 -1
- package/dist/eslint.mjs +1 -1
- package/dist/{guardrails-PoMIcyGb.mjs → guardrails-CNmSFSxO.mjs} +128 -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,14 @@ 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
|
+
/** `options` without `pathsBasePath`, the directory of the config that declares `paths`, which TypeScript adds to the key of a parse in {@link documents} though it changes no parse. The programs of configs that keep `paths` in different directories, as the tsconfig Nuxt generates for each site does, then share the files they all read. */
|
|
1880
|
+
function registrySettings(options) {
|
|
1881
|
+
return {
|
|
1882
|
+
...options,
|
|
1883
|
+
pathsBasePath: void 0
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1879
1886
|
function normalize(file) {
|
|
1880
1887
|
return resolve(file).replaceAll("\\", "/");
|
|
1881
1888
|
}
|
|
@@ -1899,7 +1906,7 @@ const tsxViews = /* @__PURE__ */ new Map();
|
|
|
1899
1906
|
function tsxView(name, text, language) {
|
|
1900
1907
|
const cached = tsxViews.get(name);
|
|
1901
1908
|
if (cached?.text === text) return cached;
|
|
1902
|
-
const parsed =
|
|
1909
|
+
const parsed = typescript6_default.createSourceFile(name, text, language, true, typescript6_default.ScriptKind.TSX);
|
|
1903
1910
|
tsxViews.set(name, parsed);
|
|
1904
1911
|
return parsed;
|
|
1905
1912
|
}
|
|
@@ -1909,7 +1916,7 @@ function readView(host, name) {
|
|
|
1909
1916
|
}
|
|
1910
1917
|
/** Whether `sourceFile` is `view` parsed as its kind, JSX read as JSX. */
|
|
1911
1918
|
function parses(sourceFile, view) {
|
|
1912
|
-
return sourceFile?.text === view.text && sourceFile.languageVariant ===
|
|
1919
|
+
return sourceFile?.text === view.text && sourceFile.languageVariant === typescript6_default.LanguageVariant.JSX === view.tsx;
|
|
1913
1920
|
}
|
|
1914
1921
|
function build(config, path, view) {
|
|
1915
1922
|
const parsed = project(config);
|
|
@@ -1919,13 +1926,14 @@ function build(config, path, view) {
|
|
|
1919
1926
|
...parsed.options,
|
|
1920
1927
|
allowNonTsExtensions: true
|
|
1921
1928
|
} : parsed.options;
|
|
1922
|
-
const host =
|
|
1929
|
+
const host = typescript6_default.createCompilerHost(options, true);
|
|
1930
|
+
const settings = registrySettings(options);
|
|
1923
1931
|
host.getSourceFile = (name, language) => {
|
|
1924
1932
|
const content = normalize(name) === path ? view : readView(host, name);
|
|
1925
1933
|
if (content === void 0) return void 0;
|
|
1926
|
-
return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name,
|
|
1934
|
+
return content.tsx ? tsxView(name, content.text, language) : documents.acquireDocument(name, settings, typescript6_default.ScriptSnapshot.fromString(content.text), content.text, void 0, language);
|
|
1927
1935
|
};
|
|
1928
|
-
const program =
|
|
1936
|
+
const program = typescript6_default.createProgram({
|
|
1929
1937
|
rootNames,
|
|
1930
1938
|
options,
|
|
1931
1939
|
host,
|
|
@@ -1961,7 +1969,7 @@ function nodeAt(sourceFile, { range: [start, end] }, test) {
|
|
|
1961
1969
|
function visit(node) {
|
|
1962
1970
|
if (found !== void 0 || node.pos > start || node.end < end) return;
|
|
1963
1971
|
if (test(node) && node.getStart(sourceFile) === start && node.end === end) found = node;
|
|
1964
|
-
else
|
|
1972
|
+
else typescript6_default.forEachChild(node, visit);
|
|
1965
1973
|
}
|
|
1966
1974
|
visit(sourceFile);
|
|
1967
1975
|
return found;
|
|
@@ -2024,7 +2032,7 @@ function callsFirstParameter(call) {
|
|
|
2024
2032
|
}
|
|
2025
2033
|
return false;
|
|
2026
2034
|
}
|
|
2027
|
-
const HOLDERS =
|
|
2035
|
+
const HOLDERS = typescript6_default.SymbolFlags.ObjectLiteral | typescript6_default.SymbolFlags.Interface | typescript6_default.SymbolFlags.TypeLiteral;
|
|
2028
2036
|
function declaredIn(symbol, path) {
|
|
2029
2037
|
return symbol?.declarations?.some((declaration) => declaration.getSourceFile().fileName.includes(path)) === true;
|
|
2030
2038
|
}
|
|
@@ -2040,8 +2048,8 @@ function isTable(checker, type) {
|
|
|
2040
2048
|
function isHolder(type) {
|
|
2041
2049
|
if (type.isIntersection()) return type.types.every(isHolder);
|
|
2042
2050
|
const symbol = type.getSymbol();
|
|
2043
|
-
if (symbol?.declarations?.some(
|
|
2044
|
-
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/");
|
|
2045
2053
|
}
|
|
2046
2054
|
function members$1(type) {
|
|
2047
2055
|
return type.isUnion() ? type.types : [type];
|
|
@@ -2049,7 +2057,7 @@ function members$1(type) {
|
|
|
2049
2057
|
/** The values an array, a tuple or a holder keeps in its properties and index signatures, which awaiting it leaves as they are. */
|
|
2050
2058
|
function heldValues(checker, type) {
|
|
2051
2059
|
if (checker.isArrayType(type) || checker.isTupleType(type)) {
|
|
2052
|
-
const element = checker.getIndexTypeOfType(type,
|
|
2060
|
+
const element = checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number);
|
|
2053
2061
|
return element === void 0 ? [] : [element];
|
|
2054
2062
|
}
|
|
2055
2063
|
if (!isHolder(type)) return [];
|
|
@@ -2071,26 +2079,26 @@ function holdsQuery(checker, type) {
|
|
|
2071
2079
|
}
|
|
2072
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. */
|
|
2073
2081
|
function callbackResult(checker, callback) {
|
|
2074
|
-
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));
|
|
2075
2083
|
}
|
|
2076
2084
|
const executorsByFile = /* @__PURE__ */ new WeakMap();
|
|
2077
2085
|
/** `expression` without the parentheses, `as`, `<T>`, `satisfies` and `!` around it. */
|
|
2078
2086
|
function unwrapped(expression) {
|
|
2079
|
-
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;
|
|
2080
2088
|
}
|
|
2081
2089
|
/** The function a declaration holds: the initialiser of a variable or property, the value a shorthand property names, or the declaration itself. */
|
|
2082
2090
|
function declaredFunctions(checker, declaration) {
|
|
2083
|
-
if (
|
|
2084
|
-
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];
|
|
2085
2093
|
}
|
|
2086
2094
|
/** `value` as a member access the source names, or `undefined` for any other expression. */
|
|
2087
2095
|
function namedMember(value) {
|
|
2088
|
-
if (
|
|
2096
|
+
if (typescript6_default.isPropertyAccessExpression(value)) return {
|
|
2089
2097
|
receiver: value.expression,
|
|
2090
2098
|
key: value,
|
|
2091
2099
|
name: value.name.text
|
|
2092
2100
|
};
|
|
2093
|
-
return
|
|
2101
|
+
return typescript6_default.isElementAccessExpression(value) && typescript6_default.isStringLiteralLike(value.argumentExpression) ? {
|
|
2094
2102
|
receiver: value.expression,
|
|
2095
2103
|
key: value.argumentExpression,
|
|
2096
2104
|
name: value.argumentExpression.text
|
|
@@ -2098,15 +2106,15 @@ function namedMember(value) {
|
|
|
2098
2106
|
}
|
|
2099
2107
|
/** The declarations of `member` on the value its receiver variable is initialised with, past any type annotation that names only a signature. */
|
|
2100
2108
|
function initialisedMember(checker, member) {
|
|
2101
|
-
const receiver =
|
|
2102
|
-
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 ?? [] : [];
|
|
2103
2111
|
}
|
|
2104
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. */
|
|
2105
2113
|
function namedFunctions(checker, argument) {
|
|
2106
2114
|
const value = unwrapped(argument);
|
|
2107
|
-
if (
|
|
2115
|
+
if (typescript6_default.isFunctionExpression(value) || typescript6_default.isArrowFunction(value)) return [value];
|
|
2108
2116
|
const member = namedMember(value);
|
|
2109
|
-
if (!
|
|
2117
|
+
if (!typescript6_default.isIdentifier(value) && member === void 0) return [];
|
|
2110
2118
|
return [...checker.getSymbolAtLocation(member?.key ?? value)?.declarations ?? [], ...member === void 0 ? [] : initialisedMember(checker, member)].flatMap((declaration) => declaredFunctions(checker, declaration));
|
|
2111
2119
|
}
|
|
2112
2120
|
/** The functions `sourceFile` hands to `new Promise` as its executor, inline or by name. */
|
|
@@ -2115,9 +2123,9 @@ function promiseExecutors(checker, sourceFile) {
|
|
|
2115
2123
|
if (known !== void 0) return known;
|
|
2116
2124
|
const executors = /* @__PURE__ */ new Set();
|
|
2117
2125
|
const visit = (node) => {
|
|
2118
|
-
const argument =
|
|
2126
|
+
const argument = typescript6_default.isNewExpression(node) && typescript6_default.isIdentifier(node.expression) && node.expression.text === "Promise" ? node.arguments?.[0] : void 0;
|
|
2119
2127
|
for (const executor of argument ? namedFunctions(checker, argument) : []) executors.add(executor);
|
|
2120
|
-
|
|
2128
|
+
typescript6_default.forEachChild(node, visit);
|
|
2121
2129
|
};
|
|
2122
2130
|
visit(sourceFile);
|
|
2123
2131
|
executorsByFile.set(sourceFile, executors);
|
|
@@ -2127,7 +2135,7 @@ function promiseExecutors(checker, sourceFile) {
|
|
|
2127
2135
|
function resolvedValue(checker, call) {
|
|
2128
2136
|
const parameter = checker.getSymbolAtLocation(call.expression)?.valueDeclaration;
|
|
2129
2137
|
const executor = parameter?.parent;
|
|
2130
|
-
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;
|
|
2131
2139
|
}
|
|
2132
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. */
|
|
2133
2141
|
const noUnrunQueryRule = defineRule({
|
|
@@ -2152,22 +2160,22 @@ const noUnrunQueryRule = defineRule({
|
|
|
2152
2160
|
ReturnStatement(node) {
|
|
2153
2161
|
const fn = enclosingFunction(node);
|
|
2154
2162
|
if (fn === null || node.argument === null || !resultIsAwaited(fn)) return;
|
|
2155
|
-
check(node.argument, (typed) => typeOf(nodeAt(typed.sourceFile, node,
|
|
2163
|
+
check(node.argument, (typed) => typeOf(nodeAt(typed.sourceFile, node, typescript6_default.isReturnStatement)?.expression, typed));
|
|
2156
2164
|
},
|
|
2157
2165
|
ArrowFunctionExpression(node) {
|
|
2158
2166
|
if (node.body.type === "BlockStatement" || !resultIsAwaited(node)) return;
|
|
2159
|
-
check(node.body, (typed) => typeOf(nodeAt(typed.sourceFile, node,
|
|
2167
|
+
check(node.body, (typed) => typeOf(nodeAt(typed.sourceFile, node, typescript6_default.isArrowFunction)?.body, typed));
|
|
2160
2168
|
},
|
|
2161
2169
|
CallExpression(node) {
|
|
2162
2170
|
if (isPromiseCallback(node)) {
|
|
2163
2171
|
for (const argument of node.arguments) if (!isFunction(argument)) check(argument, (typed) => {
|
|
2164
|
-
const callback = nodeAt(typed.sourceFile, argument,
|
|
2172
|
+
const callback = nodeAt(typed.sourceFile, argument, typescript6_default.isExpression);
|
|
2165
2173
|
return callback === void 0 ? [] : callbackResult(typed.checker, callback);
|
|
2166
2174
|
});
|
|
2167
2175
|
}
|
|
2168
2176
|
const [value] = node.arguments;
|
|
2169
2177
|
if (value !== void 0 && callsFirstParameter(node)) check(value, (typed) => {
|
|
2170
|
-
const call = nodeAt(typed.sourceFile, node,
|
|
2178
|
+
const call = nodeAt(typed.sourceFile, node, typescript6_default.isCallExpression);
|
|
2171
2179
|
return typeOf(call && resolvedValue(typed.checker, call), typed);
|
|
2172
2180
|
});
|
|
2173
2181
|
}
|
|
@@ -2176,18 +2184,18 @@ const noUnrunQueryRule = defineRule({
|
|
|
2176
2184
|
});
|
|
2177
2185
|
//#endregion
|
|
2178
2186
|
//#region src/oxc/guardrails/any-leaks.ts
|
|
2179
|
-
const UNTYPED$1 =
|
|
2187
|
+
const UNTYPED$1 = typescript6_default.TypeFlags.Any | typescript6_default.TypeFlags.Unknown;
|
|
2180
2188
|
/** Whether `type` is `any` itself, not an error type from an import the program cannot resolve, such as another component. */
|
|
2181
2189
|
function isAnyType(checker, type) {
|
|
2182
2190
|
return type === checker.getAnyType();
|
|
2183
2191
|
}
|
|
2184
2192
|
/** Whether `type` is `unknown`. */
|
|
2185
2193
|
function isUnknown(type) {
|
|
2186
|
-
return type !== void 0 && (type.flags &
|
|
2194
|
+
return type !== void 0 && (type.flags & typescript6_default.TypeFlags.Unknown) !== 0;
|
|
2187
2195
|
}
|
|
2188
2196
|
/** The element type of an array or a readonly array, whether or not an alias names it, `undefined` for another type. */
|
|
2189
2197
|
function arrayElement(checker, type) {
|
|
2190
|
-
return checker.isArrayType(type) ? checker.getIndexTypeOfType(type,
|
|
2198
|
+
return checker.isArrayType(type) ? checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number) : void 0;
|
|
2191
2199
|
}
|
|
2192
2200
|
/** Whether `type` is undeclared, `any` or `unknown`, an error type included. */
|
|
2193
2201
|
function takesAnything(type) {
|
|
@@ -2195,11 +2203,11 @@ function takesAnything(type) {
|
|
|
2195
2203
|
}
|
|
2196
2204
|
/** Whether `type` is an object type, such as an interface, a reference or an anonymous type. */
|
|
2197
2205
|
function isObjectType(type) {
|
|
2198
|
-
return (type.flags &
|
|
2206
|
+
return (type.flags & typescript6_default.TypeFlags.Object) !== 0;
|
|
2199
2207
|
}
|
|
2200
2208
|
/** Whether `type` is a reference to a generic type, such as `Set<string>`, an array or a tuple. */
|
|
2201
2209
|
function isReference$1(type) {
|
|
2202
|
-
return (type.objectFlags &
|
|
2210
|
+
return (type.objectFlags & typescript6_default.ObjectFlags.Reference) !== 0;
|
|
2203
2211
|
}
|
|
2204
2212
|
/**
|
|
2205
2213
|
* The generic reference `type` is, such as `Set<any>`, `any[]` or a tuple,
|
|
@@ -2212,7 +2220,7 @@ function reference(type) {
|
|
|
2212
2220
|
}
|
|
2213
2221
|
/** Whether `node` is `new Map()`, which the lib types `Map<any, any>` and tsgolint lets into any `Map`. */
|
|
2214
2222
|
function isEmptyMap(node) {
|
|
2215
|
-
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);
|
|
2216
2224
|
}
|
|
2217
2225
|
/**
|
|
2218
2226
|
* Whether a `sender` value lets `any` into a `receiver` slot as an argument,
|
|
@@ -2249,7 +2257,7 @@ function isAnyOrAnyArray(checker, type) {
|
|
|
2249
2257
|
//#endregion
|
|
2250
2258
|
//#region src/oxc/guardrails/any-arguments.ts
|
|
2251
2259
|
function isTupleTarget(target) {
|
|
2252
|
-
return (target.objectFlags &
|
|
2260
|
+
return (target.objectFlags & typescript6_default.ObjectFlags.Tuple) !== 0;
|
|
2253
2261
|
}
|
|
2254
2262
|
function tupleOf(type) {
|
|
2255
2263
|
if (!isObjectType(type) || !isReference$1(type)) return void 0;
|
|
@@ -2276,11 +2284,11 @@ function restOf(checker, type, index) {
|
|
|
2276
2284
|
};
|
|
2277
2285
|
}
|
|
2278
2286
|
function calleeOf(call) {
|
|
2279
|
-
return
|
|
2287
|
+
return typescript6_default.isTaggedTemplateExpression(call) ? call.tag : call.expression;
|
|
2280
2288
|
}
|
|
2281
2289
|
function argumentsOf(call) {
|
|
2282
|
-
if (!
|
|
2283
|
-
return
|
|
2290
|
+
if (!typescript6_default.isTaggedTemplateExpression(call)) return call.arguments ?? [];
|
|
2291
|
+
return typescript6_default.isTemplateExpression(call.template) ? call.template.templateSpans.map((span) => span.expression) : [];
|
|
2284
2292
|
}
|
|
2285
2293
|
function parameterCursor(checker, call, signature) {
|
|
2286
2294
|
const fixed = [];
|
|
@@ -2288,7 +2296,7 @@ function parameterCursor(checker, call, signature) {
|
|
|
2288
2296
|
for (const [index, parameter] of signature.getParameters().entries()) {
|
|
2289
2297
|
const type = checker.getTypeOfSymbolAtLocation(parameter, call);
|
|
2290
2298
|
const declaration = parameter.getDeclarations()?.[0];
|
|
2291
|
-
if (declaration !== void 0 &&
|
|
2299
|
+
if (declaration !== void 0 && typescript6_default.isParameter(declaration) && declaration.dotDotDotToken !== void 0) {
|
|
2292
2300
|
rest = restOf(checker, type, index);
|
|
2293
2301
|
break;
|
|
2294
2302
|
}
|
|
@@ -2326,9 +2334,9 @@ function unsafeArguments(checker, call) {
|
|
|
2326
2334
|
const signature = checker.getResolvedSignature(call);
|
|
2327
2335
|
if (signature === void 0) return [];
|
|
2328
2336
|
const cursor = parameterCursor(checker, call, signature);
|
|
2329
|
-
if (
|
|
2337
|
+
if (typescript6_default.isTaggedTemplateExpression(call)) cursor.next();
|
|
2330
2338
|
return args.flatMap((argument) => {
|
|
2331
|
-
if (!
|
|
2339
|
+
if (!typescript6_default.isSpreadElement(argument)) {
|
|
2332
2340
|
const parameter = cursor.next();
|
|
2333
2341
|
return parameter !== void 0 && leaks(checker, checker.getTypeAtLocation(argument), parameter, argument) ? [argument] : [];
|
|
2334
2342
|
}
|
|
@@ -2340,17 +2348,17 @@ function unsafeArguments(checker, call) {
|
|
|
2340
2348
|
const parameter = cursor.next();
|
|
2341
2349
|
return parameter !== void 0 && leaks(checker, element, parameter) ? [argument] : [];
|
|
2342
2350
|
});
|
|
2343
|
-
if ((tuple.target.combinedFlags &
|
|
2351
|
+
if ((tuple.target.combinedFlags & typescript6_default.ElementFlags.Variable) !== 0) cursor.consumeRest();
|
|
2344
2352
|
return unsafe;
|
|
2345
2353
|
});
|
|
2346
2354
|
}
|
|
2347
2355
|
//#endregion
|
|
2348
2356
|
//#region src/oxc/guardrails/type-order.ts
|
|
2349
2357
|
function isObject(type) {
|
|
2350
|
-
return (type.flags &
|
|
2358
|
+
return (type.flags & typescript6_default.TypeFlags.Object) !== 0;
|
|
2351
2359
|
}
|
|
2352
2360
|
function isReference(type) {
|
|
2353
|
-
return isObject(type) && (type.objectFlags &
|
|
2361
|
+
return isObject(type) && (type.objectFlags & typescript6_default.ObjectFlags.Reference) !== 0;
|
|
2354
2362
|
}
|
|
2355
2363
|
function compareText(a, b) {
|
|
2356
2364
|
if (a === b) return 0;
|
|
@@ -2359,7 +2367,7 @@ function compareText(a, b) {
|
|
|
2359
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. */
|
|
2360
2368
|
function nameSymbol(type) {
|
|
2361
2369
|
if (type.aliasSymbol !== void 0) return type.aliasSymbol;
|
|
2362
|
-
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;
|
|
2363
2371
|
}
|
|
2364
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. */
|
|
2365
2373
|
function compareNodes(a, b) {
|
|
@@ -2444,8 +2452,8 @@ function anyKind(checker, type) {
|
|
|
2444
2452
|
/** The function a returned `value` leaves. */
|
|
2445
2453
|
function ownerOf(value) {
|
|
2446
2454
|
let owner = value.parent;
|
|
2447
|
-
while (!
|
|
2448
|
-
if (
|
|
2455
|
+
while (!typescript6_default.isFunctionLike(owner)) {
|
|
2456
|
+
if (typescript6_default.isSourceFile(owner)) return void 0;
|
|
2449
2457
|
owner = owner.parent;
|
|
2450
2458
|
}
|
|
2451
2459
|
return owner;
|
|
@@ -2453,15 +2461,15 @@ function ownerOf(value) {
|
|
|
2453
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. */
|
|
2454
2462
|
function contextOf(checker, node) {
|
|
2455
2463
|
const { parent } = node;
|
|
2456
|
-
if (
|
|
2457
|
-
if (
|
|
2458
|
-
if (
|
|
2459
|
-
if (
|
|
2460
|
-
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;
|
|
2461
2469
|
}
|
|
2462
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. */
|
|
2463
2471
|
function declaringType(checker, owner) {
|
|
2464
|
-
return (
|
|
2472
|
+
return (typescript6_default.isArrowFunction(owner) || typescript6_default.isFunctionExpression(owner) ? contextOf(checker, owner) : void 0) ?? checker.getTypeAtLocation(owner);
|
|
2465
2473
|
}
|
|
2466
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. */
|
|
2467
2475
|
function callSignatures(checker, type) {
|
|
@@ -2502,7 +2510,7 @@ function returnLeaks(checker, value) {
|
|
|
2502
2510
|
if (owner === void 0) return false;
|
|
2503
2511
|
const sender = checker.getTypeAtLocation(value);
|
|
2504
2512
|
const returns = callSignatures(checker, declaringType(checker, owner)).map((signature) => signature.getReturnType());
|
|
2505
|
-
const isAsync =
|
|
2513
|
+
const isAsync = typescript6_default.canHaveModifiers(owner) && (typescript6_default.getModifiers(owner)?.some((modifier) => modifier.kind === typescript6_default.SyntaxKind.AsyncKeyword) ?? false);
|
|
2506
2514
|
if (owner.type !== void 0 && annotationExcuses(checker, sender, returns, isAsync)) return false;
|
|
2507
2515
|
const kind = anyKind(checker, sender);
|
|
2508
2516
|
return kind === "safe" ? leaks(checker, sender, returns[0], value) : !anyExcuses(checker, kind, returns, isAsync);
|
|
@@ -2522,11 +2530,11 @@ function leaksIntoContext(checker, value) {
|
|
|
2522
2530
|
function isDestructuringTarget(literal) {
|
|
2523
2531
|
let child = literal;
|
|
2524
2532
|
let parent = literal.parent;
|
|
2525
|
-
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)) {
|
|
2526
2534
|
child = parent;
|
|
2527
2535
|
parent = parent.parent;
|
|
2528
2536
|
}
|
|
2529
|
-
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;
|
|
2530
2538
|
}
|
|
2531
2539
|
function returned(checker, value) {
|
|
2532
2540
|
return returnLeaks(checker, value) ? [{
|
|
@@ -2536,36 +2544,36 @@ function returned(checker, value) {
|
|
|
2536
2544
|
}
|
|
2537
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. */
|
|
2538
2546
|
function spreadFindings(checker, spread) {
|
|
2539
|
-
return
|
|
2547
|
+
return typescript6_default.isArrayLiteralExpression(spread.parent) && !isDestructuringTarget(spread.parent) && isAnyOrAnyArray(checker, checker.getTypeAtLocation(spread.expression)) ? [{
|
|
2540
2548
|
kind: "assignment",
|
|
2541
2549
|
node: spread
|
|
2542
2550
|
}] : [];
|
|
2543
2551
|
}
|
|
2544
2552
|
function propertyFindings(checker, property) {
|
|
2545
2553
|
if (isDestructuringTarget(property.parent)) {
|
|
2546
|
-
const fallback =
|
|
2554
|
+
const fallback = typescript6_default.isShorthandPropertyAssignment(property) ? property.objectAssignmentInitializer : void 0;
|
|
2547
2555
|
return fallback !== void 0 && assignmentLeaks(checker, fallback, checker.getTypeAtLocation(property.name)) ? [{
|
|
2548
2556
|
kind: "assignment",
|
|
2549
2557
|
node: property
|
|
2550
2558
|
}] : [];
|
|
2551
2559
|
}
|
|
2552
|
-
return leaksIntoContext(checker,
|
|
2560
|
+
return leaksIntoContext(checker, typescript6_default.isPropertyAssignment(property) ? property.initializer : property.name) ? [{
|
|
2553
2561
|
kind: "assignment",
|
|
2554
2562
|
node: property
|
|
2555
2563
|
}] : [];
|
|
2556
2564
|
}
|
|
2557
2565
|
function isPattern(node) {
|
|
2558
|
-
return
|
|
2566
|
+
return typescript6_default.isObjectBindingPattern(node) || typescript6_default.isArrayBindingPattern(node) || typescript6_default.isObjectLiteralExpression(node) || typescript6_default.isArrayLiteralExpression(node);
|
|
2559
2567
|
}
|
|
2560
2568
|
/** The key a property name spells, a computed literal such as `['a']` included. */
|
|
2561
2569
|
function literalKey(name) {
|
|
2562
|
-
if (
|
|
2563
|
-
const key =
|
|
2564
|
-
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;
|
|
2565
2573
|
}
|
|
2566
2574
|
/** The target and default of an assignment pattern element, as in `a = fallback`. */
|
|
2567
2575
|
function withDefault(element) {
|
|
2568
|
-
return
|
|
2576
|
+
return typescript6_default.isBinaryExpression(element) && element.operatorToken.kind === typescript6_default.SyntaxKind.EqualsToken ? {
|
|
2569
2577
|
target: element.left,
|
|
2570
2578
|
initializer: element.right
|
|
2571
2579
|
} : {
|
|
@@ -2574,19 +2582,19 @@ function withDefault(element) {
|
|
|
2574
2582
|
};
|
|
2575
2583
|
}
|
|
2576
2584
|
function objectElements(pattern) {
|
|
2577
|
-
if (
|
|
2585
|
+
if (typescript6_default.isObjectBindingPattern(pattern)) return pattern.elements.map((element) => ({
|
|
2578
2586
|
key: element.dotDotDotToken === void 0 ? literalKey(element.propertyName ?? element.name) : void 0,
|
|
2579
2587
|
target: element.name,
|
|
2580
2588
|
initializer: element.initializer,
|
|
2581
2589
|
node: element
|
|
2582
2590
|
}));
|
|
2583
2591
|
return pattern.properties.map((property) => {
|
|
2584
|
-
if (
|
|
2592
|
+
if (typescript6_default.isPropertyAssignment(property)) return {
|
|
2585
2593
|
key: literalKey(property.name),
|
|
2586
2594
|
...withDefault(property.initializer),
|
|
2587
2595
|
node: property
|
|
2588
2596
|
};
|
|
2589
|
-
if (
|
|
2597
|
+
if (typescript6_default.isShorthandPropertyAssignment(property)) return {
|
|
2590
2598
|
key: property.name.text,
|
|
2591
2599
|
target: property.name,
|
|
2592
2600
|
initializer: property.objectAssignmentInitializer,
|
|
@@ -2602,14 +2610,14 @@ function objectElements(pattern) {
|
|
|
2602
2610
|
}
|
|
2603
2611
|
function arrayElements(pattern) {
|
|
2604
2612
|
return pattern.elements.flatMap((element, index) => {
|
|
2605
|
-
if (
|
|
2606
|
-
if (
|
|
2613
|
+
if (typescript6_default.isOmittedExpression(element)) return [];
|
|
2614
|
+
if (typescript6_default.isBindingElement(element)) return [{
|
|
2607
2615
|
key: element.dotDotDotToken === void 0 ? String(index) : void 0,
|
|
2608
2616
|
target: element.name,
|
|
2609
2617
|
initializer: element.initializer,
|
|
2610
2618
|
node: element
|
|
2611
2619
|
}];
|
|
2612
|
-
if (
|
|
2620
|
+
if (typescript6_default.isSpreadElement(element)) return [{
|
|
2613
2621
|
key: void 0,
|
|
2614
2622
|
target: element.expression,
|
|
2615
2623
|
initializer: void 0,
|
|
@@ -2648,7 +2656,7 @@ function slotFindings(checker, element, source) {
|
|
|
2648
2656
|
* `typescript/no-unsafe-assignment` leaves them.
|
|
2649
2657
|
*/
|
|
2650
2658
|
function destructuredFindings(checker, pattern, source) {
|
|
2651
|
-
if (
|
|
2659
|
+
if (typescript6_default.isObjectBindingPattern(pattern) || typescript6_default.isObjectLiteralExpression(pattern)) return objectElements(pattern).flatMap((element) => slotFindings(checker, element, source));
|
|
2652
2660
|
if (isAnyOrAnyArray(checker, source)) return [{
|
|
2653
2661
|
kind: "assignment",
|
|
2654
2662
|
node: pattern
|
|
@@ -2658,7 +2666,7 @@ function destructuredFindings(checker, pattern, source) {
|
|
|
2658
2666
|
/** The elements a pattern `name`, annotated or not, takes `any` into from `initializer`. */
|
|
2659
2667
|
function bindingFindings(checker, name, initializer) {
|
|
2660
2668
|
const source = checker.getTypeAtLocation(initializer);
|
|
2661
|
-
return
|
|
2669
|
+
return typescript6_default.isIdentifier(name) ? [] : destructuredFindings(checker, name, source);
|
|
2662
2670
|
}
|
|
2663
2671
|
function declarationFindings(checker, node, initializer) {
|
|
2664
2672
|
return assignmentLeaks(checker, initializer, node.type && checker.getTypeAtLocation(node.name)) ? [{
|
|
@@ -2668,7 +2676,7 @@ function declarationFindings(checker, node, initializer) {
|
|
|
2668
2676
|
}
|
|
2669
2677
|
/** A JSX attribute whose value lets `any` into the prop it fills. */
|
|
2670
2678
|
function attributeFindings(checker, attribute) {
|
|
2671
|
-
const value = attribute.initializer !== void 0 &&
|
|
2679
|
+
const value = attribute.initializer !== void 0 && typescript6_default.isJsxExpression(attribute.initializer) ? attribute.initializer.expression : void 0;
|
|
2672
2680
|
return value !== void 0 && leaksIntoContext(checker, value) ? [{
|
|
2673
2681
|
kind: "assignment",
|
|
2674
2682
|
node: value
|
|
@@ -2682,42 +2690,42 @@ function fieldFindings(checker, field) {
|
|
|
2682
2690
|
}] : [];
|
|
2683
2691
|
}
|
|
2684
2692
|
function assignmentFindings(checker, node) {
|
|
2685
|
-
if (
|
|
2686
|
-
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) {
|
|
2687
2695
|
if (assignmentLeaks(checker, node.right, checker.getTypeAtLocation(node.left))) return [{
|
|
2688
2696
|
kind: "assignment",
|
|
2689
2697
|
node
|
|
2690
2698
|
}];
|
|
2691
|
-
return
|
|
2699
|
+
return typescript6_default.isObjectLiteralExpression(node.left) || typescript6_default.isArrayLiteralExpression(node.left) ? destructuredFindings(checker, node.left, checker.getTypeAtLocation(node.right)) : [];
|
|
2692
2700
|
}
|
|
2693
|
-
if (
|
|
2701
|
+
if (typescript6_default.isParameter(node) && node.initializer !== void 0) return leaksIntoContext(checker, node.initializer) ? [{
|
|
2694
2702
|
kind: "assignment",
|
|
2695
2703
|
node
|
|
2696
2704
|
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2697
|
-
if (
|
|
2705
|
+
if (typescript6_default.isBindingElement(node) && node.initializer !== void 0) return assignmentLeaks(checker, node.initializer, checker.getTypeAtLocation(node.name)) ? [{
|
|
2698
2706
|
kind: "assignment",
|
|
2699
2707
|
node
|
|
2700
2708
|
}] : bindingFindings(checker, node.name, node.initializer);
|
|
2701
|
-
if (
|
|
2702
|
-
if (
|
|
2703
|
-
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);
|
|
2704
2712
|
return [];
|
|
2705
2713
|
}
|
|
2706
2714
|
function nodeFindings(checker, node) {
|
|
2707
|
-
if (
|
|
2708
|
-
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) => ({
|
|
2709
2717
|
kind: "argument",
|
|
2710
2718
|
node: argument
|
|
2711
2719
|
}));
|
|
2712
|
-
if (
|
|
2713
|
-
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);
|
|
2714
2722
|
return assignmentFindings(checker, node);
|
|
2715
2723
|
}
|
|
2716
2724
|
function findings({ checker, sourceFile }) {
|
|
2717
2725
|
const found = [];
|
|
2718
2726
|
function visit(node) {
|
|
2719
2727
|
found.push(...nodeFindings(checker, node));
|
|
2720
|
-
|
|
2728
|
+
typescript6_default.forEachChild(node, visit);
|
|
2721
2729
|
}
|
|
2722
2730
|
visit(sourceFile);
|
|
2723
2731
|
return found;
|
|
@@ -2785,14 +2793,14 @@ const MAX_DEPTH$1 = 8;
|
|
|
2785
2793
|
const INDEX = /^\d+$/u;
|
|
2786
2794
|
/** The type a written value has: a shorthand property reads its variable, as a direct assignment would. */
|
|
2787
2795
|
function valueType(checker, value) {
|
|
2788
|
-
const shorthand =
|
|
2796
|
+
const shorthand = typescript6_default.isShorthandPropertyAssignment(value.parent) && value.parent.name === value ? checker.getShorthandAssignmentValueSymbol(value.parent) : void 0;
|
|
2789
2797
|
return shorthand === void 0 ? checker.getTypeAtLocation(value) : checker.getTypeOfSymbolAtLocation(shorthand, value);
|
|
2790
2798
|
}
|
|
2791
2799
|
function propertyName(property) {
|
|
2792
|
-
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;
|
|
2793
2801
|
return {
|
|
2794
2802
|
name: property.name.text,
|
|
2795
|
-
value:
|
|
2803
|
+
value: typescript6_default.isPropertyAssignment(property) ? property.initializer : property.name
|
|
2796
2804
|
};
|
|
2797
2805
|
}
|
|
2798
2806
|
function objectFits(checker, literal, type, depth) {
|
|
@@ -2802,20 +2810,20 @@ function objectFits(checker, literal, type, depth) {
|
|
|
2802
2810
|
if (named === void 0) return false;
|
|
2803
2811
|
names.add(named.name);
|
|
2804
2812
|
const field = checker.getPropertyOfType(type, named.name);
|
|
2805
|
-
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);
|
|
2806
2814
|
if (fieldType === void 0 || !literalFits(checker, named.value, fieldType, depth + 1)) return false;
|
|
2807
2815
|
}
|
|
2808
|
-
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));
|
|
2809
2817
|
}
|
|
2810
2818
|
function arrayFits(checker, literal, type, depth) {
|
|
2811
2819
|
const { elements } = literal;
|
|
2812
|
-
if (elements.some((element) =>
|
|
2820
|
+
if (elements.some((element) => typescript6_default.isSpreadElement(element) || typescript6_default.isOmittedExpression(element))) return false;
|
|
2813
2821
|
if (checker.isTupleType(type)) {
|
|
2814
2822
|
const slots = checker.getPropertiesOfType(type).filter((slot) => INDEX.test(slot.name));
|
|
2815
|
-
const required = slots.filter((slot) => (slot.flags &
|
|
2823
|
+
const required = slots.filter((slot) => (slot.flags & typescript6_default.SymbolFlags.Optional) === 0);
|
|
2816
2824
|
return elements.length >= required.length && elements.length <= slots.length && elements.every((element, index) => literalFits(checker, element, checker.getTypeOfSymbolAtLocation(slots[index], literal), depth + 1));
|
|
2817
2825
|
}
|
|
2818
|
-
const element = checker.getIndexTypeOfType(type,
|
|
2826
|
+
const element = checker.getIndexTypeOfType(type, typescript6_default.IndexKind.Number);
|
|
2819
2827
|
return element !== void 0 && elements.every((value) => literalFits(checker, value, element, depth + 1));
|
|
2820
2828
|
}
|
|
2821
2829
|
/**
|
|
@@ -2827,35 +2835,35 @@ function arrayFits(checker, literal, type, depth) {
|
|
|
2827
2835
|
*/
|
|
2828
2836
|
function literalFits(checker, expression, type, depth = 0) {
|
|
2829
2837
|
let value = expression;
|
|
2830
|
-
while (
|
|
2838
|
+
while (typescript6_default.isParenthesizedExpression(value)) value = value.expression;
|
|
2831
2839
|
if (checker.isTypeAssignableTo(valueType(checker, value), type)) return true;
|
|
2832
|
-
if (!
|
|
2840
|
+
if (!typescript6_default.isObjectLiteralExpression(value) && !typescript6_default.isArrayLiteralExpression(value)) return false;
|
|
2833
2841
|
if (depth === MAX_DEPTH$1) return true;
|
|
2834
2842
|
if (type.isUnion()) return type.types.some((member) => literalFits(checker, value, member, depth));
|
|
2835
|
-
return
|
|
2843
|
+
return typescript6_default.isObjectLiteralExpression(value) ? objectFits(checker, value, type, depth) : arrayFits(checker, value, type, depth);
|
|
2836
2844
|
}
|
|
2837
2845
|
//#endregion
|
|
2838
2846
|
//#region src/oxc/guardrails/rules/no-unsafe-object-assign.ts
|
|
2839
|
-
const UNTYPED =
|
|
2847
|
+
const UNTYPED = typescript6_default.TypeFlags.Any | typescript6_default.TypeFlags.Unknown;
|
|
2840
2848
|
const MAX_DEPTH = 4;
|
|
2841
2849
|
function members(type) {
|
|
2842
2850
|
return type.isUnion() ? type.types : [type];
|
|
2843
2851
|
}
|
|
2844
2852
|
/** Whether `type` is `any`, or holds `any` in a union, an intersection or the elements of an array or tuple, as in `any[]`. */
|
|
2845
2853
|
function holdsAny(checker, type, depth = 0) {
|
|
2846
|
-
if (type.flags &
|
|
2854
|
+
if (type.flags & typescript6_default.TypeFlags.Any) return true;
|
|
2847
2855
|
if (depth === MAX_DEPTH) return false;
|
|
2848
|
-
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;
|
|
2849
2857
|
return (type.isUnionOrIntersection() ? type.types : element === void 0 ? [] : [element]).some((member) => holdsAny(checker, member, depth + 1));
|
|
2850
2858
|
}
|
|
2851
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. */
|
|
2852
2860
|
function insideGeneric(declaration) {
|
|
2853
|
-
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;
|
|
2854
2862
|
return false;
|
|
2855
2863
|
}
|
|
2856
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. */
|
|
2857
2865
|
function acceptedTypes(checker, field, source) {
|
|
2858
|
-
const setter = field.declarations?.find(
|
|
2866
|
+
const setter = field.declarations?.find(typescript6_default.isSetAccessorDeclaration);
|
|
2859
2867
|
const parameter = setter?.parameters[0];
|
|
2860
2868
|
const read = checker.getTypeOfSymbolAtLocation(field, source);
|
|
2861
2869
|
if (setter === void 0 || parameter === void 0) return [read];
|
|
@@ -2867,15 +2875,15 @@ function untyped(type) {
|
|
|
2867
2875
|
function typeVerdict({ checker, exactOptional }, type, accepted, optional) {
|
|
2868
2876
|
if (accepted.length === 0 || accepted.some(untyped)) return void 0;
|
|
2869
2877
|
if (untyped(type) || holdsAny(checker, type) && !accepted.some((member) => holdsAny(checker, member))) return "untypedField";
|
|
2870
|
-
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";
|
|
2871
2879
|
}
|
|
2872
2880
|
function fieldWrite(check, property, field, source) {
|
|
2873
2881
|
const { checker } = check;
|
|
2874
2882
|
const accepted = acceptedTypes(checker, field, source);
|
|
2875
2883
|
if (accepted === void 0) return void 0;
|
|
2876
2884
|
const declaration = property.valueDeclaration;
|
|
2877
|
-
const written = declaration !== void 0 && declaration.getSourceFile() === source.getSourceFile() && declaration.pos >= source.pos && declaration.end <= source.end && (
|
|
2878
|
-
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);
|
|
2879
2887
|
if (kind === void 0 || kind === "mistypedField" && written !== void 0 && accepted.some((type) => literalFits(checker, written, type))) return void 0;
|
|
2880
2888
|
return {
|
|
2881
2889
|
kind,
|
|
@@ -2883,13 +2891,13 @@ function fieldWrite(check, property, field, source) {
|
|
|
2883
2891
|
};
|
|
2884
2892
|
}
|
|
2885
2893
|
/** A primitive source member, such as the `false` of `flag && { ... }`, whose apparent members (`valueOf`) `Object.assign` never copies. */
|
|
2886
|
-
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;
|
|
2887
2895
|
/** Whether the target declares a field that does not take `unknown`, which an untyped string-keyed source could overwrite. */
|
|
2888
2896
|
function hasTypedField(checker, target) {
|
|
2889
2897
|
return checker.getPropertiesOfType(target).some((field) => !untyped(checker.getTypeOfSymbol(field)));
|
|
2890
2898
|
}
|
|
2891
2899
|
function untypedKeys(checker, member) {
|
|
2892
|
-
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));
|
|
2893
2901
|
}
|
|
2894
2902
|
function sourceWrites(check, target, source) {
|
|
2895
2903
|
const { checker } = check;
|
|
@@ -2922,7 +2930,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2922
2930
|
const linted = lintedSource(context.filename, context.sourceCode.text);
|
|
2923
2931
|
const typed = linted && typedFile(context.filename, linted.text);
|
|
2924
2932
|
const [start, end] = node.range;
|
|
2925
|
-
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);
|
|
2926
2934
|
if (typed === void 0 || call === void 0) return;
|
|
2927
2935
|
const declared = typed.checker.getTypeAtLocation(call.arguments[0]);
|
|
2928
2936
|
const target = declared.isTypeParameter() ? typed.checker.getBaseConstraintOfType(declared) ?? declared : declared;
|
|
@@ -2932,7 +2940,7 @@ const noUnsafeObjectAssignRule = defineRule({
|
|
|
2932
2940
|
exactOptional: typed.options.exactOptionalPropertyTypes === true
|
|
2933
2941
|
};
|
|
2934
2942
|
call.arguments.slice(1).forEach((source, index) => {
|
|
2935
|
-
if (
|
|
2943
|
+
if (typescript6_default.isSpreadElement(source)) return;
|
|
2936
2944
|
for (const write of sourceWrites(check, target, source)) context.report({
|
|
2937
2945
|
node: node.arguments[index + 1],
|
|
2938
2946
|
messageId: write.kind,
|
|
@@ -3001,7 +3009,7 @@ function isStringLiteral(node) {
|
|
|
3001
3009
|
function moduleResolves(config, filename, text, source) {
|
|
3002
3010
|
if (resolves(config, source.value, filename)) return true;
|
|
3003
3011
|
const typed = typedFile(filename, text);
|
|
3004
|
-
const literal = typed && nodeAt(typed.sourceFile, source,
|
|
3012
|
+
const literal = typed && nodeAt(typed.sourceFile, source, typescript6_default.isStringLiteral);
|
|
3005
3013
|
return typed === void 0 || literal === void 0 || typed.checker.getSymbolAtLocation(literal) !== void 0;
|
|
3006
3014
|
}
|
|
3007
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. */
|