Enforces Zig coding style conventions including naming, formatting, idioms, and best practices. Use when writing new code, reviewing changes, or refactoring for consistency.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Enforces Zig coding style conventions including naming, formatting, idioms, and best practices. Use when writing new code, reviewing changes, or refactoring for consistency.
Zig Style Enforcer
This skill ensures code follows Zig conventions and idioms for consistency and readability.
// GOOD: snake_case for files
server.zig
config_parser.zig
value_list.zig
// BAD
Server.zig // PascalCase
configParser.zig // camelCase
Zig Idioms
Use const by Default
// GOOD: const for immutable
const allocator = std.heap.page_allocator;
const file_path = "config.json";
// BAD: var when const would work
var allocator = std.heap.page_allocator;
// GOOD: var only when needed
var counter: usize = 0;
counter += 1; // Mutated, so var is correct
Use defer for Cleanup
// GOOD: defer immediately after allocation
const buffer = try allocator.alloc(u8, 1024);
defer allocator.free(buffer);
var file = try std.fs.cwd().openFile(path, .{});
defer file.close();
// BAD: defer far from allocation
const buffer = try allocator.alloc(u8, 1024);
// ... lots of code ...
defer allocator.free(buffer); // Easy to miss
// GOOD: Doc comments for public API
/// Executes the next instruction.
///
/// Returns ServerError if execution fails.
pub fn execute(self: *Server) ServerError!void {
// TODO: Add support for tail call optimization
}
// BAD: Useless comments
// This function executes
pub fn execute(self: *Server) !void { }
// BAD: Comments state the obvious
// Increment the counter
counter += 1;
// GOOD: Comments explain why
// Skip null terminators in name table
if (byte == 0) continue;
Don't Use Global State
// BAD: Global mutable state
var global_server: Server = undefined;
pub fn execute() void {
global_server.run();
}
// GOOD: Pass state explicitly
pub fn execute(server: *Server) void {
server.run();
}
Style Checklist
When writing code:
Functions and variables use snake_case
Types use PascalCase
Use const by default, var only when mutating
defer immediately after allocation
Prefer slices over raw pointers
Use tagged unions for variants
Explicit field initialization
Doc comments on public API
Exhaustive switch statements
Lines under 100 characters
No trailing whitespace
When reviewing code:
Naming consistent with conventions
Cleanup properly structured with defer
Error handling explicit, not silent
Comments add value, not noise
Code formatted consistently
Tests descriptive and comprehensive
Formatting
Use zig fmt to automatically format code:
# Format a single file
zig fmt src/server.zig
# Format entire project
zig fmt src/