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
exit 0
fi
if ! command -v golangci-lint &> /dev/null; then
echo "installing golangci-lint..."
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
fi
make lint vet test-race
make build lint vet test-race
\ No newline at end of file
......@@ -26,6 +26,10 @@ jobs:
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
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
uses: actions/checkout@v2
with:
......
run:
timeout: 10m
linters:
enable:
- misspell
- gofmt
- unconvert
GO ?= go
GOLANGCI_LINT ?= golangci-lint
GOLANGCI_LINT_VERSION ?= v1.26.0
LDFLAGS ?= -s -w
ifdef COMMIT
......@@ -7,7 +8,7 @@ LDFLAGS += -X github.com/ethersphere/bee.commit="$(COMMIT)"
endif
.PHONY: all
all: build lint vet test binary
all: build lint vet test-race binary
.PHONY: binary
binary: export CGO_ENABLED=0
......@@ -19,9 +20,13 @@ dist:
mkdir $@
.PHONY: lint
lint:
lint: linter
$(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
vet:
$(GO) vet ./...
......
......@@ -30,22 +30,22 @@ var (
type Interface interface {
// 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.
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
}
type breaker struct {
limit int // breaker will not exeucute any more tasks after limit number of consequtive failuers happen
consFailedCalls int // current number of consequtive fails
limit int // breaker will not execute any more tasks after limit number of consecutive failures happen
consFailedCalls int // current number of consecutive fails
firstFailedTimestamp time.Time
closedTimestamp time.Time
backoff time.Duration // initial backoff 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
}
......
......@@ -47,13 +47,13 @@ func newMetrics() metrics {
Namespace: m.Namespace,
Subsystem: subsystem,
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{
Namespace: m.Namespace,
Subsystem: subsystem,
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{
Namespace: m.Namespace,
......
......@@ -111,7 +111,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
}
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()}
err = ps.sendReceipt(w, receipt)
if err != nil {
......@@ -133,7 +133,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
}
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()}
return ps.sendReceipt(w, receipt)
}
......
......@@ -7,8 +7,8 @@ import (
"encoding/binary"
"testing"
"github.com/ethersphere/bee/pkg/validator"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/validator"
)
// TestContentAddressValidator checks that the validator evaluates correctly
......@@ -28,7 +28,7 @@ func TestContentAddressValidator(t *testing.T) {
fooLength := len(foo)
fooBytes := make([]byte, 8+fooLength)
binary.LittleEndian.PutUint64(fooBytes, uint64(fooLength))
copy(fooBytes[8:], []byte(foo))
copy(fooBytes[8:], foo)
ch := swarm.NewChunk(address, fooBytes)
if !validator.Validate(ch) {
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