Skip to content

Commit b7ea1ca

Browse files
authored
Merge pull request #616 from innogames/go122
linter update
2 parents d60fdda + 3898a58 commit b7ea1ca

File tree

23 files changed

+54
-48
lines changed

23 files changed

+54
-48
lines changed

.golangci.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
21
issues:
32
exclude-rules:
43
- path: _test\.go
54
linters:
65
- errcheck
6+
- perfsprint
7+
- usestdlibvars
8+
79

810
linters:
911
enable:
@@ -14,12 +16,14 @@ linters:
1416
- dogsled
1517
- dupl
1618
- errcheck
19+
- errname
1720
- errorlint
1821
- exhaustive
1922
- exportloopref
2023
- fatcontext
21-
- gochecknoinits
24+
- gci
2225
- gocheckcompilerdirectives
26+
- gochecknoinits
2327
- gocritic
2428
- gocyclo
2529
- gofumpt
@@ -31,12 +35,14 @@ linters:
3135
- ineffassign
3236
- intrange
3337
- loggercheck
34-
- mirror
3538
- makezero
36-
- misspell
3739
- mirror
40+
- misspell
41+
- musttag
3842
- nakedret
43+
- nilerr
3944
- nolintlint
45+
- noctx
4046
- perfsprint
4147
- prealloc
4248
- predeclared
@@ -45,12 +51,26 @@ linters:
4551
- staticcheck
4652
- stylecheck
4753
- tagalign
54+
- tenv
4855
- testifylint
4956
- thelper
5057
- typecheck
5158
- unconvert
5259
- unparam
5360
- unused
61+
- usestdlibvars
5462
- wastedassign
5563
- whitespace
5664
fast: false
65+
66+
govet:
67+
enable-all: true
68+
disable:
69+
- structtag
70+
71+
gofumpt:
72+
extra-rules: true
73+
74+
perfsprint:
75+
errorf: false
76+
strconcat: false

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dep:
3131
@go mod vendor
3232

3333
lint:
34-
golangci-lint run
34+
golangci-lint run --fix
3535

3636
docker-build:
3737
docker build . --force-rm -t brainexe/slack-bot:latest

bot/app/start.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/innogames/slack-bot/v2/bot/util"
1212
"github.com/innogames/slack-bot/v2/client"
1313
"github.com/innogames/slack-bot/v2/command"
14-
1514
log "github.com/sirupsen/logrus"
1615
)
1716

bot/config/config_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"os"
54
"path"
65
"testing"
76

@@ -70,10 +69,10 @@ func TestLoadFile(t *testing.T) {
7069
}
7170

7271
func TestEnvironment(t *testing.T) {
73-
os.Setenv("BOT_TIMEZONE", "Europe/Berlin")
74-
os.Setenv("BOT_SLACK_TOKEN", "mySlackToken")
75-
os.Setenv("BOT_SLACK_SOCKET_TOKEN", "mySlackSocketToken")
76-
os.Setenv("BOT_GITHUB_ACCESS_TOKEN", "myGithubToken")
72+
t.Setenv("BOT_TIMEZONE", "Europe/Berlin")
73+
t.Setenv("BOT_SLACK_TOKEN", "mySlackToken")
74+
t.Setenv("BOT_SLACK_SOCKET_TOKEN", "mySlackSocketToken")
75+
t.Setenv("BOT_GITHUB_ACCESS_TOKEN", "myGithubToken")
7776

7877
// load example file == okay
7978
cfg, err := Load("../../config.example.yaml")

bot/matcher/options.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import (
66
"slices"
77
"strings"
88

9-
"github.com/innogames/slack-bot/v2/client"
10-
119
"github.com/innogames/slack-bot/v2/bot/msg"
10+
"github.com/innogames/slack-bot/v2/client"
1211
)
1312

1413
func NewOptionMatcher(baseCommand string, whiteList []string, run Runner, slackClient client.SlackClient) Matcher {

bot/stats/metrics_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/innogames/slack-bot/v2/bot/config"
1111
"github.com/innogames/slack-bot/v2/bot/util"
12-
1312
"github.com/stretchr/testify/assert"
1413
)
1514

bot/tester/formatter_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/gookit/color"
7-
87
"github.com/stretchr/testify/assert"
98
)
109

