@antelopejs/tooling-configs 0.2.15 → 0.2.17

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 (41) hide show
  1. package/README.md +88 -48
  2. package/dist/bin/api-diff.mjs +409 -97
  3. package/dist/bin/body-check.d.mts +1 -0
  4. package/dist/bin/body-check.mjs +344 -0
  5. package/dist/bin/check-size.mjs +3 -3
  6. package/dist/bin/checks.mjs +3 -3
  7. package/dist/bin/comment-proof.mjs +4 -3
  8. package/dist/bin/garden.mjs +5 -5
  9. package/dist/bin/ratchet.mjs +267 -7
  10. package/dist/bin/suppressions.mjs +118 -80
  11. package/dist/bin/sync.mjs +490 -35
  12. package/dist/bin/verify.mjs +48 -26
  13. package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
  14. package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
  15. package/dist/{ci-workflow-C0nT5SnX.mjs → ci-workflow-ChW4He0r.mjs} +103 -3
  16. package/dist/{files-2FikHZ9F.mjs → files-Bc036sJW.mjs} +2 -2
  17. package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
  18. package/dist/oxc/anti-slop/index.mjs +160 -13
  19. package/dist/oxc/fmt.mjs +1 -1
  20. package/dist/oxc/guardrails/index.d.mts +1 -1
  21. package/dist/oxc/guardrails/index.mjs +645 -1
  22. package/dist/oxc/lint.d.mts +11 -3
  23. package/dist/oxc/lint.mjs +21 -8
  24. package/dist/oxlint-Bltmk8-6.mjs +94 -0
  25. package/dist/{package-Dtjt_lSa.mjs → package-DTxLPNDu.mjs} +3 -2
  26. package/dist/proof-stamp-w-3j47A-.mjs +279 -0
  27. package/dist/ratchet-DwRj9h4L.mjs +275 -0
  28. package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
  29. package/dist/shared-CoUt4GUm.mjs +73 -0
  30. package/dist/{size-BVgNbLO6.mjs → size-DNtWruCO.mjs} +3 -3
  31. package/dist/suppression-base-DAfCXwjL.mjs +95 -0
  32. package/dist/{suppression-budget-Yyf5_J5l.mjs → suppression-budget-Bd2GqMYb.mjs} +248 -33
  33. package/dist/{suppressions-BJAngUxo.mjs → suppressions-BD_f8f7L.mjs} +180 -18
  34. package/dist/typescript-BmS5BmrS.mjs +222 -0
  35. package/dist/verify/index.mjs +1 -1
  36. package/package.json +4 -2
  37. package/dist/kinds-Bzyyi9yk.mjs +0 -25
  38. package/dist/ratchet-DRdIYwmv.mjs +0 -80
  39. package/dist/shared-CsXIMK3I.mjs +0 -34
  40. package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
  41. package/dist/typescript-C54ONh9m.mjs +0 -433
@@ -908,18 +908,57 @@ const noReflectGetRule = defineRule({
908
908
  }
909
909
  });
910
910
  //#endregion
911
- //#region src/oxc/anti-slop/rules/no-runtime-typeof.ts
911
+ //#region src/oxc/anti-slop/shared/type-guards.ts
912
+ /** Files whose functions may declare a type predicate in JSDoc instead of a TypeScript return type. */
913
+ const JSDOC_PREDICATE_FILE = /\.m?js$/;
914
+ /** A `@returns {x is T}` type, `x` captured: `asserts x is T` does not match. */
915
+ const JSDOC_PREDICATE = /^\s*([A-Za-z_$][\w$]*)\s+is\s+\S/;
912
916
  function isRuntimeFunction(node) {
913
917
  return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
914
918
  }
