Merge pull request #321 from harmony-ek/goimports

s/gofmt/goimports/
pull/338/head
Eugene Kim 6 years ago committed by GitHub
commit 2e3340fc1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .travis.yml
  2. 4
      CONTRIBUTING.md
  3. 2
      api/proto/node/pingpong.go
  4. 5
      cmd/client/txgen/main.go
  5. 5
      cmd/client/wallet/wallet_test.go
  6. 4
      cmd/harmony.go
  7. 3
      consensus/consensus_leader_msg_test.go
  8. 6
      consensus/consensus_leader_test.go
  9. 5
      consensus/consensus_validator_test.go
  10. 2
      internal/beaconchain/libs/beaconchain.go
  11. 3
      node/node_handler_test.go
  12. 2
      p2p/host.go
  13. 4
      p2p/p2p.go
  14. 12
      scripts/dirnames.sh
  15. 19
      scripts/go_executable_build.sh
  16. 7
      scripts/goimports.sh
  17. 8
      scripts/golint.sh
  18. 7
      scripts/list_harmony_go_files.sh
  19. 4
      scripts/print_file.sh
  20. 21
      scripts/setup_bls_build_flags.sh
  21. 73
      scripts/travis_checker.sh
  22. 15
      test/deploy.sh

@ -19,6 +19,7 @@ install:
- cd ../harmony
- go get -t -v ./...
- go get -u golang.org/x/lint/golint
- go get -u golang.org/x/tools/cmd/goimports
- go get gopkg.in/check.v1
- ./scripts/travis_checker.sh
- go build -v ./...

