Apply corrections identified by SonarQube (#8457)

This commit is contained in:
Michael Telatynski 2022-05-03 22:04:37 +01:00 committed by GitHub
parent 99cb83a9df
commit 964c60d086
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 211 additions and 232 deletions

View file

@ -20,6 +20,7 @@ import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Optional } from "matrix-events-sdk";
import { MatrixClientPeg } from '../MatrixClientPeg';
@ -159,7 +160,7 @@ export default class DMRoomMap {
return joinedRooms[0];
}
public getUserIdForRoomId(roomId: string) {
public getUserIdForRoomId(roomId: string): Optional<string> {
if (this.roomToUser == null) {
// we lazily populate roomToUser so you can use
// this class just to call getDMRoomsForUserId

View file

@ -261,7 +261,7 @@ async function deriveKeys(salt: Uint8Array, iterations: number, password: string
throw friendlyError('subtleCrypto.importKey failed for HMAC key: ' + e, cryptoFailMsg());
});
return await Promise.all([aesProm, hmacProm]);
return Promise.all([aesProm, hmacProm]);
}
const HEADER_LINE = '-----BEGIN MEGOLM SESSION DATA-----';

View file

@ -136,7 +136,8 @@ export const getCurrentPosition = async (): Promise<GeolocationPosition> => {
export type ClearWatchCallback = () => void;
export const watchPosition = (
onWatchPosition: PositionCallback,
onWatchPositionError: (error: GeolocationError) => void): ClearWatchCallback => {
onWatchPositionError: (error: GeolocationError) => void,
): ClearWatchCallback => {
try {
const onError = (error) => onWatchPositionError(mapGeolocationError(error));
const watchId = getGeolocation().watchPosition(onWatchPosition, onError, GeolocationOptions);

View file

@ -80,7 +80,9 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
};
const onResetLocationPublishError = () => {
liveBeaconIds.map(beaconId => OwnBeaconStore.instance.resetLocationPublishError(beaconId));
liveBeaconIds.forEach(beaconId => {
OwnBeaconStore.instance.resetLocationPublishError(beaconId);
});
};
return {

View file

@ -23,7 +23,7 @@ export async function getDrawable(url: string): Promise<CanvasImageSource> {
if ('createImageBitmap' in window) {
const response = await fetch(url);
const blob = await response.blob();
return await createImageBitmap(blob);
return createImageBitmap(blob);
} else {
return new Promise<HTMLImageElement>((resolve, reject) => {
const img = document.createElement("img");

View file

@ -34,8 +34,7 @@ import * as Avatar from "../../Avatar";
import EventTile from "../../components/views/rooms/EventTile";
import DateSeparator from "../../components/views/messages/DateSeparator";
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
import { ExportType } from "./exportUtils";
import { IExportOptions } from "./exportUtils";
import { ExportType, IExportOptions } from "./exportUtils";
import MatrixClientContext from "../../contexts/MatrixClientContext";
import getExportCSS from "./exportCSS";
import { textForEvent } from "../../TextForEvent";
@ -417,7 +416,7 @@ export default class HTMLExporter extends Exporter {
content += body;
prevEvent = event;
}
return await this.wrapHTML(content);
return this.wrapHTML(content);
}
public async export() {

View file

@ -84,8 +84,8 @@ export async function createThumbnail(
} catch (e) {
// Fallback support for other browsers (Safari and Firefox for now)
canvas = document.createElement("canvas");
(canvas as HTMLCanvasElement).width = targetWidth;
(canvas as HTMLCanvasElement).height = targetHeight;
canvas.width = targetWidth;
canvas.height = targetHeight;
context = canvas.getContext("2d");
}

View file

@ -32,6 +32,8 @@ import MatrixSchemePermalinkConstructor from "./MatrixSchemePermalinkConstructor
// to add to permalinks. The servers are appended as ?via=example.org
const MAX_SERVER_CANDIDATES = 3;
const ANY_REGEX = /.*/;
// Permalinks can have servers appended to them so that the user
// receiving them can have a fighting chance at joining the room.
// These servers are called "candidates" at this point because
@ -207,7 +209,7 @@ export class RoomPermalinkCreator {
private updateAllowedServers() {
const bannedHostsRegexps = [];
let allowedHostsRegexps = [new RegExp(".*")]; // default allow everyone
let allowedHostsRegexps = [ANY_REGEX]; // default allow everyone
if (this.room.currentState) {
const aclEvent = this.room.currentState.getStateEvents("m.room.server_acl", "");
if (aclEvent && aclEvent.getContent()) {

View file

@ -23,10 +23,9 @@ import { getE2EEWellKnown } from "./WellKnownUtils";
import dis from "../dispatcher/dispatcher";
import { getDisplayAliasForAliasSet } from "../Rooms";
import { _t } from "../languageHandler";
import { instanceForInstanceId, protocolNameForInstanceId } from "./DirectoryUtils";
import { instanceForInstanceId, protocolNameForInstanceId, ALL_ROOMS, Protocols } from "./DirectoryUtils";
import SdkConfig from "../SdkConfig";
import { GenericError } from "./error";
import { ALL_ROOMS, Protocols } from "./DirectoryUtils";
export function privateShouldBeEncrypted(): boolean {
const e2eeWellKnown = getE2EEWellKnown();

View file

@ -16,8 +16,7 @@ limitations under the License.
import React from "react";
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomType } from "matrix-js-sdk/src/@types/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { RoomType, EventType } from "matrix-js-sdk/src/@types/event";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
import { calculateRoomVia } from "./permalinks/Permalinks";
@ -38,7 +37,6 @@ import { shouldShowComponent } from "../customisations/helpers/UIComponents";
import { UIComponent } from "../settings/UIFeature";
import { OpenSpacePreferencesPayload, SpacePreferenceTab } from "../dispatcher/payloads/OpenSpacePreferencesPayload";
import { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload";
import dis from "../dispatcher/dispatcher";
import { OpenAddExistingToSpaceDialogPayload } from "../dispatcher/payloads/OpenAddExistingToSpaceDialogPayload";
export const shouldShowSpaceSettings = (space: Room) => {
@ -60,14 +58,14 @@ export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
});
export function showSpaceSettings(space: Room) {
dis.dispatch<OpenSpaceSettingsPayload>({
defaultDispatcher.dispatch<OpenSpaceSettingsPayload>({
action: Action.OpenSpaceSettings,
space,
});
}
export const showAddExistingRooms = (space: Room): void => {
dis.dispatch<OpenAddExistingToSpaceDialogPayload>({
defaultDispatcher.dispatch<OpenAddExistingToSpaceDialogPayload>({
action: Action.OpenAddToExistingSpaceDialog,
space,
});
@ -168,7 +166,7 @@ export const bulkSpaceBehaviour = async (
};
export const showSpacePreferences = (space: Room, initialTabId?: SpacePreferenceTab) => {
dis.dispatch<OpenSpacePreferencesPayload>({
defaultDispatcher.dispatch<OpenSpacePreferencesPayload>({
action: Action.OpenSpacePreferences,
space,
initialTabId,

View file

@ -24,7 +24,7 @@ import { logger } from "matrix-js-sdk/src/logger";
export async function copyPlaintext(text: string): Promise<boolean> {
try {
if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
if (navigator?.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
return true;
} else {