915
- function isInsideTypeGuard(node) {
919
+ /** Return the statement or member a JSDoc block documenting this function is attached to. */
920
+ function documentedNode(fn) {
921
+ const parent = fn.parent;
922
+ if ((parent.type === "Property" || parent.type === "MethodDefinition") && parent.value === fn) return parent;
923
+ let node = fn;
924
+ if (parent.type === "VariableDeclarator" && parent.init === fn && parent.parent.type === "VariableDeclaration" && parent.parent.declarations.length === 1) node = parent.parent;
925
+ const container = node.parent;
926
+ return container !== null && (container.type === "ExportNamedDeclaration" || container.type === "ExportDefaultDeclaration") ? container : node;
927
+ }
928
+ /** Return the type inside the braces of the first `@returns {...}` tag of a JSDoc block. */
929
+ function jsDocReturnType(text) {
930
+ const tag = /@returns\s*\{/.exec(text);
931
+ if (tag === null) return null;
932
+ const start = tag.index + tag[0].length;
933
+ let depth = 1;
934
+ for (let index = start; index < text.length; index++) if (text[index] === "{") depth++;
935
+ else if (text[index] === "}" && --depth === 0) return text.slice(start, index);
936
+ return null;
937
+ }
938
+ /** Return whether the JSDoc block right before the function declares `@returns {param is T}` for one of its parameters. */
939
+ function hasJsDocTypePredicate(fn, sourceCode) {
940
+ const comment = sourceCode.getCommentsBefore(documentedNode(fn)).at(-1);
941
+ if (comment === void 0 || comment.type !== "Block" || !comment.value.startsWith("*")) return false;
942
+ const returnType = jsDocReturnType(comment.value);
943
+ const subject = returnType === null ? void 0 : JSDOC_PREDICATE.exec(returnType)?.[1];
944
+ return subject !== void 0 && fn.params.some((parameter) => parameter.type === "Identifier" && parameter.name === subject);
945
+ }
946
+ /** Return whether a function declares a type predicate or assertion, or a JSDoc `@returns {x is T}` in a `.js`/`.mjs` file. */
947
+ function isTypeGuard(fn, sourceCode, filename) {
948
+ if (fn.returnType?.typeAnnotation.type === "TSTypePredicate") return true;
949
+ return JSDOC_PREDICATE_FILE.test(filename) && hasJsDocTypePredicate(fn, sourceCode);
950
+ }
951
+ /** Return the nearest runtime function around a node when that function is a type guard. */
952
+ function enclosingTypeGuard(node, sourceCode, filename) {
916
953
  let current = node.parent;
917
954
  while (current !== null && current.type !== "Program") {
918
- if (isRuntimeFunction(current)) return current.returnType?.typeAnnotation.type === "TSTypePredicate";
955
+ if (isRuntimeFunction(current)) return isTypeGuard(current, sourceCode, filename) ? current : null;
919
956
  current = current.parent;
920
957
  }
921
- return false;
958
+ return null;
922
959
  }
960
+ //#endregion
961
+ //#region src/oxc/anti-slop/rules/no-runtime-typeof.ts
923
962
  /** Return whether typeof safely probes for the existence of a possibly absent binding. */
924
963
  function isExistenceProbe(node) {
925
964
  const parent = node.parent;
@@ -933,12 +972,37 @@ function isExistenceProbe(node) {
933
972
  const other = parent.left === node ? parent.right : parent.left;
934
973
  return other.type === "Literal" && other.value === "undefined";
935
974
  }
975
+ /** Built-ins whose `.constructor` comparison re-implements a `typeof` result. */
976
+ const TYPEOF_CONSTRUCTORS = /* @__PURE__ */ new Set([
977
+ "String",
978
+ "Number",
979
+ "Boolean",
980
+ "BigInt",
981
+ "Symbol",
982
+ "Function"
983
+ ]);
984
+ /** Return the built-in name when the comparison is `x.constructor === String` or its mirror. */
985
+ function constructorCheckTarget(node) {
986
+ if (![
987
+ "===",
988
+ "!==",
989
+ "==",
990
+ "!="
991
+ ].includes(node.operator)) return void 0;
992
+ for (const [operand, other] of [[node.left, node.right], [node.right, node.left]]) {
993
+ const side = operand.type === "ChainExpression" ? operand.expression : operand;
994
+ if (side.type === "MemberExpression" && !side.computed && side.property.type === "Identifier" && side.property.name === "constructor" && other.type === "Identifier" && TYPEOF_CONSTRUCTORS.has(other.name)) return other.name;
995
+ }
996
+ }
936
997
  /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
937
998
  const noRuntimeTypeofRule = defineRule({
938
999
  meta: {
939
1000
  type: "problem",
940
1001
  docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary." },
941
- messages: { runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value." },
1002
+ messages: {
1003
+ 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
+ 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`."
1005
+ },
942
1006
  schema: [{
943
1007
  type: "object",
944
1008
  properties: { allowInTypeGuards: { type: "boolean" } },
@@ -947,14 +1011,26 @@ const noRuntimeTypeofRule = defineRule({
947
1011
  defaultOptions: [{ allowInTypeGuards: false }]
948
1012
  },
949
1013
  createOnce(context) {
950
- return { UnaryExpression(node) {
1014
+ function allowedInTypeGuard(node) {
951
1015
  const option = context.options?.[0];
952
- const allowInTypeGuards = typeof option === "object" && option !== null && !Array.isArray(option) && option.allowInTypeGuards === true;
953
- if (node.operator === "typeof" && !isExistenceProbe(node) && (!allowInTypeGuards || !isInsideTypeGuard(node))) context.report({
954
- node,
955
- messageId: "runtimeTypeof"
956
- });
957
- } };
1016
+ return typeof option === "object" && option !== null && !Array.isArray(option) && option.allowInTypeGuards === true && enclosingTypeGuard(node, context.sourceCode, context.filename) !== null;
1017
+ }
1018
+ return {
1019
+ UnaryExpression(node) {
1020
+ if (node.operator === "typeof" && !isExistenceProbe(node) && !allowedInTypeGuard(node)) context.report({
1021
+ node,
1022
+ messageId: "runtimeTypeof"
1023
+ });
1024
+ },
1025
+ BinaryExpression(node) {
1026
+ const name = constructorCheckTarget(node);
1027
+ if (name !== void 0 && !allowedInTypeGuard(node)) context.report({
1028
+ node,
1029
+ messageId: "constructorCheck",
1030
+ data: { name }
1031
+ });
1032
+ }
1033
+ };
958
1034
  }
959
1035
  });
960
1036
  //#endregion
@@ -998,11 +1074,59 @@ function isTypePredicateSubject(owner, parameterName) {
998
1074
  const predicate = owner.returnType?.typeAnnotation;
999
1075
  return predicate?.type === "TSTypePredicate" && predicate.parameterName.type === "Identifier" && predicate.parameterName.name === parameterName;
1000
1076
  }
1077
+ /** Parameter decorators that inject a request value: interface-api's `JSONBody` and `Parameter`, and dms-lang's `JsonBody`. The decorated parameter is the I/O boundary the value is decoded at. */
1078
+ const BOUNDARY_PARAMETER_DECORATORS = /* @__PURE__ */ new Set([
1079
+ "JSONBody",
1080
+ "JsonBody",
1081
+ "Parameter"
1082
+ ]);
1083
+ function decoratorName(decorator) {
1084
+ const target = decorator.expression.type === "CallExpression" ? decorator.expression.callee : decorator.expression;
1085
+ return target.type === "Identifier" ? target.name : null;
1086
+ }
1087
+ function hasBoundaryDecorator(parameter) {
1088
+ return (parameter.decorators ?? []).some((decorator) => {
1089
+ const name = decoratorName(decorator);
1090
+ return name !== null && BOUNDARY_PARAMETER_DECORATORS.has(name);
1091
+ });
1092
+ }
1093
+ function isThisParameter(parameter) {
1094
+ return parameter.type === "Identifier" && parameter.name === "this";
1095
+ }
1096
+ /** Return whether a function is passed directly as argument `position` of a `.method(...)` call. */
1097
+ function isMethodArgument(owner, method, position) {
1098
+ const call = owner.parent;
1099
+ return call.type === "CallExpression" && call.arguments[position] === owner && call.callee.type === "MemberExpression" && !call.callee.computed && call.callee.property.type === "Identifier" && call.callee.property.name === method;
1100
+ }
1101
+ /** Return whether a callback is written directly as `.catch(onRejected)` or `.then(_, onRejected)`. */
1102
+ function isRejectionCallback(owner) {
1103
+ return isRuntimeFunction(owner) && (isMethodArgument(owner, "catch", 0) || isMethodArgument(owner, "then", 1));
1104
+ }
1105
+ /** Return whether a binding is the second parameter of a `new Promise(...)` executor. */
1106
+ function isPromiseExecutorReject(binding) {
1107
+ const executor = binding.parent;
1108
+ if (executor === null || !isRuntimeFunction(executor) || executor.params[1] !== binding) return false;
1109
+ const construction = executor.parent;
1110
+ return construction.type === "NewExpression" && construction.arguments[0] === executor && construction.callee.type === "Identifier" && construction.callee.name === "Promise";
1111
+ }
1112
+ /** Return whether a `(reason: unknown) => void` type is declared as a promise's `reject` or typed on a `new Promise` executor's reject parameter. */
1113
+ function isRejectFunctionType(owner) {
1114
+ if (owner.type !== "TSFunctionType" || owner.params.length !== 1 || owner.returnType.typeAnnotation.type !== "TSVoidKeyword" || owner.parent.type !== "TSTypeAnnotation") return false;
1115
+ const holder = owner.parent.parent;
1116
+ if (holder.type === "TSPropertySignature" || holder.type === "PropertyDefinition") return !holder.computed && holder.key.type === "Identifier" && holder.key.name === "reject";
1117
+ return holder.type === "Identifier" && (holder.name === "reject" || isPromiseExecutorReject(holder));
1118
+ }
1119
+ /** 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) {
1121
+ if (isThisParameter(parameter) || hasBoundaryDecorator(parameter)) return true;
1122
+ if (owner.params[0] === parameter && isRejectionCallback(owner)) return true;
1123
+ return isRejectFunctionType(owner);
1124
+ }
1001
1125
  /** Disallow unknown inputs except explicitly named error-cause enrichment. */
1002
1126
  const noUnknownParametersRule = defineRule({
1003
1127
  meta: {
1004
1128
  type: "problem",
1005
- docs: { description: "Disallow explicitly unknown function parameters except `cause` and type-predicate subjects; decode unknown input at its I/O boundary instead." },
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." },
1006
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." }
1007
1131
  },
1008
1132
  createOnce(context) {
@@ -1011,6 +1135,7 @@ const noUnknownParametersRule = defineRule({
1011
1135
  const annotation = functionParameterTypeAnnotation(parameter);
1012
1136
  if (annotation === null || annotation === void 0) continue;
1013
1137
  if (!containsUnknownType(annotation.typeAnnotation)) continue;
1138
+ if (isExemptPosition(node, parameter)) continue;
1014
1139
  const name = functionParameterBindingName(parameter, context.sourceCode);
1015
1140
  if (name === "cause" || isTypePredicateSubject(node, name)) continue;
1016
1141
  context.report({
@@ -1157,6 +1282,27 @@ function isTypeNode(node) {
1157
1282
  function typeReferenceName$1(type) {
1158
1283
  return type.typeName.type === "Identifier" ? type.typeName.name : null;
1159
1284
  }
1285
+ /** Return whether a type is literally `Record<string, unknown>`. */
1286
+ function isStringUnknownRecord(node) {
1287
+ if (node.type !== "TSTypeReference" || typeReferenceName$1(node) !== "Record") return false;
1288
+ const params = node.typeArguments?.params ?? [];
1289
+ const [key, value] = params;
1290
+ return params.length === 2 && key?.type === "TSStringKeyword" && value?.type === "TSUnknownKeyword";
1291
+ }
1292
+ /** Return whether a type is the whole target of a `value is T` predicate. */
1293
+ function isTypePredicateTarget(node) {
1294
+ const annotation = node.parent;
1295
+ return annotation.type === "TSTypeAnnotation" && annotation.parent.type === "TSTypePredicate" && !annotation.parent.asserts;
1296
+ }
1297
+ /** Return whether a type is written in the body of its nearest function, and that function is a type guard. */
1298
+ function isInsideTypeGuardBody(node, sourceCode, filename) {
1299
+ const body = enclosingTypeGuard(node, sourceCode, filename)?.body;
1300
+ return body !== void 0 && body !== null && node.start >= body.start && node.end <= body.end;
1301
+ }
1302
+ /** `Record<string, unknown>` is the narrowing a type guard establishes before it reads keys, so it passes as a predicate target or inside a guard body. */
1303
+ function isTypeGuardRecord(node, sourceCode, filename) {
1304
+ return isStringUnknownRecord(node) && (isTypePredicateTarget(node) || isInsideTypeGuardBody(node, sourceCode, filename));
1305
+ }
1160
1306
  function isInsideTypeAliasDeclaration(node) {
1161
1307
  let current = node.parent;
1162
1308
  while (current !== null && current.type !== "Program") {
@@ -1209,6 +1355,7 @@ const noUnsafeDictionaryTypeRule = defineRule({
1209
1355
  };
1210
1356
  const reportIfUnsafe = (node) => {
1211
1357
  if (environment === null || !shouldReportType(node, environment)) return;
1358
+ if (isTypeGuardRecord(node, context.sourceCode, context.filename)) return;
1212
1359
  const unsafe = classifyUnsafeDictionary(node, environment);
1213
1360
  if (unsafe === null) return;
1214
1361
  report(node, unsafe.unsafeValue);
package/dist/oxc/fmt.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "../shared-CsXIMK3I.mjs";
1
+ import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "../shared-CoUt4GUm.mjs";
2
2
  import { defineConfig } from "oxfmt";
3
3
  //#region src/oxc/fmt.ts
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  import { n as TEST_FILE_GLOBS, t as ASSERTION_FUNCTION_NAMES } from "../../shared-BG0Nkzh0.mjs";
2
2
  //#region src/oxc/guardrails/index.d.ts
3
- /** AntelopeJS rules that reject comments and low-evidence tests. */
3
+ /** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards and low-evidence tests. */
4
4
  declare const guardrailsPlugin: import("@oxlint/plugins").Plugin;
5
5
  //#endregion
6
6
  export { ASSERTION_FUNCTION_NAMES, TEST_FILE_GLOBS, guardrailsPlugin as default };