command/admin/stats.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package admin
22

33
import (
44
"fmt"
5+
"math"
56
"runtime"
67
"strings"
78
"time"
@@ -97,6 +98,10 @@ func formatStats(key string) string {
9798
return "0"
9899
}
99100

101+
if value > uint(math.MaxInt) {
102+
return fmt.Sprintf("overflow: %d", value)
103+
}
104+
100105
return util.FormatInt(int(value))
101106
}
102107

command/custom_commmands/integration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package custom_commmands
33
import (
44
"testing"
55

6-
"github.com/innogames/slack-bot/v2/bot/config"
7-
86
"github.com/innogames/slack-bot/v2/bot"
7+
"github.com/innogames/slack-bot/v2/bot/config"
98
"github.com/innogames/slack-bot/v2/bot/msg"
109
"github.com/innogames/slack-bot/v2/mocks"
1110
"github.com/stretchr/testify/assert"

command/custom_variables/integration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package custom_variables
33
import (
44
"testing"
55

6-
"github.com/innogames/slack-bot/v2/bot/config"
7-
86
"github.com/innogames/slack-bot/v2/bot"
7+
"github.com/innogames/slack-bot/v2/bot/config"
98
"github.com/innogames/slack-bot/v2/bot/msg"
109
"github.com/innogames/slack-bot/v2/mocks"
1110
"github.com/stretchr/testify/assert"

command/delay.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
"sync"
77
"time"
88

9-
"github.com/slack-go/slack"
10-
119
"github.com/innogames/slack-bot/v2/bot"
1210
"github.com/innogames/slack-bot/v2/bot/matcher"
1311
"github.com/innogames/slack-bot/v2/bot/msg"
1412
"github.com/innogames/slack-bot/v2/bot/util"
1513
"github.com/innogames/slack-bot/v2/client"
1614
"github.com/innogames/slack-bot/v2/command/queue"
15+
"github.com/slack-go/slack"
1716
)
1817

1918
// NewDelayCommand delays the command execution by the given time

command/games/number_guesser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestNumberGuesser(t *testing.T) {
8585

8686
actual = commands.Run(message)
8787
assert.True(t, actual)
88-
assert.Equal(t, 1, len(gameCommand.games))
88+
assert.Len(t, gameCommand.games, 1)
8989

9090
game := gameCommand.games[message.User]
9191
assert.GreaterOrEqual(t, game.randomNumber, 0)

command/jenkins/client/parameters.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/innogames/slack-bot/v2/bot/util"
8-
97
"github.com/innogames/slack-bot/v2/bot/config"
8+
"github.com/innogames/slack-bot/v2/bot/util"
109
"github.com/innogames/slack-bot/v2/client/vcs"
1110
)
1211

command/jenkins/inform_idle_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/innogames/slack-bot/v2/mocks"
10-
119
"github.com/bndr/gojenkins"
1210
"github.com/innogames/slack-bot/v2/bot"
1311
"github.com/innogames/slack-bot/v2/bot/msg"
1412
"github.com/innogames/slack-bot/v2/command/queue"
13+
"github.com/innogames/slack-bot/v2/mocks"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

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

116115
executors := make([]executor, 0, running+idle)
117-
for i := 0; i < idle; i++ {
116+
for range idle {
118117
executors = append(executors, executor{
119118
currentExecutable{0},
120119
})
121120
}
122-
for i := 0; i < running; i++ {
121+
for range running {
123122
executors = append(executors, executor{
124123
currentExecutable{12},
125124
})

command/jenkins/nodes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package jenkins
22

33
import (
44
"context"
5-
"fmt"
65
"testing"
76

87
"github.com/bndr/gojenkins"
@@ -11,6 +10,7 @@ import (
1110
"github.com/innogames/slack-bot/v2/bot/msg"
1211
"github.com/innogames/slack-bot/v2/command/jenkins/client"
1312
"github.com/innogames/slack-bot/v2/mocks"
13+
"github.com/pkg/errors"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/mock"
1616
)
@@ -37,8 +37,8 @@ func TestNodes(t *testing.T) {
3737
message.Text = "list jenkins nodes"
3838

3939
ctx := context.Background()
40-
jenkinsClient.On("GetAllNodes", ctx).Return(nil, fmt.Errorf("an error occurred")).Once()
41-
mocks.AssertError(slackClient, message, fmt.Errorf("an error occurred"))
40+
jenkinsClient.On("GetAllNodes", ctx).Return(nil, errors.New("an error occurred")).Once()
41+
mocks.AssertError(slackClient, message, errors.New("an error occurred"))
4242
actual := command.Run(message)
4343
assert.True(t, actual)
4444
})

command/jenkins/trigger_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"errors"
66
"testing"
77

8-
"github.com/innogames/slack-bot/v2/mocks"
9-
108
"github.com/innogames/slack-bot/v2/bot"
119
"github.com/innogames/slack-bot/v2/bot/config"
1210
"github.com/innogames/slack-bot/v2/bot/msg"
11+
"github.com/innogames/slack-bot/v2/mocks"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/mock"
1514
)

command/jira/client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package jira
33
import (
44
"testing"
55

6-
"github.com/stretchr/testify/require"
7-
86
"github.com/innogames/slack-bot/v2/bot/config"
97
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
109
)
1110

1211
func TestJiraClient(t *testing.T) {

command/openai/command.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/innogames/slack-bot/v2/bot/stats"
1515
"github.com/innogames/slack-bot/v2/bot/storage"
1616
"github.com/innogames/slack-bot/v2/bot/util"
17-
1817
log "github.com/sirupsen/logrus"
1918
"github.com/slack-go/slack"
2019
)

command/pullrequest/github.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import (
44
"context"
55
"text/template"
66

7-
"github.com/pkg/errors"
8-
97
"github.com/google/go-github/github"
108
"github.com/innogames/slack-bot/v2/bot"
119
"github.com/innogames/slack-bot/v2/bot/config"
1210
"github.com/innogames/slack-bot/v2/bot/matcher"
1311
"github.com/innogames/slack-bot/v2/client"
12+
"github.com/pkg/errors"
1413
"golang.org/x/oauth2"
1514
)
1615

command/pullrequest/gitlab.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import (
55
"strings"
66
"text/template"
77

8-
"github.com/pkg/errors"
9-
10-
log "github.com/sirupsen/logrus"
11-
128
"github.com/innogames/slack-bot/v2/bot"
139
"github.com/innogames/slack-bot/v2/bot/config"
1410
"github.com/innogames/slack-bot/v2/bot/matcher"
11+
"github.com/pkg/errors"
12+
log "github.com/sirupsen/logrus"
1513
"github.com/xanzy/go-gitlab"
1614
)
1715

command/retry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package command
33
import (
44
"fmt"
55

6-
"github.com/pkg/errors"
7-
86
"github.com/innogames/slack-bot/v2/bot"
97
"github.com/innogames/slack-bot/v2/bot/config"
108
"github.com/innogames/slack-bot/v2/bot/matcher"
119
"github.com/innogames/slack-bot/v2/bot/msg"
1210
"github.com/innogames/slack-bot/v2/bot/storage"
1311
"github.com/innogames/slack-bot/v2/client"
12+
"github.com/pkg/errors"
1413
log "github.com/sirupsen/logrus"
1514
"github.com/slack-go/slack"
1615
)

command/user_status.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/innogames/slack-bot/v2/command/queue"
8-
97
"github.com/innogames/slack-bot/v2/bot"
108
"github.com/innogames/slack-bot/v2/bot/matcher"
119
"github.com/innogames/slack-bot/v2/bot/msg"
10+
"github.com/innogames/slack-bot/v2/command/queue"
1211
)
1312

1413
const notifyCheckInterval = time.Minute * 1

command/weather/weather_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/innogames/slack-bot/v2/bot/util"
11-
1210
"github.com/innogames/slack-bot/v2/bot"
1311
"github.com/innogames/slack-bot/v2/bot/config"
1412
"github.com/innogames/slack-bot/v2/bot/msg"
13+
"github.com/innogames/slack-bot/v2/bot/util"
1514
"github.com/innogames/slack-bot/v2/mocks"
1615
"github.com/stretchr/testify/assert"
1716
)

0 commit comments

Comments
 (0)