gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
390 stars 22 forks source link

[Feature request] Add version and expose through flag #53

Closed mx-psi closed 8 months ago

mx-psi commented 3 years ago

Hi, it would be useful for debugging if ineffassign was versioned and one could get that version through --version flag. Right now it's hard to know what version of ineffassign is installed. Ideally one would get the commit of the build but I don't know if that can be done easily and keep the installation through go get.

gordonklaus commented 3 years ago

I can see how this would be useful if you don't have control over which version you're running. Maybe in the meantime you can depend on a specific version? go get supports version tags, as in:

GO111MODULE=on go get github.com/gordonklaus/ineffassign@v0.0.0-20210103220932-664217a59c00

(You need GO111MODULE=on when running outside a module, until Go module mode is the default.)

It looks like we might be able to use runtime/debug.BuildInfo to get the version but I also see that there are open issues about getting the version of the main module. Needs investigation.

kolyshkin commented 2 years ago

With go 1.18, you can use

[kir@kir-rhat ~]$ go version -m `which ineffassign`
/home/kir/go/bin/ineffassign: go1.18.1
    path    github.com/gordonklaus/ineffassign
    mod github.com/gordonklaus/ineffassign  v0.0.0-20210914165742-4cc7213b9bc8  h1:PVRE9d4AQKmbelZ7emNig1+NT27DUmKZn5qXxfio54U=
    dep golang.org/x/mod    v0.4.2  h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    dep golang.org/x/sys    v0.0.0-20210510120138-977fb7262007  h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
    dep golang.org/x/tools  v0.1.5  h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
    dep golang.org/x/xerrors    v0.0.0-20200804184101-5ec99f83aff1  h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    build   -compiler=gc
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=amd64
    build   GOOS=linux
    build   GOAMD64=v1