From e57067747fb76e84ccd3d4c54c75e098427f9a3c Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 10:01:39 +0200 Subject: [PATCH 1/6] Move linter configuration into .golangci.yml --- .golangci.yml | 28 ++++++++++++++++++++++++++++ hack/run-lint.sh | 21 ++------------------- 2 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..0ab3b74e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +# options for analysis running +run: + # which dirs to skip: they won't be analyzed; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but next dirs are always skipped independently + # from this option's value: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs: + - hack + - docs + +linters: + enable: + - gocritic + - goimports + - golint + - gosimple + - interfacer + - maligned + - misspell + - unconvert + - unparam + - stylecheck + - staticcheck + - structcheck + - prealloc + disable: + - errcheck diff --git a/hack/run-lint.sh b/hack/run-lint.sh index 95710c61..6ad52a06 100755 --- a/hack/run-lint.sh +++ b/hack/run-lint.sh @@ -16,28 +16,11 @@ set -euo pipefail -SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) - if ! [[ -x "$GOPATH/bin/golangci-lint" ]] then echo 'Installing golangci-lint' curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$GOPATH/bin" v1.16.0 fi -"$GOPATH/bin/golangci-lint" run \ - --no-config \ - -D errcheck \ - -E gocritic \ - -E goimports \ - -E golint \ - -E gosimple \ - -E interfacer \ - -E maligned \ - -E misspell \ - -E unconvert \ - -E unparam \ - -E stylecheck \ - -E staticcheck \ - -E structcheck \ - -E prealloc \ - --skip-dirs hack,docs +# configured by .golangci.yml +"$GOPATH/bin/golangci-lint" run From 2e96eaa8bb3c73b3e1a35420a04a7ba0f03a5fb5 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 10:02:19 +0200 Subject: [PATCH 2/6] Expect local import in separate group --- .golangci.yml | 7 +++++++ docs/CONTRIBUTOR_GUIDE.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 0ab3b74e..ff0bbe92 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,10 @@ +# all available settings of specific linters +linters-settings: + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: sigs.k8s.io/krew + # options for analysis running run: # which dirs to skip: they won't be analyzed; diff --git a/docs/CONTRIBUTOR_GUIDE.md b/docs/CONTRIBUTOR_GUIDE.md index f3fa15e1..92f61dbe 100644 --- a/docs/CONTRIBUTOR_GUIDE.md +++ b/docs/CONTRIBUTOR_GUIDE.md @@ -31,7 +31,7 @@ go get golang.org/x/tools/cmd/goimports and run: ```bash -goimports -w cmd pkg +goimports -local sigs.k8s.io/krew -w cmd pkg ``` In addition, a boilerplate license header is expected in all source files. From 3d51f58696f4b577abf8e208a2021df12268b9b6 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 10:03:25 +0200 Subject: [PATCH 3/6] Make verify-gofmt.sh more resilient wrt filenames with spaces --- hack/verify-gofmt.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index a2df0d43..816ba554 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -files=$(find . -name "*.go" | grep -v vendor/ | xargs gofmt -l -s) +set -euo pipefail + +files=$(find . -name "*.go" -not -path './vendor/*' -print0 | xargs -0 gofmt -l -s) if [[ $files ]]; then echo "Gofmt errors in files:" echo "$files" - diff=$(find . -name "*.go" | grep -v vendor/ | xargs gofmt -d -s) + diff=$(find . -name "*.go" -not -path './vendor/*' -print0 | xargs -0 gofmt -d -s) echo "$diff" exit 1 fi From 4bec3b896b73e0e39dda70245aa240ec5f871361 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 10:05:33 +0200 Subject: [PATCH 4/6] Apply standard imports sort order to all go files --- cmd/krew/cmd/list.go | 1 + cmd/krew/cmd/root.go | 10 +++++----- cmd/krew/cmd/search.go | 4 ++-- cmd/krew/cmd/uninstall.go | 6 +++--- cmd/krew/cmd/update.go | 1 + cmd/krew/cmd/version.go | 1 + cmd/krew/main.go | 1 + cmd/validate-krew-manifest/main_test.go | 1 + pkg/download/downloader_test.go | 1 + pkg/environment/environment_test.go | 1 + pkg/index/indexscanner/scanner.go | 6 +++--- pkg/index/validate.go | 1 + pkg/index/validate_test.go | 1 + pkg/installation/install.go | 4 ++-- pkg/installation/util_test.go | 1 + 15 files changed, 25 insertions(+), 15 deletions(-) diff --git a/cmd/krew/cmd/list.go b/cmd/krew/cmd/list.go index 1a85546a..ab1afdda 100644 --- a/cmd/krew/cmd/list.go +++ b/cmd/krew/cmd/list.go @@ -24,6 +24,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "sigs.k8s.io/krew/pkg/installation" ) diff --git a/cmd/krew/cmd/root.go b/cmd/krew/cmd/root.go index 0da61c3c..0941e7a6 100644 --- a/cmd/krew/cmd/root.go +++ b/cmd/krew/cmd/root.go @@ -18,14 +18,14 @@ import ( "flag" "os" - isatty "github.com/mattn/go-isatty" - "github.com/pkg/errors" - "sigs.k8s.io/krew/pkg/environment" - "sigs.k8s.io/krew/pkg/gitutil" - "github.com/golang/glog" + "github.com/mattn/go-isatty" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" + + "sigs.k8s.io/krew/pkg/environment" + "sigs.k8s.io/krew/pkg/gitutil" ) var ( diff --git a/cmd/krew/cmd/search.go b/cmd/krew/cmd/search.go index 22a6b546..f6a7a64d 100644 --- a/cmd/krew/cmd/search.go +++ b/cmd/krew/cmd/search.go @@ -19,11 +19,11 @@ import ( "strings" "github.com/pkg/errors" - "sigs.k8s.io/krew/pkg/index/indexscanner" - "github.com/sahilm/fuzzy" "github.com/spf13/cobra" + "sigs.k8s.io/krew/pkg/index" + "sigs.k8s.io/krew/pkg/index/indexscanner" "sigs.k8s.io/krew/pkg/installation" ) diff --git a/cmd/krew/cmd/uninstall.go b/cmd/krew/cmd/uninstall.go index 106b2a2f..0acf2185 100644 --- a/cmd/krew/cmd/uninstall.go +++ b/cmd/krew/cmd/uninstall.go @@ -18,11 +18,11 @@ import ( "fmt" "os" - "github.com/pkg/errors" - "sigs.k8s.io/krew/pkg/installation" - "github.com/golang/glog" + "github.com/pkg/errors" "github.com/spf13/cobra" + + "sigs.k8s.io/krew/pkg/installation" ) // uninstallCmd represents the uninstall command diff --git a/cmd/krew/cmd/update.go b/cmd/krew/cmd/update.go index 02622969..30ee3a89 100644 --- a/cmd/krew/cmd/update.go +++ b/cmd/krew/cmd/update.go @@ -21,6 +21,7 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/gitutil" ) diff --git a/cmd/krew/cmd/version.go b/cmd/krew/cmd/version.go index 3aa25cd9..b6523abb 100644 --- a/cmd/krew/cmd/version.go +++ b/cmd/krew/cmd/version.go @@ -21,6 +21,7 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" "github.com/spf13/cobra" + "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/environment" "sigs.k8s.io/krew/pkg/version" diff --git a/cmd/krew/main.go b/cmd/krew/main.go index c8498382..666fce35 100644 --- a/cmd/krew/main.go +++ b/cmd/krew/main.go @@ -16,6 +16,7 @@ package main import ( "github.com/golang/glog" + "sigs.k8s.io/krew/cmd/krew/cmd" ) diff --git a/cmd/validate-krew-manifest/main_test.go b/cmd/validate-krew-manifest/main_test.go index 1d23ef9d..2322b4ae 100644 --- a/cmd/validate-krew-manifest/main_test.go +++ b/cmd/validate-krew-manifest/main_test.go @@ -22,6 +22,7 @@ import ( "gopkg.in/yaml.v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/krew/pkg/constants" "sigs.k8s.io/krew/pkg/index" "sigs.k8s.io/krew/pkg/testutil" diff --git a/pkg/download/downloader_test.go b/pkg/download/downloader_test.go index f1995cbc..dbcb5f46 100644 --- a/pkg/download/downloader_test.go +++ b/pkg/download/downloader_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/pkg/errors" + "sigs.k8s.io/krew/pkg/testutil" ) diff --git a/pkg/environment/environment_test.go b/pkg/environment/environment_test.go index ee2bfd44..75fdc6d0 100644 --- a/pkg/environment/environment_test.go +++ b/pkg/environment/environment_test.go @@ -21,6 +21,7 @@ import ( "testing" "k8s.io/client-go/util/homedir" + "sigs.k8s.io/krew/pkg/testutil" ) diff --git a/pkg/index/indexscanner/scanner.go b/pkg/index/indexscanner/scanner.go index 460f5809..6a34d8b1 100644 --- a/pkg/index/indexscanner/scanner.go +++ b/pkg/index/indexscanner/scanner.go @@ -23,11 +23,11 @@ import ( "path/filepath" "strings" - "github.com/pkg/errors" - "sigs.k8s.io/krew/pkg/index" - "github.com/golang/glog" + "github.com/pkg/errors" "k8s.io/apimachinery/pkg/util/yaml" + + "sigs.k8s.io/krew/pkg/index" ) // LoadPluginListFromFS will parse and retrieve all plugin files. diff --git a/pkg/index/validate.go b/pkg/index/validate.go index 545192c3..93ddd1af 100644 --- a/pkg/index/validate.go +++ b/pkg/index/validate.go @@ -19,6 +19,7 @@ import ( "strings" "github.com/pkg/errors" + "sigs.k8s.io/krew/pkg/constants" ) diff --git a/pkg/index/validate_test.go b/pkg/index/validate_test.go index 6bda5b7f..f5fb91f4 100644 --- a/pkg/index/validate_test.go +++ b/pkg/index/validate_test.go @@ -18,6 +18,7 @@ import ( "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/krew/pkg/constants" ) diff --git a/pkg/installation/install.go b/pkg/installation/install.go index d2b7458c..f44c4778 100644 --- a/pkg/installation/install.go +++ b/pkg/installation/install.go @@ -20,13 +20,13 @@ import ( "runtime" "strings" + "github.com/golang/glog" "github.com/pkg/errors" + "sigs.k8s.io/krew/pkg/download" "sigs.k8s.io/krew/pkg/environment" "sigs.k8s.io/krew/pkg/index" "sigs.k8s.io/krew/pkg/pathutil" - - "github.com/golang/glog" ) // Plugin Lifecycle Errors diff --git a/pkg/installation/util_test.go b/pkg/installation/util_test.go index 1cf134bf..54e3b04b 100644 --- a/pkg/installation/util_test.go +++ b/pkg/installation/util_test.go @@ -22,6 +22,7 @@ import ( "testing" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/krew/pkg/index" ) From a2b56e426aed5037c1f63d4454786418771be4d6 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 12:23:08 +0200 Subject: [PATCH 5/6] Fix typos in messages --- pkg/download/downloader_test.go | 4 ++-- pkg/index/indexscanner/scanner_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/download/downloader_test.go b/pkg/download/downloader_test.go index dbcb5f46..b8960dbb 100644 --- a/pkg/download/downloader_test.go +++ b/pkg/download/downloader_test.go @@ -248,12 +248,12 @@ func Test_download(t *testing.T) { } downloadedData, err := ioutil.ReadAll(io.NewSectionReader(reader, 0, size)) if err != nil { - t.Errorf("failed to read downlaod data: %v", err) + t.Errorf("failed to read download data: %v", err) return } wantData, err := ioutil.ReadAll(io.NewSectionReader(tt.wantReader, 0, tt.wantSize)) if err != nil { - t.Errorf("failed to read downlaod data: %v", err) + t.Errorf("failed to read download data: %v", err) return } diff --git a/pkg/index/indexscanner/scanner_test.go b/pkg/index/indexscanner/scanner_test.go index f026a109..0244feb4 100644 --- a/pkg/index/indexscanner/scanner_test.go +++ b/pkg/index/indexscanner/scanner_test.go @@ -83,7 +83,7 @@ func Test_readIndexFile(t *testing.T) { return } if !sel.Matches(tt.matchFirst) || sel.Matches(neverMatch) { - t.Errorf("readIndexFile() didn't parse label selector propperly: %##v", sel) + t.Errorf("readIndexFile() didn't parse label selector properly: %##v", sel) return } }) From 7d974e0f7c09ea8d317b37f114a0284ba2dc6d24 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 25 Jun 2019 12:47:51 +0200 Subject: [PATCH 6/6] Also apply formatting to the `test` directory --- docs/CONTRIBUTOR_GUIDE.md | 2 +- test/krew/index.go | 1 + test/krew/krew.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CONTRIBUTOR_GUIDE.md b/docs/CONTRIBUTOR_GUIDE.md index 92f61dbe..085bc8a9 100644 --- a/docs/CONTRIBUTOR_GUIDE.md +++ b/docs/CONTRIBUTOR_GUIDE.md @@ -31,7 +31,7 @@ go get golang.org/x/tools/cmd/goimports and run: ```bash -goimports -local sigs.k8s.io/krew -w cmd pkg +goimports -local sigs.k8s.io/krew -w cmd pkg test ``` In addition, a boilerplate license header is expected in all source files. diff --git a/test/krew/index.go b/test/krew/index.go index b727c18e..0385b4a3 100644 --- a/test/krew/index.go +++ b/test/krew/index.go @@ -23,6 +23,7 @@ import ( "sync" "github.com/golang/glog" + "sigs.k8s.io/krew/pkg/constants" ) diff --git a/test/krew/krew.go b/test/krew/krew.go index afe55241..9e10dcdd 100644 --- a/test/krew/krew.go +++ b/test/krew/krew.go @@ -24,6 +24,7 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" + "sigs.k8s.io/krew/pkg/testutil" )