MM-52532: Fix golangci warnings for public module (#23918)

https://mattermost.atlassian.net/browse/MM-52532

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-06-30 20:12:56 +05:30
коммит произвёл GitHub
родитель d74ee1a3da
Коммит d9a28c1244
13 изменённых файлов: 73 добавлений и 77 удалений

Просмотреть файл

@@ -44,10 +44,6 @@ issues:
text: "var-naming|error-naming|exported|increment-decrement|error-strings|if-return|unused-parameter|blank-imports|context-as-argument|empty-block" 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. # We need to fix the unused parameter issues and remove the exception.
- linters:
- revive
path: "public/*" # TODO: fix this
- linters: - linters:
- revive - revive
path: "enterprise" # TODO: fix this path: "enterprise" # TODO: fix this

Просмотреть файл

@@ -81,8 +81,8 @@ func (b *Bot) Trace() map[string]any {
// Clone returns a shallow copy of the bot. // Clone returns a shallow copy of the bot.
func (b *Bot) Clone() *Bot { func (b *Bot) Clone() *Bot {
copy := *b bCopy := *b
return &copy return &bCopy
} }
// IsValidCreate validates bot for Create call. This skips validations of fields that are auto-filled on Create // IsValidCreate validates bot for Create call. This skips validations of fields that are auto-filled on Create

Просмотреть файл

@@ -243,11 +243,11 @@ func (o *Channel) Props_() StringInterface {
} }
func (o *Channel) DeepCopy() *Channel { func (o *Channel) DeepCopy() *Channel {
copy := *o cCopy := *o
if copy.SchemeId != nil { if cCopy.SchemeId != nil {
copy.SchemeId = NewString(*o.SchemeId) cCopy.SchemeId = NewString(*o.SchemeId)
} }
return &copy return &cCopy
} }
func (o *Channel) Etag() string { func (o *Channel) Etag() string {

Просмотреть файл

@@ -76,14 +76,14 @@ func (o *ClusterDiscovery) IsEqual(in *ClusterDiscovery) bool {
} }
func FilterClusterDiscovery(vs []*ClusterDiscovery, f func(*ClusterDiscovery) bool) []*ClusterDiscovery { func FilterClusterDiscovery(vs []*ClusterDiscovery, f func(*ClusterDiscovery) bool) []*ClusterDiscovery {
copy := make([]*ClusterDiscovery, 0) cdCopy := make([]*ClusterDiscovery, 0)
for _, v := range vs { for _, v := range vs {
if f(v) { if f(v) {
copy = append(copy, v) cdCopy = append(cdCopy, v)
} }
} }
return copy return cdCopy
} }
func (o *ClusterDiscovery) IsValid() *AppError { func (o *ClusterDiscovery) IsValid() *AppError {

Просмотреть файл

@@ -81,8 +81,8 @@ func (c *Compliance) PreSave() {
} }
func (c *Compliance) DeepCopy() *Compliance { func (c *Compliance) DeepCopy() *Compliance {
copy := *c cCopy := *c
return &copy return &cCopy
} }
func (c *Compliance) JobName() string { func (c *Compliance) JobName() string {

Просмотреть файл

@@ -92,7 +92,7 @@ func (o *FileInfoList) SortByCreateAt() {
func (o *FileInfoList) Etag() string { func (o *FileInfoList) Etag() string {
id := "0" id := "0"
var t int64 = 0 var t int64
for _, v := range o.FileInfos { for _, v := range o.FileInfos {
if v.UpdateAt > t { if v.UpdateAt > t {

Просмотреть файл

@@ -207,11 +207,11 @@ type AnalyticsPostCountsOptions struct {
} }
func (o *PostPatch) WithRewrittenImageURLs(f func(string) string) *PostPatch { func (o *PostPatch) WithRewrittenImageURLs(f func(string) string) *PostPatch {
copy := *o //nolint:revive pCopy := *o //nolint:revive
if copy.Message != nil { if pCopy.Message != nil {
*copy.Message = RewriteImageURLs(*o.Message, f) *pCopy.Message = RewriteImageURLs(*o.Message, f)
} }
return &copy return &pCopy
} }
func (o *PostPatch) Auditable() map[string]interface{} { func (o *PostPatch) Auditable() map[string]interface{} {
@@ -296,15 +296,15 @@ func (o *Post) ShallowCopy(dst *Post) error {
// Clone shallowly copies the post and returns the copy. // Clone shallowly copies the post and returns the copy.
func (o *Post) Clone() *Post { func (o *Post) Clone() *Post {
copy := &Post{} //nolint:revive pCopy := &Post{} //nolint:revive
o.ShallowCopy(copy) o.ShallowCopy(pCopy)
return copy return pCopy
} }
func (o *Post) ToJSON() (string, error) { func (o *Post) ToJSON() (string, error) {
copy := o.Clone() //nolint:revive pCopy := o.Clone() //nolint:revive
copy.StripActionIntegrations() pCopy.StripActionIntegrations()
b, err := json.Marshal(copy) b, err := json.Marshal(pCopy)
return string(b), err return string(b), err
} }
@@ -707,12 +707,12 @@ var markdownDestinationEscaper = strings.NewReplacer(
// WithRewrittenImageURLs returns a new shallow copy of the post where the message has been // WithRewrittenImageURLs returns a new shallow copy of the post where the message has been
// rewritten via RewriteImageURLs. // rewritten via RewriteImageURLs.
func (o *Post) WithRewrittenImageURLs(f func(string) string) *Post { func (o *Post) WithRewrittenImageURLs(f func(string) string) *Post {
copy := o.Clone() pCopy := o.Clone()
copy.Message = RewriteImageURLs(o.Message, f) pCopy.Message = RewriteImageURLs(o.Message, f)
if copy.MessageSource == "" && copy.Message != o.Message { if pCopy.MessageSource == "" && pCopy.Message != o.Message {
copy.MessageSource = o.Message pCopy.MessageSource = o.Message
} }
return copy return pCopy
} }
// RewriteImageURLs takes a message and returns a copy that has all of the image URLs replaced // RewriteImageURLs takes a message and returns a copy that has all of the image URLs replaced

Просмотреть файл

@@ -47,11 +47,11 @@ func (o *PostList) Clone() *PostList {
} }
func (o *PostList) ForPlugin() *PostList { func (o *PostList) ForPlugin() *PostList {
copy := o.Clone() plCopy := o.Clone()
for k, p := range copy.Posts { for k, p := range plCopy.Posts {
copy.Posts[k] = p.ForPlugin() plCopy.Posts[k] = p.ForPlugin()
} }
return copy return plCopy
} }
func (o *PostList) ToSlice() []*Post { func (o *PostList) ToSlice() []*Post {
@@ -68,12 +68,12 @@ func (o *PostList) ToSlice() []*Post {
} }
func (o *PostList) WithRewrittenImageURLs(f func(string) string) *PostList { func (o *PostList) WithRewrittenImageURLs(f func(string) string) *PostList {
copy := *o plCopy := *o
copy.Posts = make(map[string]*Post) plCopy.Posts = make(map[string]*Post)
for id, post := range o.Posts { for id, post := range o.Posts {
copy.Posts[id] = post.WithRewrittenImageURLs(f) plCopy.Posts[id] = post.WithRewrittenImageURLs(f)
} }
return &copy return &plCopy
} }
func (o *PostList) StripActionIntegrations() { func (o *PostList) StripActionIntegrations() {
@@ -87,9 +87,9 @@ func (o *PostList) StripActionIntegrations() {
} }
func (o *PostList) ToJSON() (string, error) { func (o *PostList) ToJSON() (string, error) {
copy := *o plCopy := *o
copy.StripActionIntegrations() plCopy.StripActionIntegrations()
b, err := json.Marshal(&copy) b, err := json.Marshal(&plCopy)
return string(b), err return string(b), err
} }
@@ -164,7 +164,7 @@ func (o *PostList) SortByCreateAt() {
func (o *PostList) Etag() string { func (o *PostList) Etag() string {
id := "0" id := "0"
var t int64 = 0 var t int64
for _, v := range o.Posts { for _, v := range o.Posts {
if v.UpdateAt > t { if v.UpdateAt > t {

Просмотреть файл

@@ -23,9 +23,9 @@ func MakePostSearchResults(posts *PostList, matches PostSearchMatches) *PostSear
} }
func (o *PostSearchResults) ToJSON() (string, error) { func (o *PostSearchResults) ToJSON() (string, error) {
copy := *o psCopy := *o
copy.PostList.StripActionIntegrations() psCopy.PostList.StripActionIntegrations()
b, err := json.Marshal(&copy) b, err := json.Marshal(&psCopy)
return string(b), err return string(b), err
} }
@@ -35,7 +35,7 @@ func (o *PostSearchResults) EncodeJSON(w io.Writer) error {
} }
func (o *PostSearchResults) ForPlugin() *PostSearchResults { func (o *PostSearchResults) ForPlugin() *PostSearchResults {
copy := *o plCopy := *o
copy.PostList = copy.PostList.ForPlugin() plCopy.PostList = plCopy.PostList.ForPlugin()
return &copy return &plCopy
} }

Просмотреть файл

@@ -70,8 +70,8 @@ type PushNotification struct {
} }
func (pn *PushNotification) DeepCopy() *PushNotification { func (pn *PushNotification) DeepCopy() *PushNotification {
copy := *pn pnCopy := *pn
return &copy return &pnCopy
} }
func (pn *PushNotification) SetDeviceIdAndPlatform(deviceId string) { func (pn *PushNotification) SetDeviceIdAndPlatform(deviceId string) {

Просмотреть файл

@@ -677,7 +677,7 @@ func TestNowhereNil(t *testing.T) {
t.Parallel() t.Parallel()
var nilStringPtr *string var nilStringPtr *string
var nonNilStringPtr *string = new(string) var nonNilStringPtr = new(string)
var nilSlice []string var nilSlice []string
var nilStruct *struct{} var nilStruct *struct{}
var nilMap map[bool]bool var nilMap map[bool]bool

Просмотреть файл

@@ -177,16 +177,16 @@ type WebSocketEvent struct {
// PrecomputeJSON precomputes and stores the serialized JSON for all fields other than Sequence. // PrecomputeJSON precomputes and stores the serialized JSON for all fields other than Sequence.
// This makes ToJSON much more efficient when sending the same event to multiple connections. // This makes ToJSON much more efficient when sending the same event to multiple connections.
func (ev *WebSocketEvent) PrecomputeJSON() *WebSocketEvent { func (ev *WebSocketEvent) PrecomputeJSON() *WebSocketEvent {
copy := ev.Copy() evCopy := ev.Copy()
event, _ := json.Marshal(copy.event) event, _ := json.Marshal(evCopy.event)
data, _ := json.Marshal(copy.data) data, _ := json.Marshal(evCopy.data)
broadcast, _ := json.Marshal(copy.broadcast) broadcast, _ := json.Marshal(evCopy.broadcast)
copy.precomputedJSON = &precomputedWebSocketEventJSON{ evCopy.precomputedJSON = &precomputedWebSocketEventJSON{
Event: json.RawMessage(event), Event: json.RawMessage(event),
Data: json.RawMessage(data), Data: json.RawMessage(data),
Broadcast: json.RawMessage(broadcast), Broadcast: json.RawMessage(broadcast),
} }
return copy return evCopy
} }
func (ev *WebSocketEvent) Add(key string, value any) { func (ev *WebSocketEvent) Add(key string, value any) {
@@ -207,14 +207,14 @@ func NewWebSocketEvent(event, teamId, channelId, userId string, omitUsers map[st
} }
func (ev *WebSocketEvent) Copy() *WebSocketEvent { func (ev *WebSocketEvent) Copy() *WebSocketEvent {
copy := &WebSocketEvent{ evCopy := &WebSocketEvent{
event: ev.event, event: ev.event,
data: ev.data, data: ev.data,
broadcast: ev.broadcast, broadcast: ev.broadcast,
sequence: ev.sequence, sequence: ev.sequence,
precomputedJSON: ev.precomputedJSON, precomputedJSON: ev.precomputedJSON,
} }
return copy return evCopy
} }
func (ev *WebSocketEvent) DeepCopy() *WebSocketEvent { func (ev *WebSocketEvent) DeepCopy() *WebSocketEvent {
@@ -226,14 +226,14 @@ func (ev *WebSocketEvent) DeepCopy() *WebSocketEvent {
} }
} }
copy := &WebSocketEvent{ evCopy := &WebSocketEvent{
event: ev.event, event: ev.event,
data: dataCopy, data: dataCopy,
broadcast: ev.broadcast.copy(), broadcast: ev.broadcast.copy(),
sequence: ev.sequence, sequence: ev.sequence,
precomputedJSON: ev.precomputedJSON.copy(), precomputedJSON: ev.precomputedJSON.copy(),
} }
return copy return evCopy
} }
func (ev *WebSocketEvent) GetData() map[string]any { func (ev *WebSocketEvent) GetData() map[string]any {
@@ -249,27 +249,27 @@ func (ev *WebSocketEvent) GetSequence() int64 {
} }
func (ev *WebSocketEvent) SetEvent(event string) *WebSocketEvent { func (ev *WebSocketEvent) SetEvent(event string) *WebSocketEvent {
copy := ev.Copy() evCopy := ev.Copy()
copy.event = event evCopy.event = event
return copy return evCopy
} }
func (ev *WebSocketEvent) SetData(data map[string]any) *WebSocketEvent { func (ev *WebSocketEvent) SetData(data map[string]any) *WebSocketEvent {
copy := ev.Copy() evCopy := ev.Copy()
copy.data = data evCopy.data = data
return copy return evCopy
} }
func (ev *WebSocketEvent) SetBroadcast(broadcast *WebsocketBroadcast) *WebSocketEvent { func (ev *WebSocketEvent) SetBroadcast(broadcast *WebsocketBroadcast) *WebSocketEvent {
copy := ev.Copy() evCopy := ev.Copy()
copy.broadcast = broadcast evCopy.broadcast = broadcast
return copy return evCopy
} }
func (ev *WebSocketEvent) SetSequence(seq int64) *WebSocketEvent { func (ev *WebSocketEvent) SetSequence(seq int64) *WebSocketEvent {
copy := ev.Copy() evCopy := ev.Copy()
copy.sequence = seq evCopy.sequence = seq
return copy return evCopy
} }
func (ev *WebSocketEvent) IsValid() bool { func (ev *WebSocketEvent) IsValid() bool {

Просмотреть файл

@@ -70,11 +70,11 @@ func TestWebSocketEventImmutable(t *testing.T) {
require.Equal(t, newM.data, data) require.Equal(t, newM.data, data)
require.Equal(t, newM.data, newM.GetData()) require.Equal(t, newM.data, newM.GetData())
copy := m.Copy() mCopy := m.Copy()
if copy == m { if mCopy == m {
require.Fail(t, "pointers should not be the same") require.Fail(t, "pointers should not be the same")
} }
require.Equal(t, m, copy) require.Equal(t, m, mCopy)
} }
func TestWebSocketEventFromJSON(t *testing.T) { func TestWebSocketEventFromJSON(t *testing.T) {