Skip to content

Commit 2a0012c

Browse files
committed
upgrade golangci-lint to v2
1 parent 8858a22 commit 2a0012c

21 files changed

+174
-145
lines changed

.golangci.yml

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
modules-download-mode: readonly
4-
5-
linters-settings:
6-
gofmt:
7-
simplify: true
8-
goimports:
9-
local-prefixes: github.com/lukegb/mattermost-plugin-uffd
10-
govet:
11-
enable-all: true
12-
disable:
13-
- fieldalignment
14-
misspell:
15-
locale: US
16-
174
linters:
18-
disable-all: true
5+
default: none
196
enable:
207
- bodyclose
218
- errcheck
229
- gocritic
23-
- gofmt
24-
- goimports
2510
- gosec
26-
- gosimple
2711
- govet
2812
- ineffassign
2913
- misspell
3014
- nakedret
3115
- revive
3216
- staticcheck
33-
- stylecheck
34-
- typecheck
3517
- unconvert
3618
- unused
3719
- whitespace
38-
39-
issues:
40-
exclude-rules:
41-
- path: server/configuration.go
42-
linters:
43-
- unused
44-
- path: _test\.go
45-
linters:
46-
- bodyclose
47-
- scopelint # https://github.com/kyoh86/scopelint/issues/4
48-
- linters:
49-
- revive
50-
text: unused-parameter
20+
settings:
21+
govet:
22+
disable:
23+
- fieldalignment
24+
enable-all: true
25+
misspell:
26+
locale: US
27+
exclusions:
28+
generated: lax
29+
presets:
30+
- comments
31+
- common-false-positives
32+
- legacy
33+
- std-error-handling
34+
rules:
35+
- linters: [ govet ]
36+
text: 'shadow: declaration of "(err|ctx|appErr)" shadows declaration at'
37+
- linters:
38+
- unused
39+
path: server/configuration.go
40+
- linters:
41+
- bodyclose
42+
- scopelint
43+
path: _test\.go
44+
- linters:
45+
- revive
46+
text: unused-parameter
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$
51+
formatters:
52+
enable:
53+
- gofmt
54+
- goimports
55+
settings:
56+
gofmt:
57+
simplify: true
58+
goimports:
59+
local-prefixes:
60+
- github.com/lukegb/mattermost-plugin-uffd
61+
exclusions:
62+
generated: lax
63+
paths:
64+
- third_party$
65+
- builtin$
66+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ apply:
164164
## Install go tools
165165
install-go-tools:
166166
@echo Installing go tools
167-
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
167+
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2
168168
$(GO) install gotest.tools/gotestsum@v1.7.0
169169

170170
## Runs eslint and golangci-lint

build/pluginctl/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func checkJSONLogsSetting(ctx context.Context, client *model.Client4) error {
178178
return fmt.Errorf("failed to fetch config: %w", err)
179179
}
180180
if cfg.LogSettings.FileJson == nil || !*cfg.LogSettings.FileJson {
181-
return errors.New("JSON output for file logs are disabled. Please enable LogSettings.FileJson via the configration in Mattermost.") //nolint:revive,stylecheck
181+
return errors.New("JSON output for file logs are disabled. Please enable LogSettings.FileJson via the configration in Mattermost.") //nolint:all
182182
}
183183

184184
return nil

server/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
1515
router := mux.NewRouter()
1616

17-
router.HandleFunc("/login", p.HttpSyncThenLogin).Methods(http.MethodGet)
17+
router.HandleFunc("/login", p.HTTPSyncThenLogin).Methods(http.MethodGet)
1818

1919
apiRouter := router.PathPrefix("/api/v1").Subrouter()
2020
apiRouter.Use(p.MattermostAuthorizationRequired)
2121
// No particular permissions are required to force a sync (at the moment...)
22-
apiRouter.HandleFunc("/sync", p.HttpSyncNow).Methods(http.MethodPost)
22+
apiRouter.HandleFunc("/sync", p.HTTPSyncNow).Methods(http.MethodPost)
2323

2424
router.ServeHTTP(w, r)
2525
}
@@ -37,7 +37,7 @@ func (p *Plugin) MattermostAuthorizationRequired(next http.Handler) http.Handler
3737
}
3838

