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 Apr 12, 2024
1 parent d8b1222 commit 0f72323
Show file tree
Hide file tree
Showing 38 changed files with 145 additions and 266 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: 110
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
3 changes: 1 addition & 2 deletions cmd/collect/collect.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package collect

import (
"github.com/spf13/cobra"

"github.com/metal-toolbox/mctl/cmd"
"github.com/spf13/cobra"
)

var collect = &cobra.Command{
Expand Down
11 changes: 3 additions & 8 deletions cmd/collect/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"log"

"github.com/google/uuid"
"github.com/spf13/cobra"

coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
rctypes "github.com/metal-toolbox/rivets/condition"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/spf13/cobra"
)

type collectInventoryFlags struct {
Expand All @@ -21,16 +19,13 @@ type collectInventoryFlags struct {
skipBiosConfigCollect bool
}

var (
flagsDefinedCollectInventory *collectInventoryFlags
)
var flagsDefinedCollectInventory *collectInventoryFlags

var collectInventoryCmd = &cobra.Command{
Use: "inventory",
Short: "Collect current server firmware status and bios configuration",
Run: func(cmd *cobra.Command, _ []string) {
collectInventory(cmd.Context())

},
}

Expand Down
6 changes: 2 additions & 4 deletions cmd/collect/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"log"

"github.com/google/uuid"
"github.com/spf13/cobra"

rctypes "github.com/metal-toolbox/rivets/condition"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/spf13/cobra"
)

type inventoryStatusParams struct {
Expand Down
11 changes: 5 additions & 6 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (
"strings"
"time"

bmclibcomm "github.com/bmc-toolbox/common"
"github.com/davecgh/go-spew/spew"
"github.com/google/uuid"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/pkg/errors"
"golang.org/x/net/context"

bmclibcomm "github.com/bmc-toolbox/common"
coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
rt "github.com/metal-toolbox/rivets/types"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

var (
Expand Down Expand Up @@ -265,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
7 changes: 2 additions & 5 deletions cmd/create/bomupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"log"
"os"

"github.com/spf13/cobra"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/spf13/cobra"
)

// Create Bom informations.
Expand All @@ -16,9 +15,7 @@ type uploadBomFileFlags struct {
bomXlsxFile string
}

var (
flagsUploadBomFileFlags *uploadBomFileFlags
)
var flagsUploadBomFileFlags *uploadBomFileFlags

var uploadBomFile = &cobra.Command{
Use: "bom",
Expand Down
1 change: 0 additions & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package create

import (
"github.com/metal-toolbox/mctl/cmd"

"github.com/spf13/cobra"
)

Expand Down
8 changes: 2 additions & 6 deletions cmd/create/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"os"

fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"

"github.com/spf13/cobra"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/spf13/cobra"
)

// Create
Expand All @@ -19,9 +17,7 @@ type createFirmwareFlags struct {
firmwareConfigFile string
}

var (
flagsDefinedCreateFirmware *createFirmwareFlags
)
var flagsDefinedCreateFirmware *createFirmwareFlags

var createFirmware = &cobra.Command{
Use: "firmware",
Expand Down
12 changes: 3 additions & 9 deletions cmd/create/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"os"

"github.com/google/uuid"
"github.com/spf13/cobra"

fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"
mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/metal-toolbox/mctl/pkg/model"
"github.com/spf13/cobra"
)

var (
Expand Down Expand Up @@ -46,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 @@ -59,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 @@ -111,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
Loading

0 comments on commit 0f72323

Please sign in to comment.