@antelopejs/tooling-configs 0.2.17 → 0.2.18

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.
Files changed (39) hide show
  1. package/README.md +27 -18
  2. package/dist/bin/api-diff.mjs +25 -14
  3. package/dist/bin/body-check.mjs +3 -3
  4. package/dist/bin/capture.d.mts +1 -0
  5. package/dist/bin/capture.mjs +559 -0
  6. package/dist/bin/check-size.mjs +3 -3
  7. package/dist/bin/checks.mjs +2 -2
  8. package/dist/bin/comment-proof.mjs +3 -3
  9. package/dist/bin/garden.mjs +1 -1
  10. package/dist/bin/ratchet.mjs +146 -100
  11. package/dist/bin/suppressions.mjs +5 -5
  12. package/dist/bin/sync.mjs +115 -169
  13. package/dist/bin/verify.mjs +238 -125
  14. package/dist/capture/index.d.mts +50 -0
  15. package/dist/capture/index.mjs +2 -0
  16. package/dist/{files-Bc036sJW.mjs → files-DJ0TeaTU.mjs} +10 -4
  17. package/dist/formal/index.d.mts +40 -0
  18. package/dist/formal/index.mjs +205 -0
  19. package/dist/oxc/anti-slop/index.mjs +717 -16
  20. package/dist/oxc/fmt.mjs +1 -1
  21. package/dist/oxc/guardrails/index.d.mts +1 -1
  22. package/dist/oxc/guardrails/index.mjs +93 -5
  23. package/dist/oxc/lint.d.mts +9 -0
  24. package/dist/oxc/lint.mjs +14 -3
  25. package/dist/{oxlint-Bltmk8-6.mjs → oxlint-DIV-lLSS.mjs} +7 -3
  26. package/dist/{package-DTxLPNDu.mjs → package-BRTjkzt5.mjs} +26 -1
  27. package/dist/{proof-stamp-w-3j47A-.mjs → proof-stamp-DDDC0J6l.mjs} +3 -3
  28. package/dist/{ratchet-DwRj9h4L.mjs → ratchet-BAcLRYuM.mjs} +194 -21
  29. package/dist/scenes-DZVXkcxS.mjs +104 -0
  30. package/dist/shared-igPpEDpS.mjs +622 -0
  31. package/dist/{size-DNtWruCO.mjs → size-DBatLT-F.mjs} +2 -2
  32. package/dist/{suppression-base-DAfCXwjL.mjs → suppression-base-9L8dlMQK.mjs} +36 -11
  33. package/dist/{suppression-budget-Bd2GqMYb.mjs → suppression-budget-C0SkPO5R.mjs} +56 -19
  34. package/dist/{suppressions-BD_f8f7L.mjs → suppressions-DM60NkvL.mjs} +1 -1
  35. package/dist/templates-CypDm-j9.mjs +121 -0
  36. package/dist/{typescript-BmS5BmrS.mjs → typescript-CM0LrVP7.mjs} +2 -2
  37. package/dist/verify/index.d.mts +6 -1
  38. package/package.json +28 -4
  39. package/dist/shared-CoUt4GUm.mjs +0 -73
