diff --git a/.golangci.yml b/.golangci.yml index 32caaa3a..952b0819 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,9 +1,11 @@ - issues: exclude-rules: - path: _test\.go linters: - errcheck + - perfsprint + - usestdlibvars + linters: enable: @@ -14,12 +16,14 @@ linters: - dogsled - dupl - errcheck + - errname - errorlint - exhaustive - exportloopref - fatcontext - - gochecknoinits + - gci - gocheckcompilerdirectives + - gochecknoinits - gocritic - gocyclo - gofumpt @@ -31,12 +35,14 @@ linters: - ineffassign - intrange - loggercheck - - mirror - makezero - - misspell - mirror + - misspell + - musttag - nakedret + - nilerr - nolintlint + - noctx - perfsprint - prealloc - predeclared @@ -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 diff --git a/Makefile b/Makefile index 83cab7ed..6a3b2046 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bot/app/start.go b/bot/app/start.go index 2b0f8ab5..7d1d5600 100644 --- a/bot/app/start.go +++ b/bot/app/start.go @@ -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" ) diff --git a/bot/config/config_test.go b/bot/config/config_test.go index beaad5fa..fe39ea9e 100644 --- a/bot/config/config_test.go +++ b/bot/config/config_test.go @@ -1,7 +1,6 @@ package config import ( - "os" "path" "testing" @@ -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") diff --git a/bot/matcher/options.go b/bot/matcher/options.go index cbf187ea..ecd59449 100644 --- a/bot/matcher/options.go +++ b/bot/matcher/options.go @@ -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 { diff --git a/bot/stats/metrics_test.go b/bot/stats/metrics_test.go index 638a01fc..e545beb8 100644 --- a/bot/stats/metrics_test.go +++ b/bot/stats/metrics_test.go @@ -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" ) diff --git a/bot/tester/formatter_test.go b/bot/tester/formatter_test.go index 79d73bde..1416c540 100644 --- a/bot/tester/formatter_test.go +++ b/bot/tester/formatter_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/gookit/color" - "github.com/stretchr/testify/assert" ) diff --git a/command/admin/stats.go b/command/admin/stats.go index 52d922ee..9868f79b 100644 --- a/command/admin/stats.go +++ b/command/admin/stats.go @@ -2,6 +2,7 @@ package admin import ( "fmt" + "math" "runtime" "strings" "time" @@ -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)) } diff --git a/command/custom_commmands/integration_test.go b/command/custom_commmands/integration_test.go index 86a4db7e..5b0c6f4b 100644 --- a/command/custom_commmands/integration_test.go +++ b/command/custom_commmands/integration_test.go @@ -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" diff --git a/command/custom_variables/integration_test.go b/command/custom_variables/integration_test.go index 849628d5..e836c05f 100644 --- a/command/custom_variables/integration_test.go +++ b/command/custom_variables/integration_test.go @@ -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" diff --git a/command/delay.go b/command/delay.go index 59f455a6..ce4db780 100644 --- a/command/delay.go +++ b/command/delay.go @@ -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 diff --git a/command/games/number_guesser_test.go b/command/games/number_guesser_test.go index 6c0fc4fb..dc9f0bb8 100644 --- a/command/games/number_guesser_test.go +++ b/command/games/number_guesser_test.go @@ -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) diff --git a/command/jenkins/client/parameters.go b/command/jenkins/client/parameters.go index fafc97fa..6647898c 100644 --- a/command/jenkins/client/parameters.go +++ b/command/jenkins/client/parameters.go @@ -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" ) diff --git a/command/jenkins/inform_idle_test.go b/command/jenkins/inform_idle_test.go index daccec68..273c408d 100644 --- a/command/jenkins/inform_idle_test.go +++ b/command/jenkins/inform_idle_test.go @@ -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" ) @@ -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}, }) diff --git a/command/jenkins/nodes_test.go b/command/jenkins/nodes_test.go index 546eff66..24029970 100644 --- a/command/jenkins/nodes_test.go +++ b/command/jenkins/nodes_test.go @@ -2,7 +2,6 @@ package jenkins import ( "context" - "fmt" "testing" "github.com/bndr/gojenkins" @@ -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" ) @@ -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) }) diff --git a/command/jenkins/trigger_test.go b/command/jenkins/trigger_test.go index 488970b4..b335619f 100644 --- a/command/jenkins/trigger_test.go +++ b/command/jenkins/trigger_test.go @@ -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" ) diff --git a/command/jira/client_test.go b/command/jira/client_test.go index c915bd2c..67afa9d7 100644 --- a/command/jira/client_test.go +++ b/command/jira/client_test.go @@ -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) { diff --git a/command/openai/command.go b/command/openai/command.go index 7c32d4aa..bdb5084f 100644 --- a/command/openai/command.go +++ b/command/openai/command.go @@ -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" ) diff --git a/command/pullrequest/github.go b/command/pullrequest/github.go index d6fbaf5f..7c959c6e 100644 --- a/command/pullrequest/github.go +++ b/command/pullrequest/github.go @@ -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" ) diff --git a/command/pullrequest/gitlab.go b/command/pullrequest/gitlab.go index f99aa0e7..17d844e2 100644 --- a/command/pullrequest/gitlab.go +++ b/command/pullrequest/gitlab.go @@ -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" ) diff --git a/command/retry.go b/command/retry.go index dba9d899..9fae8b64 100644 --- a/command/retry.go +++ b/command/retry.go @@ -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" ) diff --git a/command/user_status.go b/command/user_status.go index 25e99a9c..14a3aa72 100644 --- a/command/user_status.go +++ b/command/user_status.go @@ -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 diff --git a/command/weather/weather_test.go b/command/weather/weather_test.go index a8ee8ca3..f3902adb 100644 --- a/command/weather/weather_test.go +++ b/command/weather/weather_test.go @@ -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" )