Skip to content

Commit 22498e2

Browse files
authored
Implement new gometalinter capabilities and take care of warnings about them (#464)
* Updated build-tools to 1.5.1 https://github.com/drud/build-tools/releases/tag/1.5.1 * gofmt -s -w updates for dockerutils.go pkg/dockerutil/dockerutils.go:1::warning: file is not gofmted with -s (gofmt) * gofmt -s simplification of local_test.go * gofmt -s simplify utils.go for loop * gofmt -s simplify testcommon_test.go array definition * Add gometalinter pragma/comment to ignore utils.go setLetterBytes() * Add vetshadow to GOMETALINTER_ARGS * Change assert import to asrt to lose shadow warnings * Change homedir imports to gohomedir to avoid shadowing * Fix several shadow warnings, pragma out the others * Make 'staticrequired' target an alias of 'gometalinter' * Use gometalinter instead of staticrequired in circleci
1 parent fe18da2 commit 22498e2

38 files changed

+138
-129
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
name: ddev tests
3232
no_output_timeout: "20m"
3333

34-
- run: make -s staticrequired
34+
- run: make -s gometalinter
3535

3636
- run:
3737
command: bin/linux/ddev version
@@ -88,7 +88,7 @@ jobs:
8888
name: ddev tests
8989
no_output_timeout: "20m"
9090

91-
- run: make -s staticrequired
91+
- run: make -s gometalinter
9292

9393
# Now build using the regular ddev-only technique - this results in a fully clean set of executables.
9494
# Earlier process updated submodules so now we clean them up to continue.

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Makefile for a standard golang repo with associated container
22

3+
GOMETALINTER_ARGS := --vendored-linters --disable-all --enable=gofmt --enable=vet --enable vetshadow --enable=golint --enable=errcheck --enable=staticcheck --enable=ineffassign --enable=varcheck --enable=deadcode --deadline=2m
4+
35
##### These variables need to be adjusted in most repositories #####
46

57
# This repo's root import path (under GOPATH).
@@ -89,4 +91,4 @@ setup:
8991
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/linux
9092

9193
# Required static analysis targets used in circleci - these cause fail if they don't work
92-
staticrequired: gofmt govet golint errcheck staticcheck codecoroner
94+
staticrequired: gometalinter

build-tools/circleci-config-yaml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ stages:
1616

1717
- run: make test
1818

19-
- run: make -s gofmt golint
19+
- run: make -s gometalinter
2020

build-tools/makefile_components/base_build_go.mak

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BUILD_BASE_DIR ?= $$PWD
2121
# Expands SRC_DIRS into the common golang ./dir/... format for "all below"
2222
SRC_AND_UNDER = $(patsubst %,./%/...,$(SRC_DIRS))
2323

24-
GOMETALINTER_ARGS ?= --vendored-linters --disable=gocyclo --disable=gotype --disable=goconst --disable=gas --deadline=2m
24+
GOMETALINTER_ARGS ?= --vendored-linters --disable-all --enable=gofmt --enable=vet --enable=golint --enable=errcheck --enable=staticcheck --enable=ineffassign --enable=varcheck --enable=deadcode --deadline=2m
2525

2626

2727
COMMIT := $(shell git describe --tags --always --dirty)
@@ -59,8 +59,6 @@ linux darwin windows: $(GOFILES)
5959
@$(shell touch $@)
6060
@echo $(VERSION) >VERSION.txt
6161

62-
static: govendor gofmt govet lint
63-
6462
govendor:
6563
@echo -n "Using govendor to check for missing dependencies and unused dependencies: "
6664
@docker run -t --rm -u $(shell id -u):$(shell id -g) \

cmd/ddev/cmd/auth_pantheon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/drud/ddev/pkg/util"
77
"github.com/drud/go-pantheon/pkg/pantheon"
8-
"github.com/mitchellh/go-homedir"
8+
gohomedir "github.com/mitchellh/go-homedir"
99
"github.com/spf13/cobra"
1010
)
1111

@@ -22,7 +22,7 @@ var PantheonAuthCommand = &cobra.Command{
2222
if len(args) != 1 {
2323
util.Failed("Too many arguments detected. Please provide only your Pantheon Machine token., e.g. `ddev auth-pantheon [token]`. See https://pantheon.io/docs/machine-tokens/ for instructions on creating a token.")
2424
}
25-
userDir, err := homedir.Dir()
25+
userDir, err := gohomedir.Dir()
2626
util.CheckErr(err)
2727
sessionLocation := filepath.Join(userDir, ".ddev", "pantheonconfig.json")
2828

cmd/ddev/cmd/describe_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"github.com/drud/ddev/pkg/plugins/platform"
88
"github.com/drud/ddev/pkg/testcommon"
99
"github.com/drud/ddev/pkg/util"
10-
"github.com/stretchr/testify/assert"
10+
asrt "github.com/stretchr/testify/assert"
1111
)
1212

