diff --git a/.travis.yml b/.travis.yml index 564f7880..f19ca4ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,10 @@ notifications: email: false before_install: - go get github.com/mitchellh/gox -- go get gopkg.in/alecthomas/gometalinter.v2 -- gometalinter.v2 --install script: - hack/verify-boilerplate.sh - hack/gofmt.sh -- hack/gometalinter.sh +- hack/run_lint.sh - go test -v -coverprofile=coverage.txt -covermode=atomic ./... - hack/make-all.sh after_success: diff --git a/cmd/krew/cmd/search.go b/cmd/krew/cmd/search.go index 0d28dd55..22a6b546 100644 --- a/cmd/krew/cmd/search.go +++ b/cmd/krew/cmd/search.go @@ -96,7 +96,7 @@ Examples: func limitString(s string, length int) string { if len(s) > length && length > 3 { - s = string(s[:length-3]) + "..." + s = s[:length-3] + "..." } return s } diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index 7d6b59c5..a6c9cc5b 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -66,7 +66,7 @@ To package a plugin via krew, you need to: To make a plugin available to everyone via krew, you need to: 1. Make the archive file (`.zip` or `.tar.gz`) **publicly downloadable** on a - URL (you can host it youself or use GitHub releases feature). + URL (you can host it yourself or use GitHub releases feature). 2. Submit the plugin manifest file to the [krew index][index] repository. Plugin packages need to be available to download from the public Internet. @@ -139,7 +139,7 @@ architectures using the keys `os` and `arch` respectively. os: linux ``` -**Example:** Match to a Linux or macOS platform, any architecure: +**Example:** Match to a Linux or macOS platform, any architecture: ```yaml ... diff --git a/hack/cloudbuild-release.yaml b/hack/cloudbuild-release.yaml index c04ed7bb..bc039a2a 100644 --- a/hack/cloudbuild-release.yaml +++ b/hack/cloudbuild-release.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Used to push tagged releses to Google Cloud Storage with the tag name +# Used to push tagged releases to Google Cloud Storage with the tag name # as well as "latest" steps: - name: 'gcr.io/cloud-builders/docker' diff --git a/hack/gometalinter.json b/hack/gometalinter.json deleted file mode 100644 index af2f5569..00000000 --- a/hack/gometalinter.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Vendor": true, - "EnableGC": true, - "Debug": false, - "Sort": ["linter", "severity", "path"], - "Enable": [ - "deadcode", - "gofmt", - "golint", - "gosimple", - "ineffassign", - "vet" - ], - - "LineLength": 200 -} diff --git a/hack/gometalinter.sh b/hack/run_lint.sh similarity index 51% rename from hack/gometalinter.sh rename to hack/run_lint.sh index 6774fec5..ff61abf3 100755 --- a/hack/gometalinter.sh +++ b/hack/run_lint.sh @@ -14,12 +14,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -euo pipefail -#!/bin/bash -set -e -o pipefail +HACK=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -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 -gometalinter.v2 \ - ${GOMETALINTER_OPTS:-"--deadline=5m"} \ - --config $SCRIPTDIR/gometalinter.json ./... +"$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 diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index 6a17a643..ab0d767a 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "net/http" "os" - "path" "path/filepath" "strings" @@ -166,8 +165,7 @@ var defaultExtractors = map[string]extractor{ "application/x-gzip": extractTARGZ, } -func extractArchive(filename, dst string, at io.ReaderAt, size int64) error { - // TODO(lbb): Keep the filename for later direct download +func extractArchive(dst string, at io.ReaderAt, size int64) error { // TODO(ahmetb) This package is not architected well, this method should not // be receiving this many args. Primary problem is at GetInsecure and // GetWithSha256 methods that embed extraction in them, which is orthogonal. @@ -206,5 +204,5 @@ func (d Downloader) Get(uri, dst string) error { if err != nil { return errors.Wrapf(err, "failed to get the uri %q", uri) } - return extractArchive(path.Base(uri), dst, body, size) + return extractArchive(dst, body, size) } diff --git a/pkg/download/downloader_test.go b/pkg/download/downloader_test.go index d0132ab3..6c61a858 100644 --- a/pkg/download/downloader_test.go +++ b/pkg/download/downloader_test.go @@ -145,7 +145,7 @@ func collectFiles(t *testing.T, scanPath string) []string { } fp = strings.TrimPrefix(fp, scanPath) if info.IsDir() { - fp = fp + "/" + fp += "/" } outFiles = append(outFiles, fp) return nil @@ -456,7 +456,7 @@ func Test_extractArchive(t *testing.T) { return } - if err := extractArchive(tt.args.filename, tt.args.dst, fd, st.Size()); (err != nil) != tt.wantErr { + if err := extractArchive(tt.args.dst, fd, st.Size()); (err != nil) != tt.wantErr { t.Errorf("extractArchive() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/pkg/download/fetch_test.go b/pkg/download/fetch_test.go deleted file mode 100644 index 275e7cc6..00000000 --- a/pkg/download/fetch_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019 The Kubernetes Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package download - -import "io" - -// FakeFetcher is used for testing. -type FakeFetcher struct { - io.ReadCloser -} - -// Get gets the file and returns an stream to read the file. -func (ff FakeFetcher) Get(uri string) (io.ReadCloser, error) { - return ff.ReadCloser, nil -} diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index bb98decf..d86b543d 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -32,7 +32,7 @@ type Paths struct { } // MustGetKrewPaths returns the inferred paths for krew. By default, it assumes -// $HOME/.krew as the base path, but can be overriden via KREW_ROOT environment +// $HOME/.krew as the base path, but can be overridden via KREW_ROOT environment // variable. func MustGetKrewPaths() Paths { base := filepath.Join(homedir.HomeDir(), ".krew") diff --git a/pkg/installation/install.go b/pkg/installation/install.go index 5a6d4277..4fca7026 100644 --- a/pkg/installation/install.go +++ b/pkg/installation/install.go @@ -183,7 +183,7 @@ func pluginNameToBin(name string, isWindows bool) string { name = strings.Replace(name, "-", "_", -1) name = "kubectl-" + name if isWindows { - name = name + ".exe" + name += ".exe" } return name } diff --git a/pkg/installation/move.go b/pkg/installation/move.go index 072992f0..8021f2b6 100644 --- a/pkg/installation/move.go +++ b/pkg/installation/move.go @@ -63,7 +63,7 @@ func findMoveTargets(fromDir, toDir string, fo index.FileOperation) ([]move, err return nil, errors.Errorf("no files in the plugin archive matched the glob pattern=%s", fo.From) } - var moves []move + moves := make([]move, 0, len(gl)) for _, v := range gl { newPath := filepath.Join(newDir, filepath.Base(filepath.FromSlash(v))) // Check secure path diff --git a/pkg/installation/upgrade.go b/pkg/installation/upgrade.go index 7b8f7003..31f29302 100644 --- a/pkg/installation/upgrade.go +++ b/pkg/installation/upgrade.go @@ -84,7 +84,7 @@ func removePluginVersionFromFS(p environment.Paths, plugin index.Plugin, newVers return errors.Wrap(err, "failed to find current krew version") } glog.V(1).Infof("Detected running krew version=%s", executedKrewVersion) - return handleKrewRemove(p, plugin, newVersion, oldVersion, executedKrewVersion) + return handleKrewRemove(p, plugin, newVersion, executedKrewVersion) } glog.V(1).Infof("Remove old plugin installation under %q", p.PluginVersionInstallPath(plugin.Name, oldVersion)) @@ -92,7 +92,7 @@ func removePluginVersionFromFS(p environment.Paths, plugin index.Plugin, newVers } // handleKrewRemove will remove and unlink old krew versions. -func handleKrewRemove(p environment.Paths, plugin index.Plugin, newVersion, oldVersion, currentKrewVersion string) error { +func handleKrewRemove(p environment.Paths, plugin index.Plugin, newVersion, currentKrewVersion string) error { dir, err := ioutil.ReadDir(p.PluginInstallPath(plugin.Name)) if err != nil { return errors.Wrap(err, "can't read plugin dir") diff --git a/pkg/installation/util_test.go b/pkg/installation/util_test.go index 3f94f10c..49b9e49f 100644 --- a/pkg/installation/util_test.go +++ b/pkg/installation/util_test.go @@ -21,9 +21,8 @@ import ( "runtime" "testing" - "sigs.k8s.io/krew/pkg/index" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/krew/pkg/index" ) func Test_osArch_default(t *testing.T) { diff --git a/pkg/version/version.go b/pkg/version/version.go index c0d11848..ff1e602c 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -16,7 +16,7 @@ package version var ( - // gitCommit contains the git commit idenifier. + // gitCommit contains the git commit identifier. gitCommit string // gitTag contains the git tag or describe output.