Skip to content

Commit 50b197f

Browse files
authored
Merge pull request #110 from uthark/gometalinter
Add gometalinter to pre-commit hook
2 parents 8127b09 + 6fd0330 commit 50b197f

File tree

12 files changed

+43
-118
lines changed

12 files changed

+43
-118
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ before_install:
1313
- go get -u github.com/onsi/ginkgo/ginkgo
1414
- go get -u github.com/monopole/mdrip
1515
- go get -u github.com/fzipp/gocyclo
16+
- go get -u gopkg.in/alecthomas/gometalinter.v2 && gometalinter.v2 --install
1617

1718
# Install must be set to prevent default `go get` to run.
1819
# The dependencies have already been vendored by `dep` so

bin/pre-commit.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
# Make sure, we run in the root of the repo and
45
# therefore run the tests on all packages
@@ -36,14 +37,27 @@ function testGoCyclo {
3637
diff <(echo -n) <(go_dirs | xargs -0 gocyclo -over 15)
3738
}
3839

39-
function testGoImports {
40-
diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l)
41-
}
42-
4340
function testGoLint {
4441
diff -u <(echo -n) <(go_dirs | xargs -0 golint --min_confidence 0.85 )
4542
}
4643

44+
function testGoMetalinter {
45+
diff -u <(echo -n) <(go_dirs | xargs -0 gometalinter.v2 --disable-all --deadline 5m \
46+
--enable=misspell \
47+
--enable=structcheck \
48+
--enable=deadcode \
49+
--enable=goimports \
50+
--enable=varcheck \
51+
--enable=goconst \
52+
--enable=ineffassign \
53+
--enable=nakedret \
54+
--enable=interfacer \
55+
--enable=misspell \
56+
--line-length=170 --enable=lll \
57+
--dupl-threshold=400 --enable=dupl)
58+
}
59+
60+
4761
function testGoVet {
4862
go vet -all ./...
4963
}
@@ -57,7 +71,7 @@ function testExamples {
5771
}
5872

5973
runTest testGoFmt
60-
runTest testGoImports
74+
runTest testGoMetalinter
6175
runTest testGoLint
6276
runTest testGoVet
6377
runTest testGoCyclo

pkg/commands/configmap.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
7676
&config.FileSources,
7777
"from-file",
7878
[]string{},
79-
"Key file can be specified using its file path, in which case file basename will be used as configmap key, or optionally with a key and file path, in which case the given key will be used. Specifying a directory will iterate each named file in the directory whose basename is a valid configmap key.")
79+
"Key file can be specified using its file path, in which case file basename will be used as configmap "+
80+
"key, or optionally with a key and file path, in which case the given key will be used. Specifying a "+
81+
"directory will iterate each named file in the directory whose basename is a valid configmap key.")
8082
cmd.Flags().StringArrayVar(
8183
&config.LiteralSources,
8284
"from-literal",

pkg/commands/init.go

Lines changed: 0 additions & 96 deletions
This file was deleted.

pkg/configmapandsecret/util/env_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func processEnvFileLine(line []byte, filePath string,
6666
// from the environment.
6767
value = os.Getenv(key)
6868
}
69-
return
69+
return key, value, err
7070
}
7171

7272
// addFromEnvFile processes an env file allows a generic addTo to handle the

pkg/configmapandsecret/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ParseRFC3339(s string, nowFn func() metav1.Time) (metav1.Time, error) {
4242
}
4343

