Skip to content
Permalink
Browse files

Put local imports in a separate import group (#222)

* Move linter configuration into .golangci.yml

* Expect local import in separate group

* Make verify-gofmt.sh more resilient wrt filenames with spaces

* Apply standard imports sort order to all go files

* Fix typos in messages

* Also apply formatting to the `test` directory
  • Loading branch information...
corneliusweig authored and k8s-ci-robot committed Jun 25, 2019
1 parent d6629aa commit cc140f111479fbd8d36946613a60f212173cbe17
@@ -0,0 +1,35 @@
# 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;
# 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
@@ -24,6 +24,7 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"

"sigs.k8s.io/krew/pkg/installation"
)

@@ -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 (
@@ -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"
)

@@ -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
@@ -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"
)
@@ -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"
@@ -16,6 +16,7 @@ package main

import (
"github.com/golang/glog"

"sigs.k8s.io/krew/cmd/krew/cmd"
)

@@ -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"
@@ -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 test
```

In addition, a boilerplate license header is expected in all source files.
@@ -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
@@ -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
@@ -25,6 +25,7 @@ import (
"testing"

"github.com/pkg/errors"

"sigs.k8s.io/krew/pkg/testutil"
)

@@ -247,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
}

@@ -21,6 +21,7 @@ import (
"testing"

"k8s.io/client-go/util/homedir"

"sigs.k8s.io/krew/pkg/testutil"
)

@@ -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.
@@ -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
}
})
@@ -19,6 +19,7 @@ import (
"strings"

"github.com/pkg/errors"

"sigs.k8s.io/krew/pkg/constants"
)

@@ -18,6 +18,7 @@ import (
"testing"

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

"sigs.k8s.io/krew/pkg/constants"
)

@@ -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
@@ -22,6 +22,7 @@ import (
"testing"

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

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

@@ -23,6 +23,7 @@ import (
"sync"

"github.com/golang/glog"

"sigs.k8s.io/krew/pkg/constants"
)

@@ -24,6 +24,7 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"

"sigs.k8s.io/krew/pkg/testutil"
)

0 comments on commit cc140f1

Please sign in to comment.
You can’t perform that action at this time.