Run gosimple against codebase (#12928)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d7649fbf31
Коммит
7a665aacdd
@@ -607,8 +607,7 @@ func TestUploadFiles(t *testing.T) {
|
||||
|
||||
expected, err := ioutil.ReadFile(filepath.Join(testDir, name))
|
||||
require.Nil(t, err)
|
||||
|
||||
if bytes.Compare(data, expected) != 0 {
|
||||
if !bytes.Equal(data, expected) {
|
||||
tf, err := ioutil.TempFile("", fmt.Sprintf("test_%v_*_%s", i, name))
|
||||
require.Nil(t, err)
|
||||
_, _ = io.Copy(tf, bytes.NewReader(data))
|
||||
|
||||
@@ -397,7 +397,6 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m["location"] = location
|
||||
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
return
|
||||
}
|
||||
|
||||
func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -415,5 +414,4 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1369,7 +1369,8 @@ func TestGetUsersByGroupChannelIds(t *testing.T) {
|
||||
usersByChannelId, resp := th.Client.GetUsersByGroupChannelIds([]string{gc1.Id})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
users, _ := usersByChannelId[gc1.Id]
|
||||
users, ok := usersByChannelId[gc1.Id]
|
||||
assert.True(t, ok)
|
||||
userIds := []string{}
|
||||
for _, user := range users {
|
||||
userIds = append(userIds, user.Id)
|
||||
@@ -1381,7 +1382,7 @@ func TestGetUsersByGroupChannelIds(t *testing.T) {
|
||||
usersByChannelId, resp = th.Client.GetUsersByGroupChannelIds([]string{gc1.Id})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, ok := usersByChannelId[gc1.Id]
|
||||
_, ok = usersByChannelId[gc1.Id]
|
||||
require.False(t, ok)
|
||||
|
||||
th.Client.Logout()
|
||||
|
||||
@@ -366,8 +366,8 @@ func ShouldSendPushNotification(user *model.User, channelNotifyProps model.Strin
|
||||
func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps model.StringMap, post *model.Post, wasMentioned bool) bool {
|
||||
userNotifyProps := user.NotifyProps
|
||||
userNotify := userNotifyProps[model.PUSH_NOTIFY_PROP]
|
||||
channelNotify, _ := channelNotifyProps[model.PUSH_NOTIFY_PROP]
|
||||
if channelNotify == "" {
|
||||
channelNotify, ok := channelNotifyProps[model.PUSH_NOTIFY_PROP]
|
||||
if !ok || channelNotify == "" {
|
||||
channelNotify = model.CHANNEL_NOTIFY_DEFAULT
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,6 @@ func (a *App) OverrideIconURLIfEmoji(post *model.Post) {
|
||||
} else {
|
||||
mlog.Warn("Failed to retrieve URL for overriden profile icon (emoji)", mlog.String("emojiName", emojiName), mlog.Err(err))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *App) PreparePostForClient(originalPost *model.Post, isNewPost bool, isEditPost bool) *model.Post {
|
||||
|
||||
@@ -307,18 +307,22 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
t.Run("does not override icon URL", func(t *testing.T) {
|
||||
clientPost := prepare(false, url, emoji)
|
||||
|
||||
s, _ := clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_URL]
|
||||
s, ok := clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_URL]
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, url, s)
|
||||
s, _ = clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_EMOJI]
|
||||
s, ok = clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_EMOJI]
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, emoji, s)
|
||||
})
|
||||
|
||||
t.Run("overrides icon URL", func(t *testing.T) {
|
||||
clientPost := prepare(true, url, emoji)
|
||||
|
||||
s, _ := clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_URL]
|
||||
s, ok := clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_URL]
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, overridenUrl, s)
|
||||
s, _ = clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_EMOJI]
|
||||
s, ok = clientPost.Props[model.POST_PROPS_OVERRIDE_ICON_EMOJI]
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, emoji, s)
|
||||
})
|
||||
|
||||
|
||||
@@ -633,7 +633,7 @@ func (a *App) OriginChecker() func(*http.Request) bool {
|
||||
|
||||
func (s *Server) checkPushNotificationServerUrl() {
|
||||
notificationServer := *s.Config().EmailSettings.PushNotificationServer
|
||||
if strings.HasPrefix(notificationServer, "http://") == true {
|
||||
if strings.HasPrefix(notificationServer, "http://") {
|
||||
mlog.Warn("Your push notification server is configured with HTTP. For improved security, update to HTTPS in your configuration.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,10 +331,7 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
||||
|
||||
// If the event is destined to a specific user
|
||||
if len(msg.Broadcast.UserId) > 0 {
|
||||
if webCon.UserId == msg.Broadcast.UserId {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return webCon.UserId == msg.Broadcast.UserId
|
||||
}
|
||||
|
||||
// if the user is omitted don't send the message
|
||||
@@ -397,10 +394,5 @@ func (webCon *WebConn) IsMemberOfTeam(teamId string) bool {
|
||||
currentSession = session
|
||||
}
|
||||
|
||||
member := currentSession.GetTeamByTeamId(teamId)
|
||||
|
||||
if member != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return currentSession.GetTeamByTeamId(teamId) != nil
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func createCommandCmdF(command *cobra.Command, args []string) error {
|
||||
autocompleteHint, _ := command.Flags().GetString("autocompleteHint")
|
||||
post, errp := command.Flags().GetBool("post")
|
||||
method := "P"
|
||||
if errp != nil || post == false {
|
||||
if errp != nil || !post {
|
||||
method = "G"
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ func modifyCommandCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
post, err := command.Flags().GetBool("post")
|
||||
method := "P"
|
||||
if err != nil || post == false {
|
||||
if err != nil || !post {
|
||||
method = "G"
|
||||
}
|
||||
modifiedCommand.Method = method
|
||||
|
||||
@@ -41,7 +41,7 @@ func parseLogMessage(msg string) (result LogEntry, err error) {
|
||||
} else {
|
||||
d, ok := token.(json.Delim)
|
||||
if !ok || d != '{' {
|
||||
return result, errors.New(fmt.Sprintf("input is not a JSON object, found: %v", token))
|
||||
return result, fmt.Errorf("input is not a JSON object, found: %v", token)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func parseLogMessage(msg string) (result LogEntry, err error) {
|
||||
} else {
|
||||
d, ok := token.(json.Delim)
|
||||
if !ok || d != '}' {
|
||||
return result, errors.New(fmt.Sprintf("failed to read '}', read: %v", token))
|
||||
return result, fmt.Errorf("failed to read '}', read: %v", token)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2880,7 +2880,7 @@ func (ss *ServiceSettings) isValid() *AppError {
|
||||
return NewAppError("Config.IsValid", "model.config.is_valid.webserver_security.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if *ss.ConnectionSecurity == CONN_SECURITY_TLS && *ss.UseLetsEncrypt == false {
|
||||
if *ss.ConnectionSecurity == CONN_SECURITY_TLS && !*ss.UseLetsEncrypt {
|
||||
appErr := NewAppError("Config.IsValid", "model.config.is_valid.tls_cert_file.app_error", nil, "", http.StatusBadRequest)
|
||||
|
||||
if *ss.TLSCertFile == "" {
|
||||
|
||||
@@ -111,11 +111,7 @@ func (s *SlackAttachment) Equals(input *SlackAttachment) bool {
|
||||
}
|
||||
}
|
||||
|
||||
if s.Timestamp != input.Timestamp {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
return s.Timestamp == input.Timestamp
|
||||
}
|
||||
|
||||
type SlackAttachmentField struct {
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestKVSetJSON(t *testing.T) {
|
||||
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
err := p.KVSetJSON("test-key", func() { return })
|
||||
err := p.KVSetJSON("test-key", func() {})
|
||||
api.AssertExpectations(t)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
@@ -124,7 +124,7 @@ func TestKVCompareAndSetJSON(t *testing.T) {
|
||||
api.AssertNotCalled(t, "KVCompareAndSet")
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
ok, err := p.KVCompareAndSetJSON("test-key", func() { return }, map[string]interface{}{})
|
||||
ok, err := p.KVCompareAndSetJSON("test-key", func() {}, map[string]interface{}{})
|
||||
|
||||
api.AssertExpectations(t)
|
||||
assert.Equal(t, false, ok)
|
||||
@@ -137,7 +137,7 @@ func TestKVCompareAndSetJSON(t *testing.T) {
|
||||
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
ok, err := p.KVCompareAndSetJSON("test-key", map[string]interface{}{}, func() { return })
|
||||
ok, err := p.KVCompareAndSetJSON("test-key", map[string]interface{}{}, func() {})
|
||||
|
||||
api.AssertExpectations(t)
|
||||
assert.False(t, ok)
|
||||
@@ -211,7 +211,7 @@ func TestKVCompareAndDeleteJSON(t *testing.T) {
|
||||
api.AssertNotCalled(t, "KVCompareAndDelete")
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
ok, err := p.KVCompareAndDeleteJSON("test-key", func() { return })
|
||||
ok, err := p.KVCompareAndDeleteJSON("test-key", func() {})
|
||||
|
||||
api.AssertExpectations(t)
|
||||
assert.Equal(t, false, ok)
|
||||
@@ -266,7 +266,7 @@ func TestKVSetWithExpiryJSON(t *testing.T) {
|
||||
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
err := p.KVSetWithExpiryJSON("test-key", func() { return }, 100)
|
||||
err := p.KVSetWithExpiryJSON("test-key", func() {}, 100)
|
||||
|
||||
api.AssertExpectations(t)
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -55,11 +55,10 @@ func (s LocalCacheRoleStore) GetByNames(names []string) ([]*model.Role, *model.A
|
||||
|
||||
roles, _ := s.RoleStore.GetByNames(rolesToQuery)
|
||||
|
||||
if roles != nil {
|
||||
for _, role := range roles {
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.roleCache, role.Name, role)
|
||||
}
|
||||
for _, role := range roles {
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.roleCache, role.Name, role)
|
||||
}
|
||||
|
||||
return append(foundRoles, roles...), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1359,8 +1359,7 @@ func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) string {
|
||||
var querystr string
|
||||
querystr = `
|
||||
querystr := `
|
||||
SELECT
|
||||
CONCAT(MAX(UpdateAt), '.', COUNT(Id)) as etag
|
||||
FROM
|
||||
|
||||
@@ -84,7 +84,7 @@ func getTestResourcesToSetup() []testResourceDetails {
|
||||
testResourcesToSetup[i].src = srcPath
|
||||
} else if testResource.resType == resourceTypeFolder {
|
||||
srcPath, found = findDir(testResource.src)
|
||||
if found == false {
|
||||
if !found {
|
||||
panic(fmt.Sprintf("Failed to find folder %s", testResource.src))
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user