Skip to content

Commit 4e93233

Browse files
authored
Merge pull request #28236 from element-hq/t3chguy/sonar-happy
2 parents d638d5d + 51c308f commit 4e93233

18 files changed

Lines changed: 46 additions & 67 deletions

src/AddThreepid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export default class AddThreepid {
201201
// implemented it without, so this may just succeed and that's OK.
202202
return [true];
203203
} catch (err) {
204-
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
204+
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data?.flows) {
205205
// doesn't look like an interactive-auth failure
206206
throw err;
207207
}
@@ -300,7 +300,7 @@ export default class AddThreepid {
300300
// implemented it without, so this may just succeed and that's OK.
301301
return [true];
302302
} catch (err) {
303-
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) {
303+
if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data?.flows) {
304304
// doesn't look like an interactive-auth failure
305305
throw err;
306306
}

src/Avatar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function isValidHexColor(color: string): boolean {
6868
return (
6969
typeof color === "string" &&
7070
(color.length === 7 || color.length === 9) &&
71-
color.charAt(0) === "#" &&
71+
color.startsWith("#") &&
7272
!color
7373
.slice(1)
7474
.split("")

src/ContentMessages.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,7 @@ export default class ContentMessages {
396396
}
397397

398398
public getUploadLimit(): number | null {
399-
if (this.mediaConfig !== null && this.mediaConfig["m.upload.size"] !== undefined) {
400-
return this.mediaConfig["m.upload.size"];
401-
} else {
402-
return null;
403-
}
399+
return this.mediaConfig?.["m.upload.size"] ?? null;
404400
}
405401

406402
public async sendContentListToRoom(
@@ -578,7 +574,7 @@ export default class ContentMessages {
578574
logger.error(e);
579575
content.msgtype = MsgType.File;
580576
}
581-
} else if (file.type.indexOf("audio/") === 0) {
577+
} else if (file.type.startsWith("audio/")) {
582578
content.msgtype = MsgType.Audio;
583579
try {
584580
const audioInfo = await infoForAudioFile(file);
@@ -588,7 +584,7 @@ export default class ContentMessages {
588584
logger.error(e);
589585
content.msgtype = MsgType.File;
590586
}
591-
} else if (file.type.indexOf("video/") === 0) {
587+
} else if (file.type.startsWith("video/")) {
592588
content.msgtype = MsgType.Video;
593589
try {
594590
const videoInfo = await infoForVideoFile(matrixClient, roomId, file);
@@ -648,11 +644,7 @@ export default class ContentMessages {
648644
}
649645

650646
private isFileSizeAcceptable(file: File): boolean {
651-
if (
652-
this.mediaConfig !== null &&
653-
this.mediaConfig["m.upload.size"] !== undefined &&
654-
file.size > this.mediaConfig["m.upload.size"]
655-
) {
647+
if (this.mediaConfig?.["m.upload.size"] !== undefined && file.size > this.mediaConfig["m.upload.size"]) {
656648
return false;
657649
}
658650
return true;

src/IdentityAuthClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export default class IdentityAuthClient {
170170
// XXX: The spec is `token`, but we used `access_token` for a Sydent release.
171171
const { access_token: accessToken, token } =
172172
await this.identityClient.registerWithIdentityServer(hsOpenIdToken);
173-
const identityAccessToken = token ? token : accessToken;
173+
const identityAccessToken = token || accessToken;
174174
if (check) await this.checkToken(identityAccessToken);
175175
return identityAccessToken;
176176
}

src/Lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise<Matr
661661
logger.log("Pickle key not created");
662662
}
663663

664-
return doSetLoggedIn(Object.assign({}, credentials, { pickleKey }), true, true);
664+
return doSetLoggedIn({ ...credentials, pickleKey: pickleKey ?? undefined }, true, true);
665665
}
666666

667667
/**

src/NodeAnimator.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ interface IProps {
1818
// either a list of child nodes, or a single child.
1919
children: React.ReactNode;
2020

21-
// optional transition information for changing existing children
22-
transition?: object;
23-
2421
// a list of state objects to apply to each child node in turn
2522
startStyles: React.CSSProperties[];
2623

src/Notifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type of tile.
7171
*/
7272
const msgTypeHandlers: Record<string, (event: MatrixEvent) => string | null> = {
7373
[MsgType.KeyVerificationRequest]: (event: MatrixEvent) => {
74-
const name = (event.sender || {}).name;
74+
const name = event.sender?.name;
7575
return _t("notifier|m.key.verification.request", { name });
7676
},
7777
[M_LOCATION.name]: (event: MatrixEvent) => {
@@ -233,7 +233,7 @@ class NotifierClass extends TypedEventEmitter<keyof EmittedEvents, EmittedEvents
233233

234234
// Play notification sound here
235235
const sound = this.getSoundForRoom(room.roomId);
236-
logger.log(`Got sound ${(sound && sound.name) || "default"} for ${room.roomId}`);
236+
logger.log(`Got sound ${sound?.name || "default"} for ${room.roomId}`);
237237

238238
if (sound) {
239239
await this.backgroundAudio.play(sound.url);

src/PosthogAnalytics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ export class PosthogAnalytics {
296296
// until the next time account data is refreshed and this function is called (most likely on next
297297
// page load). This will happen pretty infrequently, so we can tolerate the possibility.
298298
analyticsID = analyticsIdGenerator();
299-
await client.setAccountData(
300-
PosthogAnalytics.ANALYTICS_EVENT_TYPE,
301-
Object.assign({ id: analyticsID }, accountData),
302-
);
299+
await client.setAccountData(PosthogAnalytics.ANALYTICS_EVENT_TYPE, {
300+
id: analyticsID,
301+
...accountData,
302+
});
303303
}
304304
if (this.posthog.get_distinct_id() === analyticsID) {
305305
// No point identifying again

src/RoomInvite.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ export interface IInviteResult {
3535
* @param {function} progressCallback optional callback, fired after each invite.
3636
* @returns {Promise} Promise
3737
*/
38-
export function inviteMultipleToRoom(
38+
export async function inviteMultipleToRoom(
3939
client: MatrixClient,
4040
roomId: string,
4141
addresses: string[],
4242
progressCallback?: () => void,
4343
): Promise<IInviteResult> {
4444
const inviter = new MultiInviter(client, roomId, progressCallback);
45-
return inviter.invite(addresses, undefined).then((states) => Promise.resolve({ states, inviter }));
45+
return { states: await inviter.invite(addresses), inviter };
4646
}
4747

4848
export function showStartChatInviteDialog(initialText = ""): void {
@@ -104,7 +104,7 @@ export function inviteUsersToRoom(
104104
logger.error(err.stack);
105105
Modal.createDialog(ErrorDialog, {
106106
title: _t("invite|failed_title"),
107-
description: err && err.message ? err.message : _t("invite|failed_generic"),
107+
description: err?.message ?? _t("invite|failed_generic"),
108108
});
109109
});
110110
}

src/SlashCommands.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ export const Commands = [
450450
const matches = args.match(/^(\S+)$/);
451451
if (matches) {
452452
let roomAlias = matches[1];
453-
if (roomAlias[0] !== "#") return reject(this.getUsage());
453+
if (!roomAlias.startsWith("#")) return reject(this.getUsage());
454454

455455
if (!roomAlias.includes(":")) {
456456
roomAlias += ":" + cli.getDomain();
@@ -994,7 +994,7 @@ Commands.forEach((cmd) => {
994994
export function parseCommandString(input: string): { cmd?: string; args?: string } {
995995
// trim any trailing whitespace, as it can confuse the parser for IRC-style commands
996996
input = input.trimEnd();
997-
if (input[0] !== "/") return {}; // not a command
997+
if (!input.startsWith("/")) return {}; // not a command
998998

999999
const bits = input.match(/^(\S+?)(?:[ \n]+((.|\n)*))?$/);
10001000
let cmd: string;

0 commit comments

Comments
 (0)