@@ -625,7 +625,7 @@ function typePredicateSubjectIndex(sourceCode, owner) {
625
625
  function annotationTarget(annotation, environment) {
626
626
  return annotation === null || annotation === void 0 ? null : classifyWideningTarget(annotation.typeAnnotation, environment);
627
627
  }
628
- function enclosingFunction(node) {
628
+ function enclosingFunction$1(node) {
629
629
  let current = node.parent;
630
630
  while (current !== null && current.type !== "Program") {
631
631
  if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") return current;
@@ -726,7 +726,7 @@ const noKnownValueWideningRule = defineRule({
726
726
  },
727
727
  ReturnStatement(node) {
728
728
  if (node.argument === null) return;
729
- const owner = enclosingFunction(node);
729
+ const owner = enclosingFunction$1(node);
730
730
  reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
731
731
  },
732
732
  ArrowFunctionExpression(node) {
@@ -908,9 +908,78 @@ const noReflectGetRule = defineRule({
908
908
  }
909
909
  });
910
910
  //#endregion
911
+ //#region src/oxc/anti-slop/shared/binding-origin.ts
912
+ /** Return the variable an identifier refers to, searching outward from its scope, or null for an unresolved global. */
913
+ function variableOf(identifier, sourceCode) {
914
+ let scope = sourceCode.getScope(identifier);
915
+ while (scope !== null) {
916
+ const variable = scope.set.get(identifier.name);
917
+ if (variable !== void 0) return variable;
918
+ scope = scope.upper;
919
+ }
920
+ return null;
921
+ }
922
+ /**
923
+ * Return whether a definition takes its value from another module: an `import` declaration, or `import x = require()`.
924
+ * An `import x = Namespace.member` only renames a name, so its value comes from where that name is declared.
925
+ */
926
+ function isModuleImport(definition) {
927
+ if (definition.type !== "ImportBinding") return false;
928
+ const { node } = definition;
929
+ return node.type !== "TSImportEqualsDeclaration" || node.moduleReference.type === "TSExternalModuleReference";
930
+ }
931
+ /**
932
+ * Return whether a name has no definition in this file: a name no scope binds, or a global the environment declares (`Array`,
933
+ * `Error`), which oxlint binds to a variable with no definition.
934
+ */
935
+ function isGlobalName(identifier, sourceCode) {
936
+ const variable = variableOf(identifier, sourceCode);
937
+ return variable === null || variable.defs.length === 0;
938
+ }
939
+ /** Return whether a node sits inside another, or is it. */
940
+ function isWithin(node, ancestor) {
941
+ for (let at = node; at !== null; at = at.parent) if (at === ancestor) return true;
942
+ return false;
943
+ }
944
+ /**
945
+ * Return whether a name read inside a namespace block may be a member that another block of the same namespace declares.
946
+ * TypeScript merges the blocks of one namespace, and the scope manager does not, so a name that has no definition in the file
947
+ * (see `isGlobalName`), or whose definitions sit outside the block, may resolve to such a member and not to the binding the
948
+ * scope manager found.
949
+ */
950
+ function mayBeMergedMember(identifier, variable) {
951
+ for (let node = identifier.parent; node !== null; node = node.parent) {
952
+ if (node.type !== "TSModuleBlock") continue;
953
+ const block = node;
954
+ return variable === null || variable.defs.length === 0 || !variable.defs.every((definition) => isWithin(definition.node, block));
955
+ }
956
+ return false;
957
+ }
958
+ /**
959
+ * Return whether a name no scope binds is a global that nothing in this file writes, including a global that a `declare global`
960
+ * introduces.
961
+ */
962
+ function isUnwrittenGlobal(identifier, sourceCode) {
963
+ const scope = sourceCode.scopeManager.globalScope;
964
+ return scope !== null && !scope.through.some((reference) => reference.identifier.name === identifier.name && reference.isWrite());
965
+ }
966
+ /**
967
+ * Return whether a name takes its value from outside this file, which only a binding or reference the code can place proves:
968
+ * a module import, or a parameter, that nothing here defaults, assigns or redeclares, or a global that nothing here writes,
969
+ * and that no block of a namespace may shadow with a merged member. The kind of the first definition does not say it: a
970
+ * default, an assignment and a later `var` give a parameter a value written here, and an `import x = Namespace.member` is no
971
+ * module import. Any other name is not outside.
972
+ */
973
+ function isSuppliedFromOutside(identifier, sourceCode) {
974
+ const variable = variableOf(identifier, sourceCode);
975
+ if (mayBeMergedMember(identifier, variable)) return false;
976
+ if (variable === null) return isUnwrittenGlobal(identifier, sourceCode);
977
+ return variable.defs.every((definition) => definition.type === "Parameter" || isModuleImport(definition)) && variable.references.every((reference) => !reference.isWrite());
978
+ }
979
+ //#endregion
911
980
  //#region src/oxc/anti-slop/shared/type-guards.ts
912
981
  /** Files whose functions may declare a type predicate in JSDoc instead of a TypeScript return type. */
913
- const JSDOC_PREDICATE_FILE = /\.m?js$/;
982
+ const JSDOC_PREDICATE_FILE = /\.[cm]?js$/;
914
983
  /** A `@returns {x is T}` type, `x` captured: `asserts x is T` does not match. */
915
984
  const JSDOC_PREDICATE = /^\s*([A-Za-z_$][\w$]*)\s+is\s+\S/;
916
985
  function isRuntimeFunction(node) {
@@ -943,7 +1012,7 @@ function hasJsDocTypePredicate(fn, sourceCode) {
943
1012
  const subject = returnType === null ? void 0 : JSDOC_PREDICATE.exec(returnType)?.[1];
944
1013
  return subject !== void 0 && fn.params.some((parameter) => parameter.type === "Identifier" && parameter.name === subject);
945
1014
  }
946
- /** Return whether a function declares a type predicate or assertion, or a JSDoc `@returns {x is T}` in a `.js`/`.mjs` file. */
1015
+ /** Return whether a function declares a type predicate or assertion, or a JSDoc `@returns {x is T}` in a `.js`, `.mjs` or `.cjs` file. */
947
1016
  function isTypeGuard(fn, sourceCode, filename) {
948
1017
  if (fn.returnType?.typeAnnotation.type === "TSTypePredicate") return true;
949
1018
  return JSDOC_PREDICATE_FILE.test(filename) && hasJsDocTypePredicate(fn, sourceCode);
@@ -972,6 +1041,57 @@ function isExistenceProbe(node) {
972
1041
  const other = parent.left === node ? parent.right : parent.left;
973
1042
  return other.type === "Literal" && other.value === "undefined";
974
1043
  }
1044
+ /** Return the name a callee is read from, through members and type wrappers, or null when it is read from `this`, a call or anything else. */
1045
+ function rootOf(node) {
1046
+ switch (node.type) {
1047
+ case "Identifier": return node;
1048
+ case "MemberExpression": return rootOf(node.object);
1049
+ case "TSNonNullExpression":
1050
+ case "TSAsExpression":
1051
+ case "TSSatisfiesExpression":
1052
+ case "TSTypeAssertion": return rootOf(node.expression);
1053
+ default: return null;
1054
+ }
1055
+ }
1056
+ /** Return whether a callee is read from a name that takes its value from outside this file, through members and type wrappers. */
1057
+ function isReadFromOutside(callee, sourceCode) {
1058
+ const root = rootOf(callee);
1059
+ return root !== null && isSuppliedFromOutside(root, sourceCode);
1060
+ }
1061
+ /**
1062
+ * Return whether a callee only raises or records the message it is given: a bare `assert(...)`, or the `log` method of any object,
1063
+ * when its root is a module import, a global or a parameter. A root written in this file (a function, a class, a `const`, `this`, a
1064
+ * parameter this file defaults or assigns) can compare or store the message, so it is no sink. A call to any other name can too
1065
+ * (`assert.equal`, `Set#add`, `emit`).
1066
+ */
1067
+ function isMessageSink(callee, sourceCode) {
1068
+ if (!isReadFromOutside(callee, sourceCode)) return false;
1069
+ if (callee.type === "Identifier") return callee.name === "assert";
1070
+ return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "log";
1071
+ }
1072
+ /**
1073
+ * Return whether a message ends at this parent: it is thrown, handed to the `assert` or `log` call that stands as a statement,
1074
+ * or handed to the `new` a `throw` throws when its class is read from outside this file, as `Error` is. Any other call, and a text a function returns, can be tested or used as a key by
1075
+ * whatever receives it, so they are not message sinks.
1076
+ */
1077
+ function endsMessage(parent, sourceCode) {
1078
+ switch (parent.type) {
1079
+ case "ThrowStatement": return true;
1080
+ case "CallExpression": return parent.parent.type === "ExpressionStatement" && isMessageSink(parent.callee, sourceCode);
1081
+ case "NewExpression": return parent.parent.type === "ThrowStatement" && isReadFromOutside(parent.callee, sourceCode);
1082
+ default: return false;
1083
+ }
1084
+ }
1085
+ /**
1086
+ * Return whether a `typeof` only fills in the text of a message that a `throw`, an `assert` or a `log` call, or the `new` under a `throw` takes.
1087
+ * Such a template holds other text, so no comparison with a `typeof` result matches it, and TypeScript narrows nothing from it.
1088
+ */
1089
+ function isMessageText(node, sourceCode) {
1090
+ let current = node.parent;
1091
+ if (current.type !== "TemplateLiteral" || current.quasis.every((quasi) => quasi.value.raw === "")) return false;
1092
+ while (current.parent.type === "TemplateLiteral" || current.parent.type === "ConditionalExpression" && current.parent.test !== current) current = current.parent;
1093
+ return endsMessage(current.parent, sourceCode);
1094
+ }
975
1095
  /** Built-ins whose `.constructor` comparison re-implements a `typeof` result. */
976
1096
  const TYPEOF_CONSTRUCTORS = /* @__PURE__ */ new Set([
977
1097
  "String",
@@ -998,7 +1118,7 @@ function constructorCheckTarget(node) {
998
1118
  const noRuntimeTypeofRule = defineRule({
999
1119
  meta: {
1000
1120
  type: "problem",
1001
- docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary." },
1121
+ docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary. A `typeof` that only fills in the text of a message checks nothing." },
1002
1122
  messages: {
1003
1123
  runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
1004
1124
  constructorCheck: "`.constructor === {{name}}` is a `typeof` check in another form. Parse input at its I/O boundary, or move the check into a type guard such as `(value: unknown): value is string`."
@@ -1017,7 +1137,7 @@ const noRuntimeTypeofRule = defineRule({
1017
1137
  }
1018
1138
  return {
1019
1139
  UnaryExpression(node) {
1020
- if (node.operator === "typeof" && !isExistenceProbe(node) && !allowedInTypeGuard(node)) context.report({
1140
+ if (node.operator === "typeof" && !isExistenceProbe(node) && !isMessageText(node, context.sourceCode) && !allowedInTypeGuard(node)) context.report({
1021
1141
  node,
1022
1142
  messageId: "runtimeTypeof"
1023
1143
  });
@@ -1069,6 +1189,555 @@ const noForbiddenTermInSymbolNamesRule = defineRule({
1069
1189
  }
1070
1190
  });
1071
1191
  //#endregion
1192
+ //#region src/oxc/anti-slop/shared/brand-probe.ts
1193
+ /** Primitive types a probe may hand back: a derived value, never an object shape the function claims to know. */
1194
+ const PRIMITIVE_TYPES = /* @__PURE__ */ new Set([
1195
+ "TSBigIntKeyword",
1196
+ "TSBooleanKeyword",
1197
+ "TSNullKeyword",
1198
+ "TSNumberKeyword",
1199
+ "TSStringKeyword",
1200
+ "TSSymbolKeyword",
1201
+ "TSUndefinedKeyword",
1202
+ "TSVoidKeyword"
1203
+ ]);
1204
+ function isPrimitiveType(type) {
1205
+ if (type.type === "TSUnionType") return type.types.every(isPrimitiveType);
1206
+ if (type.type === "TSParenthesizedType") return isPrimitiveType(type.typeAnnotation);
1207
+ return PRIMITIVE_TYPES.has(type.type) || type.type === "TSLiteralType";
1208
+ }
1209
+ /** Return whether a call creates a symbol: `Symbol(...)` or `Symbol.for(...)` on the global `Symbol`. */
1210
+ function createsSymbol(node, sourceCode) {
1211
+ if (node === null || node === void 0 || node.type !== "CallExpression") return false;
1212
+ const { callee } = node;
1213
+ const root = callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "for" ? callee.object : callee;
1214
+ return root.type === "Identifier" && root.name === "Symbol" && isGlobalName(root, sourceCode);
1215
+ }
1216
+ /** Return whether an expression is a symbol this file creates: a `const` bound to `Symbol(...)` or `Symbol.for(...)`, or such a call. */
1217
+ function isOwnSymbol(node, sourceCode) {
1218
+ if (node.type !== "Identifier") return createsSymbol(node, sourceCode);
1219
+ const definition = variableOf(node, sourceCode)?.defs[0];
1220
+ const declarator = definition?.node;
1221
+ return definition?.type === "Variable" && declarator?.type === "VariableDeclarator" && declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" && createsSymbol(declarator.init, sourceCode);
1222
+ }
1223
+ /** Return whether a reference reads a symbol-keyed member of the value (`value[BRAND]`) or asks `BRAND in value`. */
1224
+ function isProbe(reference, sourceCode) {
1225
+ const user = reference.parent;
1226
+ if (user.type === "MemberExpression") return user.object === reference && user.computed && isOwnSymbol(user.property, sourceCode);
1227
+ return user.type === "BinaryExpression" && user.operator === "in" && user.right === reference && isOwnSymbol(user.left, sourceCode);
1228
+ }
1229
+ /** Return the type-predicate subject a call position names, for a callee declared in this file. */
1230
+ function declaredFunctionOf(callee, sourceCode) {
1231
+ if (callee.type !== "Identifier") return null;
1232
+ const definition = variableOf(callee, sourceCode)?.defs[0];
1233
+ if (definition?.type === "FunctionName" && isRuntimeFunction(definition.node)) return definition.node;
1234
+ const declarator = definition?.node;
1235
+ if (definition?.type === "Variable" && declarator?.type === "VariableDeclarator" && declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" && declarator.init !== null && declarator.init !== void 0 && isRuntimeFunction(declarator.init)) return declarator.init;
1236
+ return null;
1237
+ }
1238
+ function parameterAt(owner, position, sourceCode) {
1239
+ const parameter = owner.params[position];
1240
+ if (parameter?.type !== "Identifier") return null;
1241
+ return sourceCode.getDeclaredVariables(owner).find((variable) => variable.name === parameter.name && variable.defs[0]?.type === "Parameter") ?? null;
1242
+ }
1243
+ /** Return whether a function declared in this file is a type guard on the parameter at `position`. */
1244
+ function guardsParameterAt(owner, position) {
1245
+ const predicate = owner.returnType?.typeAnnotation;
1246
+ const parameter = owner.params[position];
1247
+ return predicate?.type === "TSTypePredicate" && !predicate.asserts && predicate.parameterName.type === "Identifier" && parameter?.type === "Identifier" && predicate.parameterName.name === parameter.name;
1248
+ }
1249
+ /** Operators whose result is a boolean about the operands, which a probe may hand back. */
1250
+ const COMPARISONS = /* @__PURE__ */ new Set([
1251
+ "===",
1252
+ "!==",
1253
+ "==",
1254
+ "!=",
1255
+ "<",
1256
+ ">",
1257
+ "<=",
1258
+ ">="
1259
+ ]);
1260
+ /** Return whether a function declares a primitive return type, so what it hands back is a derived value. */
1261
+ function returnsPrimitive(fn) {
1262
+ const returned = fn.returnType?.typeAnnotation;
1263
+ return returned !== void 0 && isPrimitiveType(returned);
1264
+ }
1265
+ /** Return the function a node is written in. */
1266
+ function enclosingFunction(node) {
1267
+ for (let at = node.parent; at !== null; at = at.parent) if (isRuntimeFunction(at)) return at;
1268
+ return null;
1269
+ }
1270
+ /** Return whether every reference of a `const` or function binding is a use that `reaches` accepts. */
1271
+ function everyUseReaches(variable, reaches) {
1272
+ if (variable === null || variable === void 0) return false;
1273
+ const reads = variable.references.filter((reference) => !reference.init);
1274
+ return reads.length > 0 && variable.references.every((reference) => reference.init || !reference.isWrite()) && reads.every((reference) => reaches(reference.identifier));
1275
+ }
1276
+ /**
1277
+ * Return whether the value an expression yields reaches nothing but the result of the probe. The value may be tested,
1278
+ * compared, negated, read further (`.identity`), pass through `Boolean(...)`, a type wrapper, a `&&`, `||`, `??` or a
1279
+ * conditional branch, be held in a `const` whose uses obey the same rule, or be returned. Only the probe ends the walk. A function that is not the
1280
+ * probe may return it when it is declared in this file and every use of it is a call whose value obeys the same rule, or when it
1281
+ * declares a primitive return type and nothing in the file refers to it (an exported sibling probe).
1282
+ * An assignment, a `delete`, an update, a call of the value, an argument to any other call, a store or a spread refuses.
1283
+ */
1284
+ function resultReachesOnlyReturn(node, owner, sourceCode, seen) {
1285
+ if (seen.has(node)) return true;
1286
+ seen.add(node);
1287
+ const user = node.parent;
1288
+ if (user === null) return false;
1289
+ const next = (target) => resultReachesOnlyReturn(target, owner, sourceCode, seen);
1290
+ switch (user.type) {
1291
+ case "ChainExpression":
1292
+ case "TSAsExpression":
1293
+ case "TSNonNullExpression":
1294
+ case "TSSatisfiesExpression":
1295
+ case "TSTypeAssertion": return next(user);
1296
+ case "MemberExpression": return user.object === node && next(user);
1297
+ case "UnaryExpression": return (user.operator === "!" || user.operator === "typeof") && next(user);
1298
+ case "BinaryExpression": return COMPARISONS.has(user.operator) && next(user);
1299
+ case "LogicalExpression": return next(user);
1300
+ case "ConditionalExpression": return user.test === node || next(user);
1301
+ case "IfStatement": return user.test === node;
1302
+ case "ExpressionStatement": return true;
1303
+ case "CallExpression": return user.callee.type === "Identifier" && user.callee.name === "Boolean" && isGlobalName(user.callee, sourceCode) && user.arguments[0] === node && next(user);
1304
+ case "VariableDeclarator":
1305
+ if (user.id.type !== "Identifier" || user.parent.type !== "VariableDeclaration" || user.parent.kind !== "const") return false;
1306
+ return everyUseReaches(sourceCode.getDeclaredVariables(user).find((each) => each.name === user.id.name), next);
1307
+ case "ReturnStatement":
1308
+ case "ArrowFunctionExpression": {
1309
+ if (user.type === "ArrowFunctionExpression" && user.body !== node) return false;
1310
+ const returner = user.type === "ArrowFunctionExpression" ? user : enclosingFunction(user);
1311
+ if (returner === null) return false;
1312
+ if (returner === owner) return true;
1313
+ const bound = readerVariable(returner, sourceCode);
1314
+ if (returnsPrimitive(returner) && bound !== null && bound.references.length === 0) return true;
1315
+ return everyUseReaches(bound, (use) => use.parent.type === "CallExpression" && use.parent.callee === use && next(use.parent));
1316
+ }
1317
+ default: return false;
1318
+ }
1319
+ }
1320
+ /** Return the variable a function declared in this file is bound to. */
1321
+ function readerVariable(reader, sourceCode) {
1322
+ if (reader.type === "FunctionDeclaration") return reader.id === null ? null : sourceCode.getDeclaredVariables(reader).find((variable) => variable.name === reader.id?.name && variable.defs[0]?.type === "FunctionName") ?? null;
1323
+ const declarator = reader.parent;
1324
+ if (declarator.type !== "VariableDeclarator" || declarator.init !== reader || declarator.id.type !== "Identifier") return null;
1325
+ return sourceCode.getDeclaredVariables(declarator).find((variable) => variable.name === declarator.id.name) ?? null;
1326
+ }
1327
+ const REFUSED = {
1328
+ allowed: false,
1329
+ probed: false
1330
+ };
1331
+ function combine(uses) {
1332
+ return {
1333
+ allowed: uses.every((use) => use.allowed),
1334
+ probed: uses.some((use) => use.probed)
1335
+ };
1336
+ }
1337
+ /**
1338
+ * Walk every use of a value. A use is allowed when it is a symbol-keyed probe, an argument to a type guard declared in this
1339
+ * file, the initializer of a `const` alias whose own uses are allowed, or an argument to a function declared in this file whose
1340
+ * matching parameter's uses are allowed. Any other use (a store, a return, a call elsewhere, a cast, an assignment) refuses.
1341
+ */
1342
+ function usesOf(variable, owner, sourceCode, seen) {
1343
+ if (seen.has(variable)) return {
1344
+ allowed: true,
1345
+ probed: false
1346
+ };
1347
+ seen.add(variable);
1348
+ const reads = variable.references.filter((reference) => !reference.init);
1349
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init) || reads.length === 0) return REFUSED;
1350
+ return combine(reads.map((reference) => {
1351
+ const { identifier } = reference;
1352
+ if (isProbe(identifier, sourceCode)) return resultReachesOnlyReturn(identifier.parent, owner, sourceCode, /* @__PURE__ */ new Set()) ? {
1353
+ allowed: true,
1354
+ probed: true
1355
+ } : REFUSED;
1356
+ const user = identifier.parent;
1357
+ if (user.type === "VariableDeclarator" && user.init === identifier && user.id.type === "Identifier" && user.parent.type === "VariableDeclaration" && user.parent.kind === "const") {
1358
+ const alias = sourceCode.getDeclaredVariables(user).find((each) => each.name === user.id.name);
1359
+ return alias === void 0 ? REFUSED : usesOf(alias, owner, sourceCode, seen);
1360
+ }
1361
+ if (user.type !== "CallExpression") return REFUSED;
1362
+ const position = user.arguments.findIndex((argument) => argument === identifier);
1363
+ const callee = declaredFunctionOf(user.callee, sourceCode);
1364
+ if (position < 0 || callee === null) return REFUSED;
1365
+ if (guardsParameterAt(callee, position)) return {
1366
+ allowed: true,
1367
+ probed: false
1368
+ };
1369
+ const parameter = parameterAt(callee, position, sourceCode);
1370
+ return parameter === null ? REFUSED : usesOf(parameter, owner, sourceCode, seen);
1371
+ }));
1372
+ }
1373
+ /**
1374
+ * Return whether a function is a brand probe on a parameter typed `unknown`: it declares a primitive return type, so the
1375
+ * value it hands back is derived, and the only things it does with the parameter are to read a symbol-keyed member that this
1376
+ * file creates (or ask `in` with one), through guards and readers declared in this file, and at least one such read happens.
1377
+ * Storing, forwarding, casting or returning the parameter, reading it by a string key, or a reader imported from elsewhere
1378
+ * is not one.
1379
+ */
1380
+ function isBrandProbe(owner, parameter, sourceCode) {
1381
+ const returned = owner.returnType?.typeAnnotation;
1382
+ if (parameter === void 0 || returned === void 0 || !isPrimitiveType(returned)) return false;
1383
+ const uses = usesOf(parameter, owner, sourceCode, /* @__PURE__ */ new Set());
1384
+ return uses.allowed && uses.probed;
1385
+ }
1386
+ //#endregion
1387
+ //#region src/oxc/anti-slop/shared/caught-callback.ts
1388
+ /** Return whether an identifier is a catch clause's own binding, never reassigned, so it holds exactly what was thrown. */
1389
+ function isCaughtValue(node, sourceCode) {
1390
+ if (node.type !== "Identifier") return false;
1391
+ const definition = variableOf(node, sourceCode)?.defs[0];
1392
+ if (definition?.type !== "CatchClause" || definition.node.type !== "CatchClause") return false;
1393
+ return definition.node.param?.type === "Identifier" && definition.node.param.name === node.name && variableOf(node, sourceCode)?.references.every((reference) => !reference.isWrite()) === true;
1394
+ }
1395
+ /** Return whether a use of a callback leaves it unable to run with anything but what a call site passes: a plain test of whether it exists. */
1396
+ function isExistenceTest(reference) {
1397
+ const user = reference.parent;
1398
+ return user.type === "ConditionalExpression" && user.test === reference || user.type === "IfStatement" && user.test === reference || user.type === "LogicalExpression" && user.operator === "&&" && user.left === reference;
1399
+ }
1400
+ /** Return whether a call hands a caught value to every parameter of the callback type that is `unknown`. */
1401
+ function passesCaughtValues(call, unknownPositions, sourceCode) {
1402
+ return unknownPositions.every((position) => {
1403
+ const argument = call.arguments[position];
1404
+ return argument !== void 0 && isCaughtValue(argument, sourceCode);
1405
+ });
1406
+ }
1407
+ function parameterVariable(owner, parameter, sourceCode) {
1408
+ return sourceCode.getDeclaredVariables(owner).find((variable) => variable.name === parameter.name && variable.defs[0]?.type === "Parameter");
1409
+ }
1410
+ /**
1411
+ * Return whether a function type is the type of a callback parameter that the function only calls with a caught value.
1412
+ * The callback parameter is a plain identifier of a function that has a body, its type is written directly as a function
1413
+ * type, it is called at least once, and every use of it is such a call (with a caught value in each `unknown` position of
1414
+ * the type) or a test of whether it exists. A callback that is stored, passed on, never called, or called with any other
1415
+ * value is not one: the thrown value has no type JavaScript promises, so `unknown` is the true type only there.
1416
+ */
1417
+ function isCaughtValueCallbackType(owner, sourceCode) {
1418
+ const annotation = owner.parent;
1419
+ if (annotation.type !== "TSTypeAnnotation") return false;
1420
+ const callback = annotation.parent;
1421
+ if (callback.type !== "Identifier") return false;
1422
+ const holder = callback.parent;
1423
+ if (!isRuntimeFunction(holder) || holder.body === null || holder.body === void 0) return false;
1424
+ const unknownPositions = owner.params.flatMap((parameter, position) => {
1425
+ const type = functionParameterTypeAnnotation(parameter)?.typeAnnotation;
1426
+ return type !== void 0 && containsUnknownType(type) ? [position] : [];
1427
+ });
1428
+ const reads = parameterVariable(holder, callback, sourceCode)?.references.filter((reference) => !reference.init);
1429
+ if (reads === void 0) return false;
1430
+ const calls = reads.filter((reference) => !isExistenceTest(reference.identifier));
1431
+ return calls.length > 0 && calls.every((reference) => {
1432
+ const call = reference.identifier.parent;
1433
+ return call.type === "CallExpression" && call.callee === reference.identifier && passesCaughtValues(call, unknownPositions, sourceCode);
1434
+ });
1435
+ }
1436
+ //#endregion
1437
+ //#region src/oxc/anti-slop/shared/callee-origin.ts
1438
+ const NO_VARIABLES = /* @__PURE__ */ new Set();
1439
+ /** Return the name an `import x = Outer.Inner.member` reads first, the one the file must declare. */
1440
+ function entityRoot(name) {
1441
+ return name.type === "TSQualifiedName" ? entityRoot(name.left) : name;
1442
+ }
1443
+ /** Return the name an `import x = Namespace.member` reads, or null for a module import, which another file gives a value. */
1444
+ function aliasRoot(definition) {
1445
+ const { node } = definition;
1446
+ if (node.type !== "TSImportEqualsDeclaration") return null;
1447
+ return node.moduleReference.type === "TSExternalModuleReference" ? null : entityRoot(node.moduleReference);
1448
+ }
1449
+ /** Return whether a definition is a `const` with an initializer, a parameter or an import, so that nothing but a write reference changes its value. */
1450
+ function isFixedDefinition(definition) {
1451
+ const { node } = definition;
1452
+ return definition.type !== "Variable" || node.type === "VariableDeclarator" && node.init !== null && node.parent.type === "VariableDeclaration" && node.parent.kind === "const";
1453
+ }
1454
+ /**
1455
+ * Classify a name by every definition and write it has, not by its first definition. It is outside this file only when
1456
+ * `isSuppliedFromOutside` places it there. A name no scope binds, or that a merged namespace member may shadow, is unplaced.
1457
+ * A function, class, namespace or catch binding is a declaration written here. Any other name is a variable read through the
1458
+ * expressions written to it.
1459
+ */
1460
+ function bindingOf(identifier, sourceCode) {
1461
+ if (isSuppliedFromOutside(identifier, sourceCode)) return { kind: "outside" };
1462
+ const variable = variableOf(identifier, sourceCode);
1463
+ if (variable === null || mayBeMergedMember(identifier, variable)) return { kind: "unplaced" };
1464
+ const declared = variable.defs.find((definition) => ![
1465
+ "Variable",
1466
+ "Parameter",
1467
+ "ImportBinding"
1468
+ ].includes(definition.type));
1469
+ if (declared !== void 0) return {
1470
+ kind: "declaration",
1471
+ type: declared.type
1472
+ };
1473
+ const writes = variable.references.filter((reference) => reference.isWrite());
1474
+ return {
1475
+ kind: "variable",
1476
+ variable,
1477
+ sources: [...variable.defs.map(aliasRoot), ...writes.map((write) => write.writeExpr)].filter((source) => source !== null),
1478
+ constant: variable.defs.every(isFixedDefinition) && writes.every((write) => write.writeExpr !== null)
1479
+ };
1480
+ }
1481
+ /** Return the expression a type wrapper, an `await` or an optional chain only passes through, or null when the node is none of these. */
1482
+ function passThrough(node) {
1483
+ switch (node.type) {
1484
+ case "TSAsExpression":
1485
+ case "TSSatisfiesExpression":
1486
+ case "TSNonNullExpression":
1487
+ case "TSTypeAssertion":
1488
+ case "ChainExpression": return node.expression;
1489
+ case "AwaitExpression": return node.argument;
1490
+ default: return null;
1491
+ }
1492
+ }
1493
+ /**
1494
+ * Return whether a value reaches back to code written in this file: walk through members, calls, `new`, type
1495
+ * wrappers and `const` aliases to the name or literal at the root. An import, a parameter and a global are
1496
+ * outside the file. A function, class, namespace, `let`, `var`, `this`, `super`, object literal or anything this
1497
+ * walk cannot place is inside it. A call also counts when it is handed an object that holds a function written
1498
+ * here, which it can hand back as a method. A call rooted at a global (`Object.freeze`, `Array.from`, `Promise.resolve`) is
1499
+ * no factory that wraps a schema, so a function handed to it counts too, as a callback it can call.
1500
+ */
1501
+ function isWrittenHere(node, sourceCode, seen) {
1502
+ const inner = passThrough(node);
1503
+ if (inner !== null) return isWrittenHere(inner, sourceCode, seen);
1504
+ switch (node.type) {
1505
+ case "Identifier": {
1506
+ const binding = bindingOf(node, sourceCode);
1507
+ if (binding.kind === "outside") return false;
1508
+ if (binding.kind !== "variable") return true;
1509
+ return !binding.constant || seen.has(binding.variable) || followSources(binding, sourceCode, seen, isWrittenHere);
1510
+ }
1511
+ case "ImportExpression": return false;
1512
+ case "MemberExpression": return node.object.type === "ThisExpression" ? thisFieldIsWrittenHere(node, sourceCode, seen) : isWrittenHere(node.object, sourceCode, seen);
1513
+ case "CallExpression":
1514
+ case "NewExpression": {
1515
+ const handsOver = isRootedAtGlobal(node.callee, sourceCode) ? isFunctionHere : holdsFunctionHere;
1516
+ return isWrittenHere(node.callee, sourceCode, seen) || node.arguments.some((argument) => handsOver(argument, sourceCode, seen));
1517
+ }
1518
+ case "ConditionalExpression": return isWrittenHere(node.consequent, sourceCode, seen) || isWrittenHere(node.alternate, sourceCode, seen);
1519
+ case "LogicalExpression": return isWrittenHere(node.left, sourceCode, seen) || isWrittenHere(node.right, sourceCode, seen);
1520
+ default: return true;
1521
+ }
1522
+ }
1523
+ /** Return whether a callee is read from a global that has no definition in the file, through members, calls and type wrappers. */
1524
+ function isRootedAtGlobal(node, sourceCode) {
1525
+ const inner = passThrough(node);
1526
+ if (inner !== null) return isRootedAtGlobal(inner, sourceCode);
1527
+ switch (node.type) {
1528
+ case "Identifier": return isGlobalName(node, sourceCode);
1529
+ case "MemberExpression": return isRootedAtGlobal(node.object, sourceCode);
1530
+ case "CallExpression":
1531
+ case "NewExpression": return isRootedAtGlobal(node.callee, sourceCode);
1532
+ default: return false;
1533
+ }
1534
+ }
1535
+ /** Return whether a node is a primitive value, which holds no function: a literal, a template, or the result of a unary, binary or update operator. */
1536
+ function isPrimitive(node) {
1537
+ switch (node.type) {
1538
+ case "Literal":
1539
+ case "TemplateLiteral":
1540
+ case "UnaryExpression":
1541
+ case "BinaryExpression":
1542
+ case "UpdateExpression": return true;
1543
+ default: return false;
1544
+ }
1545
+ }
1546
+ /** Return the name a class element or member is read by, or null for a computed one. A private name carries its `#`, so it is no element of the public name. */
1547
+ function elementName(key, computed) {
1548
+ if (computed) return null;
1549
+ if (key.type === "PrivateIdentifier") return `#${key.name}`;
1550
+ return key.type === "Identifier" ? key.name : null;
1551
+ }
1552
+ /** Return the class a node is written in, or null at the top level. */
1553
+ function enclosingClass(node) {
1554
+ let current = node.parent;
1555
+ while (current !== null && current.type !== "ClassDeclaration" && current.type !== "ClassExpression") current = current.parent;
1556
+ return current;
1557
+ }
1558
+ /**
1559
+ * Return what `this` is where a node is written: the instance or the class itself when the nearest non-arrow function is a
1560
+ * class method, or when no function sits between the node and a field initializer or static block. Any other function (an
1561
+ * object-literal method, a function expression, a declaration) gets its `this` from its caller, as does a node in a class
1562
+ * heritage clause, a decorator or a computed key, which the walk meets as the class itself. Those give null.
1563
+ */
1564
+ function receiverOf(node) {
1565
+ let child = node;
1566
+ for (let current = node.parent; current !== null; current = current.parent) switch (current.type) {
1567
+ case "FunctionExpression": return current.parent.type === "MethodDefinition" && current.parent.value === current ? current.parent.static ? "static" : "instance" : null;
1568
+ case "PropertyDefinition":
1569
+ case "AccessorProperty": return current.value === child ? current.static ? "static" : "instance" : null;
1570
+ case "StaticBlock": return "static";
1571
+ case "FunctionDeclaration":
1572
+ case "ClassDeclaration":
1573
+ case "ClassExpression": return null;
1574
+ default: child = current;
1575
+ }
1576
+ return null;
1577
+ }
1578
+ /**
1579
+ * Return whether `this.field` reaches back to code written here. The element is the one of that exact name, `#` included, and of
1580
+ * the receiver's kind, static or instance. A field with an initializer is read through it. A constructor parameter property is
1581
+ * an instance element handed in by the caller, as a parameter is. A name that no element or two elements declare, an
1582
+ * accessor, a method, a field without an initializer, an inherited field and a computed name are not placed, so they count as
1583
+ * written here.
1584
+ */
1585
+ function thisFieldIsWrittenHere(member, sourceCode, seen) {
1586
+ const klass = enclosingClass(member);
1587
+ const name = elementName(member.property, member.computed);
1588
+ const receiver = receiverOf(member);
1589
+ if (klass === null || name === null || receiver === null) return true;
1590
+ const elements = klass.body.body.filter((element) => (element.type === "PropertyDefinition" || element.type === "AccessorProperty" || element.type === "MethodDefinition") && element.static === (receiver === "static") && elementName(element.key, element.computed) === name);
1591
+ const handedIn = receiver === "instance" && klass.body.body.some((element) => element.type === "MethodDefinition" && declaresParameterProperty(element, name));
1592
+ if (elements.length + (handedIn ? 1 : 0) !== 1) return true;
1593
+ const [element] = elements;
1594
+ if (element === void 0) return false;
1595
+ if (element.type !== "PropertyDefinition") return true;
1596
+ return element.value === null || seen.has(element) || isWrittenHere(element.value, sourceCode, /* @__PURE__ */ new Set([...seen, element]));
1597
+ }
1598
+ /** Return whether a method declares a parameter property of this name, which only a constructor can. */
1599
+ function declaresParameterProperty(method, name) {
1600
+ return method.value.params.some((parameter) => parameter.type === "TSParameterProperty" && parameter.parameter.type === "Identifier" && parameter.parameter.name === name);
1601
+ }
1602
+ /**
1603
+ * Return whether a value is local code: a function or class written here, an object or array of such members, or a member or call
1604
+ * that reaches back to this file. Only a primitive, an import, a parameter and an object of such values are not, so a node this
1605
+ * walk does not list, a function, a class and any syntax added later included, is reported.
1606
+ */
1607
+ function isFunctionHere(node, sourceCode, seen) {
1608
+ const inner = passThrough(node);
1609
+ if (inner !== null) return isFunctionHere(inner, sourceCode, seen);
1610
+ switch (node.type) {
1611
+ case "ObjectExpression":
1612
+ case "ArrayExpression": return holdsFunctionHere(node, sourceCode, seen);
1613
+ case "ConditionalExpression": return isFunctionHere(node.consequent, sourceCode, seen) || isFunctionHere(node.alternate, sourceCode, seen);
1614
+ case "LogicalExpression": return isFunctionHere(node.left, sourceCode, seen) || isFunctionHere(node.right, sourceCode, seen);
1615
+ case "Identifier": {
1616
+ const binding = bindingOf(node, sourceCode);
1617
+ if (binding.kind === "unplaced") return true;
1618
+ if (binding.kind === "declaration") return true;
1619
+ return binding.kind === "variable" && followSources(binding, sourceCode, seen, isFunctionHere);
1620
+ }
1621
+ case "MemberExpression":
1622
+ case "CallExpression":
1623
+ case "NewExpression": return isWrittenHere(node, sourceCode, seen);
1624
+ default: return !isPrimitive(node);
1625
+ }
1626
+ }
1627
+ /**
1628
+ * Return whether an argument is an object, an array or a class whose members include a function written here, or a `this`.
1629
+ * A function handed over on its own is not: a schema may take a local refinement. A node this walk does not list is reported
1630
+ * unless it is a primitive.
1631
+ */
1632
+ function holdsFunctionHere(node, sourceCode, seen) {
1633
+ const inner = passThrough(node);
1634
+ if (inner !== null) return holdsFunctionHere(inner, sourceCode, seen);
1635
+ switch (node.type) {
1636
+ case "FunctionExpression":
1637
+ case "ArrowFunctionExpression": return false;
1638
+ case "SpreadElement": return holdsFunctionHere(node.argument, sourceCode, seen);
1639
+ case "ObjectExpression": return node.properties.some((property) => property.type === "SpreadElement" ? isFunctionHere(property.argument, sourceCode, seen) : isFunctionHere(property.value, sourceCode, seen));
1640
+ case "ArrayExpression": return node.elements.some((element) => element !== null && (element.type === "SpreadElement" ? holdsFunctionHere(element.argument, sourceCode, seen) : isFunctionHere(element, sourceCode, seen)));
1641
+ case "Identifier": {
1642
+ const binding = bindingOf(node, sourceCode);
1643
+ if (binding.kind === "unplaced") return true;
1644
+ if (binding.kind === "declaration") return binding.type !== "FunctionName";
1645
+ return binding.kind === "variable" && followSources(binding, sourceCode, seen, holdsFunctionHere);
1646
+ }
1647
+ case "MemberExpression":
1648
+ case "CallExpression":
1649
+ case "NewExpression":
1650
+ case "ConditionalExpression":
1651
+ case "LogicalExpression": return isWrittenHere(node, sourceCode, seen);
1652
+ default: return !isPrimitive(node);
1653
+ }
1654
+ }
1655
+ /** Apply a test to each expression written to a variable, once per variable on the path, and answer false for a variable written nothing. */
1656
+ function followSources(binding, sourceCode, seen, test) {
1657
+ const { sources, variable } = binding;
1658
+ return !seen.has(variable) && sources.some((source) => test(source, sourceCode, /* @__PURE__ */ new Set([...seen, variable])));
1659
+ }
1660
+ /**
1661
+ * Return whether a call goes to code written in this file. A bare callee counts when it is not outside the file, as
1662
+ * `isSuppliedFromOutside` decides, or when it is a parameter. A member callee counts when the value it is read from reaches back
1663
+ * to this file, so a member of a parameter, which the caller supplies, does not.
1664
+ */
1665
+ function calleeIsWrittenHere(call, sourceCode) {
1666
+ const { callee } = call;
1667
+ if (callee.type === "Identifier") {
1668
+ const variable = variableOf(callee, sourceCode);
1669
+ return !isSuppliedFromOutside(callee, sourceCode) || variable !== null && variable.defs.some((definition) => definition.type === "Parameter");
1670
+ }
1671
+ return callee.type === "MemberExpression" && isWrittenHere(callee.object, sourceCode, NO_VARIABLES);
1672
+ }
1673
+ //#endregion
1674
+ //#region src/oxc/anti-slop/shared/parse-boundary.ts
1675
+ /**
1676
+ * Callee names that read as a schema or decoder: `parse`, `safeParse` and their `Async` forms, `decode`,
1677
+ * `parseX` and `decodeX` helpers in either case, and interface-api-util's `assertValidation`. A name proves
1678
+ * nothing alone. A callee declared in the same file never counts (see `calleeIsWrittenHere`), so a chain of wrappers
1679
+ * cannot close on itself, and an imported callee that takes `unknown` is checked where it is declared.
1680
+ */
1681
+ const DECODER_NAME = /^(?:assertValidation|safeParse(?:Async)?|[Pp]arse(?:[A-Z]\w*)?|[Dd]ecode(?:[A-Z]\w*)?)$/;
1682
+ const PROMISE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike"]);
1683
+ function calleeName(call) {
1684
+ const { callee } = call;
1685
+ if (callee.type === "Identifier") return callee.name;
1686
+ return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null;
1687
+ }
1688
+ /** Return the initializer of the single-name `const` a variable declares. */
1689
+ function constInitializerOf(variable) {
1690
+ const declarator = variable?.defs[0]?.node;
1691
+ return declarator?.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" ? declarator.init : null;
1692
+ }
1693
+ /**
1694
+ * Return the decoder call whose direct argument a reference is. An `unknown` value is not callable, so it is
1695
+ * never the callee. A callee written in this file carries its own row and is no decoder.
1696
+ */
1697
+ function decoderCallOf(identifier, sourceCode) {
1698
+ const call = identifier.parent;
1699
+ return call.type === "CallExpression" && DECODER_NAME.test(calleeName(call) ?? "") && !calleeIsWrittenHere(call, sourceCode) ? call : null;
1700
+ }
1701
+ /** Return whether a declared return type states a value, not `unknown` or `any`, promised or not. */
1702
+ function declaresParsedType(annotation) {
1703
+ const type = annotation?.typeAnnotation;
1704
+ if (type === void 0) return false;
1705
+ const promised = type.type === "TSTypeReference" && type.typeName.type === "Identifier" && PROMISE_TYPES.has(type.typeName.name) ? type.typeArguments?.params[0] : type;
1706
+ return promised !== void 0 && promised.type !== "TSAnyKeyword" && !containsUnknownType(promised);
1707
+ }
1708
+ /** Strip what leaves a decoder's result the parsed value: `await` and the `.data` of a safe parse. */
1709
+ function parsedSource(node) {
1710
+ if (node.type === "AwaitExpression") return parsedSource(node.argument);
1711
+ return node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.property.name === "data" ? parsedSource(node.object) : node;
1712
+ }
1713
+ /** Names that read a parameter without a reference to it: the `arguments` object, and a direct `eval` that can name it in a string. */
1714
+ const IMPLICIT_READERS = /* @__PURE__ */ new Set(["arguments", "eval"]);
1715
+ /** Return the expressions a function hands back: an arrow's expression body, or what its `return` statements return. */
1716
+ function returnedExpressions(owner, returns) {
1717
+ if (owner.body === null || owner.body === void 0) return [];
1718
+ return owner.body.type === "BlockStatement" ? returns.map((statement) => statement.argument) : [owner.body];
1719
+ }
1720
+ /**
1721
+ * Return whether a parameter typed exactly `unknown` is a parse boundary: every read of it is a direct argument
1722
+ * to a schema or decoder declared outside this file, every value the function returns is such a call's result,
1723
+ * and the function declares a return type that states what it parsed. A function that stores, forwards, reads
1724
+ * by hand (through `arguments` or `eval` too) or discards the parsed value is not one.
1725
+ */
1726
+ function decodesParameterIntoResult(owner, name, annotated, facts, sourceCode) {
1727
+ if (annotated.type !== "TSUnknownKeyword" || facts.readsImplicitly || !declaresParsedType(owner.returnType)) return false;
1728
+ const reads = sourceCode.getDeclaredVariables(owner).find((variable) => variable.name === name && variable.defs[0]?.type === "Parameter")?.references.filter((reference) => !reference.init);
1729
+ const decoders = new Set(reads?.map((reference) => decoderCallOf(reference.identifier, sourceCode)));
1730
+ if (decoders.has(null)) return false;
1731
+ const results = returnedExpressions(owner, facts.returns);
1732
+ return results.length > 0 && results.every((result) => {
1733
+ if (result === null) return false;
1734
+ const source = parsedSource(result);
1735
+ if (source.type !== "Identifier") return decoders.has(source);
1736
+ const initializer = constInitializerOf(variableOf(source, sourceCode));
1737
+ return initializer !== null && decoders.has(parsedSource(initializer));
1738
+ });
1739
+ }
1740
+ //#endregion
1072
1741
  //#region src/oxc/anti-slop/rules/no-unknown-parameters.ts
1073
1742
  function isTypePredicateSubject(owner, parameterName) {
1074
1743
  const predicate = owner.returnType?.typeAnnotation;
@@ -1117,27 +1786,40 @@ function isRejectFunctionType(owner) {
1117
1786
  return holder.type === "Identifier" && (holder.name === "reject" || isPromiseExecutorReject(holder));
1118
1787
  }
1119
1788
  /** Return whether a parameter is exempt whatever its name: `this`, a boundary-decorated request value, or a promise rejection reason. */
1120
- function isExemptPosition(owner, parameter) {
1789
+ function isExemptPosition(owner, parameter, sourceCode) {
1121
1790
  if (isThisParameter(parameter) || hasBoundaryDecorator(parameter)) return true;
1122
1791
  if (owner.params[0] === parameter && isRejectionCallback(owner)) return true;
1123
- return isRejectFunctionType(owner);
1124
- }
1792
+ return isRejectFunctionType(owner) || owner.type === "TSFunctionType" && isCaughtValueCallbackType(owner, sourceCode);
1793
+ }
1794
+ /** Return whether a parameter typed exactly `unknown` is only probed for a symbol-keyed brand this file creates, see `isBrandProbe`. */
1795
+ function probesBrand(owner, name, annotated, facts, sourceCode) {
1796
+ if (annotated.type !== "TSUnknownKeyword" || facts.readsImplicitly) return false;
1797
+ return isBrandProbe(owner, sourceCode.getDeclaredVariables(owner).find((variable) => variable.name === name && variable.defs[0]?.type === "Parameter"), sourceCode);
1798
+ }
1799
+ /** The facts of a function the rule did not walk: a signature with no body. */
1800
+ const NO_FACTS = {
1801
+ returns: [],
1802
+ readsImplicitly: false
1803
+ };
1125
1804
  /** Disallow unknown inputs except explicitly named error-cause enrichment. */
1126
1805
  const noUnknownParametersRule = defineRule({
1127
1806
  meta: {
1128
1807
  type: "problem",
1129
- docs: { description: "Disallow explicitly unknown function parameters except `cause`, type-predicate subjects, `this`, request values injected by `@JSONBody`, `@JsonBody` or `@Parameter`, and promise rejection reasons; decode unknown input at its I/O boundary instead." },
1130
- messages: { unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function." }
1808
+ docs: { description: "Disallow explicitly unknown function parameters except `cause`, type-predicate subjects, `this`, request values injected by `@JSONBody`, `@JsonBody` or `@Parameter`, promise rejection reasons, the parameter of a callback type that the function only calls with a caught value, a symbol-keyed brand probe, and a parameter a function only decodes through a schema or decoder into the value it returns; decode unknown input at its I/O boundary instead." },
1809
+ messages: { unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type and run the expected schema or parser at the I/O boundary before calling this function, or make this function that parser: pass the parameter only to the schema and return its result under a declared type." }
1131
1810
  },
1132
1811
  createOnce(context) {
1133
- const checkParameters = (node) => {
1812
+ const open = [];
1813
+ const checkParameters = (node, facts = NO_FACTS) => {
1134
1814
  for (const parameter of node.params) {
1135
1815
  const annotation = functionParameterTypeAnnotation(parameter);
1136
1816
  if (annotation === null || annotation === void 0) continue;
1137
1817
  if (!containsUnknownType(annotation.typeAnnotation)) continue;
1138
- if (isExemptPosition(node, parameter)) continue;
1818
+ if (isExemptPosition(node, parameter, context.sourceCode)) continue;
1139
1819
  const name = functionParameterBindingName(parameter, context.sourceCode);
1140
1820
  if (name === "cause" || isTypePredicateSubject(node, name)) continue;
1821
+ if (isRuntimeFunction(node) && decodesParameterIntoResult(node, name, annotation.typeAnnotation, facts, context.sourceCode)) continue;
1822
+ if (isRuntimeFunction(node) && probesBrand(node, name, annotation.typeAnnotation, facts, context.sourceCode)) continue;
1141
1823
  context.report({
1142
1824
  node: annotation.typeAnnotation,
1143
1825
  messageId: "unknownParameter",
@@ -1145,10 +1827,29 @@ const noUnknownParametersRule = defineRule({
1145
1827
  });
1146
1828
  }
1147
1829
  };
1830
+ const enterFunction = () => {
1831
+ open.push({
1832
+ returns: [],
1833
+ readsImplicitly: false
1834
+ });
1835
+ };
1836
+ const leaveFunction = (node) => {
1837
+ checkParameters(node, open.pop());
1838
+ };
1148
1839
  return {
1149
- ArrowFunctionExpression: checkParameters,
1150
- FunctionDeclaration: checkParameters,
1151
- FunctionExpression: checkParameters,
1840
+ ArrowFunctionExpression: enterFunction,
1841
+ FunctionDeclaration: enterFunction,
1842
+ FunctionExpression: enterFunction,
1843
+ "ArrowFunctionExpression:exit": leaveFunction,
1844
+ "FunctionDeclaration:exit": leaveFunction,
1845
+ "FunctionExpression:exit": leaveFunction,
1846
+ ReturnStatement(node) {
1847
+ open.at(-1)?.returns.push(node);
1848
+ },
1849
+ Identifier(node) {
1850
+ if (!IMPLICIT_READERS.has(node.name)) return;
1851
+ for (const frame of open) frame.readsImplicitly = true;
1852
+ },
1152
1853
  TSCallSignatureDeclaration: checkParameters,
1153
1854
  TSConstructSignatureDeclaration: checkParameters,
1154
1855
  TSConstructorType: checkParameters,