1313
// TestDescribeBadArgs ensures the binary behaves as expected when used with invalid arguments or working directories.
1414
func TestDescribeBadArgs(t *testing.T) {
15-
assert := assert.New(t)
15+
assert := asrt.New(t)
1616

1717
// Create a temporary directory and switch to it for the duration of this test.
1818
tmpdir := testcommon.CreateTmpDir("badargs")
@@ -41,7 +41,7 @@ func TestDescribeBadArgs(t *testing.T) {
4141

4242
// TestDescribe tests that the describe command works properly when using the binary.
4343
func TestDescribe(t *testing.T) {
44-
assert := assert.New(t)
44+
assert := asrt.New(t)
4545

4646
for _, v := range DevTestSites {
4747
// First, try to do a describe from another directory.
@@ -75,7 +75,7 @@ func TestDescribe(t *testing.T) {
7575

7676
// TestDescribeAppFunction performs unit tests on the describeApp function from the working directory.
7777
func TestDescribeAppFunction(t *testing.T) {
78-
assert := assert.New(t)
78+
assert := asrt.New(t)
7979
for _, v := range DevTestSites {
8080
cleanup := v.Chdir()
8181

@@ -104,7 +104,7 @@ func TestDescribeAppFunction(t *testing.T) {
104104

105105
// TestDescribeAppUsingSitename performs unit tests on the describeApp function using the sitename as an argument.
106106
func TestDescribeAppUsingSitename(t *testing.T) {
107-
assert := assert.New(t)
107+
assert := asrt.New(t)
108108

109109
// Create a temporary directory and switch to it for the duration of this test.
110110
tmpdir := testcommon.CreateTmpDir("describeAppUsingSitename")
@@ -121,7 +121,7 @@ func TestDescribeAppUsingSitename(t *testing.T) {
121121

122122
// TestDescribeAppWithInvalidParams performs unit tests on the describeApp function using a variety of invalid parameters.
123123
func TestDescribeAppWithInvalidParams(t *testing.T) {
124-
assert := assert.New(t)
124+
assert := asrt.New(t)
125125

126126
// Create a temporary directory and switch to it for the duration of this test.
127127
tmpdir := testcommon.CreateTmpDir("TestDescribeAppWithInvalidParams")

cmd/ddev/cmd/exec_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"testing"
55

66
"github.com/drud/ddev/pkg/exec"
7-
"github.com/stretchr/testify/assert"
7+
asrt "github.com/stretchr/testify/assert"
88
)
99

1010
// TestDevExecBadArgs run `ddev exec` without the proper args
1111
func TestDevExecBadArgs(t *testing.T) {
1212
// Change to the first DevTestSite for the duration of this test.
1313
defer DevTestSites[0].Chdir()()
14-
assert := assert.New(t)
14+
assert := asrt.New(t)
1515

1616
args := []string{"exec"}
1717
out, err := exec.RunCommand(DdevBin, args)
@@ -22,7 +22,7 @@ func TestDevExecBadArgs(t *testing.T) {
2222
// TestDevExec run `ddev exec pwd` with proper args
2323
func TestDevExec(t *testing.T) {
2424

25-
assert := assert.New(t)
25+
assert := asrt.New(t)
2626
for _, v := range DevTestSites {
2727
cleanup := v.Chdir()
2828

cmd/ddev/cmd/import_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99

1010
"github.com/drud/ddev/pkg/exec"
1111
"github.com/drud/ddev/pkg/fileutil"
12-
homedir "github.com/mitchellh/go-homedir"
13-
"github.com/stretchr/testify/assert"
12+
gohomedir "github.com/mitchellh/go-homedir"
13+
asrt "github.com/stretchr/testify/assert"
1414
)
1515

1616
// TestImportTilde tests passing paths to import-files that use ~ to represent home dir.
1717
func TestImportTilde(t *testing.T) {
18-
assert := assert.New(t)
18+
assert := asrt.New(t)
1919

2020
for _, site := range DevTestSites {
2121

22-
homedir, err := homedir.Dir()
22+
homedir, err := gohomedir.Dir()
2323
assert.NoError(err)
2424
cwd, _ := os.Getwd()
2525
testFile := filepath.Join(homedir, "testfile.tar.gz")

cmd/ddev/cmd/list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55

66
"github.com/drud/ddev/pkg/exec"
77
"github.com/drud/ddev/pkg/plugins/platform"
8-
"github.com/stretchr/testify/assert"
8+
asrt "github.com/stretchr/testify/assert"
99
)
1010

1111
func TestDevList(t *testing.T) {
12-
assert := assert.New(t)
12+
assert := asrt.New(t)
1313
args := []string{"list"}
1414
out, err := exec.RunCommand(DdevBin, args)
1515
assert.NoError(err)

cmd/ddev/cmd/logs_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/drud/ddev/pkg/exec"
1212
"github.com/drud/ddev/pkg/testcommon"
1313
"github.com/drud/ddev/pkg/util"
14-
"github.com/stretchr/testify/assert"
14+
asrt "github.com/stretchr/testify/assert"
1515
)
1616

1717
func TestDevLogsBadArgs(t *testing.T) {
18-
assert := assert.New(t)
18+
assert := asrt.New(t)
1919

2020
testDir := testcommon.CreateTmpDir("no-valid-ddev-config")
2121

@@ -32,7 +32,7 @@ func TestDevLogsBadArgs(t *testing.T) {
3232

3333
// TestDevLogs tests that the Dev logs functionality is working.
3434
func TestDevLogs(t *testing.T) {
35-
assert := assert.New(t)
35+
assert := asrt.New(t)
3636

3737
for _, v := range DevTestSites {
3838
cleanup := v.Chdir()

cmd/ddev/cmd/pull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func appImport(skipConfirmation bool) {
4141
if !skipConfirmation {
4242
// Unfortunately we cannot use util.Warning here as it automatically adds a newline, which is awkward when dealing with prompts.
4343
d := color.New(color.FgYellow)
44-
_, err := d.Printf("You're about to delete the current database and files and replace with a fresh import. Would you like to continue (y/N): ")
44+
_, err = d.Printf("You're about to delete the current database and files and replace with a fresh import. Would you like to continue (y/N): ")
4545
util.CheckErr(err)
4646
if !util.AskForConfirmation() {
4747
util.Warning("Import cancelled.")

cmd/ddev/cmd/remove_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"testing"
55

66
"github.com/drud/ddev/pkg/exec"
7-
"github.com/stretchr/testify/assert"
7+
asrt "github.com/stretchr/testify/assert"
88
)
99

1010
// TestDevRestart runs `drud legacy restart` on the test apps
1111
func TestDevRemove(t *testing.T) {
12-
assert := assert.New(t)
12+
assert := asrt.New(t)
1313

1414
// Make sure we have running sites.
1515
addSites()

cmd/ddev/cmd/restart_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66

77
"github.com/drud/ddev/pkg/exec"
88
"github.com/drud/ddev/pkg/plugins/platform"
9-
"github.com/stretchr/testify/assert"
9+
asrt "github.com/stretchr/testify/assert"
1010
)
1111

1212
// TestDevRestart runs `drud legacy restart` on the test apps
1313
func TestDevRestart(t *testing.T) {
14-
assert := assert.New(t)
14+
assert := asrt.New(t)
1515
containerPrefix := "ddev"
1616
for _, site := range DevTestSites {
1717
cleanup := site.Chdir()

cmd/ddev/cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var RootCmd = &cobra.Command{
6262
}
6363

6464
if timeToCheckForUpdates {
65+
// nolint: vetshadow
6566
updateNeeded, updateURL, err := updatecheck.AvailableUpdates("drud", "ddev", version.DdevVersion)
6667

6768
if err != nil {

cmd/ddev/cmd/root_test.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/drud/ddev/pkg/appports"
1515
"github.com/drud/ddev/pkg/exec"
1616
"github.com/drud/ddev/pkg/plugins/platform"
17-
"github.com/stretchr/testify/assert"
17+
asrt "github.com/stretchr/testify/assert"
1818
)
1919

2020
var (
@@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
6767
}
6868

6969
func TestGetActiveAppRoot(t *testing.T) {
70-
assert := assert.New(t)
70+
assert := asrt.New(t)
7171

7272
_, err := platform.GetActiveAppRoot("")
7373
assert.Contains(err.Error(), "unable to determine the application for this command")
@@ -90,35 +90,37 @@ func TestGetActiveAppRoot(t *testing.T) {
9090

9191
// TestCreateGlobalDdevDir checks to make sure that ddev will create a ~/.ddev (and updatecheck)
9292
func TestCreateGlobalDdevDir(t *testing.T) {
93+
assert := asrt.New(t)
94+
9395
tmpDir := testcommon.CreateTmpDir("globalDdevCheck")
9496
origHome := os.Getenv("HOME")
9597

9698
// Make sure that the tmpDir/.ddev and tmpDir/.ddev/.update don't exist before we run ddev.
9799
_, err := os.Stat(filepath.Join(tmpDir, ".ddev"))
98-
assert.Error(t, err)
99-
assert.True(t, os.IsNotExist(err))
100+
assert.Error(err)
101+
assert.True(os.IsNotExist(err))
100102

101103
_, err = os.Stat(filepath.Join(tmpDir, ".ddev", ".update"))
102-
assert.Error(t, err)
103-
assert.True(t, os.IsNotExist(err))
104+
assert.Error(err)
105+
assert.True(os.IsNotExist(err))
104106

105107
// Change the homedir temporarily
106108
err = os.Setenv("HOME", tmpDir)
107-
assert.NoError(t, err)
109+
assert.NoError(err)
108110

109111
args := []string{"list"}
110112
_, err = exec.RunCommand(DdevBin, args)
111-
assert.NoError(t, err)
113+
assert.NoError(err)
112114

113115
_, err = os.Stat(filepath.Join(tmpDir, ".ddev", ".update"))
114-
assert.NoError(t, err)
116+
assert.NoError(err)
115117

116118
// Cleanup our tmp homedir
117119
err = os.RemoveAll(tmpDir)
118-
assert.NoError(t, err)
120+
assert.NoError(err)
119121

120122
err = os.Setenv("HOME", origHome)
121-
assert.NoError(t, err)
123+
assert.NoError(err)
122124
}
123125

124126
// addSites runs `ddev start` on the test apps

cmd/ddev/cmd/sequelpro_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
"github.com/drud/ddev/pkg/fileutil"
99
"github.com/drud/ddev/pkg/plugins/platform"
1010
"github.com/drud/ddev/pkg/testcommon"
11-
"github.com/stretchr/testify/assert"
11+
asrt "github.com/stretchr/testify/assert"
1212
)
1313

1414
// TestSequelproOperation tests basic operation.
1515
func TestSequelproOperation(t *testing.T) {
1616
if !detectSequelpro() {
1717
t.SkipNow()
1818
}
19-
assert := assert.New(t)
19+
assert := asrt.New(t)
2020
v := DevTestSites[0]
2121
cleanup := v.Chdir()
2222

@@ -40,7 +40,7 @@ func TestSequelproBadApp(t *testing.T) {
4040
t.SkipNow()
4141
}
4242

43-
assert := assert.New(t)
43+
assert := asrt.New(t)
4444

4545
// Create a temporary directory and switch to it for the duration of this test.
4646
tmpdir := testcommon.CreateTmpDir("sequelpro_badargs")

cmd/ddev/cmd/version_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"testing"
66

77
"github.com/drud/ddev/pkg/version"
8-
"github.com/stretchr/testify/assert"
8+
asrt "github.com/stretchr/testify/assert"
99
)
1010

1111
func TestVersion(t *testing.T) {
12-
assert := assert.New(t)
12+
assert := asrt.New(t)
1313
v := handleVersionCommand().String()
1414
output := strings.TrimSpace(v)
1515
assert.Contains(output, version.DdevVersion)

pkg/appimport/appimport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"path/filepath"
1111

12-
homedir "github.com/mitchellh/go-homedir"
12+
gohomedir "github.com/mitchellh/go-homedir"
1313
)
1414

1515
// ValidateAsset determines if a given asset matches the required criteria for a given asset type.
@@ -19,7 +19,7 @@ func ValidateAsset(assetPath string, assetType string) (string, error) {
1919
extensions := []string{"tar", "gz", "tgz", "zip"}
2020

2121
// Input provided via prompt or "--flag=value" is not expanded by shell. This will help ensure ~ is expanded to the user home directory.
22-
assetPath, err := homedir.Expand(assetPath)
22+
assetPath, err := gohomedir.Expand(assetPath)
2323
if err != nil {
2424
return "", fmt.Errorf(invalidAssetError, err)
2525
}

0 commit comments

Comments
 (0)