Add gosimple linter
MODIFY
linter.json
linter.json
"misspell",
"unparam",
"errcheck",
- "vet"
+ "vet",
+ "gosimple"
]
}

MODIFY
src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go
src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go
@@ -67,10 +67,7 @@ func (d *Database) CreateDevice(
}
dev, err = d.devices.insertDevice(ctx, txn, deviceID, localpart, accessToken)
- if err != nil {
return err
- }
- return nil
})
return
}

MODIFY
src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go
src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go
@@ -45,9 +45,6 @@ func (p *SyncAPIProducer) SendData(userID string, roomID string, dataType string
m.Key = sarama.StringEncoder(userID)
m.Value = sarama.ByteEncoder(value)
- if _, _, err := p.Producer.SendMessage(&m); err != nil {
+ _, _, err = p.Producer.SendMessage(&m)
return err
}
-
- return nil
-}

MODIFY
src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go
src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go
@@ -57,9 +57,6 @@ func (p *UserUpdateProducer) SendUpdate(
}
m.Value = sarama.ByteEncoder(value)
- if _, _, err := p.Producer.SendMessage(&m); err != nil {
+ _, _, err = p.Producer.SendMessage(&m)
return err
}
-
- return nil
-}

MODIFY
src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go
src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go
@@ -116,11 +116,8 @@ func (s *serverKeyStatements) upsertServerKeys(
string(request.ServerName), string(request.KeyID), nameAndKeyID(request),
int64(keys.ValidUntilTS), keyJSON,
)
- if err != nil {
return err
}
- return nil
-}
func nameAndKeyID(request gomatrixserverlib.PublicKeyRequest) string {
return string(request.ServerName) + "\x1F" + string(request.KeyID)

MODIFY
src/github.com/matrix-org/dendrite/common/test/config.go
src/github.com/matrix-org/dendrite/common/test/config.go
@@ -135,19 +135,16 @@ func NewMatrixKey(matrixKeyPath string) (err error) {
err = keyOut.Close()
})()
- if err = pem.Encode(keyOut, &pem.Block{
+ err = pem.Encode(keyOut, &pem.Block{
Type: "MATRIX PRIVATE KEY",
Headers: map[string]string{
"Key-ID": "ed25519:" + base64.RawStdEncoding.EncodeToString(data[:3]),
},
Bytes: data[3:],
- }); err != nil {
+ })
return err
}
- return nil
-}
-
const certificateDuration = time.Hour * 24 * 365 * 10
// NewTLSKey generates a new RSA TLS key and certificate and writes it to a file.
@@ -191,12 +188,9 @@ func NewTLSKey(tlsKeyPath, tlsCertPath string) error {
return err
}
defer keyOut.Close() // nolint: errcheck
- if err = pem.Encode(keyOut, &pem.Block{
+ err = pem.Encode(keyOut, &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(priv),
- }); err != nil {
+ })
return err
}
-
- return nil
-}

