Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cicd: Enable additional linters #60

Merged
merged 11 commits into from
Oct 9, 2023
119 changes: 115 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,140 @@
# Based on recommendations in https://olegk.dev/go-linters-configuration-the-right-version

run:
# linter execution
timeout: 30m
issues-exit-code: 1
concurrency: 4
# check tests as well
tests: true
elevran marked this conversation as resolved.
Show resolved Hide resolved
# fail if go.mod file is outdated.
modules-download-mode: readonly
# use the Go version from the go.mod file.
go: ""

linters:
disable-all: false
# set to true to run only fast linters (e.g., for pre-commit)
fast: false

disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- errcheck
- contextcheck
- durationcheck
- errcheck
- errname
# - errorlint
elevran marked this conversation as resolved.
Show resolved Hide resolved
- exportloopref
- gosec
- gosimple
- ginkgolinter
- gocritic
# - godot
- gofmt
# - gofumpt
- goimports
- gomoddirectives
- gosec
- gosimple
- govet
- grouper
# - lll
- loggercheck
- importas
- ineffassign
- makezero
- misspell
- nakedret
# - nestif
- nilerr
# - nilnil
# - noctx
# - nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- staticcheck
- stylecheck
# - tagliatelle
- tenv
- testableexamples
# - thelper
# - testpackage
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
# - varnamelen

linters-settings:
gocritic:
enabled-tags:
- diagnostic
# - experimental
# - opinionated
- performance
# - style
disabled-checks:
# consider enabling in performance oriented code
- hugeParam
- rangeExprCopy
- rangeValCopy

errcheck:
# change some error checks which are disabled by default
# check-type-assertions: true
# check-blank: true
# exclude-functions:
# - io/ioutil.ReadFile
# - io.Copy(*bytes.Buffer)
# - io.Copy(os.Stdout)

govet:
disable:
- fieldalignment

nakedret:
# No naked returns (default: 30)
max-func-lines: 1

staticcheck:
checks:
- "all"

stylecheck:

tagliatelle:
case:
rules:
json: snake
yaml: snake
xml: camel
bson: camel
avro: snake
mapstructure: kebab

output:
# prefer the simplest output: `line-number` without saving to file
format: line-number
print-issued-lines: false
print-linter-name: true
# allow multiple reports per line
uniq-by-line: false
# easier to follow the results with a deterministic output
sort-results: true

issues:
# setting 0 to have all the results.
max-issues-per-linter: 0
# nothing should be skipped to not miss errors.
max-same-issues: 0
# analyze only new code (manually set to false to check existing code)
new: true
# do not automatically fix (until AI assisted code improves)
fix: false
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IMG ?= $(IMAGE_TAG_BASE):$(SW_VERSION)
# Target: clean
#-----------------------------------------------------------------------------
.PHONY: clean
clean: ; $(info $(M) cleaning...) @
clean: ; $(info cleaning previous builds...) @
@rm -rf ./bin

#------------------------------------------------------
Expand All @@ -32,16 +32,16 @@ format: fmt
fmt: format-go tidy-go vet-go
vet: vet-go

lint: ; $(info $(M) running linters...)
@golangci-lint run
lint: ; $(info running linters...)
@golangci-lint run --config=./.golangci.yaml ./...
kfirtoledo marked this conversation as resolved.
Show resolved Hide resolved

tidy-go: ; $(info $(M) tidying up go.mod...)
tidy-go: ; $(info tidying up go.mod...)
@go mod tidy

format-go: tidy-go vet-go ; $(info $(M) formatting code...)
format-go: tidy-go vet-go ; $(info formatting code...)
@goimports -l -w .

vet-go: ; $(info $(M) vetting code...)
vet-go: ; $(info vetting code...)
@go vet ./...

#------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pkg/controlplane/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func GetDataplane() string {
func GetDataplaneEndpoint() string {
return s.MyInfo.DataplaneEndpoint
}
func GetChiRouter() (r *chi.Mux) {
func GetChiRouter() *chi.Mux {
return ChiRouter
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/kubernetes/kubeinformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (k *kubeData) initInformers(client kubernetes.Interface) error {
return err
}

log.Infof("Starting kubernetes informers, waiting for syncronization")
log.Infof("Starting kubernetes informers, waiting for synchronization")
informerFactory.Start(k.stopChan)
informerFactory.WaitForCacheSync(k.stopChan)
k.serviceMap = make(map[string]string)
Expand Down
1 change: 0 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (m *Metrics) aggregateMetrics(connectionStatus event.ConnectionStatusAttr)
flow.OutgoingBytes += connectionStatus.OutgoingBytes
flow.LastTstamp = connectionStatus.LastTstamp
flow.State = connectionStatus.State
// m.ConnectionFlow[connectionStatus.ConnectionID] = flow
} else {
m.ConnectionFlow[connectionStatus.ConnectionID] = &connectionStatus
}
Expand Down
1 change: 0 additions & 1 deletion pkg/policyengine/accessControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (acl *AccessControl) RulesLookup(serviceSrc string, serviceDst string, mbgD
resultAction = myRule.Action
bitrate = myRule.Bitrate
}
// plog.Infof("Rules Matched.. action=%d", myRule.Action)
}
return priority, resultAction, bitrate
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/jsonapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"strconv"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -92,7 +94,7 @@ func (c *Client) do(method, path string, body []byte) (*Response, error) {

// NewClient returns a new HTTP client.
func NewClient(host string, port uint16, tlsConfig *tls.Config) *Client {
serverURL := fmt.Sprintf("https://%s:%d", host, port)
serverURL := "https://" + net.JoinHostPort(host, strconv.Itoa(int(port)))
return &Client{
client: &http.Client{
Transport: &http.Transport{TLSClientConfig: tlsConfig},
Expand Down