4444
// HashObject encodes object using given codec and returns MD5 sum of the result.
45-
func HashObject(obj runtime.Object, codec runtime.Codec) (string, error) {
45+
func HashObject(obj runtime.Object, codec runtime.Encoder) (string, error) {
4646
data, err := runtime.Encode(codec, obj)
4747
if err != nil {
4848
return "", err

pkg/diff/program.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ func newProgram(out, errOut io.Writer) *program {
3939
}
4040

4141
func (d *program) makeCommand(args ...string) exec.Cmd {
42-
diff := ""
42+
diff := "diff"
4343
if envDiff := os.Getenv("KUBERNETES_EXTERNAL_DIFF"); envDiff != "" {
4444
diff = envDiff
4545
} else {
46-
diff = "diff"
4746
args = append([]string{"-u", "-N"}, args...)
4847
}
4948
cmd := exec.New().Command(diff, args...)

pkg/exec/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestExecutorNoArgs(t *testing.T) {
5454
}
5555

5656
cmd = ex.Command("/does/not/exist")
57-
out, err = cmd.CombinedOutput()
57+
_, err = cmd.CombinedOutput()
5858
if err == nil {
5959
t.Errorf("expected failure, got nil error")
6060
}

pkg/fs/fakefile.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ type FakeFile struct {
3131
open bool
3232
}
3333

34-
// makeFile makes a fake file.
35-
func makeFile() *FakeFile {
36-
return &FakeFile{}
37-
}
38-
3934
// makeDir makes a fake directory.
4035
func makeDir(name string) *FakeFile {
4136
return &FakeFile{name: name, dir: true}

pkg/hash/hash_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,19 @@ func TestEncodeConfigMap(t *testing.T) {
9696
// one key
9797
{"one key", &v1.ConfigMap{Data: map[string]string{"one": ""}}, `{"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
9898
// three keys (tests sorting order)
99-
{"three keys", &v1.ConfigMap{Data: map[string]string{"two": "2", "one": "", "three": "3"}}, `{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}`, ""},
99+
{"three keys", &v1.ConfigMap{Data: map[string]string{"two": "2", "one": "", "three": "3"}},
100+
`{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}`, ""},
100101
// empty binary map
101102
{"empty data", &v1.ConfigMap{BinaryData: map[string][]byte{}}, `{"data":null,"kind":"ConfigMap","name":""}`, ""},
102103
// one key with binary data
103-
{"one key", &v1.ConfigMap{BinaryData: map[string][]byte{"one": []byte("")}}, `{"binaryData":{"one":""},"data":null,"kind":"ConfigMap","name":""}`, ""},
104+
{"one key", &v1.ConfigMap{BinaryData: map[string][]byte{"one": []byte("")}},
105+
`{"binaryData":{"one":""},"data":null,"kind":"ConfigMap","name":""}`, ""},
104106
// three keys with binary data (tests sorting order)
105-
{"three keys", &v1.ConfigMap{BinaryData: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}}, `{"binaryData":{"one":"","three":"Mw==","two":"Mg=="},"data":null,"kind":"ConfigMap","name":""}`, ""},
107+
{"three keys", &v1.ConfigMap{BinaryData: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}},
108+
`{"binaryData":{"one":"","three":"Mw==","two":"Mg=="},"data":null,"kind":"ConfigMap","name":""}`, ""},
106109
// two keys, one string and one binary values
107-
{"two keys with one each", &v1.ConfigMap{Data: map[string]string{"one": ""}, BinaryData: map[string][]byte{"two": []byte("")}}, `{"binaryData":{"two":""},"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
110+
{"two keys with one each", &v1.ConfigMap{Data: map[string]string{"one": ""}, BinaryData: map[string][]byte{"two": []byte("")}},
111+
`{"binaryData":{"two":""},"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
108112
}
109113
for _, c := range cases {
110114
s, err := encodeConfigMap(c.cm)
@@ -129,7 +133,11 @@ func TestEncodeSecret(t *testing.T) {
129133
// one key
130134
{"one key", &v1.Secret{Type: "my-type", Data: map[string][]byte{"one": []byte("")}}, `{"data":{"one":""},"kind":"Secret","name":"","type":"my-type"}`, ""},
131135
// three keys (tests sorting order) - note json.Marshal base64 encodes the values because they come in as []byte
132-
{"three keys", &v1.Secret{Type: "my-type", Data: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}}, `{"data":{"one":"","three":"Mw==","two":"Mg=="},"kind":"Secret","name":"","type":"my-type"}`, ""},
136+
{"three keys", &v1.Secret{
137+
Type: "my-type",
138+
Data: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")},
139+
},
140+
`{"data":{"one":"","three":"Mw==","two":"Mg=="},"kind":"Secret","name":"","type":"my-type"}`, ""},
133141
}
134142
for _, c := range cases {
135143
s, err := encodeSecret(c.secret)

0 commit comments

Comments
 (0)