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

Ban // autofix in linter #10491

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bun-internal-test/src/banned.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" != undefined": "This is by definition Undefined Behavior.",
" == undefined": "This is by definition Undefined Behavior.",
"// autofix": "Either use _ or remove this line",
"@import(\"root\").bun.": "Only import 'bun' once",
"std.debug.assert": "Use bun.assert instead",
"std.debug.dumpStackTrace": "Use bun.handleErrorReturnTrace or bun.crash_handler.dumpStackTrace instead",
Expand Down
3 changes: 1 addition & 2 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn shell(

script_heap.* = script_ast;

const interpreter = Interpreter.init(
_ = Interpreter.init(
globalThis,
allocator,
&arena,
Expand All @@ -367,7 +367,6 @@ pub fn shell(
arena.deinit();
return .false;
};
_ = interpreter; // autofix

// return interpreter;
return .undefined;
Expand Down
10 changes: 3 additions & 7 deletions src/bun.js/api/bun/process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ pub const Process = struct {
this.onExit(status, &rusage_result);
}

pub fn watch(this: *Process, vm: anytype) JSC.Maybe(void) {
_ = vm; // autofix

pub fn watch(this: *Process, _: anytype) JSC.Maybe(void) {
if (comptime Environment.isWindows) {
this.poller.uv.ref();
return JSC.Maybe(void){ .result = {} };
Expand Down Expand Up @@ -651,8 +649,7 @@ pub const PollerWindows = union(enum) {
}
}

pub fn enableKeepingEventLoopAlive(this: *PollerWindows, event_loop: JSC.EventLoopHandle) void {
_ = event_loop; // autofix
pub fn enableKeepingEventLoopAlive(this: *PollerWindows, _: JSC.EventLoopHandle) void {
switch (this.*) {
.uv => |*process| {
process.ref();
Expand All @@ -661,8 +658,7 @@ pub const PollerWindows = union(enum) {
}
}

pub fn disableKeepingEventLoopAlive(this: *PollerWindows, event_loop: JSC.EventLoopHandle) void {
_ = event_loop; // autofix
pub fn disableKeepingEventLoopAlive(this: *PollerWindows, _: JSC.EventLoopHandle) void {

// This is disabled on Windows
// uv_unref() causes the onExitUV callback to *never* be called
Expand Down
17 changes: 5 additions & 12 deletions src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,7 @@ pub const Subprocess = struct {
}
}

pub fn init(stdio: Stdio, event_loop: *JSC.EventLoop, process: *Subprocess, result: StdioResult, allocator: std.mem.Allocator, max_size: u32, is_sync: bool) Readable {
_ = allocator; // autofix
_ = max_size; // autofix
_ = is_sync; // autofix
pub fn init(stdio: Stdio, event_loop: *JSC.EventLoop, process: *Subprocess, result: StdioResult, _: std.mem.Allocator, _: u32, _: bool) Readable {
assertStdioResult(result);

if (Environment.isWindows) {
Expand Down Expand Up @@ -490,8 +487,7 @@ pub const Subprocess = struct {
}
}

pub fn toJS(this: *Readable, globalThis: *JSC.JSGlobalObject, exited: bool) JSValue {
_ = exited; // autofix
pub fn toJS(this: *Readable, globalThis: *JSC.JSGlobalObject, _: bool) JSValue {
switch (this.*) {
// should only be reachable when the entire output is buffered.
.memfd => return this.toBufferedValue(globalThis),
Expand Down Expand Up @@ -1029,8 +1025,7 @@ pub const Subprocess = struct {
this.state = .{ .done = &.{} };
return JSC.WebCore.ReadableStream.fromBlob(globalObject, &blob, 0);
},
.err => |err| {
_ = err; // autofix
.err => {
const empty = JSC.WebCore.ReadableStream.empty(globalObject);
JSC.WebCore.ReadableStream.cancel(&JSC.WebCore.ReadableStream.fromJS(empty, globalObject).?, globalObject);
return empty;
Expand Down Expand Up @@ -1183,8 +1178,7 @@ pub const Subprocess = struct {

switch (pipe.writer.startWithCurrentPipe()) {
.result => {},
.err => |err| {
_ = err; // autofix
.err => {
pipe.deref();
return error.UnexpectedCreatingStdin;
},
Expand Down Expand Up @@ -1234,8 +1228,7 @@ pub const Subprocess = struct {

switch (pipe.writer.start(pipe.fd, true)) {
.result => {},
.err => |err| {
_ = err; // autofix
.err => {
pipe.deref();
return error.UnexpectedCreatingStdin;
},
Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/event_loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1650,9 +1650,7 @@ pub const MiniVM = struct {
return this.mini.loop;
}

pub inline fn incrementPendingUnrefCounter(this: @This()) void {
_ = this; // autofix

pub inline fn incrementPendingUnrefCounter(_: @This()) void {
@panic("FIXME TODO");
}

Expand Down
38 changes: 11 additions & 27 deletions src/bun.js/webcore/streams.zig
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,9 @@ pub const ReadableStream = struct {

pub fn fromPipe(
globalThis: *JSGlobalObject,
parent: anytype,
_: anytype,
buffered_reader: anytype,
) JSC.JSValue {
_ = parent; // autofix
JSC.markBinding(@src());
var source = FileReader.Source.new(.{
.globalThis = globalThis,
Expand Down Expand Up @@ -1468,9 +1467,8 @@ pub const SinkDestructor = struct {

pub export fn Bun__onSinkDestroyed(
ptr_value: ?*anyopaque,
sink_ptr: ?*anyopaque,
_: ?*anyopaque,
) callconv(.C) void {
_ = sink_ptr; // autofix
const ptr = Ptr.from(ptr_value);

if (ptr.isNull()) {
Expand Down Expand Up @@ -1625,10 +1623,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
return JSC.JSValue.jsUndefined();
}

pub fn unprotect(this: *@This()) void {
_ = this; // autofix

}
pub fn unprotect(_: *@This()) void {}

pub fn write(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
JSC.markBinding(@src());
Expand Down Expand Up @@ -2695,8 +2690,7 @@ pub fn ReadableStreamSource(
pub const construct = JSReadableStreamSource.construct;
pub const getIsClosedFromJS = JSReadableStreamSource.isClosed;
pub const JSReadableStreamSource = struct {
pub fn construct(globalThis: *JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) ?*ReadableStreamSourceType {
_ = callFrame; // autofix
pub fn construct(globalThis: *JSGlobalObject, _: *JSC.CallFrame) callconv(.C) ?*ReadableStreamSourceType {
globalThis.throw("Cannot construct ReadableStreamSource", .{});
return null;
}
Expand Down Expand Up @@ -2735,8 +2729,7 @@ pub fn ReadableStreamSource(
}
}

pub fn isClosed(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
_ = globalObject; // autofix
pub fn isClosed(this: *ReadableStreamSourceType, _: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
return JSC.JSValue.jsBoolean(this.is_closed);
}

Expand Down Expand Up @@ -2766,8 +2759,7 @@ pub fn ReadableStreamSource(
}
}

pub fn cancel(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
_ = globalObject; // autofix
pub fn cancel(this: *ReadableStreamSourceType, _: *JSC.JSGlobalObject, callFrame: *JSC.CallFrame) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());
this.this_jsvalue = callFrame.this();
this.cancel();
Expand Down Expand Up @@ -2811,17 +2803,13 @@ pub fn ReadableStreamSource(
return true;
}

pub fn getOnCloseFromJS(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
_ = globalObject; // autofix

pub fn getOnCloseFromJS(this: *ReadableStreamSourceType, _: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());

return this.close_jsvalue.get() orelse .undefined;
}

pub fn getOnDrainFromJS(this: *ReadableStreamSourceType, globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
_ = globalObject; // autofix

pub fn getOnDrainFromJS(this: *ReadableStreamSourceType, _: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
JSC.markBinding(@src());

if (ReadableStreamSourceType.onDrainCallbackGetCached(this.this_jsvalue)) |val| {
Expand Down Expand Up @@ -3184,8 +3172,7 @@ pub const FileSink = struct {
return .{ .result = {} };
}

pub fn flushFromJS(this: *FileSink, globalThis: *JSGlobalObject, wait: bool) JSC.Maybe(JSValue) {
_ = wait; // autofix
pub fn flushFromJS(this: *FileSink, globalThis: *JSGlobalObject, _: bool) JSC.Maybe(JSValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unused parameters should keep the variable name if comptime logic requires them. Makes it a little more clear what it would be used for. Otherwise the parameter should be completely removed from the function signature

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also interesting
Screenshot 2024-04-24 at 4 17 20 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

if (this.pending.state == .pending) {
return .{ .result = this.pending.future.promise.value() };
}
Expand Down Expand Up @@ -3233,9 +3220,8 @@ pub const FileSink = struct {

pub fn construct(
this: *FileSink,
allocator: std.mem.Allocator,
_: std.mem.Allocator,
) void {
_ = allocator; // autofix
this.* = FileSink{
.event_loop_handle = JSC.EventLoopHandle.init(JSC.VirtualMachine.get().eventLoop()),
};
Expand Down Expand Up @@ -3264,13 +3250,11 @@ pub const FileSink = struct {
return this.toResult(this.writer.writeUTF16(data.slice16()));
}

pub fn end(this: *FileSink, err: ?Syscall.Error) JSC.Maybe(void) {
pub fn end(this: *FileSink, _: ?Syscall.Error) JSC.Maybe(void) {
if (this.done) {
return .{ .result = {} };
}

_ = err; // autofix

switch (this.writer.flush()) {
.done => |written| {
this.written += @truncate(written);
Expand Down
2 changes: 0 additions & 2 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2481,8 +2481,6 @@ pub const MakePath = struct {
@ptrCast(component.path))
else
try w.sliceToPrefixedFileW(self.fd, component.path);
const is_last = it.peekNext() == null;
_ = is_last; // autofix
var result = makeOpenDirAccessMaskW(self, sub_path_w.span().ptr, access_mask, .{
.no_follow = no_follow,
.create_disposition = w.FILE_OPEN_IF,
Expand Down
3 changes: 1 addition & 2 deletions src/cli/bunx_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ pub const BunxCommand = struct {
Output.prettyErrorln("<r><red>error<r>: bunx failed to install <b>{s}<r> due to error <b>{s}<r>", .{ install_param, @errorName(err) });
Global.exit(1);
})) {
.err => |err| {
_ = err; // autofix
.err => {
Global.exit(1);
},
.result => |result| result,
Expand Down
14 changes: 4 additions & 10 deletions src/io/PipeReader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ pub fn PosixPipeReader(
return readWithFn(parent, resizable_buffer, fd, size_hint, received_hup, .pipe, bun.sys.readNonblocking);
}

fn readWithFn(parent: *This, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize, received_hup_: bool, comptime file_type: FileType, comptime sys_fn: *const fn (bun.FileDescriptor, []u8) JSC.Maybe(usize)) void {
_ = size_hint; // autofix
fn readWithFn(parent: *This, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, _: isize, received_hup_: bool, comptime file_type: FileType, comptime sys_fn: *const fn (bun.FileDescriptor, []u8) JSC.Maybe(usize)) void {
const streaming = parent.vtable.isStreamingEnabled();

var received_hup = received_hup_;
Expand Down Expand Up @@ -756,10 +755,7 @@ const PosixBufferedReader = struct {
}

// No-op on posix.
pub fn pause(this: *PosixBufferedReader) void {
_ = this; // autofix

}
pub fn pause(_: *PosixBufferedReader) void {}

pub fn takeBuffer(this: *PosixBufferedReader) std.ArrayList(u8) {
const out = this._buffer;
Expand All @@ -783,13 +779,11 @@ const PosixBufferedReader = struct {
return this.buffer();
}

pub fn disableKeepingProcessAlive(this: *@This(), event_loop_ctx: anytype) void {
_ = event_loop_ctx; // autofix
pub fn disableKeepingProcessAlive(this: *@This(), _: anytype) void {
this.updateRef(false);
}

pub fn enableKeepingProcessAlive(this: *@This(), event_loop_ctx: anytype) void {
_ = event_loop_ctx; // autofix
pub fn enableKeepingProcessAlive(this: *@This(), _: anytype) void {
this.updateRef(true);
}

Expand Down
6 changes: 3 additions & 3 deletions src/io/PipeWriter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ pub fn PosixPipeWriter(
comptime onWrite: fn (*This, written: usize, status: WriteStatus) void,
comptime registerPoll: ?fn (*This) void,
comptime onError: fn (*This, bun.sys.Error) void,
comptime onWritable: fn (*This) void,
/// onWritable
comptime _: fn (*This) void,
comptime getFileType: *const fn (*This) FileType,
) type {
_ = onWritable; // autofix
return struct {
pub fn _tryWrite(this: *This, buf_: []const u8) WriteResult {
return switch (getFileType(this)) {
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn PosixPipeWriter(
}

pub fn drainBufferedData(parent: *This, input_buffer: []const u8, max_write_size: usize, received_hup: bool) WriteResult {
_ = received_hup; // autofix
_ = received_hup; // not used currently.
var buf = input_buffer;
buf = if (max_write_size < buf.len and max_write_size > 0) buf[0..max_write_size] else buf;
const original_buf = buf;
Expand Down