Skip to content

Commit

Permalink
Merge pull request #616 from innogames/go122
Browse files Browse the repository at this point in the history
linter update
  • Loading branch information
brainexe authored Sep 6, 2024
2 parents d60fdda + 3898a58 commit b7ea1ca
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 48 deletions.
28 changes: 24 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- perfsprint
- usestdlibvars


linters:
enable:
Expand All @@ -14,12 +16,14 @@ linters:
- dogsled
- dupl
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- fatcontext
- gochecknoinits
- gci
- gocheckcompilerdirectives
- gochecknoinits
- gocritic
- gocyclo
- gofumpt
Expand All @@ -31,12 +35,14 @@ linters:
- ineffassign
- intrange
- loggercheck
- mirror
- makezero
- misspell
- mirror
- misspell
- musttag
- nakedret
- nilerr
- nolintlint
- noctx
- perfsprint
- prealloc
- predeclared
Expand All @@ -45,12 +51,26 @@ linters:
- staticcheck
- stylecheck
- tagalign
- tenv
- testifylint
- thelper
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
fast: false

govet:
enable-all: true
disable:
- structtag

gofumpt:
extra-rules: true

perfsprint:
errorf: false
strconcat: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dep:
@go mod vendor

lint:
golangci-lint run
golangci-lint run --fix

docker-build:
docker build . --force-rm -t brainexe/slack-bot:latest
Expand Down
1 change: 0 additions & 1 deletion bot/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/innogames/slack-bot/v2/bot/util"
"github.com/innogames/slack-bot/v2/client"
"github.com/innogames/slack-bot/v2/command"

log "github.com/sirupsen/logrus"
)

Expand Down
9 changes: 4 additions & 5 deletions bot/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"os"
"path"
"testing"

Expand Down Expand Up @@ -70,10 +69,10 @@ func TestLoadFile(t *testing.T) {
}

func TestEnvironment(t *testing.T) {
os.Setenv("BOT_TIMEZONE", "Europe/Berlin")
os.Setenv("BOT_SLACK_TOKEN", "mySlackToken")
os.Setenv("BOT_SLACK_SOCKET_TOKEN", "mySlackSocketToken")
os.Setenv("BOT_GITHUB_ACCESS_TOKEN", "myGithubToken")
t.Setenv("BOT_TIMEZONE", "Europe/Berlin")
t.Setenv("BOT_SLACK_TOKEN", "mySlackToken")
t.Setenv("BOT_SLACK_SOCKET_TOKEN", "mySlackSocketToken")
t.Setenv("BOT_GITHUB_ACCESS_TOKEN", "myGithubToken")

// load example file == okay
cfg, err := Load("../../config.example.yaml")
Expand Down
3 changes: 1 addition & 2 deletions bot/matcher/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"slices"
"strings"

"github.com/innogames/slack-bot/v2/client"

"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/client"
)

func NewOptionMatcher(baseCommand string, whiteList []string, run Runner, slackClient client.SlackClient) Matcher {
Expand Down
1 change: 0 additions & 1 deletion bot/stats/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/util"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 0 additions & 1 deletion bot/tester/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/gookit/color"

"github.com/stretchr/testify/assert"
)

Expand Down
5 changes: 5 additions & 0 deletions command/admin/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package admin

import (
"fmt"
"math"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -97,6 +98,10 @@ func formatStats(key string) string {
return "0"
}

if value > uint(math.MaxInt) {
return fmt.Sprintf("overflow: %d", value)
}

return util.FormatInt(int(value))
}

