Re: gouse — toggle ‘declared but not used’ errors

103 views
Skip to first unread message
Message has been deleted

Tamás Gulácsi

unread,
Aug 8, 2022, 4:42:58 AM8/8/22
to golang-nuts
This is horrible.

The 'declared but not used' error saved me hundreds of times,
and for experimenting, adding a "_ = notUsed" or hide the whole part behind an "if false" is not a burden.

george...@gmail.com a következőt írta (2022. augusztus 6., szombat, 16:26:33 UTC+2):

Hi everyone!

I created a CLI tool for toggling ‘declared but not used’ errors by using idiomatic ‘_ = notUsedVar’ and leaving a TODO comment to make sure you haven’t forgotten to remove fake usages. Serves best as back end for some wrapper in form of extension for an IDE or an editor. Easily integratable into Vim. There is also VS Code extension. Will be glad if someone will make a wrapper for GoLand.

Example:

var (
    notUsed0 = false
    used0    bool
)
notUsed1, used1 := "", ""
_, _ = used0, used1

turns into

var (
    notUsed0 = false; _ = notUsed0 /* TODO: gouse */
    used0    bool
)
notUsed1, used1 := "", ""; _ = notUsed1 /* TODO: gouse */
    _, _ = used0, used1

On the next call, gouse will return everything back to the initial state.

Jan Mercl

unread,
Aug 8, 2022, 4:54:12 AM8/8/22
to Tamás Gulácsi, golang-nuts
Put `func use(...interface{}) {}` into any *_test.go file.

Call it with any variable(s) that is/are temporarily unused during testing/debugging. It work also for unused imports by naming something from the package.

The code does not compile outside of `$ go test`, it's not possible to forget and keep it in production.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0bc57678-c86a-4769-8135-d4ccf6c1c0ean%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages