Skip to content

Commit

Permalink
Add initial linter config
Browse files Browse the repository at this point in the history
Address many of the linter complaints
Disable some of the noisier linter categories

Signed-off-by: Tom Flynn <tom.flynn@gmail.com>
  • Loading branch information
tomflynn committed Jul 10, 2023
1 parent fef9cc8 commit 666eb3a
Show file tree
Hide file tree
Showing 113 changed files with 701 additions and 1,116 deletions.
157 changes: 157 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
linters-settings:
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
# setting higher than desired for existing code
funlen:
lines: 300
statements: 150
gci:
local-prefixes: github.com/golangci/golangci-lint
grouper:
const-require-grouping: true
import-require-single-import: true
import-require-grouping: true
var-require-grouping: true
goconst:
min-len: 2
min-occurrences: 10
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- commentFormatting
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- nestingReduce
- octalLiteral
- unnamedResult
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 40
goimports:
local-prefixes: github.com/noironetworks/aci-containers
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: false
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
lll:
line-length: 160
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bidichk
- bodyclose
# - contextcheck
# - depguard
- dogsled
# - dupl
- durationcheck
# - errcheck - temporarily disabled
- errname
- errorlint
- exhaustive
# - exhaustivestruct
- exportloopref
# - forcetypeassert
# - funlen
# - grouper - disabled for now
# - gochecknoinits
# - goconst
- gocritic
# - gocyclo
- gofmt
- goimports
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
# - lll
- makezero
# - misspell
# - nakedret
- nilerr
# - nilnil
- noctx
- nolintlint
- nosprintfhostport
- promlinter
# - revive
# - rowserrcheck
# - staticcheck
# - stylecheck
- typecheck
- unconvert
# - unparam
- unused
# - wastedassign
- whitespace

# don't enable:
# - asciicheck
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl
# - interfacer

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

- linters:
- gocritic
text: "unnecessaryDefer:"

run:
timeout: 5m
skip-dirs:
- .go

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.53.3 # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "I wish I could be prepared. But, nothing to do here for the moment"
2 changes: 0 additions & 2 deletions cmd/acicontainersoperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

