Skip to content

Commit

Permalink
feat(ci): Replace gometalinter with golangci
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Sep 14, 2018
1 parent e37738f commit 5a49a5d
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 62 deletions.
5 changes: 2 additions & 3 deletions .circleci/docker/Dockerfile.linter
Expand Up @@ -4,9 +4,8 @@ FROM golang:alpine
RUN apk --no-cache --update add nodejs-npm git make musl-dev gcc g++

# gometalinter
RUN go get -u gopkg.in/alecthomas/gometalinter.v2 \
&& gometalinter.v2 -i -u \
&& ln -s /go/bin/gometalinter.v2 /usr/bin/gometalinter.v2
RUN go get -u github.com/golangci/golangci-lint/cmd/golangci-lint \
&& ln -s /go/bin/golangci-lint /usr/bin/golangci-lint

# dockerlint
RUN npm install --global dockerlint
Expand Down
36 changes: 36 additions & 0 deletions .golangci.yml
@@ -0,0 +1,36 @@
run:
deadline: 1m
tests: false
skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
- "_test.go:"

linters-settings:
golint:
min-confidence: 0
maligned:
suggest-new: true
goconst:
min-len: 5
min-occurrences: 4
misspell:
locale: US

linters:
disable-all: true
enable:
- goconst
- misspell
- deadcode
- misspell
- structcheck
- errcheck
- unused
- varcheck
- staticcheck
- unconvert
- gofmt
- goimports
- golint
- ineffassign
34 changes: 0 additions & 34 deletions .gometalinter.json

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -18,7 +18,7 @@ lint-dockerfile:

.PHONY: lint-go
lint-go:
gometalinter.v2 ./...
golangci-lint run ./...

.PHONY: lint-editorconfig
lint-editorconfig:
Expand Down
2 changes: 1 addition & 1 deletion core/Makefile
Expand Up @@ -73,7 +73,7 @@ integration: install

.PHONY: lint
lint: generate
gometalinter.v2 --config=../.gometalinter.json $(TEST_PATHS)
golangci-lint run $(TEST_PATHS)

