Z034: Use writeAll for literal prints on Io.Writer
std.Io.Writer.print takes a format string and an arguments tuple. When the
format string has no placeholders and the arguments are empty, the call does no
formatting: try writer.print("hello\n", .{});.
std.Io.Writer.print ends up calling writeAll on the literal anyway. The
empty tuple and formatting API add noise without adding behavior. Write the
call as try writer.writeAll("hello\n"); instead.
Examples
Bad
const std = @import("std");
fn render(writer: *std.Io.Writer) std.Io.Writer.Error!void {
// expect: Z034
try writer.print("hello\n", .{});
}
Escaped braces are still literal text, not placeholders:
const std = @import("std");
fn render(writer: *std.Io.Writer) std.Io.Writer.Error!void {
// expect: Z034
try writer.print("{{}}", .{});
}Good
const std = @import("std");
fn render(writer: *std.Io.Writer) std.Io.Writer.Error!void {
try writer.writeAll("hello\n");
}const std = @import("std");
fn render(writer: *std.Io.Writer) !void {
try writer.print("{s}\n", .{"hello"});
}
std.debug.print is a function, not an Io.Writer method, so it is not
affected:
const std = @import("std");
fn log() void {
std.debug.print("hello\n", .{});
}Limitations
The receiver must resolve to std.Io.Writer. Function parameters, typed local
variables, top-level declarations, and fields of types declared in the same
file are checked. Receivers with inferred types, such as
const w = foo.init();, are skipped. This avoids flagging unrelated print
methods that take the same shape but do not provide writeAll.
Rationale
The pattern compiles and produces the right bytes. It is still misleading: the
call looks like it formats something, and the empty .{ } exists only because
print requires it. writeAll names the actual operation.