Toggle ‘declared and not used’ errors in Go by using idiomatic _ = notUsedVar
and leaving a TODO comment. 
Installation
go install github.com/looshch/gouse/v2@latest
Usage
By default, gouse accepts code from stdin or from a file provided as a path
argument and writes the toggled version to stdout. ‘-w’ flag writes the result
back to the file. If multiple paths provided, ‘-w’ flag is required.
Examples
$ gouse ...input... notUsed = true ...input... ...output... notUsed = true; _ = notUsed /* TODO: gouse */ ...output...
$ gouse main.go ... notUsed = true; _ = notUsed /* TODO: gouse */ ...
$ gouse -w main.go io.go core.go $ cat main.go io.go core.go ... notUsedFromMain = true; _ = notUsedFromMain /* TODO: gouse */ ... notUsedFromIo = true; _ = notUsedFromIo /* TODO: gouse */ ... notUsedFromCore = true; _ = notUsedFromCore /* TODO: gouse */ ...
How it works
gouse first builds the input and checks the build output for ‘declared and not
used’ errors. If there are any, it creates fake usages for the reported unused
variables. If there are none, it removes previously created fake usages.
Integrations
- Vim: just bind
<cmd> w <bar> silent !gouse -w %<cr>to some mapping. - Visual Studio Code plugin.
- Open VSX Registry plugin—works in Cursor, Windsurf, Google Antigravity, Kiro, Trae, Void.
- JetBrains Marketplace—works in IntelliJ IDEA Ultimate and GoLand.
Credits
Inspired by Nikita Rabaev’s idea. Influenced by Michael Samoilenko.