mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-52532: Fix golangci warnings (#23709)
https://mattermost.atlassian.net/browse/MM-52532 - Replace golint with revive - Add makezero linter - Fix all the required linter failures Some issues in enterprise and public modules are yet to be fixed. We send this to expediate things.
This commit is contained in:
parent
62a3ee8adc
commit
c249ba4a66
@ -15,17 +15,19 @@ linters-settings:
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- typecheck # This is to improve error reporting
|
||||
- gofmt
|
||||
- golint
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- revive
|
||||
- exportloopref
|
||||
- staticcheck
|
||||
- unconvert
|
||||
- unused
|
||||
- misspell
|
||||
- goimports
|
||||
- makezero
|
||||
# TODO: enable this later
|
||||
# - errcheck
|
||||
|
||||
@ -38,8 +40,17 @@ issues:
|
||||
text: "SetupEnterprise"
|
||||
|
||||
- linters:
|
||||
- golint
|
||||
text: "should have|should be|should replace|stutters|underscore|annoying|error strings should not be capitalized"
|
||||
- revive
|
||||
text: "var-naming|error-naming|exported|increment-decrement|error-strings|if-return|unused-parameter|blank-imports|context-as-argument|empty-block"
|
||||
# We need to fix the unused parameter issues and remove the exception.
|
||||
|
||||
- linters:
|
||||
- revive
|
||||
path: "public/*" # TODO: fix this
|
||||
|
||||
- linters:
|
||||
- revive
|
||||
path: "enterprise" # TODO: fix this
|
||||
|
||||
- linters:
|
||||
- misspell
|
||||
|
@ -322,7 +322,6 @@ func (a *API) handleGetTeamUsersByID(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var users []*model.User
|
||||
var error error
|
||||
|
||||
if len(userIDs) == 0 {
|
||||
a.errorResponse(w, r, model.NewErrBadRequest("User IDs are empty"))
|
||||
@ -341,9 +340,9 @@ func (a *API) handleGetTeamUsersByID(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
users = append(users, user)
|
||||
} else {
|
||||
users, error = a.app.GetUsersList(userIDs)
|
||||
if error != nil {
|
||||
a.errorResponse(w, r, error)
|
||||
users, err = a.app.GetUsersList(userIDs)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ func (a *API) handleGetUsersList(w http.ResponseWriter, r *http.Request) {
|
||||
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
||||
|
||||
var users []*model.User
|
||||
var error error
|
||||
|
||||
if len(userIDs) == 0 {
|
||||
a.errorResponse(w, r, model.NewErrBadRequest("User IDs are empty"))
|
||||
@ -86,9 +85,9 @@ func (a *API) handleGetUsersList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
users = append(users, user)
|
||||
} else {
|
||||
users, error = a.app.GetUsersList(userIDs)
|
||||
if error != nil {
|
||||
a.errorResponse(w, r, error)
|
||||
users, err = a.app.GetUsersList(userIDs)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -849,9 +849,9 @@ func (c *Client) TeamUploadFileInfo(teamID, boardID string, fileName string) (*m
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
fileInfoResponse, error := api.FileInfoResponseFromJSON(r.Body)
|
||||
if error != nil {
|
||||
return nil, BuildErrorResponse(r, error)
|
||||
fileInfoResponse, err := api.FileInfoResponseFromJSON(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
return fileInfoResponse, BuildResponse(r)
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
|
||||
var (
|
||||
OneHour int64 = 360000
|
||||
OneDay int64 = OneHour * 24
|
||||
OneYear int64 = OneDay * 365
|
||||
OneDay = OneHour * 24
|
||||
OneYear = OneDay * 365
|
||||
)
|
||||
|
||||
func setupTestHelperForCompliance(t *testing.T, complianceLicense bool) (*TestHelper, Clients) {
|
||||
|
@ -45,10 +45,10 @@ func (pd *PluginDelivery) UserByUsername(username string) (*mm_model.User, error
|
||||
// is a special character for usernames (dot, dash or underscore). If not, it
|
||||
// returns the same string.
|
||||
func trimUsernameSpecialChar(word string) (string, bool) {
|
||||
len := len(word)
|
||||
l := len(word)
|
||||
|
||||
if len > 0 && strings.LastIndexAny(word, usernameSpecialChars) == (len-1) {
|
||||
return word[:len-1], true
|
||||
if l > 0 && strings.LastIndexAny(word, usernameSpecialChars) == (l-1) {
|
||||
return word[:l-1], true
|
||||
}
|
||||
|
||||
return word, false
|
||||
|
@ -934,9 +934,8 @@ func (s *MattermostAuthLayer) boardsFromRows(rows *sql.Rows, removeDuplicates bo
|
||||
if removeDuplicates {
|
||||
if _, ok := idMap[board.ID]; ok {
|
||||
continue
|
||||
} else {
|
||||
idMap[board.ID] = struct{}{}
|
||||
}
|
||||
idMap[board.ID] = struct{}{}
|
||||
}
|
||||
|
||||
err = json.Unmarshal(propertiesBytes, &board.Properties)
|
||||
|
@ -88,7 +88,7 @@ func (s *SQLStore) updateCardLimitTimestamp(db sq.BaseRunner, cardLimit int) (in
|
||||
Insert(s.tablePrefix+"system_settings").
|
||||
Columns("id", "value")
|
||||
|
||||
var value interface{} = 0
|
||||
var value any = 0 //nolint:revive
|
||||
if cardLimit != 0 {
|
||||
value = s.activeCardsQuery(sq.StatementBuilder, "b.update_at", cardLimit).
|
||||
OrderBy("b.update_at DESC").
|
||||
|
@ -1061,8 +1061,8 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var (
|
||||
groups = []*model.Group{}
|
||||
canSee bool = true
|
||||
groups = []*model.Group{}
|
||||
canSee = true
|
||||
)
|
||||
|
||||
if opts.FilterHasMember != "" {
|
||||
|
@ -811,10 +811,10 @@ func possibleAtMentions(message string) []string {
|
||||
// is a special character for usernames (dot, dash or underscore). If not, it
|
||||
// returns the same string.
|
||||
func trimUsernameSpecialChar(word string) (string, bool) {
|
||||
len := len(word)
|
||||
l := len(word)
|
||||
|
||||
if len > 0 && strings.LastIndexAny(word, usernameSpecialChars) == (len-1) {
|
||||
return word[:len-1], true
|
||||
if l > 0 && strings.LastIndexAny(word, usernameSpecialChars) == (l-1) {
|
||||
return word[:l-1], true
|
||||
}
|
||||
|
||||
return word, false
|
||||
|
@ -894,7 +894,7 @@ func (es *Service) InvalidateVerifyEmailTokensForUser(userID string) *model.AppE
|
||||
return model.NewAppError("InvalidateVerifyEmailTokensForUser", "api.user.invalidate_verify_email_tokens.error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
var appErr *model.AppError = nil
|
||||
var appErr *model.AppError
|
||||
for _, token := range tokens {
|
||||
tokenExtra := struct {
|
||||
UserId string
|
||||
|
@ -315,7 +315,7 @@ func (a *App) findTeamIdForFilename(post *model.Post, id, filename string) strin
|
||||
}
|
||||
|
||||
var fileMigrationLock sync.Mutex
|
||||
var oldFilenameMatchExp *regexp.Regexp = regexp.MustCompile(`^\/([a-z\d]{26})\/([a-z\d]{26})\/([a-z\d]{26})\/([^\/]+)$`)
|
||||
var oldFilenameMatchExp = regexp.MustCompile(`^\/([a-z\d]{26})\/([a-z\d]{26})\/([a-z\d]{26})\/([^\/]+)$`)
|
||||
|
||||
// Parse the path from the Filename of the form /{channelID}/{userID}/{uid}/{nameWithExtension}
|
||||
func parseOldFilenames(filenames []string, channelID, userID string) [][]string {
|
||||
|
@ -25,7 +25,7 @@ func (a *App) removeInaccessibleContentFromFilesSlice(files []*model.FileInfo) (
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var firstInaccessibleFileTime int64 = 0
|
||||
var firstInaccessibleFileTime int64
|
||||
for _, file := range files {
|
||||
if createAt := file.CreateAt; createAt < lastAccessibleFileTime {
|
||||
file.MakeContentInaccessible()
|
||||
@ -143,7 +143,7 @@ func (a *App) getFilteredAccessibleFiles(files []*model.FileInfo, options filter
|
||||
return files, 0, nil
|
||||
}
|
||||
if bounds.noAccessible() {
|
||||
var firstInaccessibleFileTime int64 = 0
|
||||
var firstInaccessibleFileTime int64
|
||||
if lenFiles > 0 {
|
||||
firstFileCreatedAt := files[0].CreateAt
|
||||
lastFileCreatedAt := files[len(files)-1].CreateAt
|
||||
@ -194,7 +194,7 @@ func linearFilterFileList(fileList *model.FileInfoList, earliestAccessibleTime i
|
||||
// this is the slower fallback that is still safe
|
||||
// if we can not assume files are ordered by CreatedAt
|
||||
func linearFilterFilesSlice(files []*model.FileInfo, earliestAccessibleTime int64) ([]*model.FileInfo, int64) {
|
||||
var firstInaccessibleFileTime int64 = 0
|
||||
var firstInaccessibleFileTime int64
|
||||
n := 0
|
||||
for i := range files {
|
||||
if createAt := files[i].CreateAt; createAt >= earliestAccessibleTime {
|
||||
|
@ -282,7 +282,7 @@ func updateRole(a *App, sc *model.SchemeConveyor, roleCreatedName, defaultRoleNa
|
||||
|
||||
_, err = a.UpdateRole(roleCreated)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("%v: %v\n", err.Message, err.DetailedError))
|
||||
return fmt.Errorf("failed to update role: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -141,7 +141,7 @@ func (ps *PlatformService) GetLogsSkipSend(page, perPage int, logFilter *model.L
|
||||
var lineCount int
|
||||
const searchPos = -1
|
||||
b := make([]byte, 1)
|
||||
var endOffset int64 = 0
|
||||
var endOffset int64
|
||||
|
||||
// if the file exists and it's last byte is '\n' - skip it
|
||||
var stat os.FileInfo
|
||||
|
@ -442,7 +442,7 @@ func (h *Hub) Start() {
|
||||
})
|
||||
continue
|
||||
}
|
||||
var latestActivity int64 = 0
|
||||
var latestActivity int64
|
||||
for _, conn := range conns {
|
||||
if !conn.active {
|
||||
continue
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
package app
|
||||
|
||||
var mattermostPluginPublicKey []byte = []byte(`-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
var mattermostPluginPublicKey = []byte(`-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQINBF3YTiEBEACgkhnZ5+xylKZhLVj193b6d/rSQuCU/zwWeZJnqyR8wRsPotXO
|
||||
CMXOUM9bTTaGfItCP9KlPPcyrshNEIgqcqhB6TSKkWSyrV5XS95Opd9Esbjw1VZq
|
||||
|
@ -124,7 +124,7 @@ func linearFilterPostList(postList *model.PostList, earliestAccessibleTime int64
|
||||
// this is the slower fallback that is still safe if we can not
|
||||
// assume posts are ordered by CreatedAt
|
||||
func linearFilterPostsSlice(posts []*model.Post, earliestAccessibleTime int64) ([]*model.Post, int64) {
|
||||
var firstInaccessiblePostTime int64 = 0
|
||||
var firstInaccessiblePostTime int64
|
||||
n := 0
|
||||
for i := range posts {
|
||||
if createAt := posts[i].CreateAt; createAt >= earliestAccessibleTime {
|
||||
@ -243,7 +243,7 @@ func (a *App) getFilteredAccessiblePosts(posts []*model.Post, options filterPost
|
||||
return posts, 0, nil
|
||||
}
|
||||
if bounds.noAccessible() {
|
||||
var firstInaccessiblePostTime int64 = 0
|
||||
var firstInaccessiblePostTime int64
|
||||
if lenPosts > 0 {
|
||||
firstPostCreatedAt := posts[0].CreateAt
|
||||
lastPostCreatedAt := posts[len(posts)-1].CreateAt
|
||||
|
@ -234,7 +234,7 @@ func (a *App) createOnboardingLinkedBoard(c request.CTX, teamId string) (*fb_mod
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
var template *fb_model.Board = nil
|
||||
var template *fb_model.Board
|
||||
for _, t := range templates {
|
||||
v := t.Properties["trackingTemplateId"]
|
||||
if v == welcomeToBoardsTemplateId {
|
||||
|
@ -727,7 +727,7 @@ func TestSanitizeTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
copyTeam := func() *model.Team {
|
||||
copy := &model.Team{}
|
||||
copy := &model.Team{} //nolint:revive
|
||||
*copy = *team
|
||||
return copy
|
||||
}
|
||||
|
@ -1513,7 +1513,7 @@ func (a *App) InvalidatePasswordRecoveryTokensForUser(userID string) *model.AppE
|
||||
return model.NewAppError("InvalidatePasswordRecoveryTokensForUser", "api.user.invalidate_password_recovery_tokens.error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
var appErr *model.AppError = nil
|
||||
var appErr *model.AppError
|
||||
for _, token := range tokens {
|
||||
tokenExtra := struct {
|
||||
UserId string
|
||||
|
@ -111,24 +111,24 @@ func TestAdjustProfileImage(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, err := th.App.AdjustImage(bytes.NewReader([]byte{}))
|
||||
require.NotNil(t, err)
|
||||
_, appErr := th.App.AdjustImage(bytes.NewReader([]byte{}))
|
||||
require.NotNil(t, appErr)
|
||||
|
||||
// test image isn't the correct dimensions
|
||||
// it should be adjusted
|
||||
testjpg, error := testutils.ReadTestFile("testjpg.jpg")
|
||||
require.NoError(t, error)
|
||||
adjusted, err := th.App.AdjustImage(bytes.NewReader(testjpg))
|
||||
require.Nil(t, err)
|
||||
testjpg, err := testutils.ReadTestFile("testjpg.jpg")
|
||||
require.NoError(t, err)
|
||||
adjusted, appErr := th.App.AdjustImage(bytes.NewReader(testjpg))
|
||||
require.Nil(t, appErr)
|
||||
assert.True(t, adjusted.Len() > 0)
|
||||
assert.NotEqual(t, testjpg, adjusted)
|
||||
|
||||
// default image should not require adjustment
|
||||
user := th.BasicUser
|
||||
image, err := th.App.GetDefaultProfileImage(user)
|
||||
require.Nil(t, err)
|
||||
image2, err := th.App.AdjustImage(bytes.NewReader(image))
|
||||
require.Nil(t, err)
|
||||
image, appErr := th.App.GetDefaultProfileImage(user)
|
||||
require.Nil(t, appErr)
|
||||
image2, appErr := th.App.AdjustImage(bytes.NewReader(image))
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, image, image2.Bytes())
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ func MakeWorker(jobServer *jobs.JobServer, app AppIface, store store.Store) mode
|
||||
jobServer.HandleJobPanic(job)
|
||||
|
||||
var err error
|
||||
var fromTS int64 = 0
|
||||
var fromTS int64
|
||||
var toTS int64 = model.GetMillis()
|
||||
if fromStr, ok := job.Data["from"]; ok {
|
||||
if fromTS, err = strconv.ParseInt(fromStr, 10, 64); err != nil {
|
||||
|
@ -14,7 +14,7 @@ type Scheduler struct {
|
||||
*jobs.PeriodicScheduler
|
||||
}
|
||||
|
||||
func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, now time.Time, pendingJobs bool, lastSuccessfulJob *model.Job) *time.Time {
|
||||
func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, _ time.Time, pendingJobs bool, lastSuccessfulJob *model.Job) *time.Time {
|
||||
nextTime := time.Now().Add(time.Duration(*cfg.AnnouncementSettings.NoticesFetchFrequency) * time.Second)
|
||||
return &nextTime
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func (s LocalCacheTermsOfServiceStore) Save(termsOfService *model.TermsOfService
|
||||
|
||||
func (s LocalCacheTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.TermsOfService, error) {
|
||||
if allowFromCache {
|
||||
if len, err := s.rootStore.termsOfServiceCache.Len(); err == nil && len != 0 {
|
||||
if l, err := s.rootStore.termsOfServiceCache.Len(); err == nil && l != 0 {
|
||||
var cacheItem *model.TermsOfService
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.termsOfServiceCache, LatestKey, &cacheItem); err == nil {
|
||||
return cacheItem, nil
|
||||
|
@ -301,7 +301,7 @@ func (th *SearchTestHelper) createDirectChannel(teamID, name, displayName string
|
||||
}
|
||||
|
||||
func (th *SearchTestHelper) createGroupChannel(teamID, displayName string, users []*model.User) (*model.Channel, error) {
|
||||
userIDS := make([]string, len(users))
|
||||
userIDS := make([]string, 0, len(users))
|
||||
for _, user := range users {
|
||||
userIDS = append(userIDS, user.Id)
|
||||
}
|
||||
@ -464,7 +464,7 @@ func (th *SearchTestHelper) assertUsersMatchInAnyOrder(t *testing.T, expected, a
|
||||
|
||||
func (th *SearchTestHelper) checkPostInSearchResults(t *testing.T, postID string, searchResults map[string]*model.Post) {
|
||||
t.Helper()
|
||||
postIDS := make([]string, len(searchResults))
|
||||
postIDS := make([]string, 0, len(searchResults))
|
||||
for ID := range searchResults {
|
||||
postIDS = append(postIDS, ID)
|
||||
}
|
||||
@ -473,7 +473,7 @@ func (th *SearchTestHelper) checkPostInSearchResults(t *testing.T, postID string
|
||||
|
||||
func (th *SearchTestHelper) checkFileInfoInSearchResults(t *testing.T, fileID string, searchResults map[string]*model.FileInfo) {
|
||||
t.Helper()
|
||||
fileIDS := make([]string, len(searchResults))
|
||||
fileIDS := make([]string, 0, len(searchResults))
|
||||
for ID := range searchResults {
|
||||
fileIDS = append(fileIDS, ID)
|
||||
}
|
||||
|
@ -355,13 +355,13 @@ func testReactionGetForPostSince(t *testing.T, ss store.Store, s SqlStore) {
|
||||
}
|
||||
|
||||
for _, reaction := range reactions {
|
||||
delete := reaction.DeleteAt
|
||||
del := reaction.DeleteAt
|
||||
update := reaction.UpdateAt
|
||||
|
||||
_, err := ss.Reaction().Save(reaction)
|
||||
require.NoError(t, err)
|
||||
|
||||
if delete > 0 {
|
||||
if del > 0 {
|
||||
_, err = ss.Reaction().Delete(reaction)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ func testRetentionPolicyStoreAddChannels(t *testing.T, ss store.Store, s SqlStor
|
||||
err := ss.RetentionPolicy().AddChannels(policy.ID, channelIDs)
|
||||
require.NoError(t, err)
|
||||
// verify that the channels were actually added
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy) //nolint:revive
|
||||
copy.ChannelIDs = append(copy.ChannelIDs, channelIDs...)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
@ -492,7 +492,7 @@ func testRetentionPolicyStoreRemoveChannels(t *testing.T, ss store.Store, s SqlS
|
||||
err := ss.RetentionPolicy().RemoveChannels(policy.ID, []string{channelID})
|
||||
require.NoError(t, err)
|
||||
// verify that the channel was actually removed
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy) //nolint:revive
|
||||
copy.ChannelIDs = make([]string, 0)
|
||||
for _, oldChannelID := range policy.ChannelIDs {
|
||||
if oldChannelID != channelID {
|
||||
@ -554,7 +554,7 @@ func testRetentionPolicyStoreAddTeams(t *testing.T, ss store.Store, s SqlStore)
|
||||
err := ss.RetentionPolicy().AddTeams(policy.ID, teamIDs)
|
||||
require.NoError(t, err)
|
||||
// verify that the teams were actually added
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy) //nolint:revive
|
||||
copy.TeamIDs = append(copy.TeamIDs, teamIDs...)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
@ -588,7 +588,7 @@ func testRetentionPolicyStoreRemoveTeams(t *testing.T, ss store.Store, s SqlStor
|
||||
err := ss.RetentionPolicy().RemoveTeams(policy.ID, []string{teamID})
|
||||
require.NoError(t, err)
|
||||
// verify that the team was actually removed
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy) //nolint:revive
|
||||
copy.TeamIDs = make([]string, 0)
|
||||
for _, oldTeamID := range policy.TeamIDs {
|
||||
if oldTeamID != teamID {
|
||||
|
@ -123,8 +123,8 @@ func UpdateAssetsSubpathInDir(subpath, directory string) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to open %s", walkPath)
|
||||
}
|
||||
new := strings.Replace(string(old), pathToReplace, newPath, -1)
|
||||
if err = os.WriteFile(walkPath, []byte(new), 0); err != nil {
|
||||
n := strings.Replace(string(old), pathToReplace, newPath, -1)
|
||||
if err = os.WriteFile(walkPath, []byte(n), 0); err != nil {
|
||||
return errors.Wrapf(err, "failed to update %s with subpath %s", walkPath, subpath)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
||||
)
|
||||
|
||||
var coverprofileCounters map[string]int = make(map[string]int)
|
||||
var coverprofileCounters = make(map[string]int)
|
||||
|
||||
var mainHelper *testlib.MainHelper
|
||||
|
||||
|
@ -1238,9 +1238,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("username", mockUser.Username, "")
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Equal("Email is required: flag accessed but not defined: email", error.Error())
|
||||
s.Require().Equal("Email is required: flag accessed but not defined: email", err.Error())
|
||||
})
|
||||
|
||||
s.Run("Create user with username missing", func() {
|
||||
@ -1250,9 +1250,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("email", mockUser.Email, "")
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Equal("Username is required: flag accessed but not defined: username", error.Error())
|
||||
s.Require().Equal("Username is required: flag accessed but not defined: username", err.Error())
|
||||
})
|
||||
|
||||
s.Run("Create user with password missing", func() {
|
||||
@ -1262,9 +1262,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("username", mockUser.Username, "")
|
||||
command.Flags().String("email", mockUser.Email, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Equal("Password is required: flag accessed but not defined: password", error.Error())
|
||||
s.Require().Equal("Password is required: flag accessed but not defined: password", err.Error())
|
||||
})
|
||||
|
||||
s.Run("Create a regular user", func() {
|
||||
@ -1281,9 +1281,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("email", mockUser.Email, "")
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Nil(error)
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(&mockUser, printer.GetLines()[0])
|
||||
s.Require().Len(printer.GetErrorLines(), 0)
|
||||
})
|
||||
@ -1307,9 +1307,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
command.Flags().Bool("disable-welcome-email", mockUser.DisableWelcomeEmail, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Nil(error)
|
||||
s.Require().Nil(err)
|
||||
printerLines := printer.GetLines()[0]
|
||||
printedUser := printerLines.(*model.User)
|
||||
|
||||
@ -1332,9 +1332,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("email", mockUser.Email, "")
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Equal("Unable to create user. Error: remote error", error.Error())
|
||||
s.Require().Equal("Unable to create user. Error: remote error", err.Error())
|
||||
})
|
||||
|
||||
s.Run("Create a sysAdmin user", func() {
|
||||
@ -1358,9 +1358,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
command.Flags().Bool("system-admin", true, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Nil(error)
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(&mockUser, printer.GetLines()[0])
|
||||
s.Require().Len(printer.GetErrorLines(), 0)
|
||||
})
|
||||
@ -1386,9 +1386,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
command.Flags().Bool("guest", true, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Nil(error)
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(&mockUser, printer.GetLines()[0])
|
||||
s.Require().Len(printer.GetErrorLines(), 0)
|
||||
})
|
||||
@ -1414,9 +1414,9 @@ func (s *MmctlUnitTestSuite) TestUserCreateCmd() {
|
||||
command.Flags().String("password", mockUser.Password, "")
|
||||
command.Flags().Bool("system-admin", true, "")
|
||||
|
||||
error := userCreateCmdF(s.client, &command, []string{})
|
||||
err := userCreateCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().Equal("Unable to update user roles. Error: remote error", error.Error())
|
||||
s.Require().Equal("Unable to update user roles. Error: remote error", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
@ -1426,9 +1426,9 @@ func (s *MmctlUnitTestSuite) TestUpdateUserEmailCmd() {
|
||||
|
||||
command := cobra.Command{}
|
||||
|
||||
error := updateUserEmailCmdF(s.client, &command, []string{})
|
||||
err := updateUserEmailCmdF(s.client, &command, []string{})
|
||||
|
||||
s.Require().EqualError(error, "expected two arguments. See help text for details")
|
||||
s.Require().EqualError(err, "expected two arguments. See help text for details")
|
||||
})
|
||||
|
||||
s.Run("Invalid email provided", func() {
|
||||
@ -1438,9 +1438,9 @@ func (s *MmctlUnitTestSuite) TestUpdateUserEmailCmd() {
|
||||
emailArg := "invalidEmail"
|
||||
command := cobra.Command{}
|
||||
|
||||
error := updateUserEmailCmdF(s.client, &command, []string{userArg, emailArg})
|
||||
err := updateUserEmailCmdF(s.client, &command, []string{userArg, emailArg})
|
||||
|
||||
s.Require().EqualError(error, "invalid email: 'invalidEmail'")
|
||||
s.Require().EqualError(err, "invalid email: 'invalidEmail'")
|
||||
})
|
||||
|
||||
s.Run("User not found using email, username or id as identifier", func() {
|
||||
@ -1562,9 +1562,9 @@ func (s *MmctlUnitTestSuite) TestUpdateUserEmailCmd() {
|
||||
Return(&updatedUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
error := updateUserEmailCmdF(s.client, &command, []string{userArg, emailArg})
|
||||
err := updateUserEmailCmdF(s.client, &command, []string{userArg, emailArg})
|
||||
|
||||
s.Require().Nil(error)
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(&updatedUser, printer.GetLines()[0])
|
||||
s.Require().Len(printer.GetErrorLines(), 0)
|
||||
})
|
||||
|
@ -237,17 +237,17 @@ func TestEqual(t *testing.T) {
|
||||
|
||||
t.Run("no diff", func(t *testing.T) {
|
||||
old := minimalConfig.Clone()
|
||||
new := minimalConfig.Clone()
|
||||
diff, err := equal(old, new)
|
||||
n := minimalConfig.Clone()
|
||||
diff, err := equal(old, n)
|
||||
require.NoError(t, err)
|
||||
require.False(t, diff)
|
||||
})
|
||||
|
||||
t.Run("diff", func(t *testing.T) {
|
||||
old := minimalConfig.Clone()
|
||||
new := minimalConfig.Clone()
|
||||
new.SqlSettings = model.SqlSettings{}
|
||||
diff, err := equal(old, new)
|
||||
n := minimalConfig.Clone()
|
||||
n.SqlSettings = model.SqlSettings{}
|
||||
diff, err := equal(old, n)
|
||||
require.NoError(t, err)
|
||||
require.True(t, diff)
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ func init() {
|
||||
|
||||
type DialContextFunction func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
|
||||
var AddressForbidden error = errors.New("address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network")
|
||||
var AddressForbidden = errors.New("address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network")
|
||||
|
||||
func dialContextFilter(dial DialContextFunction, allowHost func(host string) bool, allowIP func(ip net.IP) bool) DialContextFunction {
|
||||
return func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
|
@ -487,10 +487,7 @@ func (s *FileBackendTestSuite) TestAppendFile() {
|
||||
s.Run("should correctly append the data", func() {
|
||||
// First part needs to be at least 5MB for the S3 implementation to work.
|
||||
size := 5 * 1024 * 1024
|
||||
b := make([]byte, size)
|
||||
for i := range b {
|
||||
b[i] = 'A'
|
||||
}
|
||||
b := bytes.Repeat([]byte{'A'}, size)
|
||||
path := "tests/" + randomString()
|
||||
|
||||
written, err := s.backend.WriteFile(bytes.NewReader(b), path)
|
||||
|
@ -504,7 +504,7 @@ func (p *playbookStore) GetPlaybooksForTeam(requesterInfo app.RequesterInfo, tea
|
||||
return app.GetPlaybooksResults{}, errors.Wrap(err, "failed to get total count")
|
||||
}
|
||||
|
||||
ids := make([]string, len(playbooks))
|
||||
ids := make([]string, 0, len(playbooks))
|
||||
for _, pb := range playbooks {
|
||||
ids = append(ids, pb.ID)
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ func BotFromUser(u *User) *Bot {
|
||||
// Etag computes the etag for a list of bots.
|
||||
func (l *BotList) Etag() string {
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
var delta int64 = 0
|
||||
var t int64
|
||||
var delta int64
|
||||
|
||||
for _, v := range *l {
|
||||
if v.UpdateAt > t {
|
||||
|
@ -31,7 +31,7 @@ func (o *ChannelCounts) Etag() string {
|
||||
|
||||
md5Counts := fmt.Sprintf("%x", md5.Sum([]byte(str)))
|
||||
|
||||
var update int64 = 0
|
||||
var update int64
|
||||
for _, u := range o.UpdateTimes {
|
||||
if u > update {
|
||||
update = u
|
||||
|
@ -9,7 +9,7 @@ type ChannelData struct {
|
||||
}
|
||||
|
||||
func (o *ChannelData) Etag() string {
|
||||
var mt int64 = 0
|
||||
var mt int64
|
||||
if o.Member != nil {
|
||||
mt = o.Member.LastUpdateAt
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ type ChannelList []*Channel
|
||||
func (o *ChannelList) Etag() string {
|
||||
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
var delta int64 = 0
|
||||
var t int64
|
||||
var delta int64
|
||||
|
||||
for _, v := range *o {
|
||||
if v.LastPostAt > t {
|
||||
@ -32,8 +32,8 @@ type ChannelListWithTeamData []*ChannelWithTeamData
|
||||
func (o *ChannelListWithTeamData) Etag() string {
|
||||
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
var delta int64 = 0
|
||||
var t int64
|
||||
var delta int64
|
||||
|
||||
for _, v := range *o {
|
||||
if v.LastPostAt > t {
|
||||
|
@ -434,7 +434,7 @@ func encryptPostActionCookie(plain string, secret []byte) (string, error) {
|
||||
|
||||
sealed := aesgcm.Seal(nil, nonce, []byte(plain), nil)
|
||||
|
||||
combined := append(nonce, sealed...)
|
||||
combined := append(nonce, sealed...) //nolint:makezero
|
||||
encoded := make([]byte, base64.StdEncoding.EncodedLen(len(combined)))
|
||||
base64.StdEncoding.Encode(encoded, combined)
|
||||
|
||||
|
@ -26,13 +26,13 @@ const (
|
||||
PluginFeature = MattermostFeature("mattermost.feature.plugin")
|
||||
)
|
||||
|
||||
var validSKUs map[string]struct{} = map[string]struct{}{
|
||||
var validSKUs = map[string]struct{}{
|
||||
LicenseShortSkuProfessional: {},
|
||||
LicenseShortSkuEnterprise: {},
|
||||
}
|
||||
|
||||
// These are the features a non admin would typically ping an admin about
|
||||
var paidFeatures map[MattermostFeature]struct{} = map[MattermostFeature]struct{}{
|
||||
var paidFeatures = map[MattermostFeature]struct{}{
|
||||
PaidFeatureGuestAccounts: {},
|
||||
PaidFeatureCustomUsergroups: {},
|
||||
PaidFeatureCreateMultipleTeams: {},
|
||||
|
@ -203,7 +203,7 @@ type AnalyticsPostCountsOptions struct {
|
||||
}
|
||||
|
||||
func (o *PostPatch) WithRewrittenImageURLs(f func(string) string) *PostPatch {
|
||||
copy := *o
|
||||
copy := *o //nolint:revive
|
||||
if copy.Message != nil {
|
||||
*copy.Message = RewriteImageURLs(*o.Message, f)
|
||||
}
|
||||
@ -292,13 +292,13 @@ func (o *Post) ShallowCopy(dst *Post) error {
|
||||
|
||||
// Clone shallowly copies the post and returns the copy.
|
||||
func (o *Post) Clone() *Post {
|
||||
copy := &Post{}
|
||||
copy := &Post{} //nolint:revive
|
||||
o.ShallowCopy(copy)
|
||||
return copy
|
||||
}
|
||||
|
||||
func (o *Post) ToJSON() (string, error) {
|
||||
copy := o.Clone()
|
||||
copy := o.Clone() //nolint:revive
|
||||
copy.StripActionIntegrations()
|
||||
b, err := json.Marshal(copy)
|
||||
return string(b), err
|
||||
|
@ -271,7 +271,7 @@ func (rci *RemoteClusterInvite) Encrypt(password string) ([]byte, error) {
|
||||
// prefix the nonce to the cyphertext so we don't need to keep track of it.
|
||||
sealed := gcm.Seal(nonce, nonce, raw, nil)
|
||||
|
||||
return append(salt, sealed...), nil
|
||||
return append(salt, sealed...), nil //nolint:makezero
|
||||
}
|
||||
|
||||
func (rci *RemoteClusterInvite) Decrypt(encrypted []byte, password string) error {
|
||||
|
@ -93,7 +93,7 @@ type TeamsWithCount struct {
|
||||
}
|
||||
|
||||
func (o *Invites) ToEmailList() []string {
|
||||
emailList := make([]string, len(o.Invites))
|
||||
emailList := make([]string, 0, len(o.Invites))
|
||||
for _, invite := range o.Invites {
|
||||
emailList = append(emailList, invite["email"])
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ var versions = []string{
|
||||
"0.5.0",
|
||||
}
|
||||
|
||||
var CurrentVersion string = versions[0]
|
||||
var CurrentVersion = versions[0]
|
||||
var BuildNumber string
|
||||
var BuildDate string
|
||||
var BuildHash string
|
||||
|
@ -114,12 +114,12 @@ func TestWebSocketClose(t *testing.T) {
|
||||
|
||||
waitForResponses := func(doneChan chan struct{}, cli *WebSocketClient) {
|
||||
go func() {
|
||||
for range cli.EventChannel {
|
||||
for range cli.EventChannel { //nolint:revive
|
||||
}
|
||||
doneChan <- struct{}{}
|
||||
}()
|
||||
go func() {
|
||||
for range cli.ResponseChannel {
|
||||
for range cli.ResponseChannel { //nolint:revive
|
||||
}
|
||||
doneChan <- struct{}{}
|
||||
}()
|
||||
|
@ -36,39 +36,39 @@ func TestWebSocketEvent(t *testing.T) {
|
||||
func TestWebSocketEventImmutable(t *testing.T) {
|
||||
m := NewWebSocketEvent("some_event", NewId(), NewId(), NewId(), nil, "")
|
||||
|
||||
new := m.SetEvent("new_event")
|
||||
if new == m {
|
||||
newM := m.SetEvent("new_event")
|
||||
if newM == m {
|
||||
require.Fail(t, "pointers should not be the same")
|
||||
}
|
||||
require.NotEqual(t, m.EventType(), new.EventType())
|
||||
require.Equal(t, new.EventType(), "new_event")
|
||||
require.NotEqual(t, m.EventType(), newM.EventType())
|
||||
require.Equal(t, newM.EventType(), "new_event")
|
||||
|
||||
new = m.SetSequence(45)
|
||||
if new == m {
|
||||
newM = m.SetSequence(45)
|
||||
if newM == m {
|
||||
require.Fail(t, "pointers should not be the same")
|
||||
}
|
||||
require.NotEqual(t, m.GetSequence(), new.GetSequence())
|
||||
require.Equal(t, new.GetSequence(), int64(45))
|
||||
require.NotEqual(t, m.GetSequence(), newM.GetSequence())
|
||||
require.Equal(t, newM.GetSequence(), int64(45))
|
||||
|
||||
broadcast := &WebsocketBroadcast{}
|
||||
new = m.SetBroadcast(broadcast)
|
||||
if new == m {
|
||||
newM = m.SetBroadcast(broadcast)
|
||||
if newM == m {
|
||||
require.Fail(t, "pointers should not be the same")
|
||||
}
|
||||
require.NotEqual(t, m.GetBroadcast(), new.GetBroadcast())
|
||||
require.Equal(t, new.GetBroadcast(), broadcast)
|
||||
require.NotEqual(t, m.GetBroadcast(), newM.GetBroadcast())
|
||||
require.Equal(t, newM.GetBroadcast(), broadcast)
|
||||
|
||||
data := map[string]any{
|
||||
"key": "val",
|
||||
"key2": "val2",
|
||||
}
|
||||
new = m.SetData(data)
|
||||
if new == m {
|
||||
newM = m.SetData(data)
|
||||
if newM == m {
|
||||
require.Fail(t, "pointers should not be the same")
|
||||
}
|
||||
require.NotEqual(t, m, new)
|
||||
require.Equal(t, new.data, data)
|
||||
require.Equal(t, new.data, new.GetData())
|
||||
require.NotEqual(t, m, newM)
|
||||
require.Equal(t, newM.data, data)
|
||||
require.Equal(t, newM.data, newM.GetData())
|
||||
|
||||
copy := m.Copy()
|
||||
if copy == m {
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
)
|
||||
|
||||
var hookNameToId map[string]int = make(map[string]int)
|
||||
var hookNameToId = make(map[string]int)
|
||||
|
||||
type hooksRPCClient struct {
|
||||
client *rpc.Client
|
||||
|
@ -32,7 +32,7 @@ var T TranslateFunc
|
||||
// TDefault is the translate function using english as fallback language
|
||||
var TDefault TranslateFunc
|
||||
|
||||
var locales map[string]string = make(map[string]string)
|
||||
var locales = make(map[string]string)
|
||||
var defaultServerLocale string
|
||||
var defaultClientLocale string
|
||||
|
||||
@ -81,7 +81,7 @@ func initTranslationsWithDir(dir string) error {
|
||||
// GetTranslationFuncForDir loads translations from the filesystem into a new instance of the bundle.
|
||||
// It returns a function to access loaded translations.
|
||||
func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) {
|
||||
var availableLocals map[string]string = make(map[string]string)
|
||||
var availableLocals = make(map[string]string)
|
||||
bundle := bundle.New()
|
||||
files, _ := os.ReadDir(dir)
|
||||
for _, f := range files {
|
||||
|
Loading…
Reference in New Issue
Block a user