diff --git a/.golangci.yml b/.golangci.yml index 1499747b..a327370e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -102,7 +102,7 @@ linters-settings: #local-prefixes: github.com/org/project gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 13 + min-complexity: 25 maligned: # print struct with more effective memory layout or not, false by default suggest-new: true diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index 0d47c91e..7bea35e5 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -91,7 +91,6 @@ func GetAvatarURL( } // SetAvatarURL implements PUT /profile/{userID}/avatar_url -// nolint:gocyclo func SetAvatarURL( req *http.Request, accountDB accounts.Database, device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, @@ -209,7 +208,6 @@ func GetDisplayName( } // SetDisplayName implements PUT /profile/{userID}/displayname -// nolint:gocyclo func SetDisplayName( req *http.Request, accountDB accounts.Database, device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go index 57014bc3..088e412c 100644 --- a/clientapi/routing/state.go +++ b/clientapi/routing/state.go @@ -161,7 +161,6 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a // state to see if there is an event with that type and state key, if there // is then (by default) we return the content, otherwise a 404. // If eventFormat=true, sends the whole event else just the content. -// nolint:gocyclo func OnIncomingStateTypeRequest( ctx context.Context, device *userapi.Device, rsAPI api.RoomserverInternalAPI, roomID, evType, stateKey string, eventFormat bool, diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 8091298b..2a4a335a 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -52,7 +52,6 @@ var ( instancePeer = flag.String("peer", "", "an internet Yggdrasil peer to connect to") ) -// nolint:gocyclo func main() { flag.Parse() internal.SetupPprof() diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go index c036c0d8..9c286dfb 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go @@ -73,7 +73,6 @@ func (n *Node) DialerContext(ctx context.Context, network, address string) (net. return n.Dialer(network, address) } -// nolint:gocyclo func Setup(instanceName, storageDirectory string) (*Node, error) { n := &Node{ core: &yggdrasil.Core{}, diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/session.go b/cmd/dendrite-demo-yggdrasil/yggconn/session.go index 0cf524d9..7b56e736 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/session.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/session.go @@ -128,7 +128,6 @@ func (n *Node) Dial(network, address string) (net.Conn, error) { } // Implements http.Transport.DialContext -// nolint:gocyclo func (n *Node) DialContext(ctx context.Context, network, address string) (net.Conn, error) { s, ok1 := n.sessions.Load(address) session, ok2 := s.(*session) diff --git a/cmd/furl/main.go b/cmd/furl/main.go index bec04f0a..75e22338 100644 --- a/cmd/furl/main.go +++ b/cmd/furl/main.go @@ -20,7 +20,6 @@ var requestFrom = flag.String("from", "", "the server name that the request shou var requestKey = flag.String("key", "matrix_key.pem", "the private key to use when signing the request") var requestPost = flag.Bool("post", false, "send a POST request instead of GET (pipe input into stdin or type followed by Ctrl-D)") -// nolint:gocyclo func main() { flag.Parse() diff --git a/cmd/resolve-state/main.go b/cmd/resolve-state/main.go index 69c3489d..30331fbb 100644 --- a/cmd/resolve-state/main.go +++ b/cmd/resolve-state/main.go @@ -24,7 +24,6 @@ import ( var roomVersion = flag.String("roomversion", "5", "the room version to parse events as") -// nolint:gocyclo func main() { ctx := context.Background() cfg := setup.ParseFlags(true) diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 3afc8d5e..e9414033 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -29,7 +29,6 @@ import ( ) // MakeJoin implements the /make_join API -// nolint:gocyclo func MakeJoin( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, @@ -161,7 +160,6 @@ func MakeJoin( // SendJoin implements the /send_join API // The make-join send-join dance makes much more sense as a single // flow so the cyclomatic complexity is high: -// nolint:gocyclo func SendJoin( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index 1a854261..a5231004 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -25,7 +25,6 @@ import ( ) // MakeLeave implements the /make_leave API -// nolint:gocyclo func MakeLeave( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, @@ -118,7 +117,6 @@ func MakeLeave( } // SendLeave implements the /send_leave API -// nolint:gocyclo func SendLeave( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, diff --git a/federationapi/routing/publicrooms.go b/federationapi/routing/publicrooms.go index d923a236..ddd92c5c 100644 --- a/federationapi/routing/publicrooms.go +++ b/federationapi/routing/publicrooms.go @@ -111,7 +111,6 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO } // due to lots of switches -// nolint:gocyclo func fillInRooms(ctx context.Context, roomIDs []string, rsAPI roomserverAPI.RoomserverInternalAPI) ([]gomatrixserverlib.PublicRoom, error) { avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""} nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""} diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 02683aea..ea0b54b6 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -279,7 +279,6 @@ func (t *txnReq) haveEventIDs() map[string]bool { return result } -// nolint:gocyclo func (t *txnReq) processEDUs(ctx context.Context) { for _, e := range t.EDUs { switch e.Type { @@ -540,7 +539,6 @@ func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserv return gomatrixserverlib.Allowed(e, &authUsingState) } -// nolint:gocyclo func (t *txnReq) processEventWithMissingState(ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion) error { // Do this with a fresh context, so that we keep working even if the // original request times out. With any luck, by the time the remote @@ -832,7 +830,6 @@ retryAllowedState: // begin from. Returns an error only if we should terminate the transaction which initiated /get_missing_events // This function recursively calls txnReq.processEvent with the missing events, which will be processed before this function returns. // This means that we may recursively call this function, as we spider back up prev_events. -// nolint:gocyclo func (t *txnReq) getMissingEvents(ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion) (newEvents []*gomatrixserverlib.Event, err error) { logger := util.GetLogger(ctx).WithField("event_id", e.EventID()).WithField("room_id", e.RoomID()) needed := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{e}) @@ -935,7 +932,6 @@ func (t *txnReq) lookupMissingStateViaState(ctx context.Context, roomID, eventID return &state, nil } -// nolint:gocyclo func (t *txnReq) lookupMissingStateViaStateIDs(ctx context.Context, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion) ( *gomatrixserverlib.RespState, error) { util.GetLogger(ctx).Infof("lookupMissingStateViaStateIDs %s", eventID) diff --git a/federationsender/queue/destinationqueue.go b/federationsender/queue/destinationqueue.go index be63290c..33f77a42 100644 --- a/federationsender/queue/destinationqueue.go +++ b/federationsender/queue/destinationqueue.go @@ -173,7 +173,6 @@ func (oq *destinationQueue) wakeQueueIfNeeded() { // getPendingFromDatabase will look at the database and see if // there are any persisted events that haven't been sent to this // destination yet. If so, they will be queued up. -// nolint:gocyclo func (oq *destinationQueue) getPendingFromDatabase() { // Check to see if there's anything to do for this server // in the database. @@ -238,7 +237,6 @@ func (oq *destinationQueue) getPendingFromDatabase() { } // backgroundSend is the worker goroutine for sending events. -// nolint:gocyclo func (oq *destinationQueue) backgroundSend() { // Check if a worker is already running, and if it isn't, then // mark it as started. @@ -353,7 +351,6 @@ func (oq *destinationQueue) backgroundSend() { // nextTransaction creates a new transaction from the pending event // queue and sends it. Returns true if a transaction was sent or // false otherwise. -// nolint:gocyclo func (oq *destinationQueue) nextTransaction( pdus []*queuedPDU, edus []*queuedEDU, diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go index a6ef735c..2ebe2f64 100644 --- a/roomserver/api/wrapper.go +++ b/roomserver/api/wrapper.go @@ -172,7 +172,6 @@ func IsServerBannedFromRoom(ctx context.Context, rsAPI RoomserverInternalAPI, ro // PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the // published room directory. // due to lots of switches -// nolint:gocyclo func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI RoomserverInternalAPI) ([]gomatrixserverlib.PublicRoom, error) { avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""} nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""} diff --git a/roomserver/internal/helpers/helpers.go b/roomserver/internal/helpers/helpers.go index 036c717a..a829bffc 100644 --- a/roomserver/internal/helpers/helpers.go +++ b/roomserver/internal/helpers/helpers.go @@ -270,7 +270,6 @@ func CheckServerAllowedToSeeEvent( } // TODO: Remove this when we have tests to assert correctness of this function -// nolint:gocyclo func ScanEventTree( ctx context.Context, db storage.Database, info types.RoomInfo, front []string, visited map[string]bool, limit int, serverName gomatrixserverlib.ServerName, diff --git a/roomserver/internal/perform/perform_backfill.go b/roomserver/internal/perform/perform_backfill.go index eb47ac21..d9d720f2 100644 --- a/roomserver/internal/perform/perform_backfill.go +++ b/roomserver/internal/perform/perform_backfill.go @@ -381,7 +381,6 @@ func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatr // It returns a list of servers which can be queried for backfill requests. These servers // will be servers that are in the room already. The entries at the beginning are preferred servers // and will be tried first. An empty list will fail the request. -// nolint:gocyclo func (b *backfillRequester) ServersAtEvent(ctx context.Context, roomID, eventID string) []gomatrixserverlib.ServerName { // eventID will be a prev_event ID of a backwards extremity, meaning we will not have a database entry for it. Instead, use // its successor, so look it up. diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go index 93a52350..fa65ce9b 100644 --- a/roomserver/internal/perform/perform_invite.go +++ b/roomserver/internal/perform/perform_invite.go @@ -37,7 +37,6 @@ type Inviter struct { Inputer *input.Inputer } -// nolint:gocyclo func (r *Inviter) PerformInvite( ctx context.Context, req *api.PerformInviteRequest, diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go index 8eb6b648..453901fc 100644 --- a/roomserver/internal/perform/perform_join.go +++ b/roomserver/internal/perform/perform_join.go @@ -139,7 +139,6 @@ func (r *Joiner) performJoinRoomByAlias( } // TODO: Break this function up a bit -// nolint:gocyclo func (r *Joiner) performJoinRoomByID( ctx context.Context, req *api.PerformJoinRequest, diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 3aa51726..29dc7840 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -49,7 +49,6 @@ func (r *Queryer) QueryLatestEventsAndState( } // QueryStateAfterEvents implements api.RoomserverInternalAPI -// nolint:gocyclo func (r *Queryer) QueryStateAfterEvents( ctx context.Context, request *api.QueryStateAfterEventsRequest, @@ -372,7 +371,6 @@ func (r *Queryer) QueryServerAllowedToSeeEvent( } // QueryMissingEvents implements api.RoomserverInternalAPI -// nolint:gocyclo func (r *Queryer) QueryMissingEvents( ctx context.Context, request *api.QueryMissingEventsRequest, diff --git a/roomserver/state/state.go b/roomserver/state/state.go index 2c01ca03..0d9511ac 100644 --- a/roomserver/state/state.go +++ b/roomserver/state/state.go @@ -770,7 +770,6 @@ func (v *StateResolution) resolveConflictsV1( // Returns a list that combines the entries without conflicts with the result of state resolution for the entries with conflicts. // The returned list is sorted by state key tuple. // Returns an error if there was a problem talking to the database. -// nolint:gocyclo func (v *StateResolution) resolveConflictsV2( ctx context.Context, notConflicted, conflicted []types.StateEntry, diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index b4d9d562..24b48772 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -412,7 +412,6 @@ func (d *Database) GetLatestEventsForUpdate( return updater, err } -// nolint:gocyclo func (d *Database) StoreEvent( ctx context.Context, event *gomatrixserverlib.Event, txnAndSessionID *api.TransactionID, authEventNIDs []types.EventNID, isRejected bool, @@ -672,7 +671,6 @@ func extractRoomVersionFromCreateEvent(event *gomatrixserverlib.Event) ( // to cross-reference with other tables when loading. // // Returns the redaction event and the event ID of the redacted event if this call resulted in a redaction. -// nolint:gocyclo func (d *Database) handleRedactions( ctx context.Context, txn *sql.Tx, eventNID types.EventNID, event *gomatrixserverlib.Event, ) (*gomatrixserverlib.Event, string, error) { @@ -802,7 +800,6 @@ func (d *Database) loadEvent(ctx context.Context, eventID string) *types.Event { // GetStateEvent returns the current state event of a given type for a given room with a given state key // If no event could be found, returns nil // If there was an issue during the retrieval, returns an error -// nolint:gocyclo func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error) { roomInfo, err := d.RoomInfo(ctx, roomID) if err != nil { @@ -893,7 +890,6 @@ func (d *Database) GetRoomsByMembership(ctx context.Context, userID, membership // GetBulkStateContent returns all state events which match a given room ID and a given state key tuple. Both must be satisfied for a match. // If a tuple has the StateKey of '*' and allowWildcards=true then all state events with the EventType should be returned. -// nolint:gocyclo func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tuples []gomatrixserverlib.StateKeyTuple, allowWildcards bool) ([]tables.StrippedEvent, error) { eventTypes := make([]string, 0, len(tuples)) for _, tuple := range tuples { diff --git a/setup/base.go b/setup/base.go index 6522426c..e9aa2a45 100644 --- a/setup/base.go +++ b/setup/base.go @@ -316,7 +316,6 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli // SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on // ApiMux under /api/ and adds a prometheus handler under /metrics. -// nolint:gocyclo func (b *BaseDendrite) SetupAndServeHTTP( internalHTTPAddr, externalHTTPAddr config.HTTPAddress, certFile, keyFile *string, diff --git a/setup/mscs/msc2836/msc2836.go b/setup/mscs/msc2836/msc2836.go index 95473f97..f47a42d9 100644 --- a/setup/mscs/msc2836/msc2836.go +++ b/setup/mscs/msc2836/msc2836.go @@ -238,7 +238,6 @@ func federatedEventRelationship( } } -// nolint:gocyclo func (rc *reqCtx) process() (*gomatrixserverlib.MSC2836EventRelationshipsResponse, *util.JSONResponse) { var res gomatrixserverlib.MSC2836EventRelationshipsResponse var returnEvents []*gomatrixserverlib.HeaderedEvent diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go index a125fd78..6fdfeed6 100644 --- a/setup/mscs/msc2946/msc2946.go +++ b/setup/mscs/msc2946/msc2946.go @@ -217,7 +217,6 @@ func (w *walker) markSent(id string) { w.inMemoryBatchCache[w.callerID()] = m } -// nolint:gocyclo func (w *walker) walk() *gomatrixserverlib.MSC2946SpacesResponse { var res gomatrixserverlib.MSC2946SpacesResponse // Begin walking the graph starting with the room ID in the request in a queue of unvisited rooms diff --git a/syncapi/internal/keychange.go b/syncapi/internal/keychange.go index e980437e..0bbaf31e 100644 --- a/syncapi/internal/keychange.go +++ b/syncapi/internal/keychange.go @@ -46,7 +46,6 @@ func DeviceOTKCounts(ctx context.Context, keyAPI keyapi.KeyInternalAPI, userID, // DeviceListCatchup fills in the given response for the given user ID to bring it up-to-date with device lists. hasNew=true if the response // was filled in, else false if there are no new device list changes because there is nothing to catch up on. The response MUST // be already filled in with join/leave information. -// nolint:gocyclo func DeviceListCatchup( ctx context.Context, keyAPI keyapi.KeyInternalAPI, rsAPI roomserverAPI.RoomserverInternalAPI, userID string, res *types.Response, from, to types.LogPosition, @@ -137,7 +136,6 @@ func DeviceListCatchup( } // TrackChangedUsers calculates the values of device_lists.changed|left in the /sync response. -// nolint:gocyclo func TrackChangedUsers( ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI, userID string, newlyJoinedRooms, newlyLeftRooms []string, ) (changed, left []string, err error) { diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go index ba739148..2ef25e03 100644 --- a/syncapi/routing/messages.go +++ b/syncapi/routing/messages.go @@ -61,7 +61,6 @@ const defaultMessagesLimit = 10 // OnIncomingMessagesRequest implements the /messages endpoint from the // client-server API. // See: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages -// nolint:gocyclo func OnIncomingMessagesRequest( req *http.Request, db storage.Database, roomID string, device *userapi.Device, federation *gomatrixserverlib.FederationClient, @@ -306,7 +305,6 @@ func (r *messagesReq) retrieveEvents() ( return clientEvents, start, end, err } -// nolint:gocyclo func (r *messagesReq) filterHistoryVisible(events []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent { // TODO FIXME: We don't fully implement history visibility yet. To avoid leaking events which the // user shouldn't see, we check the recent events and remove any prior to the join event of the user diff --git a/syncapi/storage/postgres/syncserver.go b/syncapi/storage/postgres/syncserver.go index a69fda4f..6f4e7749 100644 --- a/syncapi/storage/postgres/syncserver.go +++ b/syncapi/storage/postgres/syncserver.go @@ -36,7 +36,6 @@ type SyncServerDatasource struct { } // NewDatabase creates a new sync server database -// nolint:gocyclo func NewDatabase(dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) { var d SyncServerDatasource var err error diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index ee2c176c..b8271877 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -661,7 +661,6 @@ func (d *Database) fetchMissingStateEvents( // exclusive of oldPos, inclusive of newPos, for the rooms in which // the user has new membership events. // A list of joined room IDs is also returned in case the caller needs it. -// nolint:gocyclo func (d *Database) GetStateDeltas( ctx context.Context, device *userapi.Device, r types.Range, userID string, @@ -773,7 +772,6 @@ func (d *Database) GetStateDeltas( // requests with full_state=true. // Fetches full state for all joined rooms and uses selectStateInRange to get // updates for other rooms. -// nolint:gocyclo func (d *Database) GetStateDeltasForFullStateSync( ctx context.Context, device *userapi.Device, r types.Range, userID string, diff --git a/syncapi/storage/sqlite3/filtering.go b/syncapi/storage/sqlite3/filtering.go index 050f3a26..11f3e647 100644 --- a/syncapi/storage/sqlite3/filtering.go +++ b/syncapi/storage/sqlite3/filtering.go @@ -23,7 +23,6 @@ const ( // fields might come from either a StateFilter or an EventFilter, // and it's easier just to have the caller extract the relevant // parts. -// nolint:gocyclo func prepareWithFilters( db *sql.DB, txn *sql.Tx, query string, params []interface{}, senders, notsenders, types, nottypes []string, excludeEventIDs []string, diff --git a/syncapi/storage/sqlite3/syncserver.go b/syncapi/storage/sqlite3/syncserver.go index b0e43b68..ae0647fc 100644 --- a/syncapi/storage/sqlite3/syncserver.go +++ b/syncapi/storage/sqlite3/syncserver.go @@ -52,7 +52,6 @@ func NewDatabase(dbProperties *config.DatabaseOptions) (*SyncServerDatasource, e return &d, nil } -// nolint:gocyclo func (d *SyncServerDatasource) prepare(dbProperties *config.DatabaseOptions) (err error) { if err = d.PartitionOffsetStatements.Prepare(d.db, d.writer, "syncapi"); err != nil { return err diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go index e11ac8dd..1486ad3c 100644 --- a/syncapi/streams/stream_pdu.go +++ b/syncapi/streams/stream_pdu.go @@ -137,7 +137,6 @@ func (p *PDUStreamProvider) CompleteSync( return to } -// nolint:gocyclo func (p *PDUStreamProvider) IncrementalSync( ctx context.Context, req *types.SyncRequest, @@ -254,7 +253,6 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse( return nil } -// nolint:gocyclo func (p *PDUStreamProvider) getJoinResponseForCompleteSync( ctx context.Context, roomID string,