Skip to content

Commit

Permalink
Add staticcheck and fix issues (#79)
Browse files Browse the repository at this point in the history
This adds `staticcheck` to `make lint` and fixes issues found by it.
  • Loading branch information
abhinav authored Sep 11, 2020
2 parents 501585e + cd88893 commit e315f06
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 23 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export GOBIN ?= $(shell pwd)/bin
GOLINT = $(GOBIN)/golint
GEN_ATOMICINT = $(GOBIN)/gen-atomicint
GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper
STATICCHECK = $(GOBIN)/staticcheck

GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print)

Expand All @@ -29,6 +30,9 @@ gofmt:
$(GOLINT):
cd tools && go install golang.org/x/lint/golint

$(STATICCHECK):
cd tools && go install honnef.co/go/tools/cmd/staticcheck

$(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*)
go build -o $@ ./internal/gen-atomicwrapper

Expand All @@ -39,8 +43,12 @@ $(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*)
golint: $(GOLINT)
$(GOLINT) ./...

.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) ./...

.PHONY: lint
lint: gofmt golint generatenodirty
lint: gofmt golint staticcheck generatenodirty

# comma separated list of packages to consider for code coverage.
COVER_PKG = $(shell \
Expand Down
2 changes: 1 addition & 1 deletion bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// Bool is an atomic type-safe wrapper for bool values.
type Bool struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v Uint32
}
Expand Down
2 changes: 1 addition & 1 deletion duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// Duration is an atomic type-safe wrapper for time.Duration values.
type Duration struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v Int64
}
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package atomic

// Error is an atomic type-safe wrapper for error values.
type Error struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v Value
}
Expand Down
2 changes: 1 addition & 1 deletion float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// Float64 is an atomic type-safe wrapper for float64 values.
type Float64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v Uint64
}
Expand Down
2 changes: 1 addition & 1 deletion int32.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Int32 is an atomic wrapper around int32.
type Int32 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v int32
}
Expand Down
2 changes: 1 addition & 1 deletion int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Int64 is an atomic wrapper around int64.
type Int64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v int64
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gen-atomicint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import (
// {{ .Name }} is an atomic wrapper around {{ .Wrapped }}.
type {{ .Name }} struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v {{ .Wrapped }}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gen-atomicwrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ import (
// {{ .Name }} is an atomic type-safe wrapper for {{ .Type }} values.
type {{ .Name }} struct{
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison
v {{ .Wrapped }}
}
Expand Down
11 changes: 5 additions & 6 deletions nocmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ func TestNocmpComparability(t *testing.T) {

// nocmp must not add to the size of a struct in-memory.
func TestNocmpSize(t *testing.T) {
type x struct{ i int }
type x struct{ _ int }

before := reflect.TypeOf(x{}).Size()

type y struct {
nocmp

x x
_ nocmp
_ x
}

after := reflect.TypeOf(x{}).Size()
after := reflect.TypeOf(y{}).Size()

assert.Equal(t, before, after,
"expected nocmp to have no effect on struct size")
Expand All @@ -100,7 +99,7 @@ func TestNocmpSize(t *testing.T) {
// var x atomic.Int32
// x = atomic.NewInt32(1)
func TestNocmpCopy(t *testing.T) {
type foo struct{ nocmp }
type foo struct{ _ nocmp }

t.Run("struct copy", func(t *testing.T) {
a := foo{}
Expand Down
2 changes: 1 addition & 1 deletion stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
var _stressTests = map[string]func() func(){
"i32/std": stressStdInt32,
"i32": stressInt32,
"i64/std": stressStdInt32,
"i64/std": stressStdInt64,
"i64": stressInt64,
"u32/std": stressStdUint32,
"u32": stressUint32,
Expand Down
2 changes: 1 addition & 1 deletion string.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package atomic

// String is an atomic type-safe wrapper for string values.
type String struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v Value
}
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module go.uber.org/atomic/tools

require (
golang.org/x/lint v0.0.0-20190930215403-16217165b5de
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c // indirect
honnef.co/go/tools v0.0.1-2020.1.5
)

go 1.13
20 changes: 18 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
honnef.co/go/tools v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
1 change: 1 addition & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ package tools
import (
// Tools used during development.
_ "golang.org/x/lint/golint"
_ "honnef.co/go/tools/cmd/staticcheck"
)
2 changes: 1 addition & 1 deletion uint32.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Uint32 is an atomic wrapper around uint32.
type Uint32 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v uint32
}
Expand Down
2 changes: 1 addition & 1 deletion uint64.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// Uint64 is an atomic wrapper around uint64.
type Uint64 struct {
nocmp // disallow non-atomic comparison
_ nocmp // disallow non-atomic comparison

v uint64
}
Expand Down
3 changes: 2 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "sync/atomic"
// Value shadows the type of the same name from sync/atomic
// https://godoc.org/sync/atomic#Value
type Value struct {
nocmp // disallow non-atomic comparison
atomic.Value

_ nocmp // disallow non-atomic comparison
}

0 comments on commit e315f06

Please sign in to comment.