Skip to content

Commit 78ce6f4

Browse files
authored
Merge pull request #14 from threefoldtech/development_fix_linter
fix linter
2 parents 1975919 + f12561f commit 78ce6f4

File tree

22 files changed

+58
-97
lines changed

22 files changed

+58
-97
lines changed

.golangci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
linters:
2+
enable:
3+
- errcheck
4+
- gofmt
5+
- govet
6+
- ineffassign
7+
- unconvert
8+
- staticcheck
9+
- gocyclo
10+
enable-all: false
11+
linters-settings:
12+
gocyclo:
13+
# Minimal code complexity to report.
14+
# Default: 30 (but we recommend 10-20)
15+
min-complexity: 100
16+
run:
17+
timeout: 20m

pkg/Makefile

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,21 @@ GOPATH := $(shell go env GOPATH)
33

44
all: build
55

6-
getdeps:
7-
@echo "Installing golint" && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0
8-
@echo "Installing gocyclo" && go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
9-
@echo "Installing deadcode" && go install github.com/remyoudompheng/go-misc/deadcode@latest
10-
@echo "Installing misspell" && go install github.com/client9/misspell/cmd/misspell@latest
11-
@echo "Installing ineffassign" && go install github.com/gordonklaus/ineffassign@latest
12-
@echo "Installing staticcheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
13-
14-
verifiers: vet fmt lint cyclo spelling static #deadcode
15-
16-
vet:
17-
@echo "Running $@"
18-
@go vet -atomic -bool -copylocks -nilfunc -printf -rangeloops -unreachable -unsafeptr -unusedresult ./...
6+
all: getdeps test
197

20-
fmt:
21-
@echo "Running $@"
22-
@gofmt -d .
8+
getdeps:
9+
@echo "Installing golangci-lint" && go get github.com/golangci/golangci-lint/cmd/golangci-lint && go install github.com/golangci/golangci-lint/cmd/golangci-lint
10+
go mod tidy
2311

2412
lint:
2513
@echo "Running $@"
26-
@${GOPATH}/bin/golangci-lint run
27-
28-
ineffassign:
29-
@echo "Running $@"
30-
@${GOPATH}/bin/ineffassign .
31-
32-
cyclo:
33-
@echo "Running $@"
34-
@${GOPATH}/bin/gocyclo -over 100 .
35-
36-
deadcode:
37-
@echo "Running $@"
38-
@${GOPATH}/bin/deadcode -test $(shell go list ./...) || true
39-
40-
spelling:
41-
@${GOPATH}/bin/misspell -i "monitord,forumla,etherent" -error `find .`
42-
43-
static:
44-
@${GOPATH}/bin/staticcheck -- ./...
14+
@${GOPATH}/bin/golangci-lint run -c ../.golangci.yml
4515

4616
check: test
47-
test: verifiers build
17+
test: lint build
4818
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )
4919

50-
testrace: verifiers build
20+
testrace: lint build
5121
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )
5222

5323
generate:

