Skip to content

Commit

Permalink
add golangci-lint
Browse files Browse the repository at this point in the history
gometalinter is deprecated, and golangci-lint is its recommended
successor. This commit adds golangci-lint as the linter for swarmkit. In
addition, golangci-lint found a few issues in the code that were not
yet identified, and so those issues have been fixed.

Signed-off-by: Drew Erny <[email protected]>
  • Loading branch information
dperny committed Jun 26, 2019
1 parent 3df33bc commit 27c2d27
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 36 deletions.
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
run:
tests: false
linters:
disable-all: true
enable:
- misspell
- gofmt
- goimports
- golint
- ineffassign
- deadcode
- unconvert
- govet

17 changes: 0 additions & 17 deletions .gometalinter.json

This file was deleted.

2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func (a *Agent) nodeDescriptionWithHostname(ctx context.Context, tlsInfo *api.No

// Override hostname and TLS info
if desc != nil {
if a.config.Hostname != "" && desc != nil {
if a.config.Hostname != "" {
desc.Hostname = a.config.Hostname
}
desc.TLSInfo = tlsInfo
Expand Down
2 changes: 1 addition & 1 deletion agent/exec/dockerapi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func parsePortMap(portMap nat.PortMap) ([]*api.PortConfig, error) {
return nil, err
}

protocol := api.ProtocolTCP
var protocol api.PortConfig_Protocol
switch strings.ToLower(parts[1]) {
case "tcp":
protocol = api.ProtocolTCP
Expand Down
4 changes: 2 additions & 2 deletions agent/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *session) start(ctx context.Context, description *api.NodeDescription) e
// `ctx` is done and hence fail to propagate the timeout error to the agent.
// If the error is not propogated to the agent, the agent will not close
// the session or rebuild a new session.
sessionCtx, cancelSession := context.WithCancel(ctx) // nolint: vet
sessionCtx, cancelSession := context.WithCancel(ctx) //nolint:govet

// Need to run Session in a goroutine since there's no way to set a
// timeout for an individual Recv call in a stream.
Expand All @@ -159,7 +159,7 @@ func (s *session) start(ctx context.Context, description *api.NodeDescription) e
select {
case err := <-errChan:
if err != nil {
return err // nolint: vet
return err //nolint:govet
}
case <-time.After(dispatcherRPCTimeout):
cancelSession()
Expand Down
2 changes: 1 addition & 1 deletion cmd/swarmctl/service/flagparser/tmpfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func parseTmpfs(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
// remove suffix and try again
suffix := meat[len(meat)-1]
meat = meat[:len(meat)-1]
var multiplier int64 = 1
var multiplier int64
switch suffix {
case 'g':
multiplier = 1 << 30
Expand Down
6 changes: 3 additions & 3 deletions direct.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ version/version.go:
setup: ## install dependencies
@echo "🐳 $@"
# TODO(stevvooe): Install these from the vendor directory
@go get -u github.com/alecthomas/gometalinter
@gometalinter --install
# install golangci-lint version 1.17.1 to ./bin/golangci-lint
@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.17.1
@go get -u github.com/lk4d4/vndr
@go get -u github.com/stevvooe/protobuild

Expand All @@ -65,7 +65,7 @@ checkprotos: generate ## check if protobufs needs to be generated again
check: fmt-proto
check: ## Run various source code validation tools
@echo "🐳 $@"
@gometalinter ./...
@./bin/golangci-lint run

.PHONY: fmt-proto
fmt-proto:
Expand Down
2 changes: 1 addition & 1 deletion manager/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (d *Dispatcher) Run(ctx context.Context) error {
if err != nil {
return err
}
if err == nil && len(clusters) == 1 {
if len(clusters) == 1 {
heartbeatPeriod, err := gogotypes.DurationFromProto(clusters[0].Spec.Dispatcher.HeartbeatPeriod)
if err == nil && heartbeatPeriod > 0 {
d.config.HeartbeatPeriod = heartbeatPeriod
Expand Down
2 changes: 1 addition & 1 deletion manager/drivers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (m *DriverProvider) NewSecretDriver(driver *api.Driver) (*SecretDriver, err
if m.pluginGetter == nil {
return nil, fmt.Errorf("plugin getter is nil")
}
if driver == nil && driver.Name == "" {
if driver == nil || driver.Name == "" {
return nil, fmt.Errorf("driver specification is nil")
}
// Search for the specified plugin
Expand Down
9 changes: 1 addition & 8 deletions manager/orchestrator/restart/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,13 @@ func (r *Supervisor) Cancel(taskID string) {
<-delay.doneCh
}

// CancelAll aborts all pending restarts and waits for any instances of
// StartNow that have already triggered to complete.
// CancelAll aborts all pending restarts
func (r *Supervisor) CancelAll() {
var cancelled []delayedStart

r.mu.Lock()
for _, delay := range r.delays {
delay.cancel()
}
r.mu.Unlock()

for _, delay := range cancelled {
<-delay.doneCh
}
}

// ClearServiceHistory forgets restart history related to a given service ID.
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/docker/swarmkit/manager/encryption"
"github.com/docker/swarmkit/remotes"
"github.com/docker/swarmkit/xnet"
"github.com/grpc-ecosystem/go-grpc-prometheus"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
bolt "go.etcd.io/bbolt"
Expand Down

0 comments on commit 27c2d27

Please sign in to comment.