Skip to content

Commit

Permalink
Use golangci-lint (networkservicemesh#1054)
Browse files Browse the repository at this point in the history
* Use golangci-lint

- Auto fix by goimprotrs
- Updated guide-build.md
- Disable deprecated linter
- Run static code analysis in a separate job

Signed-off-by: denis-tingajkin <[email protected]>
  • Loading branch information
denis-tingaikin authored and Nikolay Nikolaev committed May 15, 2019
1 parent 5b32efc commit 6e2d22d
Show file tree
Hide file tree
Showing 101 changed files with 509 additions and 239 deletions.
32 changes: 20 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ jobs:
command: |
./scripts/go-mod-download.sh
- run: "! go fmt ./... 2>&1 | read"
- run:
name: golint
command: |
go get golang.org/x/lint/golint
golint ./...
# - run:
# name: gosec
# command: |
# GO111MODULE=off go get github.com/securego/gosec/cmd/gosec/...
# gosec -quiet -severity low -no-fail ./...
- run: ./scripts/prepare-generate.sh
- run: sudo ./scripts/install-protoc.sh
- run: go generate ./...
Expand All @@ -51,7 +41,22 @@ jobs:
environment:
GO111MODULE: "on"

# packet
# code analysis
static-code-analysis:
resource_class: medium+
docker:
- image: circleci/golang
steps:
- checkout
- run:
name: lint
command: |
make lint-install
make lint-check-diff
environment:
GO111MODULE: "on"

# packet
packet-deploy:
docker:
- image: circleci/golang
Expand Down Expand Up @@ -551,7 +556,10 @@ workflows:
build-and-test:
jobs:
- sanity-check

- static-code-analysis:
name: "static-code-analysis"
requires:
- sanity-check
# build
- build-container:
name: "build-nsmd"
Expand Down
104 changes: 104 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
run:
concurrency: 4
deadline: 15m
issues-exit-code: 1

tests: true

skip-dirs:
- build
- conf
- controlplane/scripts
- dataplane/vppagent/build
- dataplane/vppagent/conf
- dataplane/scripts
- deployments
- docks
- scripts

linters-settings:
errcheck:
check-type-assertions: false
check-blank: false

govet:
check-shadowing: true

settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
golint:
min-confidence: 0.8
goimports:
local-prefixes: github.com/networkservicemesh/networkservicemesh
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 3
min-occurrences: 3
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
misspell:
locale: US
unused:
check-exported: true
unparam:
check-exported: true
nakedret:
max-func-lines: 30
prealloc:
simple: true
range-loops: true
for-loops: false
gocritic:
enabled-checks:
- rangeValCopy
- boolExprSimplify
- badCond
- methodExprCall
- paramTypeCombine
- ptrToRefParam
- rangeExprCopy
- captLocal
- caseOrder
- defaultCaseOrder
- dupBranchBody
- dupSubExpr
- elseif
- emptyFallthrough
- emptyStringTest
- equalFold
- indexAlloc
- nestingReduce
- nilValReturn
- yodaStyleExpr
settings:
captLocal:
paramsOnly: true
rangeValCopy:
sizeThreshold: 32

linters:
disable:
- lll
- gofmt
- unused #deprecated
enable-all: true

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude:
- should not use dot imports
15 changes: 15 additions & 0 deletions .mk/code_analysis.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: lint-fix
lint-fix:
golangci-lint run --new-from-rev=origin/master --fix

.PHONY: lint-install
lint-install:
go get github.com/golangci/golangci-lint/cmd/[email protected]

.PHONY: lint-check-diff
lint-check-diff:
golangci-lint run --new-from-rev=origin/master

.PHONY: lint-check-all
lint-check-all:
golangci-lint run ./...
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ WORKER_COUNT ?= 1
.PHONY: default
default: all

# Static code analysis
include .mk/code_analysis.mk

# Pull in k8s targets
include .mk/k8s.mk
include .mk/skydive.mk
Expand Down
4 changes: 2 additions & 2 deletions controllers/sriov-controller/dpapi-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *serviceInstanceController) startServer() error {

go s.server.Serve(sock)

// Wait for server to start by launching a blocking connexion
// Wait for server to start by launching a blocking connection
conn, err := dial(s.socket, 5*time.Second)
if err != nil {
return err
Expand Down Expand Up @@ -332,7 +332,7 @@ func (s *serviceInstanceController) Allocate(ctx context.Context, reqs *pluginap
deviceSpec.Permissions = "rw"
response.Devices = append(response.Devices, &deviceSpec)
// Getting vfio device specific specifications and storing it in the slice. The slice
// will be marshalled into json and passed to requesting POD as a mount.
// will be marshaled into json and passed to requesting POD as a mount.
vfioDev, err := s.getVFIODevSpecs(id)
if err != nil {
return nil, fmt.Errorf("allocation request failure, unable to get device %s specs with error: %+v", id, err)
Expand Down
4 changes: 2 additions & 2 deletions controllers/sriov-controller/sriov-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/ghodss/yaml"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -38,7 +38,7 @@ const (
// containersConfigPath specifies location where sriov controller stores per POD network service
// configuration file.
// TODO (sbezverk) 1. how to clean up after POD which is using this file is gone? The controller could cleanup
// this folder during a boot up, but how to detect which one is used and whcih one not?
// this folder during a boot up, but how to detect which one is used and which one not?
containersConfigPath = "/var/lib/networkservicemesh/sriov-controller/config"
)

Expand Down
5 changes: 3 additions & 2 deletions controlplane/cmd/nsmd/nsmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"time"

"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/model"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/nsm"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/nsmd"
"github.com/networkservicemesh/networkservicemesh/pkg/tools"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion controlplane/pkg/apis/local/connection/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package connection

import (
"fmt"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/connectioncontext"
"strconv"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/connectioncontext"
)

// IsValid - returns nil if Connection is minimally valid.
Expand Down
2 changes: 2 additions & 0 deletions controlplane/pkg/apis/local/networkservice/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package networkservice

import (
"fmt"

"github.com/golang/protobuf/proto"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/local/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/nsm"
)
Expand Down
6 changes: 4 additions & 2 deletions controlplane/pkg/apis/nsm/nsm.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package nsm

import (
"time"

"golang.org/x/net/context"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/connectioncontext"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"
"golang.org/x/net/context"
"time"
)

/*
Expand Down
3 changes: 2 additions & 1 deletion controlplane/pkg/apis/nsm/nsm_properties.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package nsm

import (
"github.com/sirupsen/logrus"
"os"
"strconv"
"time"

"github.com/sirupsen/logrus"
)

const (
Expand Down
2 changes: 2 additions & 0 deletions controlplane/pkg/apis/remote/networkservice/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package networkservice

import (
"fmt"

"github.com/golang/protobuf/proto"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/nsm"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/remote/connection"
)
Expand Down
8 changes: 5 additions & 3 deletions controlplane/pkg/metrics/metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package metrics
import (
"context"
"fmt"
"io"
"time"

"github.com/gogo/protobuf/proto"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
rpc "github.com/ligato/vpp-agent/api/configurator"
interfaces "github.com/ligato/vpp-agent/api/models/vpp/interfaces"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"
"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"io"
"time"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"
)

type MetricsCollector struct {
Expand Down
9 changes: 5 additions & 4 deletions controlplane/pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package model

import (
"fmt"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/nsm"
"strconv"
"sync"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/nsm"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/registry"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/selector"

"github.com/sirupsen/logrus"

local "github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/local/connection"
remote "github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/remote/connection"
"github.com/sirupsen/logrus"
)

type Dataplane struct {
Expand Down Expand Up @@ -138,7 +140,6 @@ type Model interface {
ConnectionId() string
CorrectIdGenerator(id string)


// After listener will be added it will be called for all existing dataplanes/endpoints
AddListener(listener ModelListener)
RemoveListener(listener ModelListener)
Expand Down Expand Up @@ -401,7 +402,7 @@ func (i *impl) CorrectIdGenerator(id string) {
defer i.Unlock()

value, err := strconv.ParseUint(id, 16, 64)
if err != nil {
if err != nil {
logrus.Errorf("Failed to update id genrator %v", err)
}
if i.lastConnnectionId < value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crossconnect_monitor

import (
"fmt"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/monitor"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crossconnect_monitor

import (
"github.com/golang/protobuf/ptypes/empty"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/crossconnect"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/monitor"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package local_connection_monitor

import (
"github.com/golang/protobuf/ptypes/empty"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/local/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/monitor"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package local_connection_monitor

import (
"fmt"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/local/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/monitor"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package remote_connection_monitor

import (
"fmt"

"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/apis/remote/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/pkg/monitor"
)
Expand Down
Loading

0 comments on commit 6e2d22d

Please sign in to comment.