From f8113d4e050dd7818e413459ff8138fe70ab73cc Mon Sep 17 00:00:00 2001 From: Vijay Samuel Date: Wed, 26 Apr 2017 00:06:37 -0700 Subject: [PATCH] Adding goimports support to make check and fmt --- CHANGELOG.asciidoc | 1 + filebeat/processors/kubernetes/indexing_test.go | 3 ++- libbeat/processors/kubernetes/config.go | 3 ++- libbeat/scripts/Makefile | 9 ++++++--- .../ceph/cluster_disk/cluster_disk_integration_test.go | 3 ++- .../module/ceph/pool_disk/pool_disk_integration_test.go | 3 ++- metricbeat/module/docker/image/data.go | 5 +++-- metricbeat/module/dropwizard/collector/collector.go | 3 ++- metricbeat/module/dropwizard/collector/data.go | 2 +- metricbeat/module/golang/heap/heap.go | 3 ++- metricbeat/module/golang/util.go | 3 ++- packetbeat/protos/cassandra/internal/gocql/frame.go | 5 +++-- packetbeat/protos/nfs/config.go | 3 ++- 13 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8fe093b551c4..e139969e8b8e 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -109,6 +109,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff] - Add kubernetes processor {pull}3888[3888] - Add support for include_labels and include_annotations in kubernetes processor {pull}4043[4043] - Support new `index_patterns` field when loading templates for Elasticsearch >= 6.0 {pull}4056[4056] +- Adding goimports support to make check and fmt {pull}4114[4114] *Filebeat* diff --git a/filebeat/processors/kubernetes/indexing_test.go b/filebeat/processors/kubernetes/indexing_test.go index be5f08b6e262..5ba98056d59e 100644 --- a/filebeat/processors/kubernetes/indexing_test.go +++ b/filebeat/processors/kubernetes/indexing_test.go @@ -2,9 +2,10 @@ package kubernetes import ( "fmt" + "testing" + "github.com/elastic/beats/libbeat/common" "github.com/stretchr/testify/assert" - "testing" ) func TestLogsPathMatcher(t *testing.T) { diff --git a/libbeat/processors/kubernetes/config.go b/libbeat/processors/kubernetes/config.go index 99f5a17ed2c5..01fbc5a1bb71 100644 --- a/libbeat/processors/kubernetes/config.go +++ b/libbeat/processors/kubernetes/config.go @@ -1,8 +1,9 @@ package kubernetes import ( - "github.com/elastic/beats/libbeat/common" "time" + + "github.com/elastic/beats/libbeat/common" ) type kubeAnnotatorConfig struct { diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index 03f122e14a7e..3421aca2a70c 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -30,6 +30,8 @@ COVERAGE_DIR=${BUILD_DIR}/coverage COVERAGE_TOOL=${BEAT_GOPATH}/bin/gotestcover COVERAGE_TOOL_REPO=github.com/elastic/beats/vendor/github.com/pierrre/gotestcover TESTIFY_TOOL_REPO=github.com/elastic/beats/vendor/github.com/stretchr/testify +GOIMPORTS=goimports +GOIMPORTS_REPO=golang.org/x/tools/cmd/goimports GOLINT=golint GOLINT_REPO=github.com/golang/lint/golint REVIEWDOG=reviewdog -conf ${ES_BEATS}/reviewdog.yml @@ -93,13 +95,14 @@ crosscompile: $(GOFILES) .PHONY: check check: python-env ## @build Checks project and source code if everything is according to standard - @gofmt -l ${GOFILES_NOVENDOR} | (! grep . -q) || (echo "Code differs from gofmt's style" && false) go vet ${GOPACKAGES} + @go get $(GOIMPORTS_REPO) + @goimports -l ${GOFILES_NOVENDOR} | (! grep . -q) || (echo "Code differs from goimports' style" && false) ${FIND} -name *.py -exec autopep8 -d --max-line-length 120 {} \; | (! grep . -q) || (echo "Code differs from autopep8's style" && false) .PHONY: fmt -fmt: python-env ## @build Runs `gofmt -s -l -w` and `autopep8`on the project's source code, modifying any files that do not match its style. - gofmt -s -l -w ${GOFILES_NOVENDOR} +fmt: python-env ## @build Runs `goimports -l -w` and `autopep8`on the project's source code, modifying any files that do not match its style. + goimports -l -w ${GOFILES_NOVENDOR} ${FIND} -name *.py -exec autopep8 --in-place --max-line-length 120 {} \; .PHONY: lint diff --git a/metricbeat/module/ceph/cluster_disk/cluster_disk_integration_test.go b/metricbeat/module/ceph/cluster_disk/cluster_disk_integration_test.go index 8cfd9ccf4e08..3937c7e9b984 100644 --- a/metricbeat/module/ceph/cluster_disk/cluster_disk_integration_test.go +++ b/metricbeat/module/ceph/cluster_disk/cluster_disk_integration_test.go @@ -2,9 +2,10 @@ package cluster_disk import ( "fmt" - mbtest "github.com/elastic/beats/metricbeat/mb/testing" "os" "testing" + + mbtest "github.com/elastic/beats/metricbeat/mb/testing" ) func TestData(t *testing.T) { diff --git a/metricbeat/module/ceph/pool_disk/pool_disk_integration_test.go b/metricbeat/module/ceph/pool_disk/pool_disk_integration_test.go index b7fead7b893f..3202bf3a9942 100644 --- a/metricbeat/module/ceph/pool_disk/pool_disk_integration_test.go +++ b/metricbeat/module/ceph/pool_disk/pool_disk_integration_test.go @@ -2,9 +2,10 @@ package pool_disk import ( "fmt" - mbtest "github.com/elastic/beats/metricbeat/mb/testing" "os" "testing" + + mbtest "github.com/elastic/beats/metricbeat/mb/testing" ) func TestData(t *testing.T) { diff --git a/metricbeat/module/docker/image/data.go b/metricbeat/module/docker/image/data.go index 877a3d7db639..0dc24770148c 100644 --- a/metricbeat/module/docker/image/data.go +++ b/metricbeat/module/docker/image/data.go @@ -1,11 +1,12 @@ package image import ( - "github.com/elastic/beats/libbeat/common" + "time" + "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/metricbeat/module/docker" + dc "github.com/fsouza/go-dockerclient" - "time" ) func eventsMapping(imagesList []dc.APIImages) []common.MapStr { diff --git a/metricbeat/module/dropwizard/collector/collector.go b/metricbeat/module/dropwizard/collector/collector.go index a4b35e03bdec..e98bf67a8d7a 100644 --- a/metricbeat/module/dropwizard/collector/collector.go +++ b/metricbeat/module/dropwizard/collector/collector.go @@ -2,12 +2,13 @@ package collector import ( "encoding/json" + "strings" + "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/helper" "github.com/elastic/beats/metricbeat/mb" "github.com/elastic/beats/metricbeat/mb/parse" - "strings" ) const ( diff --git a/metricbeat/module/dropwizard/collector/data.go b/metricbeat/module/dropwizard/collector/data.go index 9c795d453d59..bf54592dc69b 100644 --- a/metricbeat/module/dropwizard/collector/data.go +++ b/metricbeat/module/dropwizard/collector/data.go @@ -1,9 +1,9 @@ package collector import ( + "encoding/json" "strings" - "encoding/json" "github.com/elastic/beats/libbeat/common" ) diff --git a/metricbeat/module/golang/heap/heap.go b/metricbeat/module/golang/heap/heap.go index 573b9f280779..140fa4f4b71c 100644 --- a/metricbeat/module/golang/heap/heap.go +++ b/metricbeat/module/golang/heap/heap.go @@ -2,13 +2,14 @@ package heap import ( "encoding/json" + "runtime" + "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/helper" "github.com/elastic/beats/metricbeat/mb" "github.com/elastic/beats/metricbeat/mb/parse" "github.com/elastic/beats/metricbeat/module/golang" - "runtime" ) const ( diff --git a/metricbeat/module/golang/util.go b/metricbeat/module/golang/util.go index 0518b77d0af3..0cf09d5e4393 100644 --- a/metricbeat/module/golang/util.go +++ b/metricbeat/module/golang/util.go @@ -2,8 +2,9 @@ package golang import ( "bytes" - "github.com/elastic/beats/libbeat/logp" "strings" + + "github.com/elastic/beats/libbeat/logp" ) /** diff --git a/packetbeat/protos/cassandra/internal/gocql/frame.go b/packetbeat/protos/cassandra/internal/gocql/frame.go index 3115d78fa25d..542106c2799e 100644 --- a/packetbeat/protos/cassandra/internal/gocql/frame.go +++ b/packetbeat/protos/cassandra/internal/gocql/frame.go @@ -7,10 +7,11 @@ package cassandra import ( "errors" "fmt" - "github.com/elastic/beats/libbeat/common/streambuf" - "github.com/elastic/beats/libbeat/logp" "runtime" "sync" + + "github.com/elastic/beats/libbeat/common/streambuf" + "github.com/elastic/beats/libbeat/logp" ) var ( diff --git a/packetbeat/protos/nfs/config.go b/packetbeat/protos/nfs/config.go index eabd31e4c90b..b09b1b356163 100644 --- a/packetbeat/protos/nfs/config.go +++ b/packetbeat/protos/nfs/config.go @@ -1,8 +1,9 @@ package nfs import ( - "github.com/elastic/beats/packetbeat/config" "time" + + "github.com/elastic/beats/packetbeat/config" ) type rpcConfig struct {