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

@ -18,10 +18,14 @@ import { useEffect } from "react";
const DEBOUNCE_TIMEOUT = 100;
export function useDebouncedCallback<T extends any[]>(enabled: boolean, callback: (...params: T) => void, params: T) {
export function useDebouncedCallback<T extends any[]>(
enabled: boolean,
callback: (...params: T) => void,
params: T,
): void {
useEffect(() => {
let handle: number | null = null;
const doSearch = () => {
const doSearch = (): void => {
handle = null;
callback(...params);
};

View file

@ -21,10 +21,10 @@ import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { useTypedEventEmitter } from "./useEventEmitter";
const tryGetContent = <T extends {}>(ev?: MatrixEvent) => (ev ? ev.getContent<T>() : undefined);
const tryGetContent = <T extends {}>(ev?: MatrixEvent): T => (ev ? ev.getContent<T>() : undefined);
// Hook to simplify listening to Matrix account data
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string) => {
export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: string): T => {
const [value, setValue] = useState<T>(() => tryGetContent<T>(cli.getAccountData(eventType)));
const handler = useCallback(
@ -40,7 +40,7 @@ export const useAccountData = <T extends {}>(cli: MatrixClient, eventType: strin
};
// Hook to simplify listening to Matrix room account data
export const useRoomAccountData = <T extends {}>(room: Room, eventType: string) => {
export const useRoomAccountData = <T extends {}>(room: Room, eventType: string): T => {
const [value, setValue] = useState<T>(() => tryGetContent<T>(room.getAccountData(eventType)));
const handler = useCallback(

View file

@ -19,13 +19,13 @@ import { useCallback, useEffect, useRef } from "react";
import SettingsStore from "../settings/SettingsStore";
const debuglog = (...args: any[]) => {
const debuglog = (...args: any[]): void => {
if (SettingsStore.getValue("debug_animation")) {
logger.log.call(console, "Animation debuglog:", ...args);
}
};
export function useAnimation(enabled: boolean, callback: (timestamp: DOMHighResTimeStamp) => boolean) {
export function useAnimation(enabled: boolean, callback: (timestamp: DOMHighResTimeStamp) => boolean): void {
const handle = useRef<number | null>(null);
const handler = useCallback(

View file

@ -25,7 +25,14 @@ interface State {
device: MediaDeviceInfo | null;
}
export const useAudioDeviceSelection = (onDeviceChanged?: (device: MediaDeviceInfo) => void) => {
export const useAudioDeviceSelection = (
onDeviceChanged?: (device: MediaDeviceInfo) => void,
): {
currentDevice: MediaDeviceInfo;
currentDeviceLabel: string;
devices: MediaDeviceInfo[];
setDevice(device: MediaDeviceInfo): void;
} => {
const shouldRequestPermissionsRef = useRef<boolean>(true);
const [state, setState] = useState<State>({
devices: [],
@ -52,7 +59,7 @@ export const useAudioDeviceSelection = (onDeviceChanged?: (device: MediaDeviceIn
});
}
const setDevice = (device: MediaDeviceInfo) => {
const setDevice = (device: MediaDeviceInfo): void => {
const shouldNotify = device.deviceId !== state.device?.deviceId;
MediaDeviceHandler.instance.setDevice(device.deviceId, MediaDeviceKindEnum.AudioInput);

View file

@ -20,7 +20,10 @@ import { Dispatcher } from "flux";
import { ActionPayload } from "../dispatcher/payloads";
// Hook to simplify listening to flux dispatches
export const useDispatcher = (dispatcher: Dispatcher<ActionPayload>, handler: (payload: ActionPayload) => void) => {
export const useDispatcher = (
dispatcher: Dispatcher<ActionPayload>,
handler: (payload: ActionPayload) => void,
): void => {
// Create a ref that stores handler
const savedHandler = useRef((payload: ActionPayload) => {});

View file

@ -47,7 +47,7 @@ export function useEventEmitter(emitter: EventEmitter | undefined, eventName: st
if (!emitter) return;
// Create event listener that calls handler function stored in ref
const eventListener = (...args) => savedHandler.current(...args);
const eventListener = (...args): void => savedHandler.current(...args);
// Add event listener
emitter.on(eventName, eventListener);

View file

@ -18,13 +18,16 @@ import { useState } from "react";
const favouriteMessageIds = JSON.parse(localStorage?.getItem("io_element_favouriteMessages") ?? "[]") as string[];
export default function useFavouriteMessages() {
export default function useFavouriteMessages(): {
toggleFavourite: (eventId: string) => void;
isFavourite: (eventId: string) => boolean;
} {
const [, setX] = useState<string[]>();
//checks if an id already exist
const isFavourite = (eventId: string): boolean => favouriteMessageIds.includes(eventId);
const toggleFavourite = (eventId: string) => {
const toggleFavourite = (eventId: string): void => {
isFavourite(eventId)
? favouriteMessageIds.splice(favouriteMessageIds.indexOf(eventId), 1)
: favouriteMessageIds.push(eventId);

View file

@ -22,7 +22,7 @@ export const useLocalEcho = <T>(
errorFn: (error: Error) => void,
): [value: T, handler: (value: T) => void] => {
const [value, setValue] = useState(currentFactory);
const handler = async (value: T) => {
const handler = async (value: T): Promise<void> => {
setValue(value);
try {
await setterFn(value);

View file

@ -29,7 +29,12 @@ export interface IProfileInfo {
display_name?: string;
}
export const useProfileInfo = () => {
export const useProfileInfo = (): {
ready: boolean;
loading: boolean;
profile: IProfileInfo | null;
search(opts: IProfileInfoOpts): Promise<boolean>;
} => {
const [profile, setProfile] = useState<IProfileInfo | null>(null);
const [loading, setLoading] = useState(false);

View file

@ -38,7 +38,15 @@ export interface IPublicRoomsOpts {
let thirdParty: Protocols;
export const usePublicRoomDirectory = () => {
export const usePublicRoomDirectory = (): {
ready: boolean;
loading: boolean;
publicRooms: IPublicRoomsChunkRoom[];
protocols: Protocols | null;
config?: IPublicRoomDirectoryConfig | null;
setConfig(config: IPublicRoomDirectoryConfig): void;
search(opts: IPublicRoomsOpts): Promise<boolean>;
} => {
const [publicRooms, setPublicRooms] = useState<IPublicRoomsChunkRoom[]>([]);
const [config, setConfigInternal] = useState<IPublicRoomDirectoryConfig | null | undefined>(undefined);
@ -50,7 +58,7 @@ export const usePublicRoomDirectory = () => {
const [updateQuery, updateResult] = useLatestResult<IRoomDirectoryOptions, IPublicRoomsChunkRoom[]>(setPublicRooms);
async function initProtocols() {
async function initProtocols(): Promise<void> {
if (!MatrixClientPeg.get()) {
// We may not have a client yet when invoked from welcome page
setReady(true);
@ -63,7 +71,7 @@ export const usePublicRoomDirectory = () => {
}
}
function setConfig(config: IPublicRoomDirectoryConfig) {
function setConfig(config: IPublicRoomDirectoryConfig): void {
if (!ready) {
throw new Error("public room configuration not initialised yet");
} else {

View file

@ -19,7 +19,7 @@ import { useEffect, useState } from "react";
import SettingsStore from "../settings/SettingsStore";
// Hook to fetch the value of a setting and dynamically update when it changes
export const useSettingValue = <T>(settingName: string, roomId: string = null, excludeDefault = false) => {
export const useSettingValue = <T>(settingName: string, roomId: string = null, excludeDefault = false): T => {
const [value, setValue] = useState(SettingsStore.getValue<T>(settingName, roomId, excludeDefault));
useEffect(() => {

View file

@ -26,7 +26,11 @@ export interface SlidingSyncRoomSearchOpts {
query?: string;
}
export const useSlidingSyncRoomSearch = () => {
export const useSlidingSyncRoomSearch = (): {
loading: boolean;
rooms: Room[];
search(opts: SlidingSyncRoomSearchOpts): Promise<boolean>;
} => {
const [rooms, setRooms] = useState<Room[]>([]);
const [loading, setLoading] = useState(false);

View file

@ -20,7 +20,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import SettingsStore from "../settings/SettingsStore";
import { useAnimation } from "./useAnimation";
const debuglog = (...args: any[]) => {
const debuglog = (...args: any[]): void => {
if (SettingsStore.getValue("debug_animation")) {
logger.log.call(console, "Animation debuglog:", ...args);
}

View file

@ -36,7 +36,7 @@ export const useSpaceResults = (space?: Room, query?: string): [IHierarchyRoom[]
let unmounted = false;
(async () => {
(async (): Promise<void> => {
while (hierarchy?.canLoadMore && !unmounted && space === hierarchy.root) {
await hierarchy.load();
if (hierarchy.canLoadMore) hierarchy.load(); // start next load so that the loading attribute is right

View file

@ -20,7 +20,7 @@ import { Dispatch, SetStateAction, useState } from "react";
// Returns value and method to change the state value
export const useStateCallback = <T>(initialValue: T, callback: (v: T) => void): [T, Dispatch<SetStateAction<T>>] => {
const [value, setValue] = useState(initialValue);
const interceptSetValue = (newVal: T) => {
const interceptSetValue = (newVal: T): void => {
setValue(newVal);
callback(newVal);
};

View file

@ -20,7 +20,7 @@ import { Dispatch, SetStateAction, useState } from "react";
// Returns value, method to toggle boolean value and method to set the boolean value
export const useStateToggle = (initialValue = false): [boolean, () => void, Dispatch<SetStateAction<boolean>>] => {
const [value, setValue] = useState(initialValue);
const toggleValue = () => {
const toggleValue = (): void => {
setValue(!value);
};
return [value, toggleValue, setValue];

View file

@ -19,7 +19,7 @@ import { useEffect, useRef, useState } from "react";
type Handler = () => void;
// Hook to simplify timeouts in functional components
export const useTimeout = (handler: Handler, timeoutMs: number) => {
export const useTimeout = (handler: Handler, timeoutMs: number): void => {
// Create a ref that stores handler
const savedHandler = useRef<Handler>();
@ -38,7 +38,7 @@ export const useTimeout = (handler: Handler, timeoutMs: number) => {
};
// Hook to simplify intervals in functional components
export const useInterval = (handler: Handler, intervalMs: number) => {
export const useInterval = (handler: Handler, intervalMs: number): void => {
// Create a ref that stores handler
const savedHandler = useRef<Handler>();
@ -57,7 +57,7 @@ export const useInterval = (handler: Handler, intervalMs: number) => {
};
// Hook to simplify a variable counting down to 0, handler called when it reached 0
export const useExpiringCounter = (handler: Handler, intervalMs: number, initialCount: number) => {
export const useExpiringCounter = (handler: Handler, intervalMs: number, initialCount: number): number => {
const [count, setCount] = useState(initialCount);
useInterval(() => setCount((c) => c - 1), intervalMs);
if (count === 0) {

View file

@ -22,11 +22,17 @@ import { useEffect, useRef, useState } from "react";
* @param {boolean} defaultValue Default value
* @param {number} timeoutMs Time after that the value will be reset
*/
export const useTimeoutToggle = (defaultValue: boolean, timeoutMs: number) => {
export const useTimeoutToggle = (
defaultValue: boolean,
timeoutMs: number,
): {
value: boolean;
toggle(): void;
} => {
const timeoutId = useRef<number | undefined>();
const [value, setValue] = useState<boolean>(defaultValue);
const toggle = () => {
const toggle = (): void => {
setValue(!defaultValue);
timeoutId.current = window.setTimeout(() => setValue(defaultValue), timeoutMs);
};

View file

@ -25,7 +25,12 @@ export interface IUserDirectoryOpts {
query?: string;
}
export const useUserDirectory = () => {
export const useUserDirectory = (): {
ready: boolean;
loading: boolean;
users: DirectoryMember[];
search(opts: IUserDirectoryOpts): Promise<boolean>;
} => {
const [users, setUsers] = useState<DirectoryMember[]>([]);
const [loading, setLoading] = useState(false);

View file

@ -58,7 +58,7 @@ function useUserOnboardingContextValue<T>(defaultValue: T, callback: (cli: Matri
let handle: number | null = null;
let enabled = true;
const repeater = async () => {
const repeater = async (): Promise<void> => {
if (handle !== null) {
clearTimeout(handle);
handle = null;

View file

@ -48,7 +48,7 @@ export interface UserOnboardingTaskWithResolvedCompletion extends Omit<UserOnboa
completed: boolean;
}
const onClickStartDm = (ev: ButtonEvent) => {
const onClickStartDm = (ev: ButtonEvent): void => {
PosthogTrackers.trackInteraction("WebUserOnboardingTaskSendDm", ev);
defaultDispatcher.dispatch({ action: "view_create_chat" });
};
@ -144,7 +144,7 @@ const tasks: UserOnboardingTask[] = [
},
];
export function useUserOnboardingTasks(context: UserOnboardingContext) {
export function useUserOnboardingTasks(context: UserOnboardingContext): UserOnboardingTaskWithResolvedCompletion[] {
const useCase = useSettingValue<UseCase | null>("FTUE.useCaseSelection") ?? UseCase.Skip;
return useMemo<UserOnboardingTaskWithResolvedCompletion[]>(() => {