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.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
62a3ee8adc
Коммит
c249ba4a66
@@ -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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user