Enable @typescript-eslint/explicit-function-return-type in /src (#9788)

* Enable `@typescript-eslint/explicit-member-accessibility` on /src

* Prettier

* Enable `@typescript-eslint/explicit-function-return-type` in /src

* Fix types

* tsc strict fixes

* Delint

* Fix test

* Fix bad merge
This commit is contained in:
Michael Telatynski 2023-01-12 13:25:14 +00:00 committed by GitHub
parent 7a36ba0fde
commit 030b7e90bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
683 changed files with 3459 additions and 3013 deletions

View file

@ -174,7 +174,7 @@ export default class SettingsStore {
const watcherId = `${new Date().getTime()}_${SettingsStore.watcherCount++}_${settingName}_${roomId}`;
const localizedCallback = (changedInRoomId: string | null, atLevel: SettingLevel, newValAtLevel: any) => {
const localizedCallback = (changedInRoomId: string | null, atLevel: SettingLevel, newValAtLevel: any): void => {
if (!SettingsStore.doesSettingSupportLevel(originalSettingName, atLevel)) {
logger.warn(
`Setting handler notified for an update of an invalid setting level: ` +
@ -200,7 +200,7 @@ export default class SettingsStore {
* @param {string} watcherReference The watcher reference (received from #watchSetting)
* to cancel.
*/
public static unwatchSetting(watcherReference: string) {
public static unwatchSetting(watcherReference: string): void {
if (!SettingsStore.watchers.has(watcherReference)) {
logger.warn(`Ending non-existent watcher ID ${watcherReference}`);
return;
@ -218,12 +218,12 @@ export default class SettingsStore {
* @param {string} settingName The setting name to monitor.
* @param {String} roomId The room ID to monitor for changes in. Use null for all rooms.
*/
public static monitorSetting(settingName: string, roomId: string | null) {
public static monitorSetting(settingName: string, roomId: string | null): void {
roomId = roomId || null; // the thing wants null specifically to work, so appease it.
if (!this.monitors.has(settingName)) this.monitors.set(settingName, new Map());
const registerWatcher = () => {
const registerWatcher = (): void => {
this.monitors.get(settingName).set(
roomId,
SettingsStore.watchSetting(
@ -266,7 +266,7 @@ export default class SettingsStore {
* The level to get the display name for; Defaults to 'default'.
* @return {String} The display name for the setting, or null if not found.
*/
public static getDisplayName(settingName: string, atLevel = SettingLevel.DEFAULT) {
public static getDisplayName(settingName: string, atLevel = SettingLevel.DEFAULT): string {
if (!SETTINGS[settingName] || !SETTINGS[settingName].displayName) return null;
let displayName = SETTINGS[settingName].displayName;
@ -295,7 +295,7 @@ export default class SettingsStore {
* @param {string} settingName The setting to look up.
* @return {boolean} True if the setting is a feature.
*/
public static isFeature(settingName: string) {
public static isFeature(settingName: string): boolean {
if (!SETTINGS[settingName]) return false;
return SETTINGS[settingName].isFeature;
}
@ -634,7 +634,7 @@ export default class SettingsStore {
* @param {string} realSettingName The setting name to try and read.
* @param {string} roomId Optional room ID to test the setting in.
*/
public static debugSetting(realSettingName: string, roomId: string) {
public static debugSetting(realSettingName: string, roomId: string): void {
logger.log(`--- DEBUG ${realSettingName}`);
// Note: we intentionally use JSON.stringify here to avoid the console masking the
@ -646,7 +646,7 @@ export default class SettingsStore {
logger.log(`--- default level order: ${JSON.stringify(LEVEL_ORDER)}`);
logger.log(`--- registered handlers: ${JSON.stringify(Object.keys(LEVEL_HANDLERS))}`);
const doChecks = (settingName) => {
const doChecks = (settingName): void => {
for (const handlerName of Object.keys(LEVEL_HANDLERS)) {
const handler = LEVEL_HANDLERS[handlerName];

View file

@ -29,14 +29,14 @@ export class WatchManager {
private watchers = new Map<string, Map<string | symbol, CallbackFn[]>>(); // settingName -> roomId -> CallbackFn[]
// Proxy for handlers to delegate changes to this manager
public watchSetting(settingName: string, roomId: string | null, cb: CallbackFn) {
public watchSetting(settingName: string, roomId: string | null, cb: CallbackFn): void {
if (!this.watchers.has(settingName)) this.watchers.set(settingName, new Map());
if (!this.watchers.get(settingName).has(roomId)) this.watchers.get(settingName).set(roomId, []);
this.watchers.get(settingName).get(roomId).push(cb);
}
// Proxy for handlers to delegate changes to this manager
public unwatchSetting(cb: CallbackFn) {
public unwatchSetting(cb: CallbackFn): void {
this.watchers.forEach((map) => {
map.forEach((callbacks) => {
let idx;
@ -47,7 +47,12 @@ export class WatchManager {
});
}
public notifyUpdate(settingName: string, inRoomId: string | null, atLevel: SettingLevel, newValueAtLevel: any) {
public notifyUpdate(
settingName: string,
inRoomId: string | null,
atLevel: SettingLevel,
newValueAtLevel: any,
): void {
// Dev note: We could avoid raising changes for ultimately inconsequential changes, but
// we also don't have a reliable way to get the old value of a setting. Instead, we'll just
// let it fall through regardless and let the receiver dedupe if they want to.

View file

@ -25,7 +25,7 @@ export default class FontSizeController extends SettingController {
super();
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
// Dispatch font size change so that everything open responds to the change.
dis.dispatch<UpdateFontSizePayload>({
action: Action.UpdateFontSize,

View file

@ -64,7 +64,7 @@ export class NotificationsEnabledController extends SettingController {
return calculatedValue;
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
if (getNotifier().supportsDesktopNotifications()) {
getNotifier().setEnabled(newValue);
}

View file

@ -44,7 +44,7 @@ export class OrderedMultiController extends SettingController {
return null; // no override
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
for (const controller of this.controllers) {
controller.onChange(level, roomId, newValue);
}

View file

@ -26,7 +26,7 @@ export default class PushToMatrixClientController extends SettingController {
super();
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
// XXX does this work? This surely isn't necessarily the effective value,
// but it's what NotificationsEnabledController does...
this.setter.call(MatrixClientPeg.get(), this.inverse ? !newValue : newValue);

View file

@ -19,7 +19,7 @@ import PlatformPeg from "../../PlatformPeg";
import { SettingLevel } from "../SettingLevel";
export default class ReloadOnChangeController extends SettingController {
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
PlatformPeg.get().reload();
}
}

View file

@ -26,7 +26,7 @@ export default class SystemFontController extends SettingController {
super();
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
// Dispatch font size change so that everything open responds to the change.
dis.dispatch<UpdateSystemFontPayload>({
action: Action.UpdateSystemFont,

View file

@ -55,7 +55,7 @@ export default class ThreadBetaController extends SettingController {
return enable;
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
// Requires a reload as we change an option flag on the `js-sdk`
// And the entire sync history needs to be parsed again
PlatformPeg.get().reload();

View file

@ -26,7 +26,7 @@ export default class UseSystemFontController extends SettingController {
super();
}
public onChange(level: SettingLevel, roomId: string, newValue: any) {
public onChange(level: SettingLevel, roomId: string, newValue: any): void {
// Dispatch font size change so that everything open responds to the change.
dis.dispatch<UpdateSystemFontPayload>({
action: Action.UpdateSystemFont,

View file

@ -26,7 +26,7 @@ export default abstract class AbstractLocalStorageSettingsHandler extends Settin
private static objectCache = new Map<string, object>();
private static storageListenerBound = false;
private static onStorageEvent = (e: StorageEvent) => {
private static onStorageEvent = (e: StorageEvent): void => {
if (e.key === null) {
AbstractLocalStorageSettingsHandler.clear();
} else {
@ -36,7 +36,7 @@ export default abstract class AbstractLocalStorageSettingsHandler extends Settin
};
// Expose the clear event for Lifecycle to call, the storage listener only fires for changes from other tabs
public static clear() {
public static clear(): void {
AbstractLocalStorageSettingsHandler.itemCache.clear();
AbstractLocalStorageSettingsHandler.objectCache.clear();
}

View file

@ -45,12 +45,12 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
return SettingLevel.ACCOUNT;
}
public initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
public initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): void {
oldClient?.removeListener(ClientEvent.AccountData, this.onAccountData);
newClient.on(ClientEvent.AccountData, this.onAccountData);
}
private onAccountData = (event: MatrixEvent, prevEvent: MatrixEvent) => {
private onAccountData = (event: MatrixEvent, prevEvent: MatrixEvent): void => {
if (event.getType() === "org.matrix.preview_urls") {
let val = event.getContent()["disable"];
if (typeof val !== "boolean") {
@ -168,7 +168,7 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
// Attach a deferred *before* setting the account data to ensure we catch any requests
// which race between different lines.
const deferred = defer<void>();
const handler = (event: MatrixEvent) => {
const handler = (event: MatrixEvent): void => {
if (event.getType() !== eventType || event.getContent()[field] !== value) return;
this.client.off(ClientEvent.AccountData, handler);
deferred.resolve();
@ -229,7 +229,7 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
return objectClone(event.getContent()); // clone to prevent mutation
}
private notifyBreadcrumbsUpdate(event: MatrixEvent) {
private notifyBreadcrumbsUpdate(event: MatrixEvent): void {
let val = [];
if (event.getType() === BREADCRUMBS_LEGACY_EVENT_TYPE) {
// This seems fishy - try and get the event for the new rooms

View file

@ -43,7 +43,7 @@ export default class DefaultSettingsHandler extends SettingsHandler {
throw new Error("Cannot set values on the default level handler");
}
public canSetValue(settingName: string, roomId: string) {
public canSetValue(settingName: string, roomId: string): boolean {
return false;
}

View file

@ -99,11 +99,11 @@ export default class DeviceSettingsHandler extends AbstractLocalStorageSettingsH
return true; // It's their device, so they should be able to
}
public watchSetting(settingName: string, roomId: string, cb: CallbackFn) {
public watchSetting(settingName: string, roomId: string, cb: CallbackFn): void {
this.watchers.watchSetting(settingName, roomId, cb);
}
public unwatchSetting(cb: CallbackFn) {
public unwatchSetting(cb: CallbackFn): void {
this.watchers.unwatchSetting(cb);
}
@ -128,7 +128,7 @@ export default class DeviceSettingsHandler extends AbstractLocalStorageSettingsH
return this.getBoolean("mx_labs_feature_" + featureName);
}
private writeFeature(featureName: string, enabled: boolean | null) {
private writeFeature(featureName: string, enabled: boolean | null): void {
this.setBoolean("mx_labs_feature_" + featureName, enabled);
this.watchers.notifyUpdate(featureName, null, SettingLevel.DEVICE, enabled);
}

View file

@ -35,7 +35,7 @@ export default class PlatformSettingsHandler extends SettingsHandler {
defaultDispatcher.register(this.onAction);
}
private onAction = (payload: ActionPayload) => {
private onAction = (payload: ActionPayload): void => {
if (payload.action === Action.PlatformSet) {
this.store = {};
// Load setting values as they are async and `getValue` must be synchronous

View file

@ -36,7 +36,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
super();
}
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): void {
if (oldClient) {
oldClient.removeListener(RoomEvent.AccountData, this.onAccountData);
}
@ -44,7 +44,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
newClient.on(RoomEvent.AccountData, this.onAccountData);
}
private onAccountData = (event: MatrixEvent, room: Room, prevEvent: MatrixEvent) => {
private onAccountData = (event: MatrixEvent, room: Room, prevEvent: MatrixEvent): void => {
const roomId = room.roomId;
if (event.getType() === "org.matrix.room.preview_urls") {
@ -107,7 +107,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
await this.client.setRoomAccountData(roomId, eventType, content);
const deferred = defer<void>();
const handler = (event: MatrixEvent, room: Room) => {
const handler = (event: MatrixEvent, room: Room): void => {
if (room.roomId !== roomId || event.getType() !== eventType) return;
if (field !== null && event.getContent()[field] !== value) return;
this.client.off(RoomEvent.AccountData, handler);

View file

@ -35,7 +35,7 @@ export default class RoomSettingsHandler extends MatrixClientBackedSettingsHandl
super();
}
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): void {
if (oldClient) {
oldClient.removeListener(RoomStateEvent.Events, this.onEvent);
}
@ -43,7 +43,7 @@ export default class RoomSettingsHandler extends MatrixClientBackedSettingsHandl
newClient.on(RoomStateEvent.Events, this.onEvent);
}
private onEvent = (event: MatrixEvent, state: RoomState, prevEvent: MatrixEvent) => {
private onEvent = (event: MatrixEvent, state: RoomState, prevEvent: MatrixEvent): void => {
const roomId = event.getRoomId();
const room = this.client.getRoom(roomId);
@ -97,7 +97,7 @@ export default class RoomSettingsHandler extends MatrixClientBackedSettingsHandl
const { event_id: eventId } = await this.client.sendStateEvent(roomId, eventType, content);
const deferred = defer<void>();
const handler = (event: MatrixEvent) => {
const handler = (event: MatrixEvent): void => {
if (event.getId() !== eventId) return;
this.client.off(RoomStateEvent.Events, handler);
deferred.resolve();

View file

@ -36,16 +36,16 @@ export class FontWatcher implements IWatcher {
this.dispatcherRef = null;
}
public start() {
public start(): void {
this.updateFont();
this.dispatcherRef = dis.register(this.onAction);
}
public stop() {
public stop(): void {
dis.unregister(this.dispatcherRef);
}
private updateFont() {
private updateFont(): void {
this.setRootFontSize(SettingsStore.getValue("baseFontSize"));
this.setSystemFont({
useSystemFont: SettingsStore.getValue("useSystemFont"),
@ -53,7 +53,7 @@ export class FontWatcher implements IWatcher {
});
}
private onAction = (payload: ActionPayload) => {
private onAction = (payload: ActionPayload): void => {
if (payload.action === Action.UpdateFontSize) {
this.setRootFontSize(payload.size);
} else if (payload.action === Action.UpdateSystemFont) {
@ -71,7 +71,7 @@ export class FontWatcher implements IWatcher {
}
};
private setRootFontSize = (size: number) => {
private setRootFontSize = (size: number): void => {
const fontSize = Math.max(Math.min(FontWatcher.MAX_SIZE, size), FontWatcher.MIN_SIZE);
if (fontSize !== size) {
@ -80,7 +80,10 @@ export class FontWatcher implements IWatcher {
document.querySelector<HTMLElement>(":root").style.fontSize = toPx(fontSize);
};
private setSystemFont = ({ useSystemFont, font }: Pick<UpdateSystemFontPayload, "useSystemFont" | "font">) => {
private setSystemFont = ({
useSystemFont,
font,
}: Pick<UpdateSystemFontPayload, "useSystemFont" | "font">): void => {
if (useSystemFont) {
// Make sure that fonts with spaces in their names get interpreted properly
document.body.style.fontFamily = font

View file

@ -50,7 +50,7 @@ export default class ThemeWatcher {
this.currentTheme = this.getEffectiveTheme();
}
public start() {
public start(): void {
this.themeWatchRef = SettingsStore.watchSetting("theme", null, this.onChange);
this.systemThemeWatchRef = SettingsStore.watchSetting("use_system_theme", null, this.onChange);
if (this.preferDark.addEventListener) {
@ -61,7 +61,7 @@ export default class ThemeWatcher {
this.dispatcherRef = dis.register(this.onAction);
}
public stop() {
public stop(): void {
if (this.preferDark.addEventListener) {
this.preferDark.removeEventListener("change", this.onChange);
this.preferLight.removeEventListener("change", this.onChange);
@ -72,11 +72,11 @@ export default class ThemeWatcher {
dis.unregister(this.dispatcherRef);
}
private onChange = () => {
private onChange = (): void => {
this.recheck();
};
private onAction = (payload: ActionPayload) => {
private onAction = (payload: ActionPayload): void => {
if (payload.action === Action.RecheckTheme) {
// XXX forceTheme
this.recheck(payload.forceTheme);
@ -85,7 +85,7 @@ export default class ThemeWatcher {
// XXX: forceTheme param added here as local echo appears to be unreliable
// https://github.com/vector-im/element-web/issues/11443
public recheck(forceTheme?: string) {
public recheck(forceTheme?: string): void {
const oldTheme = this.currentTheme;
this.currentTheme = forceTheme === undefined ? this.getEffectiveTheme() : forceTheme;
if (oldTheme !== this.currentTheme) {
@ -144,7 +144,7 @@ export default class ThemeWatcher {
return SettingsStore.getValue("theme");
}
private themeBasedOnSystem() {
private themeBasedOnSystem(): string {
let newTheme: string;
if (this.preferDark.matches) {
newTheme = "dark";
@ -160,7 +160,7 @@ export default class ThemeWatcher {
return newTheme;
}
public isSystemThemeSupported() {
public isSystemThemeSupported(): boolean {
return this.preferDark.matches || this.preferLight.matches;
}
}