zigimports
tusharsadhwani/zigimports
MIT
Automatically remove unused imports and globals from Zig files.
272711
build.zig.zon build.zig
View on GitHub Updated: 5:46:23 AM Thu Sep 12 2024Size: 38KBCreated: 8:25:33 PM Mon Sep 02 2024
Dependencies:
No dependencies were found
zigimports
Automatically remove unused imports and global variables from Zig files.
Zig currently entirely ignores unused globals, which means unused imports aren't errors. They aren't even warnings.
In fact, you can have an import importing a module/file that doesn't even exist, and the Zig compiler will simply ignore it.
zigimports
helps you avoid that by cleaning up unused imports.
[!NOTE] Zig plans to eventually address this issue in the compiler directly: https://github.com/ziglang/zig/issues/335
Installation
Requires Zig 0.13.0 or newer:
zig build --release=safe
You should have the ./zig-out/bin/zigimports
binary now.
Usage
Basic usage:
$ zigimports path/to/file.zig
path/to/file.zig:1:0: std is unused
path/to/file.zig:2:0: otherfile is unused
path/to/file.zig:9:0: MyStruct is unused
$ zigimports path/to/file.zig --fix
path/to/file.zig - Removed 3 unused imports
To tidy up your entire codebase, use:
zigimports --fix .