Skip to content

Commit 3747464

Browse files
authored
Make SonarCloud happier (matrix-org#9545)
* Make SonarCloud happier * i18n * Iterate * Update AddExistingToSpaceDialog.tsx * Update SlashCommands.tsx
1 parent 77764d8 commit 3747464

33 files changed

+131
-162
lines changed

src/HtmlUtils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function formatEmojis(message: string, isHtmlMessage: boolean): (JSX.Element | s
460460
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOptsReturnString): string;
461461
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOptsReturnNode): ReactNode;
462462
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOpts = {}) {
463-
const isFormattedBody = content.format === "org.matrix.custom.html" && content.formatted_body;
463+
const isFormattedBody = content.format === "org.matrix.custom.html" && !!content.formatted_body;
464464
let bodyHasEmoji = false;
465465
let isHtmlMessage = false;
466466

@@ -511,7 +511,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
511511
decodeEntities: false,
512512
});
513513
const isPlainText = phtml.html() === phtml.root().text();
514-
isHtmlMessage = isFormattedBody && !isPlainText;
514+
isHtmlMessage = !isPlainText;
515515

516516
if (isHtmlMessage && SettingsStore.getValue("feature_latex_maths")) {
517517
// @ts-ignore - The types for `replaceWith` wrongly expect

src/Login.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ export default class Login {
7575
* @returns {MatrixClient}
7676
*/
7777
public createTemporaryClient(): MatrixClient {
78-
if (this.tempClient) return this.tempClient; // use memoization
79-
return this.tempClient = createClient({
80-
baseUrl: this.hsUrl,
81-
idBaseUrl: this.isUrl,
82-
});
78+
if (!this.tempClient) {
79+
this.tempClient = createClient({
80+
baseUrl: this.hsUrl,
81+
idBaseUrl: this.isUrl,
82+
});
83+
}
84+
return this.tempClient;
8385
}
8486

8587
public async getFlows(): Promise<Array<LoginFlow>> {

src/NodeAnimator.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export default class NodeAnimator extends React.Component<IProps> {
7979

8080
if (oldNode && (oldNode as HTMLElement).style.left !== c.props.style.left) {
8181
this.applyStyles(oldNode as HTMLElement, { left: c.props.style.left });
82-
// console.log("translation: "+oldNode.style.left+" -> "+c.props.style.left);
8382
}
8483
// clone the old element with the props (and children) of the new element
8584
// so prop updates are still received by the children.
@@ -94,7 +93,6 @@ export default class NodeAnimator extends React.Component<IProps> {
9493
if (startStyles.length > 0) {
9594
const startStyle = startStyles[0];
9695
newProps.style = startStyle;
97-
// console.log("mounted@startstyle0: "+JSON.stringify(startStyle));
9896
}
9997

10098
newProps.ref = ((n) => this.collectNode(
@@ -118,18 +116,12 @@ export default class NodeAnimator extends React.Component<IProps> {
118116
// to start with, so now we animate 1 etc.
119117
for (let i = 1; i < startStyles.length; ++i) {
120118
this.applyStyles(domNode as HTMLElement, startStyles[i]);
121-
// console.log("start:"
122-
// JSON.stringify(startStyles[i]),
123-
// );
124119
}
125120

126121
// and then we animate to the resting state
127122
setTimeout(() => {
128123
this.applyStyles(domNode as HTMLElement, restingStyle);
129124
}, 0);
130-
131-
// console.log("enter:",
132-
// JSON.stringify(restingStyle));
133125
}
134126
this.nodes[k] = node;
135127
}

src/Notifier.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ import ErrorDialog from "./components/views/dialogs/ErrorDialog";
4747
import LegacyCallHandler from "./LegacyCallHandler";
4848
import VoipUserMapper from "./VoipUserMapper";
4949
import { SdkContextClass } from "./contexts/SDKContext";
50-
import { localNotificationsAreSilenced } from "./utils/notifications";
50+
import { localNotificationsAreSilenced, createLocalNotificationSettingsIfNeeded } from "./utils/notifications";
5151
import { getIncomingCallToastKey, IncomingCallToast } from "./toasts/IncomingCallToast";
5252
import ToastStore from "./stores/ToastStore";
5353
import { ElementCall } from "./models/Call";
54-
import { createLocalNotificationSettingsIfNeeded } from './utils/notifications';
5554

5655
/*
5756
* Dispatches:

src/Searching.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,10 @@ interface IEncryptedSeshatEvent {
497497
}
498498

499499
function restoreEncryptionInfo(searchResultSlice: SearchResult[] = []): void {
500-
for (let i = 0; i < searchResultSlice.length; i++) {
501-
const timeline = searchResultSlice[i].context.getTimeline();
500+
for (const result of searchResultSlice) {
501+
const timeline = result.context.getTimeline();
502502

503-
for (let j = 0; j < timeline.length; j++) {
504-
const mxEv = timeline[j];
503+
for (const mxEv of timeline) {
505504
const ev = mxEv.event as IEncryptedSeshatEvent;
506505

507506
if (ev.curve25519Key) {

src/SlashCommands.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ export const Commands = [
716716
runFn: function(roomId, args) {
717717
const cli = MatrixClientPeg.get();
718718

719-
let targetRoomId: string;
719+
let targetRoomId: string | undefined;
720720
if (args) {
721721
const matches = args.match(/^(\S+)$/);
722722
if (matches) {
@@ -729,15 +729,9 @@ export const Commands = [
729729

730730
// Try to find a room with this alias
731731
const rooms = cli.getRooms();
732-
for (let i = 0; i < rooms.length; i++) {
733-
if (rooms[i].getCanonicalAlias() === roomAlias ||
734-
rooms[i].getAltAliases().includes(roomAlias)
735-
) {
736-
targetRoomId = rooms[i].roomId;
737-
break;
738-
}
739-
if (targetRoomId) break;
740-
}
732+
targetRoomId = rooms.find(room => {
733+
return room.getCanonicalAlias() === roomAlias || room.getAltAliases().includes(roomAlias);
734+
})?.roomId;
741735
if (!targetRoomId) {
742736
return reject(
743737
newTranslatableError(

src/WhoIsTyping.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export function usersTyping(room: Room, exclude: string[] = []): RoomMember[] {
3939
const whoIsTyping = [];
4040

4141
const memberKeys = Object.keys(room.currentState.members);
42-
for (let i = 0; i < memberKeys.length; ++i) {
43-
const userId = memberKeys[i];
44-
42+
for (const userId of memberKeys) {
4543
if (room.currentState.members[userId].typing) {
4644
if (exclude.indexOf(userId) === -1) {
4745
whoIsTyping.push(room.currentState.members[userId]);

src/components/structures/ContextMenu.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,11 @@ export const alwaysAboveLeftOf = (
524524
const menuOptions: IPosition & { chevronFace: ChevronFace } = { chevronFace };
525525

526526
const buttonRight = elementRect.right + window.scrollX;
527-
const buttonBottom = elementRect.bottom + window.scrollY;
528527
const buttonTop = elementRect.top + window.scrollY;
529528
// Align the right edge of the menu to the right edge of the button
530529
menuOptions.right = UIStore.instance.windowWidth - buttonRight;
531-
// Align the menu vertically on whichever side of the button has more space available.
532-
if (buttonBottom < UIStore.instance.windowHeight / 2) {
533-
menuOptions.top = buttonBottom + vPadding;
534-
} else {
535-
menuOptions.bottom = (UIStore.instance.windowHeight - buttonTop) + vPadding;
536-
}
530+
// Align the menu vertically above the menu
531+
menuOptions.bottom = (UIStore.instance.windowHeight - buttonTop) + vPadding;
537532

538533
return menuOptions;
539534
};

src/components/structures/MatrixChat.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
546546
}
547547

548548
private onAction = (payload: ActionPayload): void => {
549-
// console.log(`MatrixClientPeg.onAction: ${payload.action}`);
550-
551549
// Start the onboarding process for certain actions
552550
if (MatrixClientPeg.get()?.isGuest() && ONBOARDING_FLOW_STARTERS.includes(payload.action)) {
553551
// This will cause `payload` to be dispatched later, once a

src/components/structures/RightPanel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ export default class RightPanel extends React.Component<IProps, IState> {
101101
if (!this.props.room || member.roomId !== this.props.room.roomId) {
102102
return;
103103
}
104+
104105
// redraw the badge on the membership list
105-
if (this.state.phase === RightPanelPhases.RoomMemberList && member.roomId === this.props.room.roomId) {
106+
if (this.state.phase === RightPanelPhases.RoomMemberList) {
106107
this.delayedUpdate();
107108
} else if (
108-
this.state.phase === RightPanelPhases.RoomMemberInfo && member.roomId === this.props.room.roomId &&
109+
this.state.phase === RightPanelPhases.RoomMemberInfo &&
109110
member.userId === this.state.cardState.member.userId
110111
) {
111112
// refresh the member info (e.g. new power level)

0 commit comments

Comments
 (0)