Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ci): ignore shift operators in array length types

Steven Enamakel740871f3f832
diff --git a/scripts/__tests__/process-statics.test.mjs b/scripts/__tests__/process-statics.test.mjs
index 9279d30ec9..ee9f0c1767 100644
--- a/scripts/__tests__/process-statics.test.mjs
+++ b/scripts/__tests__/process-statics.test.mjs
@@ -128,7 +128,10 @@ test("comparisons and shifts inside const blocks are not generic brackets", () =
);
});
test("array length expressions do not treat shifts as generic brackets", () => {
- assert.equal(scan("static X: [Option<u8>; 1 << 2] = x;")[0].type, "[Option<u8>;1<<2]");
+ assert.equal(
+ scan("static X: [Option<u8>; 1 << 2] = x;")[0].type,
+ "[Option<u8>;1<<2]",
+ );
});
test("repository scan reads the merge base, enforces records, and fails without history", () => {
const root = mkdtempSync(join(tmpdir(), "process-statics-"));
diff --git a/scripts/ci/check-process-statics.mjs b/scripts/ci/check-process-statics.mjs
index 7c2b0146cc..be421c4946 100644
--- a/scripts/ci/check-process-statics.mjs
+++ b/scripts/ci/check-process-statics.mjs
@@ -25,17 +25,26 @@ export function declarations(text, file) {
let end = match.index + match[0].length;
const start = end;
const stack = [];
+ const arrayLengths = new Set();
for (; end < code.length; end++) {
const char = code[end];
if (!stack.length && (char === "=" || char === ";")) break;
- // Operators inside a braced const expression are not type brackets.
- if ((char === "<" || char === ">") && stack.includes("{")) continue;
+ if (char === ";" && stack.at(-1) === "[") arrayLengths.add(stack.length);
+ // Operators in const blocks and array lengths are not type brackets.
+ if (
+ (char === "<" || char === ">") &&
+ (stack.includes("{") || arrayLengths.size)
+ )
+ continue;
if ("<([{".includes(char)) stack.push(char);
else if (">)]}".includes(char) && stack.length) {
// An arrow inside a function type is not a generic closing bracket.
if (char === ">" && code[end - 1] === "-") continue;
const expected = { ">": "<", ")": "(", "]": "[", "}": "{" }[char];
- if (stack.at(-1) === expected) stack.pop();
+ if (stack.at(-1) === expected) {
+ arrayLengths.delete(stack.length);
+ stack.pop();
+ }
}
}
if (end === code.length)