Fix golangci-lint issues (#1464)

* Fix S1039: unnecessary use of fmt.Sprintf

* Fix S1036: unnecessary guard around map access

Signed-off-by: Till Faelligen <tfaelligen@gmail.com>
main
S7evinK 2020-10-01 21:00:56 +02:00 committed by GitHub
parent 7048532bc4
commit 3e01db0049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 16 deletions

View File

@ -192,9 +192,7 @@ func SendJoin(
if event.StateKey() == nil || event.StateKeyEquals("") { if event.StateKey() == nil || event.StateKeyEquals("") {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON( JSON: jsonerror.BadJSON("No state key was provided in the join event."),
fmt.Sprintf("No state key was provided in the join event."),
),
} }
} }

View File

@ -717,11 +717,7 @@ func ResolveConflictsAdhoc(
// Append the events if there is already a conflicted list for // Append the events if there is already a conflicted list for
// this tuple key, create it if not. // this tuple key, create it if not.
tuple := stateKeyTuple{event.Type(), *event.StateKey()} tuple := stateKeyTuple{event.Type(), *event.StateKey()}
if _, ok := eventMap[tuple]; ok { eventMap[tuple] = append(eventMap[tuple], event)
eventMap[tuple] = append(eventMap[tuple], event)
} else {
eventMap[tuple] = []gomatrixserverlib.Event{event}
}
} }
// Split out the events in the map into conflicted and unconflicted // Split out the events in the map into conflicted and unconflicted

View File

@ -81,7 +81,7 @@ func SimpleRoom(t *testing.T, roomID, userA, userB string) (msgs []gomatrixserve
})) }))
state = append(state, events[len(events)-1]) state = append(state, events[len(events)-1])
events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{ events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"join"}`)), Content: []byte(`{"membership":"join"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &userA, StateKey: &userA,
Sender: userA, Sender: userA,
@ -97,7 +97,7 @@ func SimpleRoom(t *testing.T, roomID, userA, userB string) (msgs []gomatrixserve
})) }))
} }
events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{ events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"join"}`)), Content: []byte(`{"membership":"join"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &userB, StateKey: &userB,
Sender: userB, Sender: userB,
@ -348,7 +348,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
Depth: int64(len(events) + 1), Depth: int64(len(events) + 1),
})) }))
events = append(events, MustCreateEvent(t, testRoomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{ events = append(events, MustCreateEvent(t, testRoomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"join"}`)), Content: []byte(`{"membership":"join"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &testUserIDA, StateKey: &testUserIDA,
Sender: testUserIDA, Sender: testUserIDA,
@ -367,7 +367,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
} }
// merge the fork, prev_events are all 3 messages, depth is increased by 1. // merge the fork, prev_events are all 3 messages, depth is increased by 1.
events = append(events, MustCreateEvent(t, testRoomID, events[len(events)-3:], &gomatrixserverlib.EventBuilder{ events = append(events, MustCreateEvent(t, testRoomID, events[len(events)-3:], &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"body":"Message merge"}`)), Content: []byte(`{"body":"Message merge"}`),
Type: "m.room.message", Type: "m.room.message",
Sender: testUserIDA, Sender: testUserIDA,
Depth: depth + 1, Depth: depth + 1,
@ -438,7 +438,7 @@ func TestGetEventsInTopologicalRangeMultiRoom(t *testing.T) {
Depth: int64(len(events) + 1), Depth: int64(len(events) + 1),
})) }))
events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{ events = append(events, MustCreateEvent(t, roomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"join"}`)), Content: []byte(`{"membership":"join"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &testUserIDA, StateKey: &testUserIDA,
Sender: testUserIDA, Sender: testUserIDA,
@ -484,7 +484,7 @@ func TestGetEventsInRangeWithEventsInsertedLikeBackfill(t *testing.T) {
// "federation" join // "federation" join
userC := fmt.Sprintf("@radiance:%s", testOrigin) userC := fmt.Sprintf("@radiance:%s", testOrigin)
joinEvent := MustCreateEvent(t, testRoomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{ joinEvent := MustCreateEvent(t, testRoomID, []gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"join"}`)), Content: []byte(`{"membership":"join"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &userC, StateKey: &userC,
Sender: userC, Sender: userC,
@ -615,14 +615,14 @@ func TestInviteBehaviour(t *testing.T) {
db := MustCreateDatabase(t) db := MustCreateDatabase(t)
inviteRoom1 := "!inviteRoom1:somewhere" inviteRoom1 := "!inviteRoom1:somewhere"
inviteEvent1 := MustCreateEvent(t, inviteRoom1, nil, &gomatrixserverlib.EventBuilder{ inviteEvent1 := MustCreateEvent(t, inviteRoom1, nil, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"invite"}`)), Content: []byte(`{"membership":"invite"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &testUserIDA, StateKey: &testUserIDA,
Sender: "@inviteUser1:somewhere", Sender: "@inviteUser1:somewhere",
}) })
inviteRoom2 := "!inviteRoom2:somewhere" inviteRoom2 := "!inviteRoom2:somewhere"
inviteEvent2 := MustCreateEvent(t, inviteRoom2, nil, &gomatrixserverlib.EventBuilder{ inviteEvent2 := MustCreateEvent(t, inviteRoom2, nil, &gomatrixserverlib.EventBuilder{
Content: []byte(fmt.Sprintf(`{"membership":"invite"}`)), Content: []byte(`{"membership":"invite"}`),
Type: "m.room.member", Type: "m.room.member",
StateKey: &testUserIDA, StateKey: &testUserIDA,
Sender: "@inviteUser2:somewhere", Sender: "@inviteUser2:somewhere",