Skip to content

Commit

Permalink
Fix new lint issues found by golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweig committed May 9, 2019
1 parent bfae01e commit e0d422a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 49 deletions.
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
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 @@ -22,8 +22,7 @@ import (
"testing"

"sigs.k8s.io/krew/pkg/index"

"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_osArch_default(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Package version contains the version information of the krew binary.
package version

const unknown = "unknown"

var (
// gitCommit contains the git commit idenifier.
gitCommit string
Expand All @@ -13,7 +15,7 @@ var (
// default "unknown" value.
func GitCommit() string {
if gitCommit == "" {
return "unknown"
return unknown
}
return gitCommit
}
Expand All @@ -22,7 +24,7 @@ func GitCommit() string {
// default "unknown" value.
func GitTag() string {
if gitTag == "" {
return "unknown"
return unknown
}
return gitTag
}
14 changes: 8 additions & 6 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package version

import "testing"

const commitSha = "abcdef"

func TestGitCommit(t *testing.T) {
orig := gitCommit
defer func() { gitCommit = orig }()

gitCommit = ""
if v := GitCommit(); v != "unknown" {
if v := GitCommit(); v != unknown {
t.Errorf("empty gitCommit, expected=\"unknown\" got=%q", v)
}

gitCommit = "abcdef"
if v := GitCommit(); v != "abcdef" {
gitCommit = commitSha
if v := GitCommit(); v != commitSha {
t.Errorf("empty gitCommit, expected=\"abcdef\" got=%q", v)
}
}
Expand All @@ -22,12 +24,12 @@ func TestGitTag(t *testing.T) {
defer func() { gitTag = orig }()

gitTag = ""
if v := GitTag(); v != "unknown" {
if v := GitTag(); v != unknown {
t.Errorf("empty gitTag, expected=\"unknown\" got=%q", v)
}

gitTag = "abcdef"
if v := GitTag(); v != "abcdef" {
gitTag = commitSha
if v := GitTag(); v != commitSha {
t.Errorf("empty gitTag, expected=\"abcdef\" got=%q", v)
}
}

0 comments on commit e0d422a

Please sign in to comment.