Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: ban comparing against undefined #10288

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bun-internal-test/src/banned.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"@import(\"root\").bun.": "Only import 'bun' once",
"std.mem.indexOfAny": "Use bun.strings.indexAny or bun.strings.indexAnyComptime",
"std.debug.print": "Don't let this be committed",
" == undefined": "This is by definition Undefined Behavior.",
" != undefined": "This is by definition Undefined Behavior.",
"undefined == ": "This is by definition Undefined Behavior.",
"undefined != ": "This is by definition Undefined Behavior.",
"": ""
}
10 changes: 10 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,16 @@ pub inline fn assert(value: bool) void {
}
}

/// This has no effect on the real code but capturing 'a' and 'b' into parameters makes assertion failures much easier inspect in a debugger.
pub inline fn assert_eql(a: anytype, b: anytype) void {
return assert(a == b);
}

/// This has no effect on the real code but capturing 'a' and 'b' into parameters makes assertion failures much easier inspect in a debugger.
pub inline fn assert_neql(a: anytype, b: anytype) void {
return assert(a != b);
}

pub inline fn unsafeAssert(condition: bool) void {
if (!condition) {
unreachable;
Expand Down
18 changes: 1 addition & 17 deletions src/install/semver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ pub const String = extern struct {
};
}

pub inline fn init(
buf: string,
in: string,
) String {
if (comptime Environment.isDebug) {
const out = realInit(buf, in);
if (!out.isInline()) {
assert(@as(u64, @bitCast(out.slice(buf)[0..8].*)) != undefined);
}

return out;
} else {
return realInit(buf, in);
}
}

pub const Formatter = struct {
str: *const String,
buf: string,
Expand Down Expand Up @@ -150,7 +134,7 @@ pub const String = extern struct {
}
};

fn realInit(
pub fn init(
buf: string,
in: string,
) String {
Expand Down
Loading