@ -3,7 +3,7 @@
## Coding Guidelines
* In general, we follow [effective_go](https://golang.org/doc/effective_go.html)
* Code must adhere to the official [Go formatting guidelines](https://golang.org/doc/effective_go.html#formatting) (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
* Code must adhere to the official [Go formatting guidelines](https://golang.org/doc/effective_go.html#formatting) (i.e. uses [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports)).
* Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
## Pull Request (PR)
@ -13,7 +13,7 @@ This [github document](https://help.github.com/articles/creating-a-pull-request/
## PR requirement
To pursue engineering excellence, we have insisted on the highest stardard on the quality of each PR.
* For each PR, please run [golint](https://github.com/golang/lint), [gofmt](https://golang.org/cmd/gofmt/), to fix the basic issues/warnings.
* For each PR, please run [golint](https://github.com/golang/lint), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), to fix the basic issues/warnings.
* Make sure you understand [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
* Add a [Test] section in every PR detailing on your test process and results. If the test log is too long, please include a link to [gist](https://gist.github.com/) and add the link to the PR.

@ -19,7 +19,7 @@ import (
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/proto"
"github.com/harmony-one/harmony/p2p"
"github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-peer"
)
// RoleType defines the role of the node

@ -20,9 +20,8 @@ import (
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
"github.com/libp2p/go-libp2p-peerstore"
"github.com/multiformats/go-multiaddr"
peerstore "github.com/libp2p/go-libp2p-peerstore"
multiaddr "github.com/multiformats/go-multiaddr"
)
var (

@ -1,14 +1,15 @@
package main
import (
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/harmony-one/harmony/api/client"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
mock_host "github.com/harmony-one/harmony/p2p/host/mock"
"testing"
"time"
)
func TestCreateWalletNode(test *testing.T) {

@ -19,8 +19,8 @@ import (
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
"github.com/libp2p/go-libp2p-peerstore"
"github.com/multiformats/go-multiaddr"
peerstore "github.com/libp2p/go-libp2p-peerstore"
multiaddr "github.com/multiformats/go-multiaddr"
)
var (

@ -1,9 +1,10 @@
package consensus
import (
"github.com/harmony-one/harmony/internal/utils"
"testing"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p/p2pimpl"
"github.com/harmony-one/harmony/p2p"

@ -3,15 +3,17 @@ package consensus
import (
"fmt"
"testing"
"time"
"crypto/sha256"
"github.com/ethereum/go-ethereum/rlp"
"github.com/golang/mock/gomock"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
mock_host "github.com/harmony-one/harmony/p2p/host/mock"
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/harmony-one/harmony/p2p/p2pimpl"

@ -2,13 +2,14 @@ package consensus
import (
"encoding/hex"
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
mock_host "github.com/harmony-one/harmony/p2p/host/mock"
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/harmony-one/harmony/p2p/p2pimpl"

@ -11,7 +11,7 @@ import (
proto_identity "github.com/harmony-one/harmony/api/proto/identity"
"github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/internal/beaconchain/rpc"
beaconchain "github.com/harmony-one/harmony/internal/beaconchain/rpc"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"

@ -1,12 +1,13 @@
package node
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
"testing"
)
func TestNodeStreamHandler(t *testing.T) {

@ -1,6 +1,6 @@
package p2p
import "github.com/libp2p/go-libp2p-peer"
import peer "github.com/libp2p/go-libp2p-peer"
// Host is the client + server in p2p network.
type Host interface {

@ -5,8 +5,8 @@ import (
"net"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/libp2p/go-libp2p-peer"
"github.com/multiformats/go-multiaddr"
peer "github.com/libp2p/go-libp2p-peer"
multiaddr "github.com/multiformats/go-multiaddr"
)
// StreamHandler handles incoming p2p message.

@ -0,0 +1,12 @@
#!/bin/sh
# Print dirname of each relative pathname from stdin (one per line).
# pathname dirname
# ----------------------
# a/b/c.go a/b
# c.go .
exec sed \
-e 's:^:./:' \
-e 's:/[^/]*$::' \
-e 's:^\./::'

@ -13,21 +13,14 @@ GOARCH=amd64
FOLDER=/${WHOAMI:-$USER}
RACE=
HMY_PATH=$GOPATH/src/github.com/harmony-one
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib
OS=$(uname -s)
case $OS in
Darwin)
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
;;
unset -v progdir
case "${0}" in
*/*) progdir="${0%/*}";;
*) progdir=.;;
esac
. "${progdir}/setup_bls_build_flags.sh"
if [ "$(uname -s)" == "Darwin" ]; then
MD5='md5 -r'
GOOS=darwin

@ -0,0 +1,7 @@
#!/bin/sh
unset -v progdir
case "${0}" in
*/*) progdir="${0%/*}";;
*) progdir=.;;
esac
"${progdir}/list_harmony_go_files.sh" | xargs goimports "$@"

@ -0,0 +1,8 @@
#!/bin/sh
unset -v progdir
case "${0}" in
*/*) progdir="${0%/*}";;
*) progdir=.;;
esac
"${progdir}/list_harmony_go_files.sh" | "${progdir}/dirnames.sh" | \
sort -u -t/ | xargs golint "$@"

@ -0,0 +1,7 @@
#!/bin/sh
exec git ls-files '*.go' | grep -v \
-e '^vendor/' \
-e '\.pb\.go$' \
-e '/mock_stream\.go' \
-e '/host_mock\.go' \
-e '/gen_[^/]*\.go'

@ -0,0 +1,4 @@
#!/bin/sh
echo "--- BEGIN ${2} ---"
cat "${1}"
echo "--- END ${2} ---"

@ -0,0 +1,21 @@
# no shebang; to be sourced from other scripts
unset -v gopath
gopath=$(go env GOPATH)
HMY_PATH="${gopath%%:*}/src/github.com/harmony-one"
: ${OPENSSL_DIR="/usr/local/opt/openssl"}
: ${MCL_DIR="${HMY_PATH}/mcl"}
: ${BLS_DIR="${HMY_PATH}/bls"}
export CGO_CFLAGS="-I${BLS_DIR}/include -I${MCL_DIR}/include"
export CGO_LDFLAGS="-L${BLS_DIR}/lib"
export LD_LIBRARY_PATH=${BLS_DIR}/lib:${MCL_DIR}/lib
OS=$(uname -s)
case $OS in
Darwin)
export CGO_CFLAGS="-I${BLS_DIR}/include -I${MCL_DIR}/include -I${OPENSSL_DIR}/include"
export CGO_LDFLAGS="-L${BLS_DIR}/lib -L${OPENSSL_DIR}/lib"
export LD_LIBRARY_PATH=${BLS_DIR}/lib:${MCL_DIR}/lib:${OPENSSL_DIR}/lib
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
;;
esac

@ -1,55 +1,20 @@
#!/bin/bash
# Print a file surrounded by BEGIN/END preamble, e.g.:
#
# --- BEGIN a.out output ---
# Hello world
# --- END a.out output ---
#
print_file() {
echo "--- BEGIN ${2} ---"
cat "${1}"
echo "--- END ${2} ---"
}
unset -v ok tmpdir go_files go_dirs gofmt_output golint_output
unset -v ok tmpdir goimports_output golint_output progdir
ok=true
case "${0}" in
*/*) progdir="${0%/*}";;
*) progdir=.;;
esac
PATH="${PATH+"${PATH}:"}${progdir}"
export PATH
tmpdir=
trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT
tmpdir=$(mktemp -d)
go_files="${tmpdir}/go_files.txt"
git ls-files '*.go' | grep -v '^vendor/' > "${go_files}"
# Print dirname of each relative pathname from stdin (one per line).
dirnames() {
# pathname dirname
# ----------------------
# a/b/c.go a/b
# c.go .
sed \
-e 's:^:./:' \
-e 's:/[^/]*$::' \
-e 's:^\./::'
}
go_dirs="${tmpdir}/go_dirs.txt"
dirnames < "${go_files}" | sort -u -t/ > "${go_dirs}"
HMY_PATH=$GOPATH/src/github.com/harmony-one
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib
OS=$(uname -s)
case $OS in
Darwin)
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
;;
esac
. "${progdir}/setup_bls_build_flags.sh"
echo "Running go test..."
if go test -v -count=1 ./...
@ -62,25 +27,25 @@ fi
echo "Running golint..."
golint_output="${tmpdir}/golint_output.txt"
if xargs golint -set_exit_status < "${go_dirs}" > "${golint_output}" 2>&1
if "${progdir}/golint.sh" -set_exit_status > "${golint_output}" 2>&1
then
echo "golint passed."
else
echo "golint FAILED!"
print_file "${golint_output}" "golint"
"${progdir}/print_file.sh" "${golint_output}" "golint"
ok=false
fi
echo "Running gofmt..."
gofmt_output="${tmpdir}/gofmt_output.txt"
xargs gofmt -d -e < "${go_files}" > "${gofmt_output}" 2>&1
if [ -s "${gofmt_output}" ]
echo "Running goimports..."
goimports_output="${tmpdir}/goimports_output.txt"
"${progdir}/goimports.sh" -d -e > "${goimports_output}" 2>&1
if [ -s "${goimports_output}" ]
then
echo "gofmt FAILED!"
print_file "${gofmt_output}" "gofmt"
echo "goimports FAILED!"
"${progdir}/print_file.sh" "${goimports_output}" "goimports"
ok=false
else
echo "gofmt passed."
echo "goimports passed."
fi
if ! ${ok}

@ -3,20 +3,7 @@
ROOT=$(dirname $0)/..
USER=$(whoami)
HMY_PATH=$GOPATH/src/github.com/harmony-one
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib
OS=$(uname -s)
case $OS in
Darwin)
export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include"
export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib"
export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
;;
esac
. "${ROOT}/scripts/setup_bls_build_flags.sh"
set -x
set -eo pipefail

Loading…
Cancel
Save