Skip to content

Commit

Permalink
Another SonarQube happiness pass (#2347)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored May 5, 2022
1 parent a388fde commit dea3f52
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 30 deletions.
18 changes: 8 additions & 10 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* Get the current dehydrated device, if any
* @return {Promise} A promise of an object containing the dehydrated device
*/
public getDehydratedDevice(): Promise<IDehydratedDevice> {
public async getDehydratedDevice(): Promise<IDehydratedDevice> {
try {
return this.http.authedRequest<IDehydratedDevice>(
return await this.http.authedRequest<IDehydratedDevice>(
undefined,
Method.Get,
"/dehydrated_device",
Expand Down Expand Up @@ -3365,7 +3365,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* data event.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
public async getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
if (this.isInitialSyncComplete()) {
const event = this.store.getAccountData(eventType);
if (!event) {
Expand All @@ -3380,11 +3380,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
$type: eventType,
});
try {
return this.http.authedRequest(
undefined, Method.Get, path, undefined,
);
return await this.http.authedRequest(undefined, Method.Get, path);
} catch (e) {
if (e.data && e.data.errcode === 'M_NOT_FOUND') {
if (e.data?.errcode === 'M_NOT_FOUND') {
return null;
}
throw e;
Expand Down Expand Up @@ -4851,7 +4849,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}
}

const populationResults: Record<string, Error> = {}; // {roomId: Error}
const populationResults: { [roomId: string]: Error } = {};
const promises = [];

const doLeave = (roomId: string) => {
Expand Down Expand Up @@ -5875,7 +5873,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*/
public setRoomMutePushRule(scope: string, roomId: string, mute: boolean): Promise<void> | void {
let promise: Promise<void>;
let hasDontNotifyRule;
let hasDontNotifyRule = false;

// Get the existing room-kind push rule if any
const roomPushRule = this.getRoomPushRule(scope, roomId);
Expand Down Expand Up @@ -5928,7 +5926,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
});
}).catch((err: Error) => {
// Update it even if the previous operation fails. This can help the
// app to recover when push settings has been modifed from another client
// app to recover when push settings has been modified from another client
this.getPushRules().then((result) => {
this.pushRules = result;
reject(err);
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/DeviceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand
'readonly', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
this.cryptoStore.getEndToEndDeviceData(txn, (deviceData) => {
this.hasFetched = Boolean(deviceData && deviceData.devices);
this.devices = deviceData ? deviceData.devices : {},
this.devices = deviceData ? deviceData.devices : {};
this.crossSigningInfo = deviceData ?
deviceData.crossSigningInfo || {} : {};
this.deviceTrackingStatus = deviceData ?
Expand Down Expand Up @@ -190,7 +190,7 @@ export class DeviceList extends TypedEventEmitter<EmittedEvents, CryptoEventHand

let savePromise = this.savePromise;
if (savePromise === null) {
savePromise = new Promise((resolve, reject) => {
savePromise = new Promise((resolve) => {
this.resolveSavePromise = resolve;
});
this.savePromise = savePromise;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/verification/SAS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ export class SAS extends Base<SasEvent, EventHandlerMap> {
do {
try {
if (this.initiatedByMe) {
return this.doSendVerification();
return await this.doSendVerification();
} else {
return this.doRespondVerification();
return await this.doRespondVerification();
}
} catch (err) {
if (err instanceof SwitchStartEventError) {
Expand Down
2 changes: 1 addition & 1 deletion src/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface ICryptoCallbacks {
export function createClient(opts: ICreateClientOpts | string) {
if (typeof opts === "string") {
opts = {
"baseUrl": opts as string,
"baseUrl": opts,
};
}
opts.request = opts.request || requestInstance;
Expand Down
1 change: 0 additions & 1 deletion src/models/event-timeline-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { EventType, RelationType } from "../@types/event";
import { RoomState } from "./room-state";
import { TypedEventEmitter } from "./typed-event-emitter";

// var DEBUG = false;
const DEBUG = true;

let debuglog: (...args: any[]) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/models/room-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import { MatrixEvent, MatrixEventEvent } from "./event";
import { MatrixClient } from "../client";
import { GuestAccess, HistoryVisibility, IJoinRuleEventContent, JoinRule } from "../@types/partials";
import { TypedEventEmitter } from "./typed-event-emitter";
import { Beacon, BeaconEvent, BeaconEventHandlerMap } from "./beacon";
import { Beacon, BeaconEvent, BeaconEventHandlerMap, getBeaconInfoIdentifier, BeaconIdentifier } from "./beacon";
import { TypedReEmitter } from "../ReEmitter";
import { M_BEACON, M_BEACON_INFO } from "../@types/beacon";
import { getBeaconInfoIdentifier, BeaconIdentifier } from "./beacon";

// possible statuses for out-of-band member loading
enum OobStatus {
Expand Down
20 changes: 10 additions & 10 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,14 +1124,14 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
* The aliases returned by this function may not necessarily
* still point to this room.
* @return {array} The room's alias as an array of strings
* @deprecated this uses m.room.aliases events, replaced by Room::getAltAliases()
*/
public getAliases(): string[] {
const aliasStrings: string[] = [];

const aliasEvents = this.currentState.getStateEvents(EventType.RoomAliases);
if (aliasEvents) {
for (let i = 0; i < aliasEvents.length; ++i) {
const aliasEvent = aliasEvents[i];
for (const aliasEvent of aliasEvents) {
if (Array.isArray(aliasEvent.getContent().aliases)) {
const filteredAliases = aliasEvent.getContent<{ aliases: string[] }>().aliases.filter(a => {
if (typeof(a) !== "string") return false;
Expand All @@ -1141,7 +1141,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
// It's probably valid by here.
return true;
});
Array.prototype.push.apply(aliasStrings, filteredAliases);
aliasStrings.push(...filteredAliases);
}
}
}
Expand Down Expand Up @@ -1644,8 +1644,8 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
eventsByThread[threadId]?.push(event);
}

Object.entries(eventsByThread).map(([threadId, events]) => (
this.addThreadedEvents(threadId, events, toStartOfTimeline)
Object.entries(eventsByThread).map(([threadId, threadEvents]) => (
this.addThreadedEvents(threadId, threadEvents, toStartOfTimeline)
));
}

Expand Down Expand Up @@ -2143,23 +2143,23 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
const threadRoots = this.findThreadRoots(events);
const eventsByThread: { [threadId: string]: MatrixEvent[] } = {};

for (let i = 0; i < events.length; i++) {
for (const event of events) {
// TODO: We should have a filter to say "only add state event types X Y Z to the timeline".
this.processLiveEvent(events[i]);
this.processLiveEvent(event);

const {
shouldLiveInRoom,
shouldLiveInThread,
threadId,
} = this.eventShouldLiveIn(events[i], events, threadRoots);
} = this.eventShouldLiveIn(event, events, threadRoots);

if (shouldLiveInThread && !eventsByThread[threadId]) {
eventsByThread[threadId] = [];
}
eventsByThread[threadId]?.push(events[i]);
eventsByThread[threadId]?.push(event);

if (shouldLiveInRoom) {
this.addLiveEvent(events[i], duplicateStrategy, fromCache);
this.addLiveEvent(event, duplicateStrategy, fromCache);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ISavedSync {
export interface IStore {
readonly accountData: Record<string, MatrixEvent>; // type : content

/** @return {Promise<bool>} whether or not the database was newly created in this session. */
/** @return {Promise<boolean>} whether or not the database was newly created in this session. */
isNewlyCreated(): Promise<boolean>;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/store/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class StubStore implements IStore {
/**
* No-op.
* @param {Room} room
* @param {integer} limit
* @param {number} limit
* @return {Array}
*/
public scrollback(room: Room, limit: number): MatrixEvent[] {
Expand Down

0 comments on commit dea3f52

Please sign in to comment.