Commit 1d685803 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

add misspell, gofmt and unconvert linters (#160)

parent e7b0f738
...@@ -8,9 +8,4 @@ if [ -z "$commits" ]; then ...@@ -8,9 +8,4 @@ if [ -z "$commits" ]; then
exit 0 exit 0
fi fi
if ! command -v golangci-lint &> /dev/null; then make build lint vet test-race
echo "installing golangci-lint..." \ No newline at end of file
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
fi
make lint vet test-race
...@@ -26,6 +26,10 @@ jobs: ...@@ -26,6 +26,10 @@ jobs:
echo "::set-env name=GOPATH::$(go env GOPATH)" echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin" echo "::add-path::$(go env GOPATH)/bin"
shell: bash shell: bash
- name: Set git to use LF
# make sure that line endings are not converted on windows
# as gofmt linter will report that they need to be changed
run: git config --global core.autocrlf false
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
......
run: run:
timeout: 10m timeout: 10m
linters:
enable:
- misspell
- gofmt
- unconvert
GO ?= go GO ?= go
GOLANGCI_LINT ?= golangci-lint GOLANGCI_LINT ?= golangci-lint
GOLANGCI_LINT_VERSION ?= v1.26.0
LDFLAGS ?= -s -w LDFLAGS ?= -s -w
ifdef COMMIT ifdef COMMIT
...@@ -7,7 +8,7 @@ LDFLAGS += -X github.com/ethersphere/bee.commit="$(COMMIT)" ...@@ -7,7 +8,7 @@ LDFLAGS += -X github.com/ethersphere/bee.commit="$(COMMIT)"
endif endif
.PHONY: all .PHONY: all
all: build lint vet test binary all: build lint vet test-race binary
.PHONY: binary .PHONY: binary
binary: export CGO_ENABLED=0 binary: export CGO_ENABLED=0
...@@ -19,9 +20,13 @@ dist: ...@@ -19,9 +20,13 @@ dist:
mkdir $@ mkdir $@
.PHONY: lint .PHONY: lint
lint: lint: linter
$(GOLANGCI_LINT) run $(GOLANGCI_LINT) run
.PHONY: linter
linter:
which $(GOLANGCI_LINT) || ( cd /tmp && GO111MODULE=on $(GO) get -u github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) )
.PHONY: vet .PHONY: vet
vet: vet:
$(GO) vet ./... $(GO) vet ./...
......
...@@ -30,22 +30,22 @@ var ( ...@@ -30,22 +30,22 @@ var (
type Interface interface { type Interface interface {
// Execute runs f() if the limit number of consecutive failed calls is not reached within fail interval. // Execute runs f() if the limit number of consecutive failed calls is not reached within fail interval.
// f() call is not locked so it can still be executed concurently. // f() call is not locked so it can still be executed concurrently.
// Returns `ErrClosed` if the limit is reached or f() result otherwise. // Returns `ErrClosed` if the limit is reached or f() result otherwise.
Execute(f func() error) error Execute(f func() error) error
// ClosedUntil retuns the timestamp when the breaker will become open again. // ClosedUntil returns the timestamp when the breaker will become open again.
ClosedUntil() time.Time ClosedUntil() time.Time
} }
type breaker struct { type breaker struct {
limit int // breaker will not exeucute any more tasks after limit number of consequtive failuers happen limit int // breaker will not execute any more tasks after limit number of consecutive failures happen
consFailedCalls int // current number of consequtive fails consFailedCalls int // current number of consecutive fails
firstFailedTimestamp time.Time firstFailedTimestamp time.Time
closedTimestamp time.Time closedTimestamp time.Time
backoff time.Duration // initial backoff duration backoff time.Duration // initial backoff duration
maxBackoff time.Duration maxBackoff time.Duration
failInterval time.Duration // consequitive failures are counted if they happen withing this interval failInterval time.Duration // consecutive failures are counted if they happen within this interval
mtx sync.Mutex mtx sync.Mutex
} }
......
...@@ -47,13 +47,13 @@ func newMetrics() metrics { ...@@ -47,13 +47,13 @@ func newMetrics() metrics {
Namespace: m.Namespace, Namespace: m.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "total_chunk_synced", Name: "total_chunk_synced",
Help: "Total chunks synced succesfully with valid receipts.", Help: "Total chunks synced successfully with valid receipts.",
}), }),
TotalChunksStoredInDB: prometheus.NewCounter(prometheus.CounterOpts{ TotalChunksStoredInDB: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace, Namespace: m.Namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "total_chunk_stored_in_DB", Name: "total_chunk_stored_in_DB",
Help: "Total chunks stored succesfully in local store.", Help: "Total chunks stored successfully in local store.",
}), }),
ChunksSentCounter: prometheus.NewCounter(prometheus.CounterOpts{ ChunksSentCounter: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace, Namespace: m.Namespace,
......
...@@ -111,7 +111,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream) ...@@ -111,7 +111,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
} }
ps.metrics.TotalChunksStoredInDB.Inc() ps.metrics.TotalChunksStoredInDB.Inc()
// Send a receipt immediately once the storage of the chunk is successfull // Send a receipt immediately once the storage of the chunk is successful
receipt := &pb.Receipt{Address: chunk.Address().Bytes()} receipt := &pb.Receipt{Address: chunk.Address().Bytes()}
err = ps.sendReceipt(w, receipt) err = ps.sendReceipt(w, receipt)
if err != nil { if err != nil {
...@@ -133,7 +133,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream) ...@@ -133,7 +133,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
} }
ps.metrics.TotalChunksStoredInDB.Inc() ps.metrics.TotalChunksStoredInDB.Inc()
// Send a receipt immediately once the storage of the chunk is successfull // Send a receipt immediately once the storage of the chunk is successful
receipt := &pb.Receipt{Address: chunk.Address().Bytes()} receipt := &pb.Receipt{Address: chunk.Address().Bytes()}
return ps.sendReceipt(w, receipt) return ps.sendReceipt(w, receipt)
} }
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"encoding/binary" "encoding/binary"
"testing" "testing"
"github.com/ethersphere/bee/pkg/validator"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/validator"
) )
// TestContentAddressValidator checks that the validator evaluates correctly // TestContentAddressValidator checks that the validator evaluates correctly
...@@ -28,7 +28,7 @@ func TestContentAddressValidator(t *testing.T) { ...@@ -28,7 +28,7 @@ func TestContentAddressValidator(t *testing.T) {
fooLength := len(foo) fooLength := len(foo)
fooBytes := make([]byte, 8+fooLength) fooBytes := make([]byte, 8+fooLength)
binary.LittleEndian.PutUint64(fooBytes, uint64(fooLength)) binary.LittleEndian.PutUint64(fooBytes, uint64(fooLength))
copy(fooBytes[8:], []byte(foo)) copy(fooBytes[8:], foo)
ch := swarm.NewChunk(address, fooBytes) ch := swarm.NewChunk(address, fooBytes)
if !validator.Validate(ch) { if !validator.Validate(ch) {
t.Fatalf("data '%s' should have validated to hash '%s'", ch.Data(), ch.Address()) t.Fatalf("data '%s' should have validated to hash '%s'", ch.Data(), ch.Address())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment