@antelopejs/tooling-configs 0.5.0 → 0.5.2

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.
@@ -447,22 +447,53 @@ function isBooleanValued(node, read, depth) {
447
447
  }
448
448
  return node.type === "CallExpression" || node.type === "UnaryExpression" && node.operator === "!";
449
449
  }
450
- /** Whether the own-key check holds whenever `node` evaluates to `outcome`. */
450
+ /** `Object.getOwnPropertyDescriptor(Object.prototype, key)?.value` or `Object.prototype[key]`: the value `Object.prototype` itself holds under the key. */
451
+ function isRootValue(node, read) {
452
+ const value = node.type === "ChainExpression" ? node.expression : node;
453
+ if (value.type !== "MemberExpression") return false;
454
+ const text = (part) => read.source.getText(part);
455
+ if (value.computed) return text(value.object) === "Object.prototype" && text(value.property) === read.key;
456
+ const call = value.object;
457
+ return value.property.type === "Identifier" && value.property.name === "value" && call.type === "CallExpression" && callName(call.callee) === "Object.getOwnPropertyDescriptor" && call.arguments.length === 2 && text(call.arguments[0]) === "Object.prototype" && text(call.arguments[1]) === read.key;
458
+ }
459
+ /** The outcome of `table[key] === <root value>` (or `!==`, either order) under which the read differs from `Object.prototype`'s own value, or `null` for another comparison. */
460
+ function differsFromRootWhen(node, read) {
461
+ const equal = EQUALITY.has(node.operator);
462
+ if (!equal && !INEQUALITY.has(node.operator)) return null;
463
+ const reads = (side) => side.type === "MemberExpression" && side.computed && read.source.getText(side.object) === read.table && read.source.getText(side.property) === read.key;
464
+ return reads(node.left) && isRootValue(node.right, read) || reads(node.right) && isRootValue(node.left, read) ? !equal : null;
465
+ }
466
+ /** `a && b` that is true, or `a || b` that is false, needs one operand to hold; `a || b` that is true, or `a && b` that is false, needs both. */
467
+ function combinedHolds(node, outcome, read, depth) {
468
+ const left = holds(node.left, outcome, read, depth);
469
+ const right = holds(node.right, outcome, read, depth);
470
+ if (node.operator === (outcome ? "&&" : "||")) return left || right;
471
+ return node.operator === (outcome ? "||" : "&&") && left && right;
472
+ }
473
+ /**
474
+ * Whether the key is safe to read whenever `node` evaluates to `outcome`: the table owns the key,
475
+ * the key is no `Object.prototype` name, or the table answers it with something other than
476
+ * `Object.prototype`'s own value.
477
+ */
451
478
  function holds(node, outcome, read, depth = 0) {
452
479
  if (depth > MAX_DEPTH$2) return false;
453
480
  switch (node.type) {
454
481
  case "ParenthesizedExpression": return holds(node.expression, outcome, read, depth);
455
- case "CallExpression": return outcome && checksOwnKey(node, read);
482
+ case "CallExpression": return outcome ? checksOwnKey(node, read) : checksOwnKey(node, {
483
+ ...read,
484
+ table: "Object.prototype"
485
+ });
456
486
  case "Identifier": {
457
487
  const value = constValue(node, read);
458
488
  return value !== null && holds(value, outcome, read, depth + 1);
459
489
  }
460
490
  case "UnaryExpression": return node.operator === "!" && holds(node.argument, !outcome, read, depth);
461
491
  case "BinaryExpression": {
492
+ if (differsFromRootWhen(node, read) === outcome) return true;
462
493
  const compared = comparedOutcome(node, outcome);
463
494
  return compared !== null && isBooleanValued(compared.operand, read, depth) && holds(compared.operand, compared.outcome, read, depth);
464
495
  }
465
- case "LogicalExpression": return node.operator === (outcome ? "&&" : "||") && (holds(node.left, outcome, read, depth) || holds(node.right, outcome, read, depth));
496
+ case "LogicalExpression": return combinedHolds(node, outcome, read, depth);
466
497
  default: return false;
467
498
  }
468
499
  }
@@ -518,10 +549,14 @@ function guardsChild(parent, child, read) {
518
549
  return statements.slice(0, Math.max(index, 0)).some((statement) => establishes(statement, read));
519
550
  }
