Skip to content

Commit

Permalink
Adding more linters and fixing the errors they find (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: ZIV NEVO <[email protected]>
  • Loading branch information
zivnevo authored Feb 5, 2024
1 parent dc26c77 commit 3595700
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
38 changes: 29 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,70 @@ linters-settings:
allowStrs: '"",".","-","/","\n","\n\n","\t","error","true","false"'
allowInts: "0,1,2,404"
allowFloats: "0.0,0.,1.0,1.,2.0,2."
tagliatelle:
case:
rules:
json: snake

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- dogsled
- dupl
- durationcheck
- errcheck
- errorlint
- exportloopref
- funlen
- ginkgolinter
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- lll
- loggercheck
- makezero
- misspell
- nakedret
- nestif
- nilerr
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- staticcheck
- stylecheck
- tagliatelle
- tenv
- testableexamples
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
- revive

# don't enable:
# - gochecknoglobals
# - gocognit
# - goerr113
# - nestif
# - testpackage
# - wsl

issues:
exclude-rules:
- path: _test\.go
Expand Down
3 changes: 2 additions & 1 deletion cmd/nettop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main

import (
"encoding/json"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -120,7 +121,7 @@ func detectTopology(args *inArgs) error {
// Takes command-line flags and returns an error rather than exiting, so it can be more easily used in testing
func _main(cmdlineArgs []string) error {
inArgs, err := parseInArgs(cmdlineArgs)
if err == flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
return nil
}
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/nettop/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ func readLines(path string) ([]string, error) {
func compareFiles(expectedFile, actualFile string) (bool, error) {
expectedLines, err1 := readLines(expectedFile)
if err1 != nil {
return false, fmt.Errorf("error reading lines from file %v", err1)
return false, fmt.Errorf("error reading lines from file %w", err1)
}
actualLines, err2 := readLines(actualFile)
if err2 != nil {
return false, fmt.Errorf("error reading lines from file %v", err2)
return false, fmt.Errorf("error reading lines from file %w", err2)
}
if len(expectedLines) != len(actualLines) {
fmt.Printf("Files line count is different: expected(%s): %d, actual(%s): %d",
Expand Down
19 changes: 10 additions & 9 deletions pkg/analyzer/resource_accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,18 @@ func (ra *resourceAccumulator) inlineConfigMapRefsAsEnvs() []FileProcessingError
// inline PodSpec->container->env->valueFrom->configMapKeyRef
for _, cfgMapKeyRef := range res.Resource.ConfigMapKeyRefs {
configmapFullName := res.Resource.Namespace + "/" + cfgMapKeyRef.Name
if cfgMap, ok := cfgMapsByName[configmapFullName]; ok {
if val, ok := cfgMap.Data[cfgMapKeyRef.Key]; ok {
if netAddr, ok := networkAddressFromStr(val); ok {
res.Resource.NetworkAddrs = append(res.Resource.NetworkAddrs, netAddr)
}
} else {
err := configMapKeyNotFound(cfgMapKeyRef.Name, cfgMapKeyRef.Key, res.Resource.Name)
parseErrors = appendAndLogNewError(parseErrors, err, ra.logger)
cfgMap, ok := cfgMapsByName[configmapFullName]
if !ok {
parseErrors = appendAndLogNewError(parseErrors, configMapNotFound(configmapFullName, res.Resource.Name), ra.logger)
continue
}
if val, ok := cfgMap.Data[cfgMapKeyRef.Key]; ok {
if netAddr, ok := networkAddressFromStr(val); ok {
res.Resource.NetworkAddrs = append(res.Resource.NetworkAddrs, netAddr)
}
} else {
parseErrors = appendAndLogNewError(parseErrors, configMapNotFound(configmapFullName, res.Resource.Name), ra.logger)
err := configMapKeyNotFound(cfgMapKeyRef.Name, cfgMapKeyRef.Key, res.Resource.Name)
parseErrors = appendAndLogNewError(parseErrors, err, ra.logger)
}
}
}
Expand Down

0 comments on commit 3595700

Please sign in to comment.