Skip to content

Commit

Permalink
Update .golangci.yml from metal-toolbox/golangci-lint-config and fix …
Browse files Browse the repository at this point in the history
…errors
  • Loading branch information
mmlb committed May 3, 2024
1 parent 5ebd89b commit c093e53
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 112 deletions.
170 changes: 70 additions & 100 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,123 +1,93 @@
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: v1.56.2 # use the fixed version to not introduce new linters unexpectedly
#
# This file lives in the github.com/metal-toolbox/golangci-lint-config repo.
#
# Do not edit this file outside of this repo otherwise we will be grumpy.
# Seriously though, this is meant to help promote a "standard" config and coding style.
# If you don't like something, lets have a discussion in GitHub issues!
#

linters-settings:
govet:
auto-fix: true
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
revive:
min-confidence: 0
gocyclo:
min-complexity: 15
dupl:
threshold: 100
threshold: 125
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
misspell:
locale: US
auto-fix: true
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- experimental
- performance
- style
- experimental
disabled-checks:
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
gofumpt:
extra-rules: true
whitespace:
auto-fix: true
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
revive:
confidence: 0

linters:
enable:
- errcheck
- gosimple
- govet
- gofmt
- gocyclo
- ineffassign
- stylecheck
- misspell
- staticcheck
- unused
- prealloc
- typecheck
# additional linters
- bodyclose
- gocritic
- goerr113
- goimports
- revive
- misspell
- noctx
- stylecheck
- gosec
- contextcheck
- durationcheck
- errchkjson
- errorlint
- gochecksumtype
- nilerr
- reassign
- whitespace
- exportloopref

enable-all: false
disable-all: true

run:
# build-tags:
skip-dirs:
- internal/fixtures
skip-files:
- "(.*/)*.*_test.go"
enable-all: true
disable-all: false
# Linters we don't like
# Comments help explain why its disabled or point at ones we should not disable but will take a little work
# If its not commented its likely because its just too annoying or we don't find useful
disable:
- copyloopvar # requires go >=1.22
- cyclop
- deadcode # deprecated
- depguard
- errname # maybe should be enabled
- exhaustivestruct # deprecated
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- godot
- godox
- golint # deprecated
- gomnd
- ifshort # deprecated
- inamedparam
- interfacebloat
- interfacer # deprecated
- intrange # requires go >=1.22
- ireturn # should be enabled, ironlib needs some changes
- lll # not previously enabled, ironlib and mctl both fail this
- maligned # deprecated
- nestif
- nilnil
- nlreturn
- nolintlint
- nonamedreturns # should be enabled, probably
- nosnakecase # deprecated
- paralleltest
- perfsprint
- scopelint # deprecated
- structcheck # deprecated
- tagliatelle
- tenv # should be enabled
- testpackage
- testifylint # should be enabled
- thelper # should be enabled
- varcheck # deprecated
- varnamelen
- wrapcheck
- wsl

issues:
exclude-rules:
- linters:
- gosec
text: "weak cryptographic primitive"

- linters:
- stylecheck
text: "ST1016"
exclude:
# Default excludes from `golangci-lint run --help` with EXC0002 removed
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments
# - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
# EXC0003 golint: False positive when tests are defined in package 'test'
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
# EXC0004 govet: Common false positives
- (possible misuse of unsafe.Pointer|should have signature)
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
- ineffective break statement. Did you mean to break out of the outer loop
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
- Use of unsafe calls should be audited
# EXC0007 gosec: Too many false-positives for parametrized shell calls
- Subprocess launch(ed with variable|ing should be audited)
# EXC0008 gosec: Duplicated errcheck checks
- (G104|G307)
# EXC0009 gosec: Too many issues in popular repos
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
- Potential file inclusion via variable
exclude-use-default: false
2 changes: 1 addition & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func FormatConditionResponse(response *coapiv1.ServerResponse, kind rctypes.Kind
func PrintResults(format string, data ...any) {
switch format {
case "text":
spew.Dump(data)
spew.Dump(data...)
case "json", "JSON":
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions cmd/create/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ var createFirmwareSet = &cobra.Command{
}

if definedfirmwareSetFlags.CreateFromFile != "" {
err = createFWSetsFromFile(cmd.Context(), client, definedfirmwareSetFlags)
if err != nil {
log.Fatal(err)
}
createFWSetsFromFile(cmd.Context(), client, definedfirmwareSetFlags)
} else {
err = createFWSetFromCLI(cmd.Context(), client, definedfirmwareSetFlags)
if err != nil {
Expand All @@ -58,7 +55,7 @@ var createFirmwareSet = &cobra.Command{
},
}

func createFWSetsFromFile(ctx context.Context, client *fleetdbapi.Client, flgs *mctl.FirmwareSetFlags) (err error) {
func createFWSetsFromFile(ctx context.Context, client *fleetdbapi.Client, flgs *mctl.FirmwareSetFlags) {
var fwsets []*fleetdbapi.ComponentFirmwareSet

fbytes, err := os.ReadFile(flgs.CreateFromFile)
Expand Down Expand Up @@ -110,8 +107,6 @@ func createFWSetsFromFile(ctx context.Context, client *fleetdbapi.Client, flgs *
log.Fatal("error adding firmware-set object: ", err)
}
}

return nil
}

func createFWSetFromCLI(ctx context.Context, client *fleetdbapi.Client, flgs *mctl.FirmwareSetFlags) (err error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var listFirmware = &cobra.Command{
if flagsDefinedListFirmware.model != "" {
// TODO - if we really want to search using multiple models
//
// fix the the firmware search in fleetdb, its currently useless
// fix the firmware search in fleetdb, its currently useless
// because fleetdb queries the data using an 'AND' instead of an 'OR'
filterParams.Model = []string{strings.ToLower(flagsDefinedListFirmware.model)}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func loadConfig(cfgFile string) (*model.Config, error) {
func validateClientParams(cfg *model.Config) error {
if cfg.FleetDBAPI != nil {
if err := validateConfigOIDC(cfg.FleetDBAPI); err != nil {
return errors.Wrap(err, "fleetdb API API config")
return errors.Wrap(err, "fleetdb API config")
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewFleetDBAPIClient(ctx context.Context, cfg *model.ConfigOIDC, reauth bool
accessToken := "fake"

if cfg == nil {
return nil, errors.Wrap(ErrNilConfig, "missing fleetdb API API client configuration")
return nil, errors.Wrap(ErrNilConfig, "missing fleetdb API client configuration")
}

if cfg.Disable {
Expand Down
1 change: 0 additions & 1 deletion pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const (

// Config struct holds the mctl configuration parameters
type Config struct {

// File is configuration file path
File string
FleetDBAPI *ConfigOIDC `mapstructure:"serverservice_api"` // TODO: implement backwards compatibility and rename.
Expand Down

0 comments on commit c093e53

Please sign in to comment.