Skip to content

Commit

Permalink
Update .golangci.yml from metal-toolbox/golangci-lint-config
Browse files Browse the repository at this point in the history
And fix the errors of course, gotta keep CI green! Most of the class of
changes are pretty small.
  • Loading branch information
mmlb committed May 20, 2024
1 parent 2da5ad5 commit d16fe10
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 239 deletions.
270 changes: 76 additions & 194 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,211 +1,93 @@
run:
# The default runtime timeout is 1m, which doesn't work well on Github Actions.
timeout: 4m
#
# 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!
#

# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
linters-settings:
cyclop:
# NOTE: This is a very high transitional threshold
max-complexity: 37
package-average: 34.0
skip-tests: true

gocognit:
# NOTE: This is a very high transitional threshold
min-complexity: 98

dupl:
threshold: 200

threshold: 125
goconst:
min-len: 4
min-occurrences: 5
ignore-tests: true

gosec:
excludes:
- G107 # Potential HTTP request made with variable url
- G204 # Subprocess launched with function call as argument or cmd arguments
- G404 # Use of weak random number generator (math/rand instead of crypto/rand

errorlint:
# these are still common in Go: for instance, exit errors.
asserts: false
# Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make
# an error part of a package API should be a concious decision by the author.
# Also see Hyrums Law.
errorf: false

exhaustive:
default-signifies-exhaustive: true

nestif:
min-complexity: 8

nolintlint:
require-explanation: true
allow-unused: false
require-specific: true

min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- experimental
- performance
- style
disabled-checks:
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
gofumpt:
extra-rules: true
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
revive:
ignore-generated-header: true
severity: warning
rules:
- name: atomic
- name: blank-imports
- name: bool-literal-in-expr
- name: confusing-naming
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: deep-exit
- name: defer
- name: range-val-in-closure
- name: range-val-address
- name: dot-imports
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: struct-tag
- name: time-naming
- name: unexported-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
- name: unconditional-recursion
- name: waitgroup-by-value

staticcheck:
go: "1.18"

unused:
go: "1.18"

output:
sort-results: true
confidence: 0

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
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
- dogsled
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- deadcode # deprecated
- depguard
- errname # maybe should be enabled
- exhaustivestruct # deprecated
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- gosec
- goheader
- goimports
- goprintffuncname
- gosimple
- govet
#- ifshort
- importas
- ineffassign
- makezero
- misspell
- nakedret
- 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
- nilerr
- noctx
- nilnil
- nlreturn
- nolintlint
- predeclared
# disabling for the initial iteration of the linting tool
# - promlinter
- revive
#- rowserrcheck
#- sqlclosecheck
- staticcheck
#- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
#- varcheck
#- wastedassign
- whitespace

# Disabled linters, due to being misaligned with Go practices
# - exhaustivestruct
# - gochecknoglobals
# - gochecknoinits
# - goconst
# - godox
# - goerr113
# - gomnd
# - lll
# - nlreturn
# - testpackage
# - wsl
# Disabled linters, due to not being relevant to our code base:
# - maligned
# - prealloc "For most programs usage of prealloc will be a premature optimization."
# Disabled linters due to bad error messages or bugs
# - tagliatelle
- 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:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- dupl
- errcheck
- forcetypeassert
- gocyclo
- gosec
- noctx

- path: .*cmd.*
linters:
- noctx

- path: main\.go
linters:
- noctx

- path: .*cmd.*
text: "deep-exit"

- path: main\.go
text: "deep-exit"

# This check is of questionable value
- linters:
- tparallel
text: "call t.Parallel on the top level as well as its subtests"

# Don't hide lint issues just because there are many of them
max-same-issues: 0
max-issues-per-linter: 0
- stylecheck
text: "ST1016"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ build:
lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run --config .golangci.yml --timeout=5m --out-format colored-line-number

lint-fix:
go run github.com/golangci/golangci-lint/cmd/[email protected] run --fix --config .golangci.yml --timeout=5m --out-format colored-line-number

test: lint
CGO_ENABLED=0 $(GOBINARY) test -timeout 1m -v -covermode=atomic ./...
3 changes: 1 addition & 2 deletions cmd/format_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package cmd
import (
"context"

"github.com/spf13/cobra"

"github.com/metal-toolbox/vogelkop/pkg/model"
"github.com/spf13/cobra"
)

var formatPartitionCmd = &cobra.Command{
Expand Down
5 changes: 2 additions & 3 deletions cmd/raid_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"context"
"strconv"

"github.com/spf13/cobra"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/vogelkop/internal/command"
"github.com/metal-toolbox/vogelkop/pkg/model"
"github.com/spf13/cobra"
)

var createRaidCmd = &cobra.Command{
Expand Down Expand Up @@ -76,7 +75,7 @@ func processDevicesLinuxSw(arrayDevices []string) []*model.BlockDevice {
}

func processDevicesHardware(arrayDevices []string) []*model.BlockDevice {
var blockDeviceIDs []int
blockDeviceIDs := make([]int, 0, len(arrayDevices))

for _, d := range arrayDevices {
intBlockDevice, err := strconv.Atoi(d)
Expand Down
3 changes: 1 addition & 2 deletions cmd/raid_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"
"strconv"

"github.com/spf13/cobra"

"github.com/metal-toolbox/vogelkop/internal/command"
"github.com/metal-toolbox/vogelkop/pkg/model"
"github.com/spf13/cobra"
)

var deleteRaidCmd = &cobra.Command{
Expand Down
3 changes: 1 addition & 2 deletions cmd/raid_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/metal-toolbox/vogelkop/internal/command"
"github.com/metal-toolbox/vogelkop/pkg/model"
"github.com/spf13/cobra"
)

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

import (
version "github.com/metal-toolbox/vogelkop/internal/version"

"github.com/spf13/cobra"
"go.uber.org/zap"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"path/filepath"
"testing"

"github.com/bmc-toolbox/common"
diskfs "github.com/diskfs/go-diskfs"
losetup "github.com/freddierice/go-losetup/v2"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/vogelkop/internal/command"
"github.com/metal-toolbox/vogelkop/pkg/model"
)
Expand Down
Loading

0 comments on commit d16fe10

Please sign in to comment.