mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
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>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -31,7 +31,7 @@ const words: Record<string, { reason: string; regex?: boolean }> = {
|
||||
"== 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) {
|
||||
|
||||
Reference in New Issue
Block a user