@antelopejs/tooling-configs 0.5.0 → 0.5.1

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.
@@ -939,75 +939,6 @@ const noReflectGetRule = defineRule({
939
939
  }
940
940
  });
941
941
  //#endregion
942
- //#region src/oxc/anti-slop/shared/binding-origin.ts
943
- /** Return the variable an identifier refers to, searching outward from its scope, or null for an unresolved global. */
944
- function variableOf(identifier, sourceCode) {
945
- let scope = sourceCode.getScope(identifier);
946
- while (scope !== null) {
947
- const variable = scope.set.get(identifier.name);
948
- if (variable !== void 0) return variable;
949
- scope = scope.upper;
950
- }
951
- return null;
952
- }
953
- /**
954
- * Return whether a definition takes its value from another module: an `import` declaration, or `import x = require()`.
955
- * An `import x = Namespace.member` only renames a name, so its value comes from where that name is declared.
956
- */
957
- function isModuleImport(definition) {
958
- if (definition.type !== "ImportBinding") return false;
959
- const { node } = definition;
960
- return node.type !== "TSImportEqualsDeclaration" || node.moduleReference.type === "TSExternalModuleReference";
961
- }
962
- /**
963
- * Return whether a name has no definition in this file: a name no scope binds, or a global the environment declares (`Array`,
964
- * `Error`), which oxlint binds to a variable with no definition.
965
- */
966
- function isGlobalName(identifier, sourceCode) {
967
- const variable = variableOf(identifier, sourceCode);
968
- return variable === null || variable.defs.length === 0;
969
- }
970
- /** Return whether a node sits inside another, or is it. */
971
- function isWithin(node, ancestor) {
972
- for (let at = node; at !== null; at = at.parent) if (at === ancestor) return true;
973
- return false;
974
- }
975
- /**
976
- * Return whether a name read inside a namespace block may be a member that another block of the same namespace declares.
977
- * TypeScript merges the blocks of one namespace, and the scope manager does not, so a name that has no definition in the file
978
- * (see `isGlobalName`), or whose definitions sit outside the block, may resolve to such a member and not to the binding the
979
- * scope manager found.
980
- */
981
- function mayBeMergedMember(identifier, variable) {
982
- for (let node = identifier.parent; node !== null; node = node.parent) {
983
- if (node.type !== "TSModuleBlock") continue;
984
- const block = node;
985
- return variable === null || variable.defs.length === 0 || !variable.defs.every((definition) => isWithin(definition.node, block));
986
- }
987
- return false;
988
- }
989
- /**
990
- * Return whether a name no scope binds is a global that nothing in this file writes, including a global that a `declare global`
991
- * introduces.
992
- */
993
- function isUnwrittenGlobal(identifier, sourceCode) {
994
- const scope = sourceCode.scopeManager.globalScope;
995
- return scope !== null && !scope.through.some((reference) => reference.identifier.name === identifier.name && reference.isWrite());
996
- }
997
- /**
998
- * Return whether a name takes its value from outside this file, which only a binding or reference the code can place proves:
999
- * a module import, or a parameter, that nothing here defaults, assigns or redeclares, or a global that nothing here writes,
1000
- * and that no block of a namespace may shadow with a merged member. The kind of the first definition does not say it: a
1001
- * default, an assignment and a later `var` give a parameter a value written here, and an `import x = Namespace.member` is no
1002
- * module import. Any other name is not outside.
1003
- */
1004
- function isSuppliedFromOutside(identifier, sourceCode) {
1005
- const variable = variableOf(identifier, sourceCode);
1006
- if (mayBeMergedMember(identifier, variable)) return false;
1007
- if (variable === null) return isUnwrittenGlobal(identifier, sourceCode);
1008
- return variable.defs.every((definition) => definition.type === "Parameter" || isModuleImport(definition)) && variable.references.every((reference) => !reference.isWrite());
1009
- }
1010
- //#endregion
1011
942
  //#region src/oxc/anti-slop/rules/no-runtime-typeof.ts
