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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 3 additions & 1 deletion
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 1 addition & 3 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 6 additions & 6 deletions
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‎

Lines changed: 3 additions & 3 deletions
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‎

Lines changed: 4 additions & 4 deletions
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‎

Lines changed: 2 additions & 2 deletions
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)

0 commit comments

Comments
 (0)