pkg/container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func (c *Module) start(ns, id string) error {
426426

427427
ctx := namespaces.WithNamespace(context.Background(), ns)
428428

429-
container, err := client.LoadContainer(ctx, string(id))
429+
container, err := client.LoadContainer(ctx, id)
430430
if err != nil {
431431
return err
432432
}
@@ -615,7 +615,7 @@ func (c *Module) Delete(ns string, id pkg.ContainerID) error {
615615
_ = task.Kill(ctx, syscall.SIGTERM)
616616
select {
617617
case <-exitC:
618-
case <-time.After(time.Duration(shutdownTimeout)):
618+
case <-time.After(shutdownTimeout):
619619
log.Debug().Str("id", string(id)).Int("signal", int(syscall.SIGKILL)).Msg("sending signal")
620620
_ = task.Kill(ctx, syscall.SIGKILL)
621621
select {

pkg/container/stats/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Monitor(addr string, ns string, id string, backend io.WriteCloser) error {
4646

4747
ctx := namespaces.WithNamespace(context.Background(), ns)
4848

49-
container, err := client.LoadContainer(ctx, string(id))
49+
container, err := client.LoadContainer(ctx, id)
5050
if err != nil {
5151
log.Error().Err(err).Msg("metric container")
5252
return err

pkg/crypto/crypto_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func TestPyNACLCompatibilityEncryption(t *testing.T) {
7777
sk := ed25519.NewKeyFromSeed(seed)
7878

7979
chiper := ""
80-
fmt.Sscanf("0bfe9e3b9ce17fe6d570b165ea2a01034326b8c81d5f2c5384c8fe886552f074ec43017465598c4f5a857b495b445be46c3df48d14878bd0b1b907", "%x", &chiper)
80+
_, err := fmt.Sscanf("0bfe9e3b9ce17fe6d570b165ea2a01034326b8c81d5f2c5384c8fe886552f074ec43017465598c4f5a857b495b445be46c3df48d14878bd0b1b907", "%x", &chiper)
81+
require.NoError(t, err)
8182

8283
decrypted, err := Decrypt([]byte(chiper), sk)
8384
require.NoError(t, err)

pkg/flist/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (f *flistModule) cleanCache(now time.Time, age time.Duration) error {
5959

6060
if sys, ok := sys.(*syscall.Stat_t); ok {
6161
// int64 cast required for arm32 targets
62-
atime := time.Unix(int64(sys.Atim.Sec), int64(sys.Atim.Nsec))
62+
atime := time.Unix(sys.Atim.Sec, sys.Atim.Nsec)
6363

6464
if now.Sub(atime) > age {
6565
if err := os.Remove(path); err != nil {

pkg/gridtypes/id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (i WorkloadID) Unique(n string) string {
7171
b = b[:13]
7272
}
7373

74-
return string(b)
74+
return b
7575
}
7676

7777
// IsValidName validates workload name

pkg/gridtypes/workload_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestTimestamp(t *testing.T) {
2121
exp, err := json.Marshal(n)
2222
require.NoError(err)
2323

24-
err = json.Unmarshal([]byte(exp), &v)
24+
err = json.Unmarshal(exp, &v)
2525
require.NoError(err)
2626

2727
require.Equal(Timestamp(n.Unix()), v)

pkg/gridtypes/zos/network_light.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NetworkID(twin uint32, network gridtypes.Name) NetID {
3232
if len(b) > 13 {
3333
b = b[:13]
3434
}
35-
return NetID(string(b))
35+
return NetID(b)
3636
}
3737

3838
func NetworkIDFromWorkloadID(wl gridtypes.WorkloadID) (NetID, error) {

pkg/netlight/ifaceutil/mac.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func DeviceNameFromInputBytes(input []byte) string {
5151
b = b[:13]
5252
}
5353

54-
return string(b)
54+
return b
5555
}
5656

5757
func isHardwareAddrInValidRange(addr net.HardwareAddr) bool {

pkg/netlight/resource/mycelium.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func inspectMyceliumFile(path string) (inspection MyceliumInspection, err error)
7474

7575
// IP return the address in the 400::/7 subnet allocated by mycelium
7676
func (m *MyceliumInspection) IP() net.IP {
77-
return net.IP(m.Address)
77+
return m.Address
7878
}
7979

8080
// Subnet return the 400::/64 subnet allocated by mycelium

pkg/perf/iperf/iperf_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (t *IperfTest) runIperfTest(ctx context.Context, clientIP string, tcp bool)
151151
operation := func() error {
152152
res := runIperfCommand(ctx, opts)
153153
if res.Error == errServerBusy {
154-
return fmt.Errorf(errServerBusy)
154+
return errors.New(errServerBusy)
155155
}
156156

157157
report = res

pkg/perf/publicip/publicip_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stub
202202
}
203203

204204
for _, node := range nodes {
205-
if node.NodeID >= uint32(nodeID) {
205+
if node.NodeID >= nodeID {
206206
continue
207207
}
208208
n, err := substrateGateway.GetNode(ctx, node.NodeID)

pkg/power/ethtool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func valueOfFlag(output []byte, flag Flag) (string, error) {
5757
if len(parts) != 2 {
5858
return "", fmt.Errorf("invalid ethtool output format (%s)", line)
5959
}
60-
return strings.TrimSpace(string(parts[1])), nil
60+
return strings.TrimSpace(parts[1]), nil
6161
}
6262

6363
return "", ErrFlagNotFound

pkg/primitives/vm-light/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (p *Manager) newPrivNetworkInterface(ctx context.Context, dl gridtypes.Depl
215215
// privIP6,
216216
},
217217
Routes: iface.Routes,
218-
IP4DefaultGateway: net.IP(iface.Routes[0].Gateway),
218+
IP4DefaultGateway: iface.Routes[0].Gateway,
219219
// IP6DefaultGateway: gw6,
220220
PublicIPv4: false,
221221
PublicIPv6: false,

pkg/provision/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *substrateTwins) GetKey(id uint32) ([]byte, error) {
4040

4141
key := user.Account.PublicKey()
4242
s.mem.Add(id, key)
43-
return []byte(key), nil
43+
return key, nil
4444
}
4545

4646
type substrateAdmins struct {

pkg/provision/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ func (e *NativeEngine) validate(ctx context.Context, dl *gridtypes.Deployment, n
572572
return ctx, fmt.Errorf("substrate is not configured in engine")
573573
}
574574

575-
contract, subErr := e.substrateGateway.GetContract(ctx, uint64(dl.ContractID))
575+
contract, subErr := e.substrateGateway.GetContract(ctx, dl.ContractID)
576576
if subErr.IsError() {
577577
return nil, errors.Wrap(subErr.Err, "failed to get deployment contract")
578578
}

pkg/provision/storage.fs/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (s *Fs) byTwin(twin uint32) ([]uint64, error) {
283283
continue
284284
}
285285

286-
ids = append(ids, uint64(id))
286+
ids = append(ids, id)
287287
}
288288

289289
return ids, nil

pkg/storage/storage_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func TestCacheResize(t *testing.T) {
416416
Excl: 1,
417417
},
418418
}
419-
vol.On("Limit", uint64(cacheSize)).Return(nil)
419+
vol.On("Limit", cacheSize).Return(nil)
420420
err := m.checkAndResizeCache(&vol, cacheSize)
421421
require.NoError(t, err)
422422

@@ -444,7 +444,7 @@ func TestCacheResize(t *testing.T) {
444444
Excl: 0, // no files
445445
},
446446
}
447-
vol.On("Limit", uint64(cacheSize)).Return(nil)
447+
vol.On("Limit", cacheSize).Return(nil)
448448
err = m.checkAndResizeCache(&vol, cacheSize)
449449
require.NoError(t, err)
450450

@@ -468,7 +468,7 @@ func TestCacheResize(t *testing.T) {
468468
Excl: 91,
469469
},
470470
}
471-
vol.On("Limit", uint64(100+cacheSize)).Return(nil)
471+
vol.On("Limit", 100+cacheSize).Return(nil)
472472
err = m.checkAndResizeCache(&vol, cacheSize)
473473
require.NoError(t, err)
474474

pkg/vm/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (m *Module) withLogs(path string, err error) error {
327327
return errors.Wrapf(err, "failed to tail machine logs: %s", tailErr)
328328
}
329329

330-
return errors.Wrapf(err, string(logs))
330+
return errors.Wrap(err, logs)
331331
}
332332

333333
func (m *Module) checkDevicesUsed(devices []string) error {

pkg/zdb/admin.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package zdb
22

33
import (
4-
"fmt"
4+
"errors"
55
"strings"
66

77
"github.com/gomodule/redigo/redis"
@@ -18,7 +18,7 @@ func (c *clientImpl) CreateNamespace(name string) error {
1818
return err
1919
}
2020
if ok != "OK" {
21-
return fmt.Errorf(ok)
21+
return errors.New(ok)
2222
}
2323
return nil
2424
}
@@ -49,7 +49,7 @@ func (c *clientImpl) DeleteNamespace(name string) error {
4949
return err
5050
}
5151
if ok != "OK" {
52-
return fmt.Errorf(ok)
52+
return errors.New(ok)
5353
}
5454
return nil
5555
}
@@ -70,7 +70,7 @@ func (c *clientImpl) NamespaceSetSize(name string, size uint64) error {
7070
return err
7171
}
7272
if ok != "OK" {
73-
return fmt.Errorf(ok)
73+
return errors.New(ok)
7474
}
7575
return nil
7676
}
@@ -84,7 +84,7 @@ func (c *clientImpl) NamespaceSetPassword(name, password string) error {
8484
return err
8585
}
8686
if ok != "OK" {
87-
return fmt.Errorf(ok)
87+
return errors.New(ok)
8888
}
8989
return nil
9090
}
@@ -98,7 +98,7 @@ func (c *clientImpl) NamespaceSetMode(name, mode string) error {
9898
return err
9999
}
100100
if ok != "OK" {
101-
return fmt.Errorf(ok)
101+
return errors.New(ok)
102102
}
103103
return nil
104104
}
@@ -116,7 +116,7 @@ func (c *clientImpl) NamespaceSetLock(name string, lock bool) error {
116116
return err
117117
}
118118
if ok != "OK" {
119-
return fmt.Errorf(ok)
119+
return errors.New(ok)
120120
}
121121
return nil
122122
}
@@ -136,7 +136,7 @@ func (c *clientImpl) NamespaceSetPublic(name string, public bool) error {
136136
return err
137137
}
138138
if ok != "OK" {
139-
return fmt.Errorf(ok)
139+
return errors.New(ok)
140140
}
141141
return nil
142142
}

tools/zos-update-worker/Makefile

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,14 @@ ldflags='-w -s -X $(version).Branch=$(branch) -X $(version).Revision=$(revision)
88
all: getdeps test
99

1010
getdeps:
11-
@echo "Installing staticcheck" && go get -u honnef.co/go/tools/cmd/staticcheck && go install honnef.co/go/tools/cmd/staticcheck
12-
@echo "Installing gocyclo" && go get -u github.com/fzipp/gocyclo/cmd/gocyclo && go install github.com/fzipp/gocyclo/cmd/gocyclo
13-
@echo "Installing deadcode" && go get -u github.com/remyoudompheng/go-misc/deadcode && go install github.com/remyoudompheng/go-misc/deadcode
14-
@echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell && go install github.com/client9/misspell/cmd/misspell
15-
@echo "Installing golangci-lint" && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
11+
@echo "Installing golangci-lint" && go get github.com/golangci/golangci-lint/cmd/golangci-lint && go install github.com/golangci/golangci-lint/cmd/golangci-lint
1612
go mod tidy
1713

18-
19-
verifiers: fmt lint cyclo deadcode spelling staticcheck
20-
21-
fmt:
22-
@echo "Running $@"
23-
@gofmt -d .
24-
2514
lint:
2615
@echo "Running $@"
27-
@${GOPATH}/bin/golangci-lint run
28-
29-
cyclo:
30-
@echo "Running $@"
31-
@${GOPATH}/bin/gocyclo -over 100 .
32-
33-
deadcode:
34-
@echo "Running $@"
35-
@${GOPATH}/bin/deadcode -test $(shell go list ./...) || true
36-
37-
spelling:
38-
@echo "Running $@"
39-
@${GOPATH}/bin/misspell -i monitord -error `find .`
40-
41-
staticcheck:
42-
@echo "Running $@"
43-
@${GOPATH}/bin/staticcheck -- ./...
16+
golangci-lint run -c ../../.golangci.yml
4417

45-
test: verifiers
18+
test: lint
4619
go test -v -vet=off ./...
4720

4821
benchmarks:
@@ -53,7 +26,7 @@ coverage: clean
5326
go test -v -vet=off ./... -coverprofile=coverage/coverage.out
5427
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
5528

56-
testrace: verifiers
29+
testrace: lint
5730
go test -v -race -vet=off ./...
5831

5932
run:

0 commit comments

Comments
 (0)