Add goconst linter
MODIFY
linter-fast.json
linter-fast.json
"gas",
"misspell",
"errcheck",
- "vet"
+ "vet",
+ "goconst"
]
}

MODIFY
linter.json
linter.json
"unparam",
"errcheck",
"vet",
- "megacheck"
+ "megacheck",
+ "goconst"
]
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go
src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go
@@ -63,22 +63,22 @@ func SelectThumbnail(desired types.ThumbnailSize, thumbnails []*types.ThumbnailM
bestFit := newThumbnailFitness()
for _, thumbnail := range thumbnails {
- if desired.ResizeMethod == "scale" && thumbnail.ThumbnailSize.ResizeMethod != "scale" {
+ if desired.ResizeMethod == types.Scale && thumbnail.ThumbnailSize.ResizeMethod != types.Scale {
continue
}
fitness := calcThumbnailFitness(thumbnail.ThumbnailSize, thumbnail.MediaMetadata, desired)
- if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter {
+ if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == types.Crop); isBetter {
bestFit = fitness
chosenThumbnail = thumbnail
}
}
for _, thumbnailSize := range thumbnailSizes {
- if desired.ResizeMethod == "scale" && thumbnailSize.ResizeMethod != "scale" {
+ if desired.ResizeMethod == types.Scale && thumbnailSize.ResizeMethod != types.Scale {
continue
}
fitness := calcThumbnailFitness(types.ThumbnailSize(thumbnailSize), nil, desired)
- if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter {
+ if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == types.Crop); isBetter {
bestFit = fitness
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
@@ -149,7 +149,7 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize
}
start := time.Now()
- width, height, err := adjustSize(dst, img, config.Width, config.Height, config.ResizeMethod == "crop", logger)
+ width, height, err := adjustSize(dst, img, config.Width, config.Height, config.ResizeMethod == types.Crop, logger)
if err != nil {
return false, err
}

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/types/types.go
src/github.com/matrix-org/dendrite/mediaapi/types/types.go
@@ -102,3 +102,9 @@ type ActiveThumbnailGeneration struct {
// The string key is a thumbnail file path
PathToResult map[string]*ThumbnailGenerationResult
}
+
+// Crop indicates we should crop the thumbnail on resize
+const Crop = "crop"
+
+// Scale indicates we should scale the thumbnail on resize
+const Scale = "scale"

MODIFY
src/github.com/matrix-org/dendrite/mediaapi/writers/download.go
src/github.com/matrix-org/dendrite/mediaapi/writers/download.go
@@ -179,9 +179,9 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
}
// Default method to scale if not set
if r.ThumbnailSize.ResizeMethod == "" {
- r.ThumbnailSize.ResizeMethod = "scale"
+ r.ThumbnailSize.ResizeMethod = types.Scale
}
- if r.ThumbnailSize.ResizeMethod != "crop" && r.ThumbnailSize.ResizeMethod != "scale" {
+ if r.ThumbnailSize.ResizeMethod != types.Crop && r.ThumbnailSize.ResizeMethod != types.Scale {
return &util.JSONResponse{
Code: 400,
JSON: jsonerror.Unknown("method must be one of crop or scale"),

MODIFY
src/github.com/matrix-org/dendrite/roomserver/input/membership.go
src/github.com/matrix-org/dendrite/roomserver/input/membership.go
@@ -23,6 +23,13 @@ import (
"github.com/matrix-org/gomatrixserverlib"
)
+// Membership values
+// TODO: Factor these out somewhere sensible?
+const join = "join"
+const leave = "leave"
+const invite = "invite"
+const ban = "ban"
+
// updateMembership updates the current membership and the invites for each
// user affected by a change in the current state of the room.
// Returns a list of output events to write to the kafka log to inform the
@@ -83,9 +90,9 @@ func updateMembership(
updates []api.OutputEvent,
) ([]api.OutputEvent, error) {
var err error
- // Default the membership to "leave" if no event was added or removed.
- old := "leave"
- new := "leave"
+ // Default the membership to Leave if no event was added or removed.
+ old := leave
+ new := leave
if remove != nil {
old, err = remove.Membership()
@@ -99,9 +106,9 @@ func updateMembership(
return nil, err
}
}
- if old == new && new != "join" {
+ if old == new && new != join {
// If the membership is the same then nothing changed and we can return
- // immediately, unless it's a "join" update (e.g. profile update).
+ // immediately, unless it's a Join update (e.g. profile update).
return updates, nil
}
@@ -111,11 +118,11 @@ func updateMembership(
}
switch new {
- case "invite":
+ case invite:
return updateToInviteMembership(mu, add, updates)
- case "join":
+ case join:
return updateToJoinMembership(mu, add, updates)
- case "leave", "ban":
+ case leave, ban:
return updateToLeaveMembership(mu, add, new, updates)
default:
panic(fmt.Errorf(
@@ -176,7 +183,7 @@ func updateToJoinMembership(
for _, eventID := range retired {
orie := api.OutputRetireInviteEvent{
EventID: eventID,
- Membership: "join",
+ Membership: join,
}
if add != nil {
orie.RetiredByEventID = add.EventID()

Add goconst linter (#246)