diff --git a/server/.golangci.yml b/server/.golangci.yml index d47221e347..a281c92caf 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -1,13 +1,10 @@ run: timeout: 10m - skip-dirs: - - channels/store/storetest/mocks linters-settings: gofmt: simplify: true govet: - check-shadowing: true enable-all: true disable: - fieldalignment @@ -33,6 +30,8 @@ linters: # - errcheck issues: + skip-dirs: + - channels/store/storetest/mocks exclude-rules: - linters: # ignore unused warnings from enterprise code diff --git a/server/Makefile b/server/Makefile index 9f4c666e18..7e64ce2a17 100644 --- a/server/Makefile +++ b/server/Makefile @@ -285,7 +285,7 @@ else endif golangci-lint: ## Run golangci-lint on codebase - $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 + $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1 @echo Running golangci-lint $(GOBIN)/golangci-lint run ./... diff --git a/server/channels/app/post_metadata.go b/server/channels/app/post_metadata.go index 013677fab7..4a257037bf 100644 --- a/server/channels/app/post_metadata.go +++ b/server/channels/app/post_metadata.go @@ -842,10 +842,9 @@ func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType s return og, nil, nil } return nil, nil, nil - } else { - // Not an image or web page with OpenGraph information - return nil, nil, nil } + // Not an image or web page with OpenGraph information + return nil, nil, nil } func parseImages(body io.Reader) (*model.PostImage, error) { diff --git a/server/channels/store/sqlstore/channel_member_history_store.go b/server/channels/store/sqlstore/channel_member_history_store.go index 6bcbbd652e..f17d935518 100644 --- a/server/channels/store/sqlstore/channel_member_history_store.go +++ b/server/channels/store/sqlstore/channel_member_history_store.go @@ -103,10 +103,9 @@ func (s SqlChannelMemberHistoryStore) hasDataAtOrBefore(time int64) (bool, error return false, err } else if result.Min.Valid { return result.Min.Int64 <= time, nil - } else { - // if the result was null, there are no rows in the table, so there is no data from before - return false, nil } + // if the result was null, there are no rows in the table, so there is no data from before + return false, nil } func (s SqlChannelMemberHistoryStore) getFromChannelMemberHistoryTable(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, error) { diff --git a/server/channels/store/sqlstore/plugin_store.go b/server/channels/store/sqlstore/plugin_store.go index a7f5ad61c1..c6018c37e1 100644 --- a/server/channels/store/sqlstore/plugin_store.go +++ b/server/channels/store/sqlstore/plugin_store.go @@ -172,9 +172,8 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte return false, nil } else if count == 1 { return true, nil - } else { - return false, errors.Wrapf(err, "got too many rows when counting PluginKeyValue with pluginId=%s, key=%s, rows=%d", kv.PluginId, kv.Key, count) } + return false, errors.Wrapf(err, "got too many rows when counting PluginKeyValue with pluginId=%s, key=%s, rows=%d", kv.PluginId, kv.Key, count) } // No rows were affected by the update, where condition was not satisfied, diff --git a/server/channels/store/sqlstore/store.go b/server/channels/store/sqlstore/store.go index 628facf665..817c1b6541 100644 --- a/server/channels/store/sqlstore/store.go +++ b/server/channels/store/sqlstore/store.go @@ -637,10 +637,9 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool { } return count > 0 - } else { - mlog.Fatal("Failed to check if column exists because of missing driver") - return false } + mlog.Fatal("Failed to check if column exists because of missing driver") + return false } func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool { @@ -685,10 +684,9 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool { } return count > 0 - } else { - mlog.Fatal("Failed to check if column exists because of missing driver") - return false } + mlog.Fatal("Failed to check if column exists because of missing driver") + return false } func (ss *SqlStore) DoesTriggerExist(triggerName string) bool { @@ -725,10 +723,9 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool { } return count > 0 - } else { - mlog.Fatal("Failed to check if column exists because of missing driver") - return false } + mlog.Fatal("Failed to check if column exists because of missing driver") + return false } func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string, mySqlColType string, postgresColType string, defaultValue string) bool { @@ -750,10 +747,9 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string, } return true - } else { - mlog.Fatal("Failed to create column because of missing driver") - return false } + mlog.Fatal("Failed to create column because of missing driver") + return false } func (ss *SqlStore) RemoveTableIfExists(tableName string) bool { diff --git a/server/channels/utils/humanize.go b/server/channels/utils/humanize.go index 47636e1eee..858ab0d851 100644 --- a/server/channels/utils/humanize.go +++ b/server/channels/utils/humanize.go @@ -14,12 +14,11 @@ func JoinList(items []string) string { return "" } else if len(items) == 1 { return items[0] - } else { - return i18n.T( - "humanize.list_join", - map[string]any{ - "OtherItems": strings.Join(items[:len(items)-1], ", "), - "LastItem": items[len(items)-1], - }) } + return i18n.T( + "humanize.list_join", + map[string]any{ + "OtherItems": strings.Join(items[:len(items)-1], ", "), + "LastItem": items[len(items)-1], + }) } diff --git a/server/channels/web/oauth.go b/server/channels/web/oauth.go index 8562c0b1e0..e9e3be899a 100644 --- a/server/channels/web/oauth.go +++ b/server/channels/web/oauth.go @@ -343,9 +343,9 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) { }) utils.RenderMobileAuthComplete(w, redirectURL) return - } else { // For web - c.App.AttachSessionCookies(c.AppContext, w, r) } + // For web + c.App.AttachSessionCookies(c.AppContext, w, r) desktopToken := "" if val, ok := props["desktop_token"]; ok { diff --git a/server/channels/web/oauth_test.go b/server/channels/web/oauth_test.go index d8307b4545..d9d63ee9d9 100644 --- a/server/channels/web/oauth_test.go +++ b/server/channels/web/oauth_test.go @@ -661,7 +661,8 @@ func HTTPGet(url string, httpClient *http.Client, authToken string, followRedire } } - if rp, err := httpClient.Do(rq); err != nil { + rp, err := httpClient.Do(rq) + if err != nil { return nil, err } else if rp.StatusCode == 304 { return rp, nil @@ -670,9 +671,8 @@ func HTTPGet(url string, httpClient *http.Client, authToken string, followRedire } else if rp.StatusCode >= 300 { defer closeBody(rp) return rp, model.AppErrorFromJSON(rp.Body) - } else { - return rp, nil } + return rp, nil } func closeBody(r *http.Response) { diff --git a/server/public/model/config.go b/server/public/model/config.go index 3e25267f04..e69bcc0d18 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -4507,9 +4507,8 @@ func isSafeLink(link *string) bool { return true } else if strings.HasPrefix(*link, "/") { return true - } else { - return false } + return false } return true diff --git a/server/public/model/user.go b/server/public/model/user.go index cc73e50f88..b367b80e3b 100644 --- a/server/public/model/user.go +++ b/server/public/model/user.go @@ -750,9 +750,8 @@ func (u *User) GetFullName() string { return u.FirstName } else if u.LastName != "" { return u.LastName - } else { - return "" } + return "" } func (u *User) getDisplayName(baseName, nameFormat string) string { diff --git a/server/public/plugin/client.go b/server/public/plugin/client.go index f681932b4c..c80ab8564e 100644 --- a/server/public/plugin/client.go +++ b/server/public/plugin/client.go @@ -16,15 +16,15 @@ const ( // // Call this when your plugin is ready to start. func ClientMain(pluginImplementation any) { - if impl, ok := pluginImplementation.(interface { + impl, ok := pluginImplementation.(interface { SetAPI(api API) SetDriver(driver Driver) - }); !ok { + }) + if !ok { panic("Plugin implementation given must embed plugin.MattermostPlugin") - } else { - impl.SetAPI(nil) - impl.SetDriver(nil) } + impl.SetAPI(nil) + impl.SetDriver(nil) pluginMap := map[string]plugin.Plugin{ "hooks": &hooksPlugin{hooks: pluginImplementation}, diff --git a/server/public/plugin/client_rpc.go b/server/public/plugin/client_rpc.go index c493250966..ffe849b844 100644 --- a/server/public/plugin/client_rpc.go +++ b/server/public/plugin/client_rpc.go @@ -196,30 +196,30 @@ func (s *hooksRPCServer) Implemented(args struct{}, reply *[]string) error { var methods []string for i := 0; i < ifaceType.NumMethod(); i++ { method := ifaceType.Method(i) - if m, ok := implType.MethodByName(method.Name); !ok { + m, ok := implType.MethodByName(method.Name) + if !ok { continue } else if m.Type.NumIn() != method.Type.NumIn()+1 { continue } else if m.Type.NumOut() != method.Type.NumOut() { continue - } else { - match := true - for j := 0; j < method.Type.NumIn(); j++ { - if m.Type.In(j+1) != method.Type.In(j) { - match = false - break - } + } + match := true + for j := 0; j < method.Type.NumIn(); j++ { + if m.Type.In(j+1) != method.Type.In(j) { + match = false + break } - for j := 0; j < method.Type.NumOut(); j++ { - if m.Type.Out(j) != method.Type.Out(j) { - match = false - break - } - } - if !match { - continue + } + for j := 0; j < method.Type.NumOut(); j++ { + if m.Type.Out(j) != method.Type.Out(j) { + match = false + break } } + if !match { + continue + } if _, ok := selfType.MethodByName(method.Name); !ok { continue } diff --git a/server/public/utils/json.go b/server/public/utils/json.go index 62443bea73..a2c809747d 100644 --- a/server/public/utils/json.go +++ b/server/public/utils/json.go @@ -28,9 +28,8 @@ func HumanizeJSONError(err error, data []byte) error { return NewHumanizedJSONError(syntaxError, data, syntaxError.Offset) } else if unmarshalError, ok := err.(*json.UnmarshalTypeError); ok { return NewHumanizedJSONError(unmarshalError, data, unmarshalError.Offset) - } else { - return err } + return err } func NewHumanizedJSONError(err error, data []byte, offset int64) *HumanizedJSONError {