Skip to content

Commit

Permalink
feat(build.sh): Enable goimports for cleanup imports + cleanup imports
Browse files Browse the repository at this point in the history
Much like 'go fmt' for cleaning up go source, 'goimports' can help
in properly formatting and grouping imports. See https://goinbigdata.com/goimports-vs-gofmt/
for a quick overview.

This commit also cleansup imports on existing files.
  • Loading branch information
rhuss committed Jun 15, 2019
1 parent 74abba5 commit 0a69adc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
golang.org/x/tools v0.0.0-20190613204242-ed0dc450797f // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20190226173710-145d52631d00
k8s.io/apimachinery v0.0.0-20190221084156-01f179d85dbc
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FY
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -325,6 +326,8 @@ golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190613204242-ed0dc450797f h1:+zypR5600WBcnJgA2nzZAsBlM8cArEGa8dhhiNE4u3w=
golang.org/x/tools v0.0.0-20190613204242-ed0dc450797f/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/api v0.3.2 h1:iTp+3yyl/KOtxa/d1/JUE0GGSoR6FuW5udver22iwpw=
google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
Expand Down
19 changes: 19 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ run() {
# Format source code
go_fmt

# Cleanup imports
go_imports

# Generate docs
# Check for license headers
check_license

Expand All @@ -77,6 +81,20 @@ go_fmt() {
go fmt ./cmd/... ./pkg/...
}

go_imports() {
set +e
which goimports >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "✋ No 'goimports' found. Please use"
echo "✋ go get golang.org/x/tools/cmd/goimports"
echo "✋ to enable import cleanup. Import cleanup skipped."
else
echo "🧽 Imports"
goimports -w cmd pkg
fi
set -e
}

go_build() {
echo "🚧 Compile"
source "./hack/build-flags.sh"
Expand Down Expand Up @@ -215,6 +233,7 @@ with the following options:
-f --fast Only compile (without formatting, testing, doc generation)
-t --test Run tests when used with --fast or --watch
-i --imports Organize and cleanup imports
-u --update Update dependencies before compiling
-w --watch Watch for source changes and recompile in fast mode
-h --help Display this help message
Expand Down
3 changes: 2 additions & 1 deletion pkg/kn/commands/namespaced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package commands

import (
"github.com/spf13/cobra"
"testing"

"github.com/spf13/cobra"
)

// testCommandGenerator generates a test cobra command
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/revision/revision_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/knative/client/pkg/kn/commands"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/printers/tableprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"reflect"
"strings"

"text/tabwriter"

metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"text/tabwriter"
)

var _ ResourcePrinter = &HumanReadablePrinter{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/serving/config_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package serving

import (
"github.com/knative/serving/pkg/apis/serving/v1beta1"
"reflect"
"testing"

"github.com/knative/serving/pkg/apis/serving/v1beta1"

servingv1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1"
corev1 "k8s.io/api/core/v1"
)
Expand Down

0 comments on commit 0a69adc

Please sign in to comment.