Skip to content

Commit

Permalink
Update golangci-lint and apply lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Mar 15, 2024
1 parent 53b22d5 commit 1e8d4dc
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 35 deletions.
46 changes: 33 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupl
Expand All @@ -25,8 +26,14 @@ linters:
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
Expand All @@ -37,22 +44,27 @@ linters:
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
Expand All @@ -63,18 +75,26 @@ linters:
- nonamedreturns
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
Expand All @@ -83,22 +103,23 @@ linters:
- usestdlibvars
- wastedassign
- whitespace
# - cyclop
- wrapcheck
- zerologlint
# - depguard
# - exhaustruct
# - funlen
# - gci
# - gocognit
# - gomnd
# - revive
# - thelper
# - varnamelen
# - wrapcheck
# - wsl
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
funlen:
lines: 150
cyclop:
max-complexity: 15
gocognit:
min-complexity: 40
revive:
rules:
- name: dot-imports
disabled: true
gocritic:
enabled-checks:
- appendAssign
Expand All @@ -110,6 +131,7 @@ linters-settings:
- badLock
- badRegexp
- badSorting
- badSyncOnceFunc
- boolExprSimplify
- builtinShadow
- builtinShadowDecl
Expand Down Expand Up @@ -175,7 +197,6 @@ linters-settings:
- sliceClear
- sloppyLen
- sloppyReassign
- sloppyTestFuncName
- sloppyTypeAssert
- sortSlice
- sprintfQuotedString
Expand All @@ -185,7 +206,6 @@ linters-settings:
- stringsCompare
- switchTrue
- syncMapLoadAndDelete
- timeCmpSimplify
- timeExprSimplify
- todoCommentWithoutDetail
- tooManyResultsChecker
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test:

${GOLANGCI_LINT}:
export \
VERSION=v1.55.2 \
VERSION=v1.56.2 \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=${BUILD_PATH} && \
curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
Expand Down
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
. "github.com/saschagrunert/demo" //nolint:revive,stylecheck // dot imports are intended here
. "github.com/saschagrunert/demo" //nolint:stylecheck // dot imports are intended here
"github.com/urfave/cli/v2"
)

Expand All @@ -28,7 +28,7 @@ func main() {
}

// setup will run before every demo.
func setup(ctx *cli.Context) error {
func setup(*cli.Context) error {
// Ensure can be used for easy sequential command execution
return Ensure(
"echo 'Doing first setup…'",
Expand All @@ -38,7 +38,7 @@ func setup(ctx *cli.Context) error {
}

// setup will run after every demo.
func cleanup(ctx *cli.Context) error {
func cleanup(*cli.Context) error {
return Ensure("echo 'Doing cleanup…'")
}

Expand Down
4 changes: 2 additions & 2 deletions demo.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package demo

import (
"fmt"
"log"
"os"
"os/signal"
"strconv"
"time"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (d *Demo) Cleanup(cleanupFn func(*cli.Context) error) {

func (d *Demo) Add(run *Run, name, description string) {
flag := &cli.BoolFlag{
Name: fmt.Sprintf("%d", len(d.runs)),
Name: strconv.Itoa(len(d.runs)),
Aliases: []string{name},
Usage: description,
}
Expand Down
3 changes: 1 addition & 2 deletions demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/urfave/cli/v2"

"github.com/saschagrunert/demo"
"github.com/urfave/cli/v2"
)

var _ = t.Describe("Demo", func() {
Expand Down
7 changes: 5 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ func (r *Run) printTitleAndDescription() error {

func write(w io.Writer, str string) error {
_, err := w.Write([]byte(str))
if err != nil {
return fmt.Errorf("write: %w", err)
}

return err
return nil
}

func (s *step) run(current, max int) error {
Expand Down Expand Up @@ -284,7 +287,7 @@ func (s *step) print(msg ...string) error {
for _, m := range msg {
for _, c := range m {
if !s.r.options.Immediate {
//nolint:gosec // the sleep has no security implications
//nolint:gosec,gomnd // the sleep has no security implications and is randomly chosen
time.Sleep(time.Duration(rand.Intn(40)) * time.Millisecond)
}
if err := write(s.r.out, fmt.Sprintf("%c", c)); err != nil {
Expand Down
15 changes: 7 additions & 8 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/urfave/cli/v2"

"github.com/saschagrunert/demo"
"github.com/urfave/cli/v2"
)

var _ = t.Describe("Run", func() {
Expand All @@ -26,7 +25,7 @@ var _ = t.Describe("Run", func() {

out = &strings.Builder{}
err := sut.SetOutput(out)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

opts = demo.Options{
AutoTimeout: 0,
Expand All @@ -42,7 +41,7 @@ var _ = t.Describe("Run", func() {
err := sut.RunWithOptions(opts)

// Then
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(out).To(ContainSubstring(title))
Expect(out).To(ContainSubstring(description[0]))
Expect(out).To(ContainSubstring(description[1]))
Expand All @@ -60,7 +59,7 @@ var _ = t.Describe("Run", func() {
err := sut.RunWithOptions(opts)

// Then
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(out).To(ContainSubstring(title))
Expect(out).To(ContainSubstring(description[0]))
Expect(out).To(ContainSubstring(description[1]))
Expand All @@ -80,7 +79,7 @@ var _ = t.Describe("Run", func() {
err := sut.RunWithOptions(opts)

// Then
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})

It("should fail to set nil output", func() {
Expand All @@ -89,7 +88,7 @@ var _ = t.Describe("Run", func() {
err := sut.SetOutput(nil)

// Then
Expect(err).NotTo(BeNil())
Expect(err).To(HaveOccurred())
})

It("should succeed to run from a cli context", func() {
Expand All @@ -105,6 +104,6 @@ var _ = t.Describe("Run", func() {
err := sut.Run(ctx)

// Then
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})
3 changes: 2 additions & 1 deletion test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewTestFramework(setup, teardown func(*TestFramework) error) *TestFramework
}

// NilFunc is a convenience function which simply does nothing.
func NilFunc(f *TestFramework) error {
func NilFunc(*TestFramework) error {
return nil
}

Expand Down Expand Up @@ -52,5 +52,6 @@ func (t *TestFramework) Describe(text string, body func()) bool {

// RunFrameworkSpecs is a convenience wrapper for running tests.
func RunFrameworkSpecs(t *testing.T, suiteName string) {
t.Helper()
ginkgo.RunSpecs(t, suiteName)
}
3 changes: 2 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package demo

import (
"fmt"
"os/exec"
)

Expand All @@ -12,7 +13,7 @@ func Ensure(commands ...string) error {
cmd.Stderr = nil
cmd.Stdout = nil
if err := cmd.Run(); err != nil {
return err
return fmt.Errorf("run command: %w", err)
}
}

Expand Down
3 changes: 1 addition & 2 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package demo_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/saschagrunert/demo"
)

Expand All @@ -14,6 +13,6 @@ var _ = t.Describe("Util", func() {
err := demo.Ensure("echo hi")

// When
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
})

0 comments on commit 1e8d4dc

Please sign in to comment.