Tool showing all assignemnts to the blank identifier

115 views
Skip to first unread message

Wojciech Muła

unread,
Nov 28, 2022, 7:44:38 AM11/28/22
to golang-nuts
Hi!

Is there any tool that would point out places with
an assignment to the blank identifier?

I'd like to spot possible refactoring/debug leftovers,
like `_ := func() {}` or unused imports.

I went through the staticcheck list of checks, but
didn't find anything similar.

cheers
Wojciech

Jan Mercl

unread,
Nov 28, 2022, 7:50:21 AM11/28/22
to Wojciech Muła, golang-nuts
$ grep -n '\b_\b :\?= ' *.go

Marcel Huijkman

unread,
Nov 29, 2022, 3:07:25 AM11/29/22
to golang-nuts
golangci-lint has :
dogsled:
# checks assignments with too many blank identifiers; default is 2
max-blank-identifiers: 0

Wojciech Muła

unread,
Nov 29, 2022, 9:16:05 AM11/29/22
to golang-nuts
On Monday, November 28, 2022 at 1:50:21 PM UTC+1 Jan Mercl wrote:
Thanks, but this will catch also things like `foo, _ := bar`, which are perfectly fine.

w.

Wojciech Muła

unread,
Nov 29, 2022, 9:17:42 AM11/29/22
to golang-nuts
On Tuesday, November 29, 2022 at 9:07:25 AM UTC+1 Marcel Huijkman wrote:
golangci-lint has :
dogsled:
# checks assignments with too many blank identifiers; default is 2
max-blank-identifiers: 0

Great, thank you.

w.
Reply all
Reply to author
Forward
0 new messages