3939
// e.g. http://localhost:8065/plugins/org.emfcamp.mattermost-plugin-uffd/login
40-
func (p *Plugin) HttpSyncThenLogin(w http.ResponseWriter, r *http.Request) {
40+
func (p *Plugin) HTTPSyncThenLogin(w http.ResponseWriter, r *http.Request) {
4141
if err := p.runSync(context.WithoutCancel(r.Context()), "HTTP /login"); err != nil {
4242
http.Redirect(w, r, "/error", http.StatusSeeOther)
4343
return
@@ -46,7 +46,7 @@ func (p *Plugin) HttpSyncThenLogin(w http.ResponseWriter, r *http.Request) {
4646
http.Redirect(w, r, "/oauth/openid/login", http.StatusSeeOther)
4747
}
4848

49-
func (p *Plugin) HttpSyncNow(w http.ResponseWriter, r *http.Request) {
49+
func (p *Plugin) HTTPSyncNow(w http.ResponseWriter, r *http.Request) {
5050
w.Header().Set("content-type", "text/plain; charset=utf-8")
5151

5252
if err := p.runSync(context.WithoutCancel(r.Context()), "HTTP /sync"); err != nil {

server/configuration.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ type configuration struct {
6565
// which the API endpoints will be derived.
6666
UffdAddress string
6767

68-
// UffdApiUser is the username used for authenticating with the UFFD API.
69-
UffdApiUser string
68+
// UffdAPIUser is the username used for authenticating with the UFFD API.
69+
UffdAPIUser string
7070

71-
// UffdApiPassword is the password used for authenticating with the UFFD API.
72-
UffdApiPassword string
71+
// UffdAPIPassword is the password used for authenticating with the UFFD API.
72+
UffdAPIPassword string
7373
}
7474

7575
// Clone shallow copies the configuration. Your implementation may require a deep copy if
@@ -125,13 +125,15 @@ func (p *Plugin) OnConfigurationChange() error {
125125
var configuration = new(configuration)
126126

127127
// Load the public configuration fields from the Mattermost server configuration.
128-
if err := p.MattermostPlugin.API.LoadPluginConfiguration(configuration); err != nil {
128+
if err := p.API.LoadPluginConfiguration(configuration); err != nil {
129129
return errors.Wrap(err, "failed to load plugin configuration")
130130
}
131131

132132
p.setConfiguration(configuration)
133133

134-
p.rescheduleSync()
134+
if err := p.rescheduleSync(); err != nil {
135+
return errors.Wrap(err, "setting up sync scheduled job")
136+
}
135137

136138
return nil
137139
}

server/job.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package main
33
import (
44
"context"
55

6+
log "github.com/sirupsen/logrus"
7+
68
"github.com/lukegb/mattermost-plugin-uffd/server/ctxlog"
79
"github.com/lukegb/mattermost-plugin-uffd/server/syncablesync"
810
"github.com/lukegb/mattermost-plugin-uffd/server/syncengine"
9-
log "github.com/sirupsen/logrus"
1011
)
1112

1213
func (p *Plugin) runSyncJob() {
13-
p.runSync(context.Background(), "schedule")
14+
_ = p.runSync(context.Background(), "schedule")
1415
}
1516

1617
func (p *Plugin) runSync(ctx context.Context, trigger string) error {
@@ -27,13 +28,13 @@ func (p *Plugin) runSync(ctx context.Context, trigger string) error {
2728

2829
l.Info("Performing UFFD group sync")
2930
se := &syncengine.SyncEngine{
30-
IdP: &syncengine.UffdIdP{
31+
IDP: &syncengine.UffdIDP{
3132
API: p.uffd,
3233
EnabledGroup: cfg.EnabledGroup,
3334
GroupFilterRegex: cfg.SyncGroupRegex,
3435
},
3536
Service: &syncengine.MattermostService{
36-
API: p.MattermostPlugin.API,
37+
API: p.API,
3738
},
3839
}
3940
out, err := se.FullSync(ctx)
@@ -46,7 +47,7 @@ func (p *Plugin) runSync(ctx context.Context, trigger string) error {
4647
l.Info("Performing syncables sync")
4748
ss := &syncablesync.Engine{
4849
API: &syncablesync.Mattermost{
49-
API: p.MattermostPlugin.API,
50+
API: p.API,
5051
SystemAdminGroup: cfg.SystemAdminGroup,
5152
SystemManagerGroup: cfg.SystemManagerGroup,
5253
},

server/plugin.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func (p *Plugin) rescheduleSync() error {
4444

4545
if p.syncJob != nil {
4646
if err := p.syncJob.Close(); err != nil {
47-
p.MattermostPlugin.API.LogError("Failed to close sync job", "err", err)
47+
p.API.LogError("Failed to close sync job", "err", err)
4848
}
4949
}
5050

5151
job, err := cluster.Schedule(
52-
p.MattermostPlugin.API,
52+
p.API,
5353
"SyncJob",
5454
cluster.MakeWaitForRoundedInterval(time.Duration(p.getConfiguration().SyncInterval)),
5555
p.runSyncJob,
@@ -65,24 +65,24 @@ func (p *Plugin) rescheduleSync() error {
6565

6666
// OnActivate is invoked when the plugin is activated. If an error is returned, the plugin will be deactivated.
6767
func (p *Plugin) OnActivate() error {
68-
p.client = pluginapi.NewClient(p.MattermostPlugin.API, p.MattermostPlugin.Driver)
68+
p.client = pluginapi.NewClient(p.API, p.Driver)
6969

7070
pluginapi.ConfigureLogrus(log.StandardLogger(), p.client)
7171

7272
cfg := p.getConfiguration()
7373
p.uffd = &uffd.API{
7474
HTTPClient: http.DefaultClient,
7575
EndpointBase: cfg.UffdAddress,
76-
Username: cfg.UffdApiUser,
77-
Password: cfg.UffdApiPassword,
76+
Username: cfg.UffdAPIUser,
77+
Password: cfg.UffdAPIPassword,
7878
}
7979

8080
if err := p.rescheduleSync(); err != nil {
8181
return fmt.Errorf("rescheduleSync: %w", err)
8282
}
8383

8484
syncMutex, err := cluster.NewMutex(
85-
p.MattermostPlugin.API,
85+
p.API,
8686
"SyncMutex",
8787
)
8888
if err != nil {
@@ -108,7 +108,7 @@ func (p *Plugin) UserWillLogIn(c *plugin.Context, user *model.User) string {
108108
if user.Props != nil && user.Props[syncengine.MMIdPUsernameProp] != user.Username {
109109
user.Username = user.Props[syncengine.MMIdPUsernameProp]
110110
var appErr *model.AppError
111-
user, appErr = p.MattermostPlugin.API.UpdateUser(user)
111+
user, appErr = p.API.UpdateUser(user)
112112
if appErr != nil {
113113
log.WithFields(log.Fields{
114114
"user": user,

server/syncablesync/mattermost_channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/mattermost/mattermost/server/public/model"
9+
810
"github.com/lukegb/mattermost-plugin-uffd/server/paginator"
911
"github.com/lukegb/mattermost-plugin-uffd/server/stringset"
10-
"github.com/mattermost/mattermost/server/public/model"
1112
)
1213

1314
type mattermostChannelHandler struct {

server/syncablesync/mattermost_systemrole.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/mattermost/mattermost/server/public/model"
9+
810
"github.com/lukegb/mattermost-plugin-uffd/server/paginator"
911
"github.com/lukegb/mattermost-plugin-uffd/server/stringset"
1012
"github.com/lukegb/mattermost-plugin-uffd/server/syncengine"
11-
"github.com/mattermost/mattermost/server/public/model"
1213
)
1314

1415
type mattermostSystemRoleHandler struct {

server/syncablesync/mattermost_systemrole_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
"testing"
66

77
"github.com/google/go-cmp/cmp"
8-
"github.com/lukegb/mattermost-plugin-uffd/server/syncengine"
98
"github.com/mattermost/mattermost/server/public/model"
9+
10+
"github.com/lukegb/mattermost-plugin-uffd/server/syncengine"
1011
)
1112

1213
var dummySystemRoleST = SyncableTarget{Type: mattermostSyncableTypeSystemRole, ID: "system_admin"}

0 commit comments

Comments
 (0)