MODIFY
src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go
src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go
@@ -347,9 +347,5 @@ func fillDisplayName(
// Use the m.room.third_party_invite event to fill the "displayname" and
// update the m.room.member event's content with it
content.ThirdPartyInvite.DisplayName = thirdPartyInviteContent.DisplayName
- if err := builder.SetContent(content); err != nil {
- return err
- }
-
- return nil
+ return builder.SetContent(content)
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go
src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go
@@ -55,7 +55,7 @@ func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path)
// check if the absolute absBasePath is a prefix of the absolute filePath
// if so, no directory escape has occurred and the filePath is valid
// Note: absBasePath is already absolute
- if strings.HasPrefix(filePath, string(absBasePath)) == false {
+ if !strings.HasPrefix(filePath, string(absBasePath)) {
return "", fmt.Errorf("Invalid filePath (not within absBasePath %v): %v", absBasePath, filePath)
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go
@@ -80,11 +80,7 @@ func SelectThumbnail(desired types.ThumbnailSize, thumbnails []*types.ThumbnailM
fitness := calcThumbnailFitness(types.ThumbnailSize(thumbnailSize), nil, desired)
if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter {
bestFit = fitness
- chosenThumbnailSize = &types.ThumbnailSize{
- Width: thumbnailSize.Width,
- Height: thumbnailSize.Height,
- ResizeMethod: thumbnailSize.ResizeMethod,
- }
+ chosenThumbnailSize = (*types.ThumbnailSize)(&thumbnailSize)
}
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go
@@ -156,7 +156,7 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize
logger.WithFields(log.Fields{
"ActualWidth": width,
"ActualHeight": height,
- "processTime": time.Now().Sub(start),
+ "processTime": time.Since(start),
}).Info("Generated thumbnail")
stat, err := os.Stat(string(dst))

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/writers/download.go
src/github.com/matrix-org/dendrite/mediaapi/writers/download.go
@@ -155,7 +155,7 @@ func (r *downloadRequest) jsonErrorResponse(w http.ResponseWriter, res util.JSON
// Validate validates the downloadRequest fields
func (r *downloadRequest) Validate() *util.JSONResponse {
- if mediaIDRegex.MatchString(string(r.MediaMetadata.MediaID)) == false {
+ if !mediaIDRegex.MatchString(string(r.MediaMetadata.MediaID)) {
return &util.JSONResponse{
Code: 404,
JSON: jsonerror.NotFound(fmt.Sprintf("mediaId must be a non-empty string using only characters in %v", mediaIDCharacters)),
@@ -337,7 +337,7 @@ func (r *downloadRequest) getThumbnailFile(
thumbnail, thumbnailSize = thumbnailer.SelectThumbnail(r.ThumbnailSize, thumbnails, thumbnailSizes)
// If dynamicThumbnails is true and we are not over-loaded then we would have generated what was requested above.
// So we don't try to generate a pre-generated thumbnail here.
- if thumbnailSize != nil && dynamicThumbnails == false {
+ if thumbnailSize != nil && !dynamicThumbnails {
r.Logger.WithFields(log.Fields{
"Width": thumbnailSize.Width,
"Height": thumbnailSize.Height,
@@ -525,7 +525,7 @@ func (r *downloadRequest) fetchRemoteFileAndStoreMetadata(
// If the file is a duplicate (has the same hash as an existing file) then
// there is valid metadata in the database for that file. As such we only
// remove the file if it is not a duplicate.
- if duplicate == false {
+ if !duplicate {
finalDir := filepath.Dir(string(finalPath))
fileutils.RemoveDir(types.Path(finalDir), r.Logger)
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go
src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go
@@ -226,7 +226,7 @@ func (r *uploadRequest) storeFileAndMetadata(tmpDir types.Path, absBasePath conf
// If the file is a duplicate (has the same hash as an existing file) then
// there is valid metadata in the database for that file. As such we only
// remove the file if it is not a duplicate.
- if duplicate == false {
+ if !duplicate {
fileutils.RemoveDir(types.Path(path.Dir(string(finalPath))), r.Logger)
}
return &util.JSONResponse{

MODIFY
src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go
src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go
@@ -102,10 +102,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *publicRoomReq) *util.JSO
request.Since = httpReq.FormValue("since")
return nil
} else if httpReq.Method == "POST" {
- if reqErr := httputil.UnmarshalJSONRequest(httpReq, request); reqErr != nil {
- return reqErr
- }
- return nil
+ return httputil.UnmarshalJSONRequest(httpReq, request)
}
return &util.JSONResponse{

MODIFY
src/github.com/matrix-org/dendrite/roomserver/alias/alias.go
src/github.com/matrix-org/dendrite/roomserver/alias/alias.go
@@ -217,11 +217,7 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
var inputRes api.InputRoomEventsResponse
// Send the request
- if err := r.InputAPI.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
- return err
- }
-
- return nil
+ return r.InputAPI.InputRoomEvents(ctx, &inputReq, &inputRes)
}
// SetupHTTP adds the RoomserverAliasAPI handlers to the http.ServeMux.

MODIFY
src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go
src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go
@@ -102,8 +102,7 @@ type latestEventsUpdater struct {
}
func (u *latestEventsUpdater) doUpdateLatestEvents() error {
- var prevEvents []gomatrixserverlib.EventReference
- prevEvents = u.event.PrevEvents()
+ prevEvents := u.event.PrevEvents()
oldLatest := u.updater.LatestEvents()
u.lastEventIDSent = u.updater.LastEventIDSent()
u.oldStateNID = u.updater.CurrentStateSnapshotNID()
@@ -194,11 +193,8 @@ func (u *latestEventsUpdater) latestState() error {
u.stateBeforeEventRemoves, u.stateBeforeEventAdds, err = state.DifferenceBetweeenStateSnapshots(
u.ctx, u.db, u.newStateNID, u.stateAtEvent.BeforeStateSnapshotNID,
)
- if err != nil {
return err
}
- return nil
-}
func calculateLatest(
oldLatest []types.StateAtEventAndReference,
@@ -211,7 +207,7 @@ func calculateLatest(
for _, l := range oldLatest {
keep := true
for _, prevEvent := range prevEvents {
- if l.EventID == prevEvent.EventID && bytes.Compare(l.EventSHA256, prevEvent.EventSHA256) == 0 {
+ if l.EventID == prevEvent.EventID && bytes.Equal(l.EventSHA256, prevEvent.EventSHA256) {
// This event can be removed from the latest events cause we've found an event that references it.
// (If an event is referenced by another event then it can't be one of the latest events in the room
// because we have an event that comes after it)

MODIFY
src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go
src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go
@@ -461,9 +461,7 @@ func (d *SyncServerDatabase) fetchMissingStateEvents(
if len(stateEvents) != len(missing) {
return nil, fmt.Errorf("failed to map all event IDs to events: (got %d, wanted %d)", len(stateEvents), len(missing))
}
- for _, e := range stateEvents {
- events = append(events, e)
- }
+ events = append(events, stateEvents...)
return events, nil
}

Add gosimple linter (#242)