Skip to content

Commit 1d68580

Browse files
authored
add misspell, gofmt and unconvert linters (ethersphere#160)
1 parent e7b0f73 commit 1d68580

File tree

9 files changed

+32
-23
lines changed

9 files changed

+32
-23
lines changed

.githooks/pre-push.bash

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@ if [ -z "$commits" ]; then
88
exit 0
99
fi
1010

11-
if ! command -v golangci-lint &> /dev/null; then
12-
echo "installing golangci-lint..."
13-
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
14-
fi
15-
16-
make lint vet test-race
11+
make build lint vet test-race

.github/workflows/go.yml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
echo "::set-env name=GOPATH::$(go env GOPATH)"
2727
echo "::add-path::$(go env GOPATH)/bin"
2828
shell: bash
29+
- name: Set git to use LF
30+
# make sure that line endings are not converted on windows
31+
# as gofmt linter will report that they need to be changed
32+
run: git config --global core.autocrlf false
2933
- name: Checkout
3034
uses: actions/checkout@v2
3135
with:

.golangci.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
run:
2-
timeout: 10m
2+
timeout: 10m
3+
linters:
4+
enable:
5+
- misspell
6+
- gofmt
7+
- unconvert

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
GO ?= go
22
GOLANGCI_LINT ?= golangci-lint
3+
GOLANGCI_LINT_VERSION ?= v1.26.0
34

45
LDFLAGS ?= -s -w
56
ifdef COMMIT
67
LDFLAGS += -X github.com/ethersphere/bee.commit="$(COMMIT)"
78
endif
89

910
.PHONY: all
10-
all: build lint vet test binary
11+
all: build lint vet test-race binary
1112

1213
.PHONY: binary
1314
binary: export CGO_ENABLED=0
@@ -19,9 +20,13 @@ dist:
1920
mkdir $@
2021

2122
.PHONY: lint
22-
lint:
23+
lint: linter
2324
$(GOLANGCI_LINT) run
2425

26+
.PHONY: linter
27+
linter:
28+
which $(GOLANGCI_LINT) || ( cd /tmp && GO111MODULE=on $(GO) get -u github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) )
29+
2530
.PHONY: vet
2631
vet:
2732
$(GO) vet ./...

pkg/p2p/libp2p/internal/breaker/breaker.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ var (
3030

3131
type Interface interface {
3232
// Execute runs f() if the limit number of consecutive failed calls is not reached within fail interval.
33-
// f() call is not locked so it can still be executed concurently.
33+
// f() call is not locked so it can still be executed concurrently.
3434
// Returns `ErrClosed` if the limit is reached or f() result otherwise.
3535
Execute(f func() error) error
3636

37-
// ClosedUntil retuns the timestamp when the breaker will become open again.
37+
// ClosedUntil returns the timestamp when the breaker will become open again.
3838
ClosedUntil() time.Time
3939
}
4040

4141
type breaker struct {
42-
limit int // breaker will not exeucute any more tasks after limit number of consequtive failuers happen
43-
consFailedCalls int // current number of consequtive fails
42+
limit int // breaker will not execute any more tasks after limit number of consecutive failures happen
43+
consFailedCalls int // current number of consecutive fails
4444
firstFailedTimestamp time.Time
4545
closedTimestamp time.Time
4646
backoff time.Duration // initial backoff duration
4747
maxBackoff time.Duration
48-
failInterval time.Duration // consequitive failures are counted if they happen withing this interval
48+
failInterval time.Duration // consecutive failures are counted if they happen within this interval
4949
mtx sync.Mutex
5050
}
5151

pkg/pushsync/metrics.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ func newMetrics() metrics {
4747
Namespace: m.Namespace,
4848
Subsystem: subsystem,
4949
Name: "total_chunk_synced",
50-
Help: "Total chunks synced succesfully with valid receipts.",
50+
Help: "Total chunks synced successfully with valid receipts.",
5151
}),
5252
TotalChunksStoredInDB: prometheus.NewCounter(prometheus.CounterOpts{
5353
Namespace: m.Namespace,
5454
Subsystem: subsystem,
5555
Name: "total_chunk_stored_in_DB",
56-
Help: "Total chunks stored succesfully in local store.",
56+
Help: "Total chunks stored successfully in local store.",
5757
}),
5858
ChunksSentCounter: prometheus.NewCounter(prometheus.CounterOpts{
5959
Namespace: m.Namespace,

pkg/pushsync/pushsync.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
111111
}
112112
ps.metrics.TotalChunksStoredInDB.Inc()
113113

114-
// Send a receipt immediately once the storage of the chunk is successfull
114+
// Send a receipt immediately once the storage of the chunk is successful
115115
receipt := &pb.Receipt{Address: chunk.Address().Bytes()}
116116
err = ps.sendReceipt(w, receipt)
117117
if err != nil {
@@ -133,7 +133,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
133133
}
134134
ps.metrics.TotalChunksStoredInDB.Inc()
135135

136-
// Send a receipt immediately once the storage of the chunk is successfull
136+
// Send a receipt immediately once the storage of the chunk is successful
137137
receipt := &pb.Receipt{Address: chunk.Address().Bytes()}
138138
return ps.sendReceipt(w, receipt)
139139
}

pkg/swarm/swarm.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414

1515
const (
1616
SectionSize = 32
17-
Branches = 128
18-
ChunkSize = SectionSize * Branches
19-
MaxPO = 16
17+
Branches = 128
18+
ChunkSize = SectionSize * Branches
19+
MaxPO = 16
2020
)
2121

2222
// Address represents an address in Swarm metric space of

pkg/validator/validator_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"encoding/binary"
88
"testing"
99

10-
"github.com/ethersphere/bee/pkg/validator"
1110
"github.com/ethersphere/bee/pkg/swarm"
11+
"github.com/ethersphere/bee/pkg/validator"
1212
)
1313

1414
// TestContentAddressValidator checks that the validator evaluates correctly
@@ -28,7 +28,7 @@ func TestContentAddressValidator(t *testing.T) {
2828
fooLength := len(foo)
2929
fooBytes := make([]byte, 8+fooLength)
3030
binary.LittleEndian.PutUint64(fooBytes, uint64(fooLength))
31-
copy(fooBytes[8:], []byte(foo))
31+
copy(fooBytes[8:], foo)
3232
ch := swarm.NewChunk(address, fooBytes)
3333
if !validator.Validate(ch) {
3434
t.Fatalf("data '%s' should have validated to hash '%s'", ch.Data(), ch.Address())

0 commit comments

Comments
 (0)