Proposal: add the --simplify option to zig fmt
gofmt supports the -s code to simplify code.
The details are available at https://github.com/golang/go/blob/master/src/cmd/gofmt/simplify.go.
I propose to add the --simplify flag to zig fmt.
Here a possible list of simplifications:
- Use struct literals when possible
- Replace
s[a..len]withs[a..] - Use tuples when creating a slice of slices, when possible The main use case is slices of strings.
Here is an example from build.zig, showing how different coding styles are used in the same file.
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
const client_cpp = b.pathJoin(
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
);
Thanks.
i dont think many of these simplifications would be possible since they may rely on type information that zig fmt doesnt have access to
i dont think many of these simplifications would be possible since they may rely on type information that
zig fmtdoesnt have access to
You are right, but the cmdFmt function can load the required information as it is done when the --ast-checkflag is set, modify the original tree and render it.