Expand Down
3 changes: 1 addition & 2 deletions command/custom_commmands/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package custom_commmands
import (
"testing"

"github.com/innogames/slack-bot/v2/bot/config"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/stretchr/testify/assert"
Expand Down
3 changes: 1 addition & 2 deletions command/custom_variables/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package custom_variables
import (
"testing"

"github.com/innogames/slack-bot/v2/bot/config"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/stretchr/testify/assert"
Expand Down
3 changes: 1 addition & 2 deletions command/delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"sync"
"time"

"github.com/slack-go/slack"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/matcher"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/bot/util"
"github.com/innogames/slack-bot/v2/client"
"github.com/innogames/slack-bot/v2/command/queue"
"github.com/slack-go/slack"
)

// NewDelayCommand delays the command execution by the given time
Expand Down
2 changes: 1 addition & 1 deletion command/games/number_guesser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestNumberGuesser(t *testing.T) {

actual = commands.Run(message)
assert.True(t, actual)
assert.Equal(t, 1, len(gameCommand.games))
assert.Len(t, gameCommand.games, 1)

game := gameCommand.games[message.User]
assert.GreaterOrEqual(t, game.randomNumber, 0)
Expand Down
3 changes: 1 addition & 2 deletions command/jenkins/client/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"fmt"
"strings"

"github.com/innogames/slack-bot/v2/bot/util"

"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/util"
"github.com/innogames/slack-bot/v2/client/vcs"
)

Expand Down
7 changes: 3 additions & 4 deletions command/jenkins/inform_idle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"testing"
"time"

"github.com/innogames/slack-bot/v2/mocks"

"github.com/bndr/gojenkins"
"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/command/queue"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -114,12 +113,12 @@ func getNodeWithExecutors(running int, idle int, name string) *gojenkins.Node {
}

executors := make([]executor, 0, running+idle)
for i := 0; i < idle; i++ {
for range idle {
executors = append(executors, executor{
currentExecutable{0},
})
}
for i := 0; i < running; i++ {
for range running {
executors = append(executors, executor{
currentExecutable{12},
})
Expand Down
6 changes: 3 additions & 3 deletions command/jenkins/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jenkins

import (
"context"
"fmt"
"testing"

"github.com/bndr/gojenkins"
Expand All @@ -11,6 +10,7 @@ import (
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/command/jenkins/client"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand All @@ -37,8 +37,8 @@ func TestNodes(t *testing.T) {
message.Text = "list jenkins nodes"

ctx := context.Background()
jenkinsClient.On("GetAllNodes", ctx).Return(nil, fmt.Errorf("an error occurred")).Once()
mocks.AssertError(slackClient, message, fmt.Errorf("an error occurred"))
jenkinsClient.On("GetAllNodes", ctx).Return(nil, errors.New("an error occurred")).Once()
mocks.AssertError(slackClient, message, errors.New("an error occurred"))
actual := command.Run(message)
assert.True(t, actual)
})
Expand Down
3 changes: 1 addition & 2 deletions command/jenkins/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"errors"
"testing"

"github.com/innogames/slack-bot/v2/mocks"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand Down
3 changes: 1 addition & 2 deletions command/jira/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package jira
import (
"testing"

"github.com/stretchr/testify/require"

"github.com/innogames/slack-bot/v2/bot/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestJiraClient(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion command/openai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/innogames/slack-bot/v2/bot/stats"
"github.com/innogames/slack-bot/v2/bot/storage"
"github.com/innogames/slack-bot/v2/bot/util"

log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)
Expand Down
3 changes: 1 addition & 2 deletions command/pullrequest/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"text/template"

"github.com/pkg/errors"

"github.com/google/go-github/github"
"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/matcher"
"github.com/innogames/slack-bot/v2/client"
"github.com/pkg/errors"
"golang.org/x/oauth2"
)

Expand Down
6 changes: 2 additions & 4 deletions command/pullrequest/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import (
"strings"
"text/template"

"github.com/pkg/errors"

log "github.com/sirupsen/logrus"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/matcher"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/xanzy/go-gitlab"
)

Expand Down
3 changes: 1 addition & 2 deletions command/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package command
import (
"fmt"

"github.com/pkg/errors"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/matcher"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/bot/storage"
"github.com/innogames/slack-bot/v2/client"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)
Expand Down
3 changes: 1 addition & 2 deletions command/user_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"fmt"
"time"

"github.com/innogames/slack-bot/v2/command/queue"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/matcher"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/command/queue"
)

const notifyCheckInterval = time.Minute * 1
Expand Down
3 changes: 1 addition & 2 deletions command/weather/weather_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"testing"
"time"

"github.com/innogames/slack-bot/v2/bot/util"

"github.com/innogames/slack-bot/v2/bot"
"github.com/innogames/slack-bot/v2/bot/config"
"github.com/innogames/slack-bot/v2/bot/msg"
"github.com/innogames/slack-bot/v2/bot/util"
"github.com/innogames/slack-bot/v2/mocks"
"github.com/stretchr/testify/assert"
)
Expand Down

0 comments on commit b7ea1ca

Please sign in to comment.