.PHONY: generate
generate: .generated
Expand Down
4 changes: 2 additions & 2 deletions core/api/node/graphql/converts.go
Expand Up @@ -48,7 +48,7 @@ func (gid *globalID) FromString(e string) error {

sid := strings.SplitN(string(bs), ":", 2)
if len(sid) != 2 {
return fmt.Errorf("Not a valid global id `%s`", bs)
return fmt.Errorf("not a valid global id `%s`", bs)
}

if kind, ok := EntityKindMap[sid[0]]; ok {
Expand All @@ -57,7 +57,7 @@ func (gid *globalID) FromString(e string) error {
return nil
}

return fmt.Errorf("Unknown entity kind `%s`", sid[0])
return fmt.Errorf("unknown entity kind `%s`", sid[0])
}

func convertContactStatus(value entity.Contact_Status) *model.BertyEntityContactStatus {
Expand Down
19 changes: 9 additions & 10 deletions core/cmd/berty/identity.go
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"os"

p2pcrypto "github.com/libp2p/go-libp2p-crypto"
Expand Down Expand Up @@ -40,14 +39,14 @@ var StringKeyTypes = map[string]KeyType{
"Secp256k1": Secp256k1,
}

var r io.Reader = rand.Reader
var r = rand.Reader

func getKeyType(t string) (KeyType, error) {
if v, ok := StringKeyTypes[t]; ok {
return v, nil
}

return Unknow, fmt.Errorf("Unknow key type")
return Unknow, fmt.Errorf("unknow key type")
}

func newIdentityCommand() *cobra.Command {
Expand Down Expand Up @@ -80,38 +79,38 @@ var cryptoKeyGenerateCmd = &cobra.Command{

t, err := getKeyType(cfgCryptoKeyType)
if err != nil {
zap.L().Fatal("Cannot get key type:", zap.String("type", cfgCryptoKeyType), zap.Error(err))
zap.L().Fatal("cannot get key type:", zap.String("type", cfgCryptoKeyType), zap.Error(err))
}

priv, pub, err := p2pcrypto.GenerateKeyPairWithReader(int(t), 2048, r)
if err != nil {
zap.L().Fatal("Error while generating key pair", zap.Error(err))
zap.L().Fatal("error while generating key pair", zap.Error(err))
}

bPriv, err := priv.Bytes()
if err != nil {
zap.L().Fatal("Invalid private key", zap.Error(err))
zap.L().Fatal("invalid private key", zap.Error(err))
}

var bPub []byte = []byte{}
if cfgCryptoPubKey {
bPub, err = pub.Bytes()
if err != nil {
zap.L().Fatal("Invalid private key", zap.Error(err))
zap.L().Fatal("invalid private key", zap.Error(err))
}
}

if cfgCryptoRaw {
if cfgCryptoPubKey {
if _, err = w.Write(bPub); err != nil {
zap.L().Fatal("Error while writing output", zap.Error(err))
zap.L().Fatal("error while writing output", zap.Error(err))
}

return
}

if _, err := w.Write(bPriv); err != nil {
zap.L().Fatal("Error while writing output", zap.Error(err))
zap.L().Fatal("error while writing output", zap.Error(err))
}

return
Expand All @@ -123,7 +122,7 @@ var cryptoKeyGenerateCmd = &cobra.Command{
}

if err != nil {
zap.L().Fatal("Error while writing output", zap.Error(err))
zap.L().Fatal("error while writing output", zap.Error(err))
}
},
}
16 changes: 8 additions & 8 deletions core/network/p2p/p2p.go
Expand Up @@ -284,7 +284,7 @@ func (d *Driver) EmitTo(ctx context.Context, channel string, e *p2p.Envelope) er
}

if len(ss) == 0 {
return fmt.Errorf("No subscribers found")
return fmt.Errorf("no subscribers found")
}

for _, s := range ss {
Expand All @@ -296,19 +296,19 @@ func (d *Driver) EmitTo(ctx context.Context, channel string, e *p2p.Envelope) er
}

if err := d.Connect(ctx, pi); err != nil {
logger().Warn("Failed to connect", zap.String("id", peerID), zap.Error(err))
logger().Warn("failed to connect", zap.String("id", peerID), zap.Error(err))
}

c, err := d.ccmanager.GetConn(ctx, peerID)
if err != nil {
logger().Warn("Failed to dial", zap.String("id", peerID), zap.Error(err))
logger().Warn("failed to dial", zap.String("id", peerID), zap.Error(err))
}

sc := p2p.NewServiceClient(c)

_, err = sc.HandleEnvelope(ctx, e)
if err != nil {
logger().Error("Failed to send envelope", zap.String("envelope", fmt.Sprintf("%+v", e)), zap.String("error", err.Error()))
logger().Error("failed to send envelope", zap.String("envelope", fmt.Sprintf("%+v", e)), zap.String("error", err.Error()))
}
}(s)
}
Expand All @@ -322,7 +322,7 @@ func (d *Driver) Announce(ctx context.Context, id string) error {

// FindSubscribers with the given ID
func (d *Driver) FindSubscribers(ctx context.Context, id string) ([]pstore.PeerInfo, error) {
logger().Debug("Looking for", zap.String("id", id))
logger().Debug("looking for", zap.String("id", id))
c, err := d.createCid(id)
if err != nil {
return nil, err
Expand All @@ -347,10 +347,10 @@ func (d *Driver) Join(ctx context.Context, id string) error {
if err := d.dht.Provide(ctx, c, true); err != nil {
// stack peer if no peer found
d.stackSub(c)
logger().Warn("Provide err", zap.Error(err))
logger().Warn("provide err", zap.Error(err))
}

logger().Debug("Announcing", zap.String("id", id))
logger().Debug("announcing", zap.String("id", id))

// Announce that you are subscribed to this conversation, but don't
// broadcast it! in this way, if you die, your announcement will die with you!
Expand All @@ -368,7 +368,7 @@ func (ds *DriverService) HandleEnvelope(ctx context.Context, e *p2p.Envelope) (*
return ds.handler(ctx, e)
}

return nil, fmt.Errorf("No handler set")
return nil, fmt.Errorf("no handler set")
}

type DriverDiscoveryNotifee Driver
Expand Down
6 changes: 3 additions & 3 deletions core/network/p2p/protocol/service/p2pgrpc/grpc.go
Expand Up @@ -42,7 +42,7 @@ func (pg *P2Pgrpc) NewListener(proto string) net.Listener {
id := getGrpcID(proto)

if pg.hasProtocol(id) {
logger().Warn("Proto already registered", zap.String("pid", id))
logger().Warn("protocol already registered", zap.String("pid", id))
return nil
}

Expand All @@ -66,11 +66,11 @@ func (pg *P2Pgrpc) NewDialer(proto string) func(string, time.Duration) (net.Conn

peerID, err := peer.IDB58Decode(target)
if err != nil {
return nil, fmt.Errorf("Failed to parse `%s`: %s", target, err.Error())
return nil, fmt.Errorf("failed to parse `%s`: %s", target, err.Error())
}

// No stream exist, creating a new one
logger().Debug("Dialing", zap.String("addr", target))
logger().Debug("dialing", zap.String("addr", target))

s, err := pg.host.NewStream(ctx, peerID, pid)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/sql/sqlcipher/sqlcipher.go
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/jinzhu/gorm"
"github.com/pkg/errors"

// sqlcipher blank import
_ "github.com/xeodou/go-sqlcipher"
)
Expand Down

0 comments on commit 5a49a5d

Please sign in to comment.