// Create Aci Operator Client
func getOperatorClient() operatorclientset.Interface {

restconfig, err := restclient.InClusterConfig()
if err != nil {
log.Errorf("Failed to obtain rest client config %v", err)
Expand All @@ -47,7 +46,6 @@ func getOperatorClient() operatorclientset.Interface {

// Create ACC provision Client
func getAccProvisionClient() accprovisioninputclientset.Interface {

restconfig, err := restclient.InClusterConfig()
if err != nil {
log.Errorf("Failed to obtain rest client config %v", err)
Expand Down
6 changes: 2 additions & 4 deletions cmd/acikubectl/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,7 @@ func clusterReport(cmd *cobra.Command, args []string) {
args: []string{"cp", systemNamespace + "/" + podName + ":" +
"/usr/local/var/lib/opflex-agent-ovs", tempName},
skipOutputFile: true,
})

cmds = append(cmds, reportCmdElem{
}, reportCmdElem{
name: fmt.Sprintf(nodeItem.path, node.Name),
args: nodeItem.argFunc(systemNamespace, podName,
nodeItem.cont, nodeItem.args),
Expand Down Expand Up @@ -661,7 +659,7 @@ func aciContainerHostVersionCmdArgs(systemNamespace string) []string {
"aci-containers-host-agent", "--version"}
}

func hostAgentLogCmdArgs(systemNamespace string, podName string, containerName string, args []string) []string {
func hostAgentLogCmdArgs(systemNamespace, podName, containerName string, args []string) []string {
return append([]string{"-n", systemNamespace, "exec", podName,
"-c", containerName}, args...)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/acikubectl/cmd/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
kubecontext "context"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/noironetworks/aci-containers/pkg/metadata"
)

Expand Down Expand Up @@ -518,7 +519,6 @@ func init() {
BoolP("raw", "", false,
"Get the raw annotation value without formatting")
getDefaultSgCmd.AddCommand(cmd)

}

set.AddCommand(setDefaultEgCmd)
Expand Down
5 changes: 3 additions & 2 deletions cmd/acikubectl/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"bytes"
kubecontext "context"
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"strings"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func getVersion(cmd *cobra.Command, args []string) {
Expand Down
8 changes: 4 additions & 4 deletions cmd/crd-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ func main() {
glog.Fatalf("Error listing all epgs: %v", err)
}

for _, epg := range list.Items {
fmt.Printf("Epg %+v \n", epg)
for i := range list.Items {
fmt.Printf("Epg %+v \n", list.Items[i])
}

cList, err := aciawClient.AciV1().Contracts("default").List(context.Background(), metav1.ListOptions{})
if err != nil {
glog.Fatalf("Error listing all contracts: %v", err)
}

for _, c := range cList.Items {
fmt.Printf("Contract %+v \n", c)
for i := range cList.Items {
fmt.Printf("Contract %+v \n", cList.Items[i])
}
}
5 changes: 3 additions & 2 deletions cmd/gbpserver/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"time"

"github.com/Shopify/sarama"
"github.com/noironetworks/aci-containers/pkg/gbpserver"
"github.com/noironetworks/aci-containers/pkg/gbpserver/kafkac"
"golang.org/x/net/context"
"google.golang.org/grpc"

"github.com/noironetworks/aci-containers/pkg/gbpserver"
"github.com/noironetworks/aci-containers/pkg/gbpserver/kafkac"
)

func handleInspect(opts *cliOpts, cfg *gbpserver.GBPServerConfig) {
Expand Down
1 change: 0 additions & 1 deletion cmd/gbpserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func parseCli(opts *cliOpts) {

// panics on error
func startEtcd(c *gbpserver.GBPServerConfig) []string {

urlMaker := func(portNo int) []url.URL {
var urlList []url.URL
var rawList = []string{fmt.Sprintf("http://localhost:%d", portNo)}
Expand Down
6 changes: 3 additions & 3 deletions cmd/hostagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ func getNodeIP() (string, error) {

restconfig, err := restclient.InClusterConfig()
if err != nil {
return "", fmt.Errorf("Error getting config: %v", err)
return "", fmt.Errorf("Error getting config: %w", err)
}

kubeClient, err := kubernetes.NewForConfig(restconfig)
if err != nil {
return "", fmt.Errorf("Error initializing client: %v", err)
return "", fmt.Errorf("Error initializing client: %w", err)
}

options.FieldSelector = fields.Set{"metadata.name": nodeName}.String()
nodeList, err := kubeClient.CoreV1().Nodes().List(context.TODO(), options)
if err != nil {
return "", fmt.Errorf("Error listing nodes: %v", err)
return "", fmt.Errorf("Error listing nodes: %w", err)
}

for _, node := range nodeList.Items {
Expand Down
3 changes: 1 addition & 2 deletions cmd/kafkakv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ looper:
break looper
}

if m.Value == nil || string(m.Value) == "" {
if m.Value == nil || len(m.Value) == 0 {
delete(kv, string(m.Key))
} else {
kv[string(m.Key)] = true
}

}
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/opflexagentcni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func loadConf(args *skel.CmdArgs) (*NetConf, *K8SArgs, string, error) {

func waitForAllNetwork(result *current.Result, id string,
timeout time.Duration) error {

for index, iface := range result.Interfaces {
netns, err := ns.GetNS(iface.Sandbox)
if err != nil {
Expand All @@ -126,12 +125,10 @@ func waitForAllNetwork(result *current.Result, id string,
}
}
return nil

}

func waitForNetwork(netns ns.NetNS, result *current.Result,
id string, index int, timeout time.Duration) error {

logger := log.WithFields(logrus.Fields{
"id": id,
})
Expand Down Expand Up @@ -228,7 +225,6 @@ func cmdAdd(args *skel.CmdArgs) error {
for _, ip := range result.IPs {
ip.Interface = &zero
}

} else {
result = &current.Result{}
result.DNS = n.DNS
Expand Down
7 changes: 2 additions & 5 deletions pkg/apicapi/apic_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type signer struct {
key interface{}
}

func hash(method string, url string, body []byte) []byte {
func hash(method, url string, body []byte) []byte {
h := sha256.New()
h.Write([]byte(method))
h.Write([]byte(url))
Expand All @@ -40,7 +40,7 @@ func hash(method string, url string, body []byte) []byte {
return h.Sum(nil)
}

func (s *signer) sign(method string, url string,
func (s *signer) sign(method, url string,
body []byte) (sig string, err error) {
h := hash(method, url, body)

Expand All @@ -56,9 +56,6 @@ func (s *signer) sign(method string, url string,
return
}

//fmt.Println("s ", method, " ", url, " ",
// base64.StdEncoding.EncodeToString(h))

sig = base64.StdEncoding.EncodeToString(raw)
return
}
Expand Down

0 comments on commit 666eb3a

Please sign in to comment.