Skip to content

Commit

Permalink
Switch linter from gometalinter to golangci-lint (#176)
Browse files Browse the repository at this point in the history
* Switch linter from gometalinter to golangci-lint

* Fix new lint issues found by golangci-lint

* Install golangci-lint with remote install script

* Fix a few typos

* Disable 'goconst' linter because it is too aggressive

* Inline string constant as allowed by the linter
  • Loading branch information
corneliusweig authored and k8s-ci-robot committed May 29, 2019
1 parent 75c1d0c commit 377dfae
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 70 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/krew/cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
...
Expand Down
2 changes: 1 addition & 1 deletion hack/cloudbuild-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 0 additions & 16 deletions hack/gometalinter.json

This file was deleted.

30 changes: 24 additions & 6 deletions hack/gometalinter.sh → hack/run_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/download/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
})
Expand Down
27 changes: 0 additions & 27 deletions pkg/download/fetch_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/installation/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/installation/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/installation/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ 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))
return os.RemoveAll(p.PluginVersionInstallPath(plugin.Name, oldVersion))
}

// 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")
Expand Down
3 changes: 1 addition & 2 deletions pkg/installation/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 377dfae

Please sign in to comment.