From e4beddb839b4aee6dcaef9f21d87862db3e2d31b Mon Sep 17 00:00:00 2001 From: "taylor.fish" Date: Mon, 11 Aug 2025 13:32:05 -0700 Subject: [PATCH] Reduce false negatives in `ban-words.test.ts` for undefined struct fields (#21748) `ban-words.test.ts` attempts to detect places where a struct field is given a default value of `undefined`, but it fails to detect cases like the following: ```zig foo: *Foo align(1) = undefined, bar: [16 * 64]Bar = undefined, baz: Baz(u8, true) = undefined, ``` This PR updates the check to detect more occurrences, while still avoiding (as far as I can tell) the inclusion of any false positives. (For internal tracking: fixes STAB-971) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- test/internal/ban-limits.json | 2 +- test/internal/ban-words.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/internal/ban-limits.json b/test/internal/ban-limits.json index 90247d51da..9994ceb9d3 100644 --- a/test/internal/ban-limits.json +++ b/test/internal/ban-limits.json @@ -7,7 +7,7 @@ ".stdDir()": 40, ".stdFile()": 18, "// autofix": 168, - ": [a-zA-Z0-9_\\.\\*\\?\\[\\]\\(\\)]+ = undefined,": 228, + ": [^=]+= undefined,$": 261, "== alloc.ptr": 0, "== allocator.ptr": 0, "@import(\"bun\").": 0, diff --git a/test/internal/ban-words.test.ts b/test/internal/ban-words.test.ts index 9e8edb43b9..8660778656 100644 --- a/test/internal/ban-words.test.ts +++ b/test/internal/ban-words.test.ts @@ -31,7 +31,7 @@ const words: Record = { "== alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" }, "!= alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" }, - [String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", regex: true }, + ": [^=]+= undefined,$": { reason: "Do not default a struct field to undefined", regex: true }, "usingnamespace": { reason: "Zig 0.15 will remove `usingnamespace`" }, "std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs" }, @@ -69,7 +69,7 @@ for (const source of sources) { if (source.startsWith("src" + path.sep + "codegen")) continue; const content = await file(source).text(); for (const word of words_keys) { - let regex = words[word].regex ? new RegExp(word, "g") : undefined; + let regex = words[word].regex ? new RegExp(word, "gm") : undefined; const did_match = regex ? regex.test(content) : content.includes(word); if (regex) regex.lastIndex = 0; if (did_match) {