how to pass analyzer's flag with 'go vet -vettool'

460 views
Skip to first unread message

Xiangdong Ji

unread,
Apr 12, 2021, 9:23:35 AM4/12/21
to golang-nuts
Hi,

I'm trying to run "go vet -vettool=$(which fieldalignment) ./..." for a large project, and wish to turn its '-fix' option on, wondering how to pass that option?

Any comment is highly appreciated.

wagner riffel

unread,
Apr 12, 2021, 9:50:16 PM4/12/21
to Xiangdong Ji, golang-nuts
On Mon Apr 12, 2021 at 10:23 AM -03, Xiangdong Ji wrote:
> Hi,
>
> I'm trying to run "go vet -vettool=$(which fieldalignment) ./..." for a
> large project, and wish to turn its '-fix' option on, wondering how to
> pass
> that option?

Hi Xiangdong, I found that surprising that even docs didn't mention
this anywhere, I also got confused by how go vet -vettool works but I
think I understood after reading the source code, after a -vettool is
specified, all flags that are not build flags should be sent to the
vettool, apparently those old tools like fieldalignemnt are broken
with the new "vet command line protocol" mentioned in the source code,
even some flags for those tools is broken, it's clear to me that
there's a bug going on here. Please also consider that possible that I
just think I understood the problem. :)

BR.

--wagner

Xiangdong Ji

unread,
Apr 13, 2021, 11:25:18 PM4/13/21
to golang-nuts
Thanks Wagner.

I concur that there might be a bug, or at least the documentation could CLARIFY whether analyzer's option is not supported or not,
referring to the usage of 'go vet' I assume the answer would be 'no'.

I tried to modify fieldalignment to turn its '-fix' option on by default, change worked as expected if running fieldalignment as a standalone
utility, but no rewriting is applied when running it as a tool of 'go vet', could any expert here shed a light? Thanks.  

wagner riffel

unread,
Apr 14, 2021, 9:50:27 AM4/14/21
to Xiangdong Ji, golang-nuts
On Wed Apr 14, 2021 at 12:25 AM -03, Xiangdong Ji wrote:
> I tried to modify fieldalignment to turn its '-fix' option on by
> default, change worked as expected if running fieldalignment as a
> standalone utility, but no rewriting is applied when running it as a
> tool of 'go vet', could any expert here shed a light? Thanks.
>

In the last time I check this, I remember I saw that `go vet` calls
`vettol` with -flags argument and then tries to match with the command
line passed, but fieldalignment doesn't list -fix, that's why I said it
was broken. Hope this might help you:
https://github.com/golang/go/blob/e22478/src/cmd/go/internal/vet/vetflag.go#L67

Reply all
Reply to author
Forward
0 new messages