ziglint Changelog View on GitHub

Z023: Parameter order convention

Structural parameters keep a fixed order among themselves: comptime T: type parameters, then comptime value parameters, then Allocator, then Io.

Runtime value parameters are position-free: they go where the API reads best. Writer-first APIs and ctx-then-callback registrations are idiomatic Zig, and this rule must not flag them.

The receiver (self, or a param of the enclosing type) is allowed first.

Examples

Bad

// expect: Z023
const std = @import("std");
fn run(io: std.Io, gpa: std.mem.Allocator) void {
    _ = .{ io, gpa };
}
// expect: Z023
fn bad(comptime size: usize, comptime T: type) void {
    _ = .{ size, T };
}

Good

// Runtime values take any position: std.fmt.format(writer, comptime fmt, args)
fn format(writer: *std.Io.Writer, comptime fmt: []const u8, args: anytype) void

// Registration reads best as (ctx, comptime cb)
fn watch(ctx: anytype, comptime cb: fn (@TypeOf(ctx)) void) void

// Structural order still applies: type params before Allocator/Io
fn process(comptime T: type, gpa: std.mem.Allocator, value: T) void

Rationale

A total order that includes runtime parameters flagged the standard library's own APIs: std.fmt.format(writer, comptime fmt, args) and std.fmt.allocPrint(gpa, comptime fmt, args) both interleave runtime and comptime parameters freely. The signal this rule can defend is the structural part — generic shape first, then compile-time values, then the allocator and IO capabilities in that order. Where data parameters sit is prose, not convention.