Skip to content

Commit

Permalink
Add staticcheck and fix issues
Browse files Browse the repository at this point in the history
This adds staticcheck as a linter to Zap and fixes issues found by it.
Specifically, it found a few unused unexported types and functions.
  • Loading branch information
abhinav committed Mar 5, 2020
1 parent e3c26b6 commit 9646482
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
8 changes: 7 additions & 1 deletion Makefile
@@ -1,6 +1,7 @@
export GOBIN ?= $(shell pwd)/bin

GOLINT = $(GOBIN)/golint
STATICCHECK = $(GOBIN)/staticcheck
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem

# Directories containing independent Go modules.
Expand All @@ -17,14 +18,16 @@ GO_FILES := $(shell \
all: lint test

.PHONY: lint
lint: $(GOLINT)
lint: $(GOLINT) $(STATICCHECK)
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
@echo "Checking vet..."
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking lint..."
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking staticcheck..."
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(STATICCHECK) ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e Makefile | tee -a lint.log
@echo "Checking for license headers..."
Expand All @@ -34,6 +37,9 @@ lint: $(GOLINT)
$(GOLINT):
go install golang.org/x/lint/golint

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

.PHONY: test
test:
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -8,4 +8,5 @@ require (
go.uber.org/atomic v1.6.0
go.uber.org/multierr v1.5.0
golang.org/x/lint v0.0.0-20190930215403-16217165b5de
honnef.co/go/tools v0.0.1-2019.2.3
)
4 changes: 0 additions & 4 deletions sugar_test.go
Expand Up @@ -159,10 +159,6 @@ func TestSugarFieldsInvalidPairs(t *testing.T) {
})
}

type stringerF func() string

func (f stringerF) String() string { return f() }

func TestSugarStructuredLogging(t *testing.T) {
tests := []struct {
msg string
Expand Down
1 change: 1 addition & 0 deletions tools_test.go
Expand Up @@ -25,4 +25,5 @@ package zap
import (
// Tools we use during development.
_ "golang.org/x/lint/golint"
_ "honnef.co/go/tools/cmd/staticcheck"
)
8 changes: 0 additions & 8 deletions zapcore/encoder_test.go
Expand Up @@ -67,14 +67,6 @@ func humanEncoderConfig() EncoderConfig {
return cfg
}

func withJSONEncoder(f func(Encoder)) {
f(NewJSONEncoder(testEncoderConfig()))
}

func withConsoleEncoder(f func(Encoder)) {
f(NewConsoleEncoder(humanEncoderConfig()))
}

func capitalNameEncoder(loggerName string, enc PrimitiveArrayEncoder) {
enc.AppendString(strings.ToUpper(loggerName))
}
Expand Down
5 changes: 0 additions & 5 deletions zapcore/error.go
Expand Up @@ -66,11 +66,6 @@ type errorGroup interface {
Errors() []error
}

type causer interface {
// Provides access to the error that caused this error.
Cause() error
}

// Note that errArry and errArrayElem are very similar to the version
// implemented in the top-level error.go file. We can't re-use this because
// that would require exporting errArray as part of the zapcore API.
Expand Down

0 comments on commit 9646482

Please sign in to comment.