From 3dca5774dd8d767c3a1a4040b1ea5a6d864ce70f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 4 Jun 2019 15:48:17 +0200 Subject: [PATCH] Updated linter and fixed warnings --- .golangci.yml | 7 +++++++ .travis.yml | 4 +--- common/formatter/formatter.go | 14 +++++--------- configs/navigate_test.go | 7 ++++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d8763c0b1d1..fd1caa762db 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,7 @@ +run: + skip-dirs: + - legacy + linters-settings: govet: check-shadowing: true @@ -21,6 +25,9 @@ linters-settings: linters: enable-all: true disable: + - goimports + - gocritic + - gochecknoglobals - gosec - deadcode - dupl diff --git a/.travis.yml b/.travis.yml index 0324dc0e39b..766eaac31cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,7 @@ env: # build and immediately stop. It's sorta like having set -e enabled in bash. # Make sure golangci-lint is vendored. before_install: - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.10.2 - # Download the binary to bin folder in $GOPATH - - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep + - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.16.0 install: true diff --git a/common/formatter/formatter.go b/common/formatter/formatter.go index 47eb0582c62..b06a30031bf 100644 --- a/common/formatter/formatter.go +++ b/common/formatter/formatter.go @@ -37,18 +37,14 @@ type Formatter interface { // PrintFunc represents a function used to print formatted data. type PrintFunc func(Formatter, interface{}) error -var formatters map[string]Formatter -var defaultFormatter Formatter +var formatters = map[string]Formatter{ + "text": &TextFormatter{}, + "json": &JSONFormatter{}, +} +var defaultFormatter = formatters["text"] var logger *logrus.Logger -func init() { - formatters = make(map[string]Formatter, 2) - AddCustomFormatter("text", &TextFormatter{}) - AddCustomFormatter("json", &JSONFormatter{}) - defaultFormatter = formatters["text"] -} - // SetFormatter sets the defaults format to the one specified, if valid. Otherwise it returns an error. func SetFormatter(formatName string) error { if !IsSupported(formatName) { diff --git a/configs/navigate_test.go b/configs/navigate_test.go index be343d40a2b..6c188933de9 100644 --- a/configs/navigate_test.go +++ b/configs/navigate_test.go @@ -36,9 +36,10 @@ func TestNavigate(t *testing.T) { "inheritance", } for _, tt := range tests { - t.Run(tt, func(t *testing.T) { - pwd := paths.New("testdata", "navigate", tt, "first", "second") - golden := filepath.Join("testdata", "navigate", tt, "golden.yaml") + _tt := tt + t.Run(_tt, func(t *testing.T) { + pwd := paths.New("testdata", "navigate", _tt, "first", "second") + golden := filepath.Join("testdata", "navigate", _tt, "golden.yaml") config, _ := configs.NewConfiguration()