Remove unnecessary type conversions from Go source

Build Status

About

The unconvert program analyzes Go packages to identify unnecessary type conversions; i.e., expressions T(x) where x already has type T.

Install

$ go get github.com/mdempsky/unconvert

Usage

$ unconvert -v bytes fmt
GOROOT/src/bytes/reader.go:117:14: unnecessary conversion
                abs = int64(r.i) + offset
                           ^
GOROOT/src/fmt/print.go:411:21: unnecessary conversion
        p.fmt.integer(int64(v), 16, unsigned, udigits)
                           ^

Flags

Using the -v flag, unconvert will also print the source line and a caret to indicate the unnecessary conversion's position therein.

Using the -apply flag, unconvert will rewrite the Go source files without the unnecessary type conversions.

Using the -all flag, unconvert will analyze the Go packages under all possible GOOS/GOARCH combinations, and only identify conversions that are unnecessary in all cases.

E.g., syscall.Timespec's Sec and Nsec fields are int64 under linux/amd64 but int32 under linux/386. An int64(ts.Sec) conversion that appears in a linux/amd64-only file will be identified as unnecessary, but it will be preserved if it occurs in a file that's compiled for both linux/amd64 and linux/386.

Owner
Matthew Dempsky
I eat plants and write Go.
Matthew Dempsky
Comments
  • Files in /usr/local/go are processed

    Files in /usr/local/go are processed

    I've reported it before here: https://github.com/alecthomas/gometalinter/issues/149, but I think that this is a better place to report it.

    I'm not (yet) sure why, but some linters generate a report from /usr/local/go.

    mark@Dymek:$ gometalinter -j4 --vendor --deadline=30s -t . | grep '^/'
    /usr/local/go/src/os/user/lookup.go:9:9:warning: undeclared name: current (unconvert)
    /usr/local/go/src/os/user/lookup.go:15:9:warning: undeclared name: lookup (unconvert)
    /usr/local/go/src/os/user/lookup.go:21:9:warning: undeclared name: lookupId (unconvert)
    /usr/local/go/src/net/lookup_unix.go:55:24:warning: undeclared name: cgoLookupHost (unconvert)
    /usr/local/go/src/net/lookup_unix.go:67:24:warning: undeclared name: cgoLookupIP (unconvert)
    /usr/local/go/src/net/lookup_unix.go:78:23:warning: undeclared name: cgoLookupPort (unconvert)
    /usr/local/go/src/net/lookup_unix.go:87:24:warning: undeclared name: cgoLookupCNAME (unconvert)
    /usr/local/go/src/net/lookup_unix.go:154:23:warning: undeclared name: cgoLookupPTR (unconvert)
    /usr/local/go/src/crypto/x509/root.go:15:10:warning: undeclared name: initSystemRoots (unconvert)
    /usr/local/go/src/os/user/lookup.go:9:9:warning: unused global variable undeclared name: current (varcheck)
    /usr/local/go/src/os/user/lookup.go:15:9:warning: unused global variable undeclared name: lookup (varcheck)
    /usr/local/go/src/os/user/lookup.go:21:9:warning: unused global variable undeclared name: lookupId (varcheck)
    /usr/local/go/src/net/lookup_unix.go:55:24:warning: unused global variable undeclared name: cgoLookupHost (varcheck)
    /usr/local/go/src/net/lookup_unix.go:67:24:warning: unused global variable undeclared name: cgoLookupIP (varcheck)
    /usr/local/go/src/net/lookup_unix.go:78:23:warning: unused global variable undeclared name: cgoLookupPort (varcheck)
    /usr/local/go/src/net/lookup_unix.go:87:24:warning: unused global variable undeclared name: cgoLookupCNAME (varcheck)
    /usr/local/go/src/net/lookup_unix.go:154:23:warning: unused global variable undeclared name: cgoLookupPTR (varcheck)
    /usr/local/go/src/crypto/x509/root.go:15:10:warning: unused global variable undeclared name: initSystemRoots (varcheck)
    /usr/local/go/src/os/user/lookup.go:9:9:warning: unused struct field undeclared name: current (structcheck)
    /usr/local/go/src/os/user/lookup.go:15:9:warning: unused struct field undeclared name: lookup (structcheck)
    /usr/local/go/src/os/user/lookup.go:21:9:warning: unused struct field undeclared name: lookupId (structcheck)
    /usr/local/go/src/net/lookup_unix.go:55:24:warning: unused struct field undeclared name: cgoLookupHost (structcheck)
    /usr/local/go/src/net/lookup_unix.go:67:24:warning: unused struct field undeclared name: cgoLookupIP (structcheck)
    /usr/local/go/src/net/lookup_unix.go:78:23:warning: unused struct field undeclared name: cgoLookupPort (structcheck)
    /usr/local/go/src/net/lookup_unix.go:87:24:warning: unused struct field undeclared name: cgoLookupCNAME (structcheck)
    /usr/local/go/src/net/lookup_unix.go:154:23:warning: unused struct field undeclared name: cgoLookupPTR (structcheck)
    /usr/local/go/src/crypto/x509/root.go:15:10:warning: unused struct field undeclared name: initSystemRoots (structcheck)
    /usr/local/go/src/os/user/lookup.go:9:9:warning: undeclared name: current (aligncheck)
    /usr/local/go/src/os/user/lookup.go:15:9:warning: undeclared name: lookup (aligncheck)
    /usr/local/go/src/os/user/lookup.go:21:9:warning: undeclared name: lookupId (aligncheck)
    /usr/local/go/src/net/lookup_unix.go:55:24:warning: undeclared name: cgoLookupHost (aligncheck)
    /usr/local/go/src/net/lookup_unix.go:67:24:warning: undeclared name: cgoLookupIP (aligncheck)
    /usr/local/go/src/net/lookup_unix.go:78:23:warning: undeclared name: cgoLookupPort (aligncheck)
    /usr/local/go/src/net/lookup_unix.go:87:24:warning: undeclared name: cgoLookupCNAME (aligncheck)
    /usr/local/go/src/net/lookup_unix.go:154:23:warning: undeclared name: cgoLookupPTR (aligncheck)
    /usr/local/go/src/crypto/x509/root.go:15:10:warning: undeclared name: initSystemRoots (aligncheck)
    

    I'm on go version go1.6.2 darwin/amd64

    mark@Dymek:$ set | grep ^GO
    GOBIN=/Users/mark/Development/GO/bin
    GOPATH=/Users/mark/Development/GO
    GOROOT=/usr/local/go
    

    /usr/local/go is a symlink, not sure if that's significant.

    When I try to run unconvert directly, I get similar behaviour.

  • Failure with go-1.10.x, caused by a new `go list` argument `-compiled`

    Failure with go-1.10.x, caused by a new `go list` argument `-compiled`

    To reproduce:

    With a clean go-1.10.x(without any installed package. Such as in travis):

    • Install unconvert:
      go get github.com/mdempsky/unconvert
      
    • Run it: unconvert math/bits, it reports an error:
      2019/03/25 16:25:53 unsupported version of go: exit status 2: flag provided but not defined: -compiled
      usage: list [-e] [-f format] [-json] [build flags] [packages]
      Run 'go help list' for details.
      

    Cause

    1. unconvert relies on golang.org/x/tools/go/packages.
    2. go get in a clean env pulls the latest golang.org/x/tools/go/packages.
    3. The latest golang.org/x/tools/go/packages(the master) is for latest go(1.12.x) and it assumes that go list is able to accept the argument -compiled.
    4. An older go(e.g. 1.10.x) does not support -compiled for go list. Thus install unconvert in a clean go-1.10.x env results in an error like above.

    As go get can not specify dependency versions, using dep to force the revision of packages to use might solve this problem.

  • Rewrite in terms of lintutil

    Rewrite in terms of lintutil

    https://godoc.org/honnef.co/go/lint/lintutil is a neat package by @dominikh that provides a framework for writing linters like unconvert.

    The main benefit of rewriting unconvert in terms of lintutil is that it would allow users to implement "meta linters" that can run many lints while traversing the AST only once. Such a thing already exists in CockroachDB (https://github.com/cockroachdb/cockroach/blob/master/pkg/cmd/metacheck/main.go).

    cc @dominikh

  • C: no such file or directory

    C: no such file or directory

    $ unconvert -v github.com/vulkan-go/vulkan
    2017/07/07 16:17:49 open /Users/xlab/Documents/dev/go/src/github.com/vulkan-go/vulkan/C: no such file or directory
    
    go version go1.9beta2 darwin/amd64
    
  • unconvert doesn't support vendoring

    unconvert doesn't support vendoring

    If you try to use unconvert on code which has vendored dependencies it reports bogus errors

    For example:

    main.go:6:2:warning: could not import github.com/pkg/errors (cannot find package "github.com/pkg/errors" in any of: (unconvert)
    main.go:11:14:warning: undeclared name: errors (unconvert)
    

    Where main.go clearly imports errors:

    package main
    
    import (
            "fmt"
    
            "github.com/pkg/errors"
    )
    
    func main() {
            err := fmt.Errorf("some error")
            fmt.Println(errors.Wrap(err, "my wrapped error"))
    }
    

    To ensure you get this error you need github.com/pkg/errors vendored and it must NOT be in your GOPATH.

    Also reported to gometalinter: https://github.com/alecthomas/gometalinter/issues/190

  • fails on cockroachdb

    fails on cockroachdb

    Cool tool!

    I tried it on cockroachdb/cockroach@ac79461:

    $ unconvert -all -apply ./...
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/util/log/clog.go:949:40: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/internal/client/txn.go:353:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/internal/client/txn.go:354:8: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/internal/client/db.go:484:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/parser/builtins.go:988:23: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/status/recorder.go:260:18: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/in_mem.go:26:3: undeclared name: RocksDB
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/in_mem.go:44:16: cannot use (InMem literal) (value of type InMem) as Engine value in variable declaration: missing method ApplyBatchRepr
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/in_mem.go:31:11: undeclared name: NewRocksDBCache
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/in_mem.go:36:3: unknown field RocksDB in struct literal
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/in_mem.go:38:12: invalid operation: db (variable of type InMem) has no field or method Open
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/merge.go:56:22: undeclared name: goMerge
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/mvcc.go:551:20: undeclared name: emptyKeyError
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/mvcc.go:950:10: undeclared name: emptyKeyError
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/mvcc.go:1289:10: undeclared name: emptyKeyError
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/mvcc.go:1506:15: undeclared name: emptyKeyError
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/engine/mvcc.go:1716:10: undeclared name: emptyKeyError
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/kv/dist_sender.go:342:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/kv/dist_sender.go:343:8: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/kv/dist_sender.go:491:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/store.go:1151:19: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/store.go:2859:31: RocksDB not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/store.go:2859:20: s.engine (variable of type github.com/cockroachdb/cockroach/storage/engine.Engine) cannot have dynamic type *invalid type (missing method ApplyBatchRepr)
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/store.go:2860:15: invalid operation: rocksdb (variable of type *invalid type) has no field or method GetSSTables
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/storage/replica_command.go:2121:18: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/testutils/localtestcluster/local_test_cluster.go:92:12: cannot use engine.NewInMem((roachpb.Attributes literal), 50 << 20, ltc.Stopper) (value of type github.com/cockroachdb/cockroach/storage/engine.InMem) as github.com/cockroachdb/cockroach/storage/engine.Engine value in assignment: missing method ApplyBatchRepr
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/scan.go:184:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/plan.go:225:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/update.go:130:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/update.go:180:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/update.go:299:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/pgwire/v3.go:639:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/sql/pgwire/v3.go:642:2: AnnotateTrace not declared by package tracing
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:339:11: NewRocksDBCache not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:367:38: cannot use engine.NewInMem(spec.Attributes, sizeInBytes, stopper) (value of type github.com/cockroachdb/cockroach/storage/engine.InMem) as github.com/cockroachdb/cockroach/storage/engine.Engine value in argument to append: missing method ApplyBatchRepr
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:382:5: NewRocksDB not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/status.go:240:15: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/updates.go:171:19: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/updates.go:272:19: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/admin.go:850:55: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:226:52: MinimumMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:227:59: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:228:56: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:233:105: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:235:10: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:249:10: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:289:10: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/context.go:308:10: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/server/testserver.go:224:43: cannot use engine.NewInMem((roachpb.Attributes literal), 100 << 20, params.Stopper) (value of type github.com/cockroachdb/cockroach/storage/engine.InMem) as github.com/cockroachdb/cockroach/storage/engine.Engine value in argument to append: missing method ApplyBatchRepr
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/cli.go:42:11: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:65:73: RocksDB not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/backtrace.go:69:10: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:139:12: invalid operation: db (variable of type *invalid type) has no field or method Iterate
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:66:11: NewRocksDBCache not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:68:8: NewRocksDB not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:74:3: DefaultMaxOpenFiles not declared by package engine
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:174:35: cannot use db (variable of type *invalid type) as github.com/cockroachdb/cockroach/storage/engine.Engine value in argument to loadRangeDescriptor: missing method ApplyBatchRepr
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:179:48: cannot use db (variable of type *invalid type) as github.com/cockroachdb/cockroach/storage/engine.Reader value in argument to storage.NewReplicaDataIterator: missing method Close
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:405:12: invalid operation: db (variable of type *invalid type) has no field or method Iterate
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:485:12: invalid operation: db (variable of type *invalid type) has no field or method Iterate
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:532:56: cannot use db (variable of type *invalid type) as github.com/cockroachdb/cockroach/storage/engine.Reader value in argument to engine.MVCCIterate: missing method Close
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:559:11: invalid operation: db (variable of type *invalid type) has no field or method NewSnapshot
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:618:56: cannot use db (variable of type *invalid type) as github.com/cockroachdb/cockroach/storage/engine.Reader value in argument to engine.MVCCIterate: missing method Close
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:710:9: invalid operation: db (variable of type *invalid type) has no field or method Compact
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/debug.go:753:19: invalid operation: db (variable of type *invalid type) has no field or method GetSSTables
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/gen.go:44:10: GetInfo not declared by package build
    /Users/tamird/src/go/src/github.com/cockroachdb/cockroach/cli/start.go:333:10: GetInfo not declared by package build
    2016/07/28 22:14:02 couldn't load packages due to errors: github.com/cockroachdb/cockroach/cli, github.com/cockroachdb/cockroach/storage/engine, github.com/cockroachdb/cockroach/testutils/localtestcluster and 9 more
    
  • Can and should unconvert simplify this case?

    Can and should unconvert simplify this case?

    Suppose there's a declaration of a []int32 slice done in the following way:

    x := []int32{
        (int32)(1),
        (int32)(5),
        (int32)(8),
    }
    

    Is there a reason unconvert can't or shouldn't simplify it to:

    x := []int32{
        1,
        5,
        8,
    }
    

    Since constants are used, the type conversion is not needed, as the constants will have their types inferred correctly from the context. Any thoughts?

  • column numbers and -apply don't always work with cgo

    column numbers and -apply don't always work with cgo

    $ go get azul3d.org/engine/gfx/internal/gl/2.0/gl
    $ unconvert azul3d.org/engine/gfx/internal/gl/2.0/gl
    panic: illegal file offset
    
    goroutine 1 [running]:
    panic(0x603c00, 0xc824298740)
        /home/u/go/src/runtime/panic.go:500 +0x189
    go/token.(*File).Pos(0xc824684420, 0xd54, 0x1)
        /home/u/go/src/go/token/position.go:237 +0x88
    main.print(0xc8201d7ef0, 0x43, 0xc8247ec0d0)
        /home/u/goget/src/github.com/mdempsky/unconvert/unconvert.go:119 +0x23a
    main.main()
        /home/u/goget/src/github.com/mdempsky/unconvert/unconvert.go:210 +0x38f
    
  • Release v1.0.0

    Release v1.0.0

    unconvert doesn't show up nicely in a go.mod (eg: github.com/mdempsky/unconvert v0.0.0-20190921185256-3ecd357795af)

    Since its been stable for quite a while, tag a v1.0.0 release?

  • Fix file name reporting for Go 1.11 [v2]

    Fix file name reporting for Go 1.11 [v2]

    unconvert output for cgo-preprocessed files is broken when using Go 1.11beta. A quick example:

    With Go 1.10:

    go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy /home/kir/go/src/github.com/docker/docker/daemon/graphdriver/copy/copy.go:242:28: unnecessary conversion

    With Go 1.11 beta2:

    go run unconvert.go github.com/docker/docker/daemon/graphdriver/copy copy.go:242:0: unnecessary conversion

    Note that there are two issues:

    • column is 0;
    • file names have path stripped.

    The issue with column is filed as https://github.com/golang/go/issues/26692; there is no way to fix it in unconvert.

    The second issue is currently discussed in https://github.com/golang/go/issues/26671, but it might not be fixed since the new documentation says:

    The filenames in line directives now remain untouched by the scanner; there is no cleanup or conversion of relative into absolute paths anymore, in sync with what the compiler's scanner/parser are doing. Any kind of filename transformation has to be done by a client. This makes the scanner code simpler and also more predictable.

    So, here's the alternative: if the file name is not absolute, prepend the path as we know it.

    Fixes #29

  • Is this a bug, a false positive, or a gap in my understanding?

    Is this a bug, a false positive, or a gap in my understanding?

    For watcher-default.go#L45, unconvert -v github.com/metaleap/go-util-fs reports:

    /home/me/c/go/src/github.com/metaleap/go-util-fs/watcher-default.go:45:33: unnecessary conversion
            me.DebounceNano = time.Duration(250 * time.Millisecond).Nanoseconds()
                                           ^
    

    I don't see any conversions anywhere near?!

    Same result with -safe, except prepended by line:

    ... huh, *ast.SelectorExpr at /home/me/c/go/src/github.com/metaleap/go-util-fs/watcher-default.go:45:20
    
  • Include unconvert as a library

    Include unconvert as a library

    Is there an interest on splitting unconvert into library and cmd? This will allow other projects like golangci-lint to use this project directly instead of depending on an old fork

    I am ready to implement the changes myself. (Original discussion https://github.com/golangci/golangci-lint/issues/1809 )

  • Missing type for functions reported without function name and other details

    Missing type for functions reported without function name and other details

    I've been using unconvert to scan couple of Go files which I have in my local. And upon running I'm getting info like,

    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    Missing type for function
    

    without any more detailed output or further information as which function or line number. I'm not sure whether this is the normal behavior or expected output.

  • Support cross-builds and cgo

    Support cross-builds and cgo

    The type of syscall.Stdin differs on Linux (int) and Windows (syscall.Handle). As such, any calling code needs to always cast syscall.Stdin to an integer to use it. But this gets flagged by unconvert on Linux.

    My current workaround is to do int(os.Stdin.Fd()) instead of syscall.Stdin. Would be nice to do without the hack.

  • Consider reporting avoidable type conversion for untyped constants (typed constants are already handled).

    Consider reporting avoidable type conversion for untyped constants (typed constants are already handled).

    Consider the following Go program:

    package main
    
    import "fmt"
    
    func main() {
    	const foo = "foo"
    
    	f(string(foo) + "bar")
    }
    
    func f(s string) {
    	fmt.Println(s)
    }
    

    I expected unconvert to report that string(foo) is an unnecessary conversion, but it didn't.

    $ unconvert
    $ echo $?
    0
    

    Is that intentional, or a missing feature?

    Tested using Go 1.8beta2 and latest version of unconvert and its depenencies:

    $ go version
    go version go1.8beta2 darwin/amd64
    $ gostatus -v .../unconvert
         github.com/mdempsky/unconvert/...
    $ go list -f '{{join .Deps "\n"}}' github.com/mdempsky/unconvert | gostatus -stdin -v
         github.com/kisielk/gotool/...
         golang.org/x/text/...
       $ golang.org/x/tools/...
    	$ Stash exists
    $ binstale unconvert
    unconvert
    	up to date: github.com/mdempsky/unconvert
    

    /cc @dominikh in case this is a better fit for one of your tools.

  • false positives in protobuf generated code

    false positives in protobuf generated code

    After fixing #16, all of the remaining issues in github.com/cockroachdb/cockroach/... are now in machine generate protobuf files.

    I'm thinking unconvert should just ignore files ending with ".pb.go", but I'm open to suggestions for alternative heuristics. E.g., are there any strings like "DO NOT EDIT" that are conventionally recognized by other linter tools?

Type check the empty interface{}

Static type checker for interface{} with a type list This is an experiment. This is a tool that performs a static type check on values of type interfa

Sep 13, 2021
The most opinionated Go source code linter for code audit.
The most opinionated Go source code linter for code audit.

go-critic Highly extensible Go source code linter providing checks currently missing from other linters. There is never too much static code analysis.

Jan 6, 2023
[mirror] This is a linter for Go source code.

Golint is a linter for Go source code. Installation Golint requires a supported release of Go. go get -u golang.org/x/lint/golint To find out where g

Dec 23, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Dec 30, 2022
Print all source code for a given go package or module.

gosrcs gosrcs is a tool to print all the source code a given go package depends on. The original motivation of this tool is to integrate go builds int

Oct 25, 2021
Detect non-inclusive language in your source code.
Detect non-inclusive language in your source code.

Detect non-inclusive language in your source code. I stay woke - Erykah Badu Creating an inclusive work environment is imperative to a healthy, suppor

Dec 25, 2022
Sep 23, 2022
May 8, 2022
Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Jan 2, 2023
Fast conversions across various Go types with a simple API.

Go Package: conv Get: go get -u github.com/cstockton/go-conv Example: // Basic types if got, err := conv.Bool(`TRUE`); err == nil { fmt.Printf("conv.

Nov 29, 2022
Common case conversions covering common initialisms.

kace go get "github.com/codemodus/kace" Package kace provides common case conversion functions which take into consideration common initialisms. Usag

Sep 27, 2022
Simple and easy to use command line application written in Go for cleaning unnecessary XCode files.

xcclear Say hello to a few extra gigabytes of space on your Mac with xcclear, a simple and easy to use command line application written in Go for clea

Dec 16, 2022
Go linter that checks types that are json encoded - reports unsupported types and unnecessary error checks

Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omited.

Oct 7, 2022
A tool that finds and removes unnecessary lines from .gitignore files.

Allyignore A tool that finds and removes unnecessary lines from .gitignore files. Installation > go install github.com/Allyedge/allyignore@latest Usag

May 10, 2022
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

typex Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration. Installation go get -u gi

Dec 6, 2022
Go generator to copy values from type to type and fields from struct to struct. Copier without reflection.

Copygen is a command-line code generator that generates type-to-type and field-to-field struct code without adding any reflection or dependenc

Dec 29, 2022
convert JSON of a specific format to a type structure(Typescript type or more)

json2type convert JSON of a specific format to a type structure(Typescript type or more) Quick Start CLI Install use go tool install go install github

Mar 28, 2022
A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type.

writehasher A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type. Example package main import ( "fmt"

Jan 10, 2022
A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod
A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

GPU Mounter GPU Mounter is a kubernetes plugin which enables add or remove GPU resources for running Pods. This Introduction(In Chinese) is recommende

Jan 5, 2023
CLI Tool to remove unwanted connections from your Chia Node based on Geo IP Location.

chia-bouncer Tiny CLI tool to remove unwanted connections from your Chia Node based on the Geo IP Location (Country). The Tool is written in golang an

Jun 25, 2021