520
551
  /**
521
- * Whether an own-key check of `table` and `key` (`Object.hasOwn`, `hasOwnProperty.call`,
522
- * `table.hasOwnProperty`, directly, negated, compared with a boolean or held in a `const`) guards
523
- * `node`: it holds in the branch of a conditional, `if`, `&&`/`||`, `while` or `for` that holds
524
- * `node`, or an earlier statement asserts it, or leaves the block or stores the key where it fails.
552
+ * Whether `node`, a read of `table[key]`, cannot answer a key only `Object.prototype` holds. It is
553
+ * compared with `Object.prototype`'s own value of the key, or a check guards it: an own-key check of
554
+ * `table` and `key` (`Object.hasOwn`, `hasOwnProperty.call`, `table.hasOwnProperty`), a failed
555
+ * `Object.prototype` membership check of `key`, or the read differing from `Object.prototype`'s
556
+ * value, directly, negated, combined with `&&`/`||`, compared with a boolean or held in a `const`.
557
+ * The check guards it when it holds in the branch of a conditional, `if`, `&&`/`||`, `while` or
558
+ * `for` that holds `node`, or an earlier statement asserts it, or leaves the block or stores the
559
+ * key where it fails.
525
560
  */
526
561
  function isOwnKeyGuarded(node, table, key, source) {
527
562
  const read = {
@@ -529,6 +564,7 @@ function isOwnKeyGuarded(node, table, key, source) {
529
564
  key,
530
565
  source
531
566
  };
567
+ if (node.parent?.type === "BinaryExpression" && differsFromRootWhen(node.parent, read) !== null) return true;
532
568
  let child = node;
533
569
  let parent = node.parent;
534
570
  while (parent !== null) {
@@ -993,6 +1029,234 @@ const noPresenceOnlyTypeGuardRule = defineRule({
993
1029
  }
994
1030
  });
995
1031
  //#endregion
1032
+ //#region src/oxc/guardrails/rules/no-read-then-insert.ts
1033
+ const READ_METHODS = /* @__PURE__ */ new Set([
1034
+ "get",
1035
+ "getBy",
1036
+ "getAll",
1037
+ "count",
1038
+ "find",
1039
+ "findOne"
1040
+ ]);
1041
+ const INSERT_METHODS = /* @__PURE__ */ new Set([
1042
+ "insert",
1043
+ "insertOne",
1044
+ "insertMany"
1045
+ ]);
1046
+ const INLINE_CALLBACK_METHODS = /* @__PURE__ */ new Set([
1047
+ "map",
1048
+ "flatMap",
1049
+ "forEach",
1050
+ "filter",
1051
+ "reduce",
1052
+ "some",
1053
+ "every",
1054
+ "then",
1055
+ "catch",
1056
+ "finally"
1057
+ ]);
1058
+ const DUPLICATE_CHECK = /duplicate|unique|conflict|E11000|^11000$|23505|ER_DUP_ENTRY/iu;
1059
+ function contains(outer, inner) {
1060
+ return outer[0] <= inner[0] && inner[1] <= outer[1];
1061
+ }
1062
+ function isScope(node) {
1063
+ return node.type === "Program" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
1064
+ }
1065
+ function enclosingScope(node) {
1066
+ let current = node.parent;
1067
+ while (current !== null) {
1068
+ if (isScope(current)) return current;
1069
+ current = current.parent;
1070
+ }
1071
+ return null;
1072
+ }
1073
+ /** A callback that runs while its caller waits: handed to `map`, `then` or the like, or to a call whose value the caller awaits or returns. A handler registered by `app.post(...)` or wrapped by `export const POST = withAuth(...)` runs later, on its own. */
1074
+ function isInlineCallback(scope) {
1075
+ const call = scope.parent;
1076
+ if (scope.type === "Program" || scope.type === "FunctionDeclaration" || call?.type !== "CallExpression" || !call.arguments.some((argument) => argument === scope)) return false;
1077
+ const method = call.callee.type === "MemberExpression" ? memberName(call.callee) : null;
1078
+ return method !== null && INLINE_CALLBACK_METHODS.has(method) || isAwaited(call);
1079
+ }
1080
+ /** Whether the call's value reaches an `await` or a `return`, through array elements, call arguments, `?.` or a `.then` chain, or is the body of an inline arrow. */
1081
+ function isAwaited(call) {
1082
+ let node = call;
1083
+ let parent = node.parent;
1084
+ while (parent !== null) {
1085
+ if (parent.type === "AwaitExpression" || parent.type === "ReturnStatement") return true;
1086
+ if (parent.type === "ArrowFunctionExpression" && parent.body === node) return isInlineCallback(parent);
1087
+ if (!(parent.type === "ArrayExpression" || parent.type === "ChainExpression" || parent.type === "SpreadElement" || parent.type === "CallExpression" || parent.type === "MemberExpression" && parent.object === node)) return false;
1088
+ node = parent;
1089
+ parent = node.parent;
1090
+ }
1091
+ return false;
1092
+ }
1093
+ /** The function a read or an insert runs in, seen through inline callbacks such as `withRetry(() => model.getAll())` or `rows.map((row) => model.insert(row))`. */
1094
+ function runningScope(node) {
1095
+ let scope = enclosingScope(node);
1096
+ while (scope !== null && isInlineCallback(scope)) scope = enclosingScope(scope);
1097
+ return scope;
1098
+ }
1099
+ function chainsFrom(node, call) {
1100
+ let current = node;
1101
+ while (current !== call) if (current.type === "CallExpression") current = current.callee;
1102
+ else if (current.type === "MemberExpression") current = current.object;
1103
+ else return false;
1104
+ return true;
1105
+ }
1106
+ function rootName(node) {
1107
+ let current = node;
1108
+ while (current.type === "MemberExpression" || current.type === "CallExpression") current = current.type === "MemberExpression" ? current.object : current.callee;
1109
+ return current.type === "Identifier" ? current.name : null;
1110
+ }
1111
+ function declares(scope, name) {
1112
+ return scope.type !== "Program" && scope.params.some((param) => param.type === "Identifier" && param.name === name);
1113
+ }
1114
+ function calledMember(node, methods) {
1115
+ if (node.callee.type !== "MemberExpression") return null;
1116
+ const name = memberName(node.callee);
1117
+ return name !== null && methods.has(name) ? node.callee : null;
1118
+ }
1119
+ function isUpsert(node) {
1120
+ return node.arguments.slice(1).some((argument) => argument.type === "ObjectExpression" && argument.properties.some((property) => property.type === "Property" && !property.computed && (property.key.type === "Identifier" && property.key.name === "conflict" || property.key.type === "Literal" && property.key.value === "conflict") && !(property.value.type === "Literal" && property.value.value === "error")));
1121
+ }
1122
+ /** `model.get` and `model.insert` touch one table, and so do `model.get` and the model's raw `model.table.insert`, but not `db.table("a")` and `db.table("b")`, nor `this.get` and `this.audit.insert`. */
1123
+ function sameTable(read, insert) {
1124
+ return read.receivers.has(insert.receiver) || insert.receiver === `${read.receiver}.table`;
1125
+ }
1126
+ /** A catch that returns, continues or breaks in its own function without a rejection, or keeps every `throw` inside a branch, can finish without rethrowing. */
1127
+ function canFinish(facts, handler) {
1128
+ const own = handler.type === "BlockStatement" ? enclosingScope(handler) : handler;
1129
+ const block = handler.type === "BlockStatement" ? handler : (handler.type === "ArrowFunctionExpression" || handler.type === "FunctionExpression") && handler.body?.type === "BlockStatement" ? handler.body : null;
1130
+ return facts.exits.some((exit) => contains(handler.range, exit.range) && enclosingScope(exit) === own && !facts.throwRanges.some((thrown) => contains(exit.range, thrown))) || !facts.throwBlocks.some((thrownIn) => thrownIn === block);
1131
+ }
1132
+ /** A catch tolerates the lost race when it rethrows nothing, or when it can finish without rethrowing and either reads the table back or checks for a duplicate outside a `throw`. */
1133
+ function recovers(facts, handler, insert) {
1134
+ if (handler.type !== "BlockStatement" && handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression") return DUPLICATE_CHECK.test(facts.text(handler));
1135
+ const range = handler.range;
1136
+ if (!facts.throwRanges.some((thrown) => contains(range, thrown))) return true;
1137
+ if (!canFinish(facts, handler)) return false;
1138
+ return facts.reads.some((read) => contains(range, read.range) && sameTable(read, insert)) || facts.duplicateChecks.some((check) => contains(range, check) && !facts.throwRanges.some((thrown) => contains(thrown, check)));
1139
+ }
1140
+ function isHandedToHelper(facts, insert, child, parent) {
1141
+ return (child.type === "ArrowFunctionExpression" || child.type === "FunctionExpression") && parent.type === "CallExpression" && parent.arguments.some((argument) => argument !== child && facts.text(argument) === insert.receiver);
1142
+ }
1143
+ function recoveryOf(insert, child, parent) {
1144
+ if (parent.type === "TryStatement" && parent.block === child) return parent.handler?.body ?? null;
1145
+ if (parent.type === "MemberExpression" && parent.object === child && chainsFrom(child, insert.call) && memberName(parent) === "catch" && parent.parent?.type === "CallExpression" && parent.parent.callee === parent) return parent.parent.arguments[0] ?? null;
1146
+ return null;
1147
+ }
1148
+ function isGuarded(facts, insert, read) {
1149
+ let child = insert.call;
1150
+ let parent = child.parent;
1151
+ while (parent !== null && child !== read.scope) {
1152
+ const between = !contains(child.range, read.range);
1153
+ if (between && insert.root !== null && isScope(child) && declares(child, insert.root)) return true;
1154
+ if (between && isHandedToHelper(facts, insert, child, parent)) return true;
1155
+ const recovery = recoveryOf(insert, child, parent);
1156
+ if (recovery !== null && recovers(facts, recovery, insert)) return true;
1157
+ child = parent;
1158
+ parent = child.parent;
1159
+ }
1160
+ return false;
1161
+ }
1162
+ function isRaced(facts, insert) {
1163
+ const start = insert.call.range[0];
1164
+ return facts.reads.some((read) => sameTable(read, insert) && read.range[1] <= start && read.scope === insert.scope && !isGuarded(facts, insert, read));
1165
+ }
1166
+ /** Writing a row that a startup read found missing races every other replica that read the same. A catch that rethrows nothing, recognises a duplicate in a condition, or reads the row back and branches, tolerates the lost race, and so does an upsert or a helper handed the table. */
1167
+ const noReadThenInsertRule = defineRule({
1168
+ meta: {
1169
+ type: "problem",
1170
+ docs: { description: "Reject an insert that follows a read of the same table unless a catch tolerates losing it." },
1171
+ messages: { readThenInsert: "`{{receiver}}` is read and then inserted into. Two replicas that start on an empty table both read nothing and both insert, so one writes a duplicate row or fails on the key. Key the row by a stable id, wrap the insert in try/catch, read the row back in the catch, and rethrow only when it is still missing, or upsert with `insert(row, { conflict: \"update\" })`." }
1172
+ },
1173
+ createOnce(context) {
1174
+ const inserts = [];
1175
+ const facts = {
1176
+ reads: [],
1177
+ duplicateChecks: [],
1178
+ throwRanges: [],
1179
+ throwBlocks: [],
1180
+ exits: [],
1181
+ text: (node) => context.sourceCode.getText(node)
1182
+ };
1183
+ const { reads, duplicateChecks, throwRanges, exits } = facts;
1184
+ function receiverChain(start) {
1185
+ const texts = /* @__PURE__ */ new Set();
1186
+ let current = start;
1187
+ while (current !== null) {
1188
+ texts.add(facts.text(current));
1189
+ if (current.type === "CallExpression") current = current.callee;
1190
+ else if (current.type === "MemberExpression") current = current.object;
1191
+ else current = null;
1192
+ }
1193
+ return texts;
1194
+ }
1195
+ return {
1196
+ before() {
1197
+ reads.length = 0;
1198
+ inserts.length = 0;
1199
+ duplicateChecks.length = 0;
1200
+ throwRanges.length = 0;
1201
+ facts.throwBlocks.length = 0;
1202
+ exits.length = 0;
1203
+ },
1204
+ ThrowStatement(node) {
1205
+ throwRanges.push(node.range);
1206
+ if (node.parent !== null) facts.throwBlocks.push(node.parent);
1207
+ },
1208
+ ReturnStatement(node) {
1209
+ exits.push(node);
1210
+ },
1211
+ ContinueStatement(node) {
1212
+ exits.push(node);
1213
+ },
1214
+ BreakStatement(node) {
1215
+ exits.push(node);
1216
+ },
1217
+ Identifier(node) {
1218
+ if (DUPLICATE_CHECK.test(node.name)) duplicateChecks.push(node.range);
1219
+ },
1220
+ TemplateLiteral(node) {
1221
+ if (node.quasis.some((quasi) => DUPLICATE_CHECK.test(quasi.value.raw))) duplicateChecks.push(node.range);
1222
+ },
1223
+ Literal(node) {
1224
+ if (DUPLICATE_CHECK.test(String(node.value))) duplicateChecks.push(node.range);
1225
+ },
1226
+ CallExpression(node) {
1227
+ if (facts.text(node.callee) === "Promise.reject") {
1228
+ throwRanges.push(node.range);
1229
+ const statement = node.parent;
1230
+ if (statement?.type === "ReturnStatement" && statement.parent !== null) facts.throwBlocks.push(statement.parent);
1231
+ }
1232
+ const read = calledMember(node, READ_METHODS);
1233
+ const scope = runningScope(node);
1234
+ if (read !== null && scope !== null) reads.push({
1235
+ range: node.range,
1236
+ scope,
1237
+ receiver: facts.text(read.object),
1238
+ receivers: receiverChain(read.object)
1239
+ });
1240
+ const insert = calledMember(node, INSERT_METHODS);
1241
+ if (insert !== null && scope !== null && !isUpsert(node)) inserts.push({
1242
+ call: node,
1243
+ scope,
1244
+ callee: insert,
1245
+ receiver: facts.text(insert.object),
1246
+ root: rootName(insert.object)
1247
+ });
1248
+ },
1249
+ "Program:exit"() {
1250
+ for (const insert of inserts) if (isRaced(facts, insert)) context.report({
1251
+ node: insert.callee,
1252
+ messageId: "readThenInsert",
1253
+ data: { receiver: insert.receiver }
1254
+ });
1255
+ }
1256
+ };
1257
+ }
1258
+ });
1259
+ //#endregion
996
1260
  //#region src/oxc/guardrails/self-package.ts
997
1261
  function isObject(value) {
998
1262
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1317,6 +1581,8 @@ function automaticTypes(config) {
1317
1581
  //#endregion
1318
1582
  //#region src/oxc/guardrails/type-checker.ts
1319
1583
  const programs = /* @__PURE__ */ new Map();
1584
+ /** The source files every program of the lint run shares, parsed once per text and per set of compiler options that change a parse. */
1585
+ const documents = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames);
1320
1586
  function normalize(file) {
1321
1587
  return resolve(file).replaceAll("\\", "/");
1322
1588
  }
@@ -1324,8 +1590,10 @@ function build(config, path, text) {
1324
1590
  const parsed = project(config);
1325
1591
  if (parsed === void 0) return void 0;
1326
1592
  const host = ts.createCompilerHost(parsed.options, true);
1327
- const read = host.getSourceFile.bind(host);
1328
- host.getSourceFile = (name, language, ...rest) => normalize(name) === path ? ts.createSourceFile(name, text, language, true) : read(name, language, ...rest);
1593
+ host.getSourceFile = (name, language) => {
1594
+ const content = normalize(name) === path ? text : host.readFile(name);
1595
+ return content === void 0 ? void 0 : documents.acquireDocument(name, parsed.options, ts.ScriptSnapshot.fromString(content), content, void 0, language);
1596
+ };
1329
1597
  const program = ts.createProgram({
1330
1598
  rootNames: [...parsed.files],
1331
1599
  options: parsed.options,
@@ -1565,7 +1833,7 @@ const requireTsconfigTypesRule = defineRule({
1565
1833
  });
1566
1834
  //#endregion
1567
1835
  //#region src/oxc/guardrails/index.ts
1568
- /** 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`. */
1836
+ /** 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`. */
1569
1837
  const guardrailsPlugin = eslintCompatPlugin({
1570
1838
  meta: { name: "antelopejs" },
1571
1839
  rules: {
@@ -1573,6 +1841,7 @@ const guardrailsPlugin = eslintCompatPlugin({
1573
1841
  "no-fs-read-in-tests": noFsReadInTestsRule,
1574
1842
  "no-inherited-key-lookup": noInheritedKeyLookupRule,
1575
1843
  "no-presence-only-type-guard": noPresenceOnlyTypeGuardRule,
1844
+ "no-read-then-insert": noReadThenInsertRule,
1576
1845
  "no-constant-value-assertion": noConstantValueAssertionRule,
1577
1846
  "no-self-import-in-tests": noSelfImportInTestsRule,
1578
1847
  "no-typeof-function-only-test": noTypeofFunctionOnlyTestRule,
@@ -72,6 +72,7 @@ declare function guardrailsRules(): {
72
72
  "antelopejs/no-comments": "error";
73
73
  "antelopejs/no-inherited-key-lookup": "error";
74
74
  "antelopejs/no-presence-only-type-guard": "error";
75
+ "antelopejs/no-read-then-insert": "error";
75
76
  "jest/no-conditional-expect": "off";
76
77
  "jest/no-export": "off";
77
78
  "jest/no-standalone-expect": "off";
@@ -83,6 +84,7 @@ declare function guardrailsRules(): {
83
84
  overrides: ({
84
85
  files: string[];
85
86
  rules: {
87
+ "antelopejs/no-read-then-insert": "off";
86
88
  "antelopejs/no-fs-read-in-tests": "error";
87
89
  "antelopejs/no-constant-value-assertion": "error";
88
90
  "antelopejs/no-self-import-in-tests": "error";
@@ -93,6 +95,7 @@ declare function guardrailsRules(): {
93
95
  files: string[];
94
96
  rules: {
95
97
  "antelopejs/no-fs-read-in-tests": "off";
98
+ "antelopejs/no-read-then-insert"?: undefined;
96
99
  "antelopejs/no-constant-value-assertion"?: undefined;
97
100
  "antelopejs/no-self-import-in-tests"?: undefined;
98
101
  "antelopejs/no-typeof-function-only-test"?: undefined;
@@ -151,6 +154,7 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
151
154
  "antelopejs/no-comments": "error";
152
155
  "antelopejs/no-inherited-key-lookup": "error";
153
156
  "antelopejs/no-presence-only-type-guard": "error";
157
+ "antelopejs/no-read-then-insert": "error";
154
158
  "jest/no-conditional-expect": "off";
155
159
  "jest/no-export": "off";
156
160
  "jest/no-standalone-expect": "off";
@@ -162,6 +166,7 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
162
166
  overrides: ({
163
167
  files: string[];
164
168
  rules: {
169
+ "antelopejs/no-read-then-insert": "off";
165
170
  "antelopejs/no-fs-read-in-tests": "error";
166
171
  "antelopejs/no-constant-value-assertion": "error";
167
172
  "antelopejs/no-self-import-in-tests": "error";
@@ -172,6 +177,7 @@ declare function antelopePreset(options?: AntelopePresetOptions): {
172
177
  files: string[];
173
178
  rules: {
174
179
  "antelopejs/no-fs-read-in-tests": "off";
180
+ "antelopejs/no-read-then-insert"?: undefined;
175
181
  "antelopejs/no-constant-value-assertion"?: undefined;
176
182
  "antelopejs/no-self-import-in-tests"?: undefined;
177
183
  "antelopejs/no-typeof-function-only-test"?: undefined;
package/dist/oxc/lint.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as findGitRoot } from "../ceilings-B7KayYIG.mjs";
2
2
  import { t as readCarriedCeilings } from "../renames-L2owF5GD.mjs";
3
- import { t as PRESET_CONFIGS } from "../templates-lJBZFskp.mjs";
3
+ import { t as PRESET_CONFIGS } from "../templates-BiXgdsRN.mjs";
4
4
  import { t as TYPE_AWARE_RULES } from "../type-aware-rules-DMuN6sHb.mjs";
5
5
  import { n as TEST_FILE_GLOBS, t as ASSERTION_FUNCTION_NAMES } from "../shared-WC0z3y9F.mjs";
6
6
  import { n as IGNORE_PATTERNS, r as SYNCED_AGENT_PATTERNS } from "../shared-igPpEDpS.mjs";
@@ -110,11 +110,13 @@ function guardrailsRules() {
110
110
  "jest/expect-expect": "off",
111
111
  "antelopejs/no-comments": "error",
112
112
  "antelopejs/no-inherited-key-lookup": "error",
113
- "antelopejs/no-presence-only-type-guard": "error"
113
+ "antelopejs/no-presence-only-type-guard": "error",
114
+ "antelopejs/no-read-then-insert": "error"
114
115
  },
115
116
  overrides: [{
116
117
  files: TEST_FILE_GLOBS,
117
118
  rules: {
119
+ "antelopejs/no-read-then-insert": "off",
118
120
  "antelopejs/no-fs-read-in-tests": "error",
119
121
  "antelopejs/no-constant-value-assertion": "error",
120
122
  "antelopejs/no-self-import-in-tests": "error",
@@ -20,8 +20,13 @@ function ruleId(code) {
20
20
  const [, plugin, rule] = match;
21
21
  return `${plugin === "typescript-eslint" ? "typescript" : plugin}/${rule}`;
22
22
  }
23
+ const NO_FILES = "No files found to lint.";
24
+ /** Whether oxlint matched no file, in which case it prints a notice before its report and exits 1. */
25
+ function foundNoFiles(stdout) {
26
+ return stdout.startsWith(NO_FILES) && stdout.includes("{");
27
+ }
23
28
  function parseReport(text) {
24
- const report = JSON.parse(text);
29
+ const report = JSON.parse(foundNoFiles(text) ? text.slice(text.indexOf("{")) : text);
25
30
  if (!Array.isArray(report?.diagnostics)) throw new Error("oxlint did not return a JSON diagnostics array.");
26
31
  return report.diagnostics;
27
32
  }
@@ -65,7 +70,7 @@ function runOxlint(root, config, files, flags) {
65
70
  if (result.error) throw result.error;
66
71
  if (result.status !== 0 && result.status !== 1) throw new Error(`oxlint failed (${result.status ?? result.signal}): ${result.stderr || result.stdout}`);
67
72
  const diagnostics = parseReport(result.stdout);
68
- if (result.status !== 0 && diagnostics.length === 0) throw new Error(`oxlint failed without diagnostics: ${result.stderr || result.stdout}`);
73
+ if (result.status !== 0 && diagnostics.length === 0 && !foundNoFiles(result.stdout)) throw new Error(`oxlint failed without diagnostics: ${result.stderr || result.stdout}`);
69
74
  return diagnostics;
70
75
  } finally {
71
76
  if (temporary) rmSync(temporary, {
@@ -40,12 +40,16 @@ function toolingVersions() {
40
40
  const lefthook = manifest.devDependencies?.lefthook;
41
41
  const knip = manifest.devDependencies?.knip;
42
42
  const tsgolint = manifest.devDependencies?.["oxlint-tsgolint"];
43
- if (!lefthook || !knip || !tsgolint || !manifest.version) throw new Error("tooling-configs must declare its version and lefthook, knip and oxlint-tsgolint devDependencies.");
43
+ const oxlint = manifest.devDependencies?.oxlint;
44
+ const oxfmt = manifest.devDependencies?.oxfmt;
45
+ if (!lefthook || !knip || !tsgolint || !oxlint || !oxfmt || !manifest.version) throw new Error("tooling-configs must declare its version and lefthook, knip, oxlint, oxfmt and oxlint-tsgolint devDependencies.");
44
46
  const tested = manifest.devDependencies ?? {};
45
47
  return {
46
48
  lefthook,
47
49
  knip,
48
50
  tsgolint,
51
+ oxlint,
52
+ oxfmt,
49
53
  capture: CAPTURE_PEERS.map((name) => {
50
54
  const range = tested[name];
51
55
  if (!range) throw new Error(`tooling-configs must declare ${name} as a devDependency.`);
@@ -155,6 +159,28 @@ function addedDevDependencies(manifest, versions, options) {
155
159
  if (options.typeAware) tools.push(["oxlint-tsgolint", versions.tsgolint]);
156
160
  return [...tools.filter(([name]) => !declared[name]), ...options.captures ? versions.capture.filter(([name, tested]) => !withinTested(declared[name], tested)) : []];
157
161
  }
162
+ /** The pack, oxlint, oxlint-tsgolint and oxfmt with the ranges `--init` declares for a repository that has none of them. Sync needs the first three installed to load its preset and run the type-aware baseline before it writes any devDependency. */
163
+ function bootstrapDependencies(manifest, versions) {
164
+ const declared = {
165
+ ...manifest.dependencies,
166
+ ...manifest.devDependencies
167
+ };
168
+ return [
169
+ ["@antelopejs/tooling-configs", `^${versions.pack}`],
170
+ ["oxlint", versions.oxlint],
171
+ ["oxlint-tsgolint", versions.tsgolint],
172
+ ["oxfmt", versions.oxfmt]
173
+ ].filter(([name]) => !declared[name]);
174
+ }
175
+ /** `current` with `added` in its sorted devDependencies, formatted as the rest of the sync writers do. */
176
+ function withDevDependencies(current, added) {
177
+ const manifest = parseManifest(current);
178
+ manifest.devDependencies = sortedEntries({
179
+ ...manifest.devDependencies,
180
+ ...Object.fromEntries(added)
181
+ });
182
+ return serializeManifest(manifest, current);
183
+ }
158
184
  function managedPackage(current, versions, options = {}) {
159
185
  if (current === void 0) throw new Error("package.json is missing.");
160
186
  const manifest = parseManifest(current);
@@ -224,4 +250,4 @@ function serializeManifest(manifest, current) {
224
250
  return `${JSON.stringify(manifest, null, indent).replaceAll("\n", newline)}${newline}`;
225
251
  }
226
252
  //#endregion
227
- export { parseManifest as a, toolingVersions as c, packageManager as i, execCommand as n, repositoryTools as o, managedPackage as r, templatePackage as s, addedDevDependencies as t };
253
+ export { packageManager as a, templatePackage as c, managedPackage as i, toolingVersions as l, bootstrapDependencies as n, parseManifest as o, execCommand as r, repositoryTools as s, addedDevDependencies as t, withDevDependencies as u };
@@ -1,4 +1,4 @@
1
- import { a as parseManifest } from "./package-Dn7VTFUW.mjs";
1
+ import { o as parseManifest } from "./package-DxxcxOzp.mjs";
2
2
  import { l as resolveRevision, u as trackedManifests } from "./files-DJ0TeaTU.mjs";
3
3
  import { o as revisionSuppressions, r as countSuppressions } from "./suppressions-BroaaGJ_.mjs";
4
4
  import { copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync } from "node:fs";
@@ -1,8 +1,8 @@
1
1
  import { a as formatCeilings, c as parseCeilings, n as MAX_FILE_BYTES, o as isPackRelease, s as isRetired, t as CEILINGS_FILE } from "./ceilings-B7KayYIG.mjs";
2
2
  import { n as renamedPaths, t as readCarriedCeilings } from "./renames-L2owF5GD.mjs";
3
- import { c as toolingVersions } from "./package-Dn7VTFUW.mjs";
3
+ import { l as toolingVersions } from "./package-DxxcxOzp.mjs";
4
4
  import { n as authoredSizes, o as isAgentFile, r as changedFiles, t as LINT_CONFIG } from "./files-DJ0TeaTU.mjs";
5
- import { t as lintDiagnostics } from "./oxlint-DIV-lLSS.mjs";
5
+ import { t as lintDiagnostics } from "./oxlint-BbpTFFmf.mjs";
6
6
  import "./suppression-budget-Dvb_IqBo.mjs";
7
7
  import { n as sizeFailure } from "./size-DBatLT-F.mjs";
8
8
  import { copyFileSync, existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
@@ -20,6 +20,7 @@ import { tmpdir } from "node:os";
20
20
  const PACK_NEW_RULES = /* @__PURE__ */ new Map([
21
21
  ["antelopejs/no-inherited-key-lookup", "0.2.17"],
22
22
  ["antelopejs/no-presence-only-type-guard", "0.2.17"],
23
+ ["antelopejs/no-read-then-insert", "0.5.1"],
23
24
  ["antelopejs/no-unsafe-object-assign", "0.4.2"],
24
25
  ["antelopejs/require-tsconfig-include", "0.2.18"],
25
26
  ["antelopejs/require-tsconfig-types", "0.4.2"],