1012
943
  /** Return whether typeof safely probes for the existence of a possibly absent binding. */
1013
944
  function isExistenceProbe(node) {
@@ -1022,57 +953,6 @@ function isExistenceProbe(node) {
1022
953
  const other = parent.left === node ? parent.right : parent.left;
1023
954
  return other.type === "Literal" && other.value === "undefined";
1024
955
  }
1025
- /** 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. */
1026
- function rootOf(node) {
1027
- switch (node.type) {
1028
- case "Identifier": return node;
1029
- case "MemberExpression": return rootOf(node.object);
1030
- case "TSNonNullExpression":
1031
- case "TSAsExpression":
1032
- case "TSSatisfiesExpression":
1033
- case "TSTypeAssertion": return rootOf(node.expression);
1034
- default: return null;
1035
- }
1036
- }
1037
- /** Return whether a callee is read from a name that takes its value from outside this file, through members and type wrappers. */
1038
- function isReadFromOutside(callee, sourceCode) {
1039
- const root = rootOf(callee);
1040
- return root !== null && isSuppliedFromOutside(root, sourceCode);
1041
- }
1042
- /**
1043
- * Return whether a callee only raises or records the message it is given: a bare `assert(...)`, or the `log` method of any object,
1044
- * 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
1045
- * 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
1046
- * (`assert.equal`, `Set#add`, `emit`).
1047
- */
1048
- function isMessageSink(callee, sourceCode) {
1049
- if (!isReadFromOutside(callee, sourceCode)) return false;
1050
- if (callee.type === "Identifier") return callee.name === "assert";
1051
- return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "log";
1052
- }
1053
- /**
1054
- * Return whether a message ends at this parent: it is thrown, handed to the `assert` or `log` call that stands as a statement,
1055
- * 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
1056
- * whatever receives it, so they are not message sinks.
1057
- */
1058
- function endsMessage(parent, sourceCode) {
1059
- switch (parent.type) {
1060
- case "ThrowStatement": return true;
1061
- case "CallExpression": return parent.parent.type === "ExpressionStatement" && isMessageSink(parent.callee, sourceCode);
1062
- case "NewExpression": return parent.parent.type === "ThrowStatement" && isReadFromOutside(parent.callee, sourceCode);
1063
- default: return false;
1064
- }
1065
- }
1066
- /**
1067
- * 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.
1068
- * Such a template holds other text, so no comparison with a `typeof` result matches it, and TypeScript narrows nothing from it.
1069
- */
1070
- function isMessageText(node, sourceCode) {
1071
- let current = node.parent;
1072
- if (current.type !== "TemplateLiteral" || current.quasis.every((quasi) => quasi.value.raw === "")) return false;
1073
- while (current.parent.type === "TemplateLiteral" || current.parent.type === "ConditionalExpression" && current.parent.test !== current) current = current.parent;
1074
- return endsMessage(current.parent, sourceCode);
1075
- }
1076
956
  /** Built-ins whose `.constructor` comparison re-implements a `typeof` result. */
1077
957
  const TYPEOF_CONSTRUCTORS = /* @__PURE__ */ new Set([
1078
958
  "String",
@@ -1106,7 +986,7 @@ function instanceofCheckTarget(node) {
1106
986
  const noRuntimeTypeofRule = defineRule({
1107
987
  meta: {
1108
988
  type: "problem",
1109
- 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." },
989
+ docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary." },
1110
990
  messages: {
1111
991
  runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
1112
992
  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`.",
@@ -1126,7 +1006,7 @@ const noRuntimeTypeofRule = defineRule({
1126
1006
  }
1127
1007
  return {
1128
1008
  UnaryExpression(node) {
1129
- if (node.operator === "typeof" && !isExistenceProbe(node) && !isMessageText(node, context.sourceCode) && !allowedInTypeGuard(node)) context.report({
1009
+ if (node.operator === "typeof" && !isExistenceProbe(node) && !allowedInTypeGuard(node)) context.report({
1130
1010
  node,
1131
1011
  messageId: "runtimeTypeof"
1132
1012
  });
@@ -1184,6 +1064,26 @@ const noForbiddenTermInSymbolNamesRule = defineRule({
1184
1064
  }
1185
1065
  });
1186
1066
  //#endregion
1067
+ //#region src/oxc/anti-slop/shared/binding-origin.ts
1068
+ /** Return the variable an identifier refers to, searching outward from its scope, or null for an unresolved global. */
1069
+ function variableOf(identifier, sourceCode) {
1070
+ let scope = sourceCode.getScope(identifier);
1071
+ while (scope !== null) {
1072
+ const variable = scope.set.get(identifier.name);
1073
+ if (variable !== void 0) return variable;
1074
+ scope = scope.upper;
1075
+ }
1076
+ return null;
1077
+ }
1078
+ /**
1079
+ * Return whether a name has no definition in this file: a name no scope binds, or a global the environment declares (`Array`,
1080
+ * `Error`), which oxlint binds to a variable with no definition.
1081
+ */
1082
+ function isGlobalName(identifier, sourceCode) {
1083
+ const variable = variableOf(identifier, sourceCode);
1084
+ return variable === null || variable.defs.length === 0;
1085
+ }
1086
+ //#endregion
1187
1087
  //#region src/oxc/anti-slop/shared/brand-probe.ts
1188
1088
  /** Primitive types a probe may hand back: a derived value, never an object shape the function claims to know. */
1189
1089
  const PRIMITIVE_TYPES = /* @__PURE__ */ new Set([
@@ -1429,269 +1329,109 @@ function isCaughtValueCallbackType(owner, sourceCode) {
1429
1329
  });
1430
1330
  }
1431
1331
  //#endregion
1432
- //#region src/oxc/anti-slop/shared/callee-origin.ts
1433
- const NO_VARIABLES = /* @__PURE__ */ new Set();
1434
- /** Return the name an `import x = Outer.Inner.member` reads first, the one the file must declare. */
1435
- function entityRoot(name) {
1436
- return name.type === "TSQualifiedName" ? entityRoot(name.left) : name;
1437
- }
1438
- /** Return the name an `import x = Namespace.member` reads, or null for a module import, which another file gives a value. */
1439
- function aliasRoot(definition) {
1440
- const { node } = definition;
1441
- if (node.type !== "TSImportEqualsDeclaration") return null;
1442
- return node.moduleReference.type === "TSExternalModuleReference" ? null : entityRoot(node.moduleReference);
1443
- }
1444
- /** 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. */
1445
- function isFixedDefinition(definition) {
1446
- const { node } = definition;
1447
- return definition.type !== "Variable" || node.type === "VariableDeclarator" && node.init !== null && node.parent.type === "VariableDeclaration" && node.parent.kind === "const";
1448
- }
1449
- /**
1450
- * Classify a name by every definition and write it has, not by its first definition. It is outside this file only when
1451
- * `isSuppliedFromOutside` places it there. A name no scope binds, or that a merged namespace member may shadow, is unplaced.
1452
- * A function, class, namespace or catch binding is a declaration written here. Any other name is a variable read through the
1453
- * expressions written to it.
1454
- */
1455
- function bindingOf(identifier, sourceCode) {
1456
- if (isSuppliedFromOutside(identifier, sourceCode)) return { kind: "outside" };
1457
- const variable = variableOf(identifier, sourceCode);
1458
- if (variable === null || mayBeMergedMember(identifier, variable)) return { kind: "unplaced" };
1459
- const declared = variable.defs.find((definition) => ![
1460
- "Variable",
1461
- "Parameter",
1462
- "ImportBinding"
1463
- ].includes(definition.type));
1464
- if (declared !== void 0) return {
1465
- kind: "declaration",
1466
- type: declared.type
1467
- };
1468
- const writes = variable.references.filter((reference) => reference.isWrite());
1469
- return {
1470
- kind: "variable",
1471
- variable,
1472
- sources: [...variable.defs.map(aliasRoot), ...writes.map((write) => write.writeExpr)].filter((source) => source !== null),
1473
- constant: variable.defs.every(isFixedDefinition) && writes.every((write) => write.writeExpr !== null)
1474
- };
1475
- }
1476
- /** Return the expression a type wrapper, an `await` or an optional chain only passes through, or null when the node is none of these. */
1477
- function passThrough(node) {
1478
- switch (node.type) {
1479
- case "TSAsExpression":
1480
- case "TSSatisfiesExpression":
1481
- case "TSNonNullExpression":
1482
- case "TSTypeAssertion":
1483
- case "ChainExpression": return node.expression;
1484
- case "AwaitExpression": return node.argument;
1485
- default: return null;
1486
- }
1487
- }
1488
- /**
1489
- * Return whether a value reaches back to code written in this file: walk through members, calls, `new`, type
1490
- * wrappers and `const` aliases to the name or literal at the root. An import, a parameter and a global are
1491
- * outside the file. A function, class, namespace, `let`, `var`, `this`, `super`, object literal or anything this
1492
- * walk cannot place is inside it. A call also counts when it is handed an object that holds a function written
1493
- * here, which it can hand back as a method. A call rooted at a global (`Object.freeze`, `Array.from`, `Promise.resolve`) is
1494
- * no factory that wraps a schema, so a function handed to it counts too, as a callback it can call.
1495
- */
1496
- function isWrittenHere(node, sourceCode, seen) {
1497
- const inner = passThrough(node);
1498
- if (inner !== null) return isWrittenHere(inner, sourceCode, seen);
1499
- switch (node.type) {
1500
- case "Identifier": {
1501
- const binding = bindingOf(node, sourceCode);
1502
- if (binding.kind === "outside") return false;
1503
- if (binding.kind !== "variable") return true;
1504
- return !binding.constant || seen.has(binding.variable) || followSources(binding, sourceCode, seen, isWrittenHere);
1505
- }
1506
- case "ImportExpression": return false;
1507
- case "MemberExpression": return node.object.type === "ThisExpression" ? thisFieldIsWrittenHere(node, sourceCode, seen) : isWrittenHere(node.object, sourceCode, seen);
1508
- case "CallExpression":
1509
- case "NewExpression": {
1510
- const handsOver = isRootedAtGlobal(node.callee, sourceCode) ? isFunctionHere : holdsFunctionHere;
1511
- return isWrittenHere(node.callee, sourceCode, seen) || node.arguments.some((argument) => handsOver(argument, sourceCode, seen));
1512
- }
1513
- case "ConditionalExpression": return isWrittenHere(node.consequent, sourceCode, seen) || isWrittenHere(node.alternate, sourceCode, seen);
1514
- case "LogicalExpression": return isWrittenHere(node.left, sourceCode, seen) || isWrittenHere(node.right, sourceCode, seen);
1515
- default: return true;
1516
- }
1332
+ //#region src/oxc/anti-slop/shared/parse-boundary.ts
1333
+ /** Callee names that read as a decoder: `parse`, `safeParse` and their `Async` forms, `decode`, and `parseX` and `decodeX` in either case. */
1334
+ const DECODER_NAME = /^(?:safeParse(?:Async)?|[Pp]arse(?:[A-Z]\w*)?|[Dd]ecode(?:[A-Z]\w*)?)$/;
1335
+ /** Packages whose exports are schemas or decoders. A subpath such as `zod/v4` counts as its package. */
1336
+ const SCHEMA_LIBRARIES = [
1337
+ "zod",
1338
+ "valibot",
1339
+ "yup",
1340
+ "joi",
1341
+ "superstruct",
1342
+ "io-ts",
1343
+ "@sinclair/typebox",
1344
+ "arktype",
1345
+ "effect",
1346
+ "@effect/schema"
1347
+ ];
1348
+ /** Calls that write properties of the object they are handed first. */
1349
+ const PROPERTY_WRITERS = /* @__PURE__ */ new Set([
1350
+ "Object.assign",
1351
+ "Object.defineProperty",
1352
+ "Object.defineProperties",
1353
+ "Object.setPrototypeOf",
1354
+ "Reflect.set",
1355
+ "Reflect.defineProperty",
1356
+ "Reflect.setPrototypeOf"
1357
+ ]);
1358
+ const PROMISE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike"]);
1359
+ function calleeName(call) {
1360
+ const { callee } = call;
1361
+ if (callee.type === "Identifier") return callee.name;
1362
+ return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null;
1517
1363
  }
1518
- /** Return whether a callee is read from a global that has no definition in the file, through members, calls and type wrappers. */
1519
- function isRootedAtGlobal(node, sourceCode) {
1520
- const inner = passThrough(node);
1521
- if (inner !== null) return isRootedAtGlobal(inner, sourceCode);
1522
- switch (node.type) {
1523
- case "Identifier": return isGlobalName(node, sourceCode);
1524
- case "MemberExpression": return isRootedAtGlobal(node.object, sourceCode);
1525
- case "CallExpression":
1526
- case "NewExpression": return isRootedAtGlobal(node.callee, sourceCode);
1527
- default: return false;
1528
- }
1364
+ /** Return the initializer of the single-name `const` a variable declares. */
1365
+ function constInitializerOf(variable) {
1366
+ const declarator = variable?.defs[0]?.node;
1367
+ return declarator?.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" ? declarator.init : null;
1529
1368
  }
1530
- /** 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. */
1531
- function isPrimitive(node) {
1532
- switch (node.type) {
1533
- case "Literal":
1534
- case "TemplateLiteral":
1535
- case "UnaryExpression":
1536
- case "BinaryExpression":
1537
- case "UpdateExpression": return true;
1538
- default: return false;
1539
- }
1369
+ function isSchemaLibrary(source) {
1370
+ return SCHEMA_LIBRARIES.some((library) => source === library || source.startsWith(`${library}/`));
1540
1371
  }
1541
- /** 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. */
1542
- function elementName(key, computed) {
1543
- if (computed) return null;
1544
- if (key.type === "PrivateIdentifier") return `#${key.name}`;
1545
- return key.type === "Identifier" ? key.name : null;
1372
+ /** Return the `a.b` name of a non-computed member callee, or null. */
1373
+ function dottedName(node) {
1374
+ return node.type === "MemberExpression" && !node.computed && node.object.type === "Identifier" && node.property.type === "Identifier" ? `${node.object.name}.${node.property.name}` : null;
1546
1375
  }
1547
- /** Return the class a node is written in, or null at the top level. */
1548
- function enclosingClass(node) {
1549
- let current = node.parent;
1550
- while (current !== null && current.type !== "ClassDeclaration" && current.type !== "ClassExpression") current = current.parent;
1376
+ /** Return the outermost member expression a reference is the object of, or the reference itself. */
1377
+ function memberChainTop(identifier) {
1378
+ let current = identifier;
1379
+ while (current.parent?.type === "MemberExpression" && current.parent.object === current) current = current.parent;
1551
1380
  return current;
1552
1381
  }
1553
1382
  /**
1554
- * Return what `this` is where a node is written: the instance or the class itself when the nearest non-arrow function is a
1555
- * class method, or when no function sits between the node and a field initializer or static block. Any other function (an
1556
- * object-literal method, a function expression, a declaration) gets its `this` from its caller, as does a node in a class
1557
- * heritage clause, a decorator or a computed key, which the walk meets as the class itself. Those give null.
1558
- */
1559
- function receiverOf(node) {
1560
- let child = node;
1561
- for (let current = node.parent; current !== null; current = current.parent) switch (current.type) {
1562
- case "FunctionExpression": return current.parent.type === "MethodDefinition" && current.parent.value === current ? current.parent.static ? "static" : "instance" : null;
1563
- case "PropertyDefinition":
1564
- case "AccessorProperty": return current.value === child ? current.static ? "static" : "instance" : null;
1565
- case "StaticBlock": return "static";
1566
- case "FunctionDeclaration":
1567
- case "ClassDeclaration":
1568
- case "ClassExpression": return null;
1569
- default: child = current;
1570
- }
1571
- return null;
1572
- }
1573
- /**
1574
- * Return whether `this.field` reaches back to code written here. The element is the one of that exact name, `#` included, and of
1575
- * the receiver's kind, static or instance. A field with an initializer is read through it. A constructor parameter property is
1576
- * an instance element handed in by the caller, as a parameter is. A name that no element or two elements declare, an
1577
- * accessor, a method, a field without an initializer, an inherited field and a computed name are not placed, so they count as
1578
- * written here.
1579
- */
1580
- function thisFieldIsWrittenHere(member, sourceCode, seen) {
1581
- const klass = enclosingClass(member);
1582
- const name = elementName(member.property, member.computed);
1583
- const receiver = receiverOf(member);
1584
- if (klass === null || name === null || receiver === null) return true;
1585
- 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);
1586
- const handedIn = receiver === "instance" && klass.body.body.some((element) => element.type === "MethodDefinition" && declaresParameterProperty(element, name));
1587
- if (elements.length + (handedIn ? 1 : 0) !== 1) return true;
1588
- const [element] = elements;
1589
- if (element === void 0) return false;
1590
- if (element.type !== "PropertyDefinition") return true;
1591
- return element.value === null || seen.has(element) || isWrittenHere(element.value, sourceCode, /* @__PURE__ */ new Set([...seen, element]));
1592
- }
1593
- /** Return whether a method declares a parameter property of this name, which only a constructor can. */
1594
- function declaresParameterProperty(method, name) {
1595
- return method.value.params.some((parameter) => parameter.type === "TSParameterProperty" && parameter.parameter.type === "Identifier" && parameter.parameter.name === name);
1596
- }
1597
- /**
1598
- * 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
1599
- * 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
1600
- * walk does not list, a function, a class and any syntax added later included, is reported.
1383
+ * Return whether this file writes a property of a variable's value: an assignment, update or `delete` on a member read from it,
1384
+ * or a call such as `Object.assign` handed it first. A write through another name is not seen.
1601
1385
  */
1602
- function isFunctionHere(node, sourceCode, seen) {
1603
- const inner = passThrough(node);
1604
- if (inner !== null) return isFunctionHere(inner, sourceCode, seen);
1605
- switch (node.type) {
1606
- case "ObjectExpression":
1607
- case "ArrayExpression": return holdsFunctionHere(node, sourceCode, seen);
1608
- case "ConditionalExpression": return isFunctionHere(node.consequent, sourceCode, seen) || isFunctionHere(node.alternate, sourceCode, seen);
1609
- case "LogicalExpression": return isFunctionHere(node.left, sourceCode, seen) || isFunctionHere(node.right, sourceCode, seen);
1610
- case "Identifier": {
1611
- const binding = bindingOf(node, sourceCode);
1612
- if (binding.kind === "unplaced") return true;
1613
- if (binding.kind === "declaration") return true;
1614
- return binding.kind === "variable" && followSources(binding, sourceCode, seen, isFunctionHere);
1386
+ function hasPropertyWrites(variable) {
1387
+ return variable.references.some(({ identifier }) => {
1388
+ const top = memberChainTop(identifier);
1389
+ const holder = top.parent;
1390
+ if (holder === null) return false;
1391
+ if (top !== identifier) {
1392
+ if (holder.type === "AssignmentExpression" && holder.left === top) return true;
1393
+ if (holder.type === "UpdateExpression") return true;
1394
+ if (holder.type === "UnaryExpression" && holder.operator === "delete") return true;
1615
1395
  }
1616
- case "MemberExpression":
1617
- case "CallExpression":
1618
- case "NewExpression": return isWrittenHere(node, sourceCode, seen);
1619
- default: return !isPrimitive(node);
1396
+ return holder.type === "CallExpression" && holder.arguments[0] === top && PROPERTY_WRITERS.has(dottedName(holder.callee) ?? "");
1397
+ });
1398
+ }
1399
+ /** Return whether a variable is an import from a schema library, or a `const` whose initializer is rooted at one. */
1400
+ function isSchemaVariable(variable, sourceCode, seen) {
1401
+ const [definition, ...others] = variable.defs;
1402
+ if (definition === void 0 || others.length > 0 || seen.has(variable) || hasPropertyWrites(variable)) return false;
1403
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
1404
+ if (definition.type === "ImportBinding") {
1405
+ const declaration = definition.parent;
1406
+ return declaration?.type === "ImportDeclaration" && isSchemaLibrary(declaration.source.value);
1620
1407
  }
1408
+ const initializer = constInitializerOf(variable);
1409
+ return initializer !== null && isRootedAtSchemaLibrary(initializer, sourceCode, /* @__PURE__ */ new Set([...seen, variable]));
1621
1410
  }
1622
- /**
1623
- * Return whether an argument is an object, an array or a class whose members include a function written here, or a `this`.
1624
- * 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
1625
- * unless it is a primitive.
1626
- */
1627
- function holdsFunctionHere(node, sourceCode, seen) {
1628
- const inner = passThrough(node);
1629
- if (inner !== null) return holdsFunctionHere(inner, sourceCode, seen);
1411
+ /** Return whether a value is read, through members, calls, type wrappers and `const` aliases, from a schema library's import. */
1412
+ function isRootedAtSchemaLibrary(node, sourceCode, seen) {
1630
1413
  switch (node.type) {
1631
- case "FunctionExpression":
1632
- case "ArrowFunctionExpression": return false;
1633
- case "SpreadElement": return holdsFunctionHere(node.argument, sourceCode, seen);
1634
- case "ObjectExpression": return node.properties.some((property) => property.type === "SpreadElement" ? isFunctionHere(property.argument, sourceCode, seen) : isFunctionHere(property.value, sourceCode, seen));
1635
- case "ArrayExpression": return node.elements.some((element) => element !== null && (element.type === "SpreadElement" ? holdsFunctionHere(element.argument, sourceCode, seen) : isFunctionHere(element, sourceCode, seen)));
1414
+ case "TSAsExpression":
1415
+ case "TSSatisfiesExpression":
1416
+ case "TSNonNullExpression":
1417
+ case "TSTypeAssertion":
1418
+ case "ChainExpression": return isRootedAtSchemaLibrary(node.expression, sourceCode, seen);
1419
+ case "MemberExpression": return isRootedAtSchemaLibrary(node.object, sourceCode, seen);
1420
+ case "CallExpression": return isRootedAtSchemaLibrary(node.callee, sourceCode, seen);
1636
1421
  case "Identifier": {
1637
- const binding = bindingOf(node, sourceCode);
1638
- if (binding.kind === "unplaced") return true;
1639
- if (binding.kind === "declaration") return binding.type !== "FunctionName";
1640
- return binding.kind === "variable" && followSources(binding, sourceCode, seen, holdsFunctionHere);
1422
+ const variable = variableOf(node, sourceCode);
1423
+ return variable !== null && isSchemaVariable(variable, sourceCode, seen);
1641
1424
  }
1642
- case "MemberExpression":
1643
- case "CallExpression":
1644
- case "NewExpression":
1645
- case "ConditionalExpression":
1646
- case "LogicalExpression": return isWrittenHere(node, sourceCode, seen);
1647
- default: return !isPrimitive(node);
1648
- }
1649
- }
1650
- /** Apply a test to each expression written to a variable, once per variable on the path, and answer false for a variable written nothing. */
1651
- function followSources(binding, sourceCode, seen, test) {
1652
- const { sources, variable } = binding;
1653
- return !seen.has(variable) && sources.some((source) => test(source, sourceCode, /* @__PURE__ */ new Set([...seen, variable])));
1654
- }
1655
- /**
1656
- * Return whether a call goes to code written in this file. A bare callee counts when it is not outside the file, as
1657
- * `isSuppliedFromOutside` decides, or when it is a parameter. A member callee counts when the value it is read from reaches back
1658
- * to this file, so a member of a parameter, which the caller supplies, does not.
1659
- */
1660
- function calleeIsWrittenHere(call, sourceCode) {
1661
- const { callee } = call;
1662
- if (callee.type === "Identifier") {
1663
- const variable = variableOf(callee, sourceCode);
1664
- return !isSuppliedFromOutside(callee, sourceCode) || variable !== null && variable.defs.some((definition) => definition.type === "Parameter");
1425
+ default: return false;
1665
1426
  }
1666
- return callee.type === "MemberExpression" && isWrittenHere(callee.object, sourceCode, NO_VARIABLES);
1667
- }
1668
- //#endregion
1669
- //#region src/oxc/anti-slop/shared/parse-boundary.ts
1670
- /**
1671
- * Callee names that read as a schema or decoder: `parse`, `safeParse` and their `Async` forms, `decode`,
1672
- * `parseX` and `decodeX` helpers in either case, and interface-api-util's `assertValidation`. A name proves
1673
- * nothing alone. A callee declared in the same file never counts (see `calleeIsWrittenHere`), so a chain of wrappers
1674
- * cannot close on itself, and an imported callee that takes `unknown` is checked where it is declared.
1675
- */
1676
- const DECODER_NAME = /^(?:assertValidation|safeParse(?:Async)?|[Pp]arse(?:[A-Z]\w*)?|[Dd]ecode(?:[A-Z]\w*)?)$/;
1677
- const PROMISE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike"]);
1678
- function calleeName(call) {
1679
- const { callee } = call;
1680
- if (callee.type === "Identifier") return callee.name;
1681
- return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null;
1682
- }
1683
- /** Return the initializer of the single-name `const` a variable declares. */
1684
- function constInitializerOf(variable) {
1685
- const declarator = variable?.defs[0]?.node;
1686
- return declarator?.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" ? declarator.init : null;
1687
1427
  }
1688
1428
  /**
1689
- * Return the decoder call whose direct argument a reference is. An `unknown` value is not callable, so it is
1690
- * never the callee. A callee written in this file carries its own row and is no decoder.
1429
+ * Return the decoder call whose direct argument a reference is: a call of a decoder name read from a schema library's import.
1430
+ * An `unknown` value is not callable, so it is never the callee. A decoder of any other origin can do anything with the value.
1691
1431
  */
1692
1432
  function decoderCallOf(identifier, sourceCode) {
1693
1433
  const call = identifier.parent;
1694
- return call.type === "CallExpression" && DECODER_NAME.test(calleeName(call) ?? "") && !calleeIsWrittenHere(call, sourceCode) ? call : null;
1434
+ return call.type === "CallExpression" && DECODER_NAME.test(calleeName(call) ?? "") && isRootedAtSchemaLibrary(call.callee, sourceCode, /* @__PURE__ */ new Set()) ? call : null;
1695
1435
  }
1696
1436
  /** Return whether a declared return type states a value, not `unknown` or `any`, promised or not. */
1697
1437
  function declaresParsedType(annotation) {
@@ -1714,7 +1454,7 @@ function returnedExpressions(owner, returns) {
1714
1454
  }
1715
1455
  /**
1716
1456
  * Return whether a parameter typed exactly `unknown` is a parse boundary: every read of it is a direct argument
1717
- * to a schema or decoder declared outside this file, every value the function returns is such a call's result,
1457
+ * to a decoder read from a schema library, every value the function returns is such a call's result,
1718
1458
  * and the function declares a return type that states what it parsed. A function that stores, forwards, reads
1719
1459
  * by hand (through `arguments` or `eval` too) or discards the parsed value is not one.
1720
1460
  */
@@ -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, inherited-key lookups, presence-only type guards, unchecked Object.assign writes, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
3
+ /** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, inserts that follow a read of the same table, unchecked Object.assign writes, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
4
4
  declare const guardrailsPlugin: import("@oxlint/plugins").Plugin;
5
5
  //#endregion
6
6
  export { ASSERTION_FUNCTION_NAMES, TEST_FILE_GLOBS, guardrailsPlugin as default };