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

@ -33,7 +33,7 @@ interface Props {
onChange: (timeout: number) => void;
}
const getLabel = (durationMs: number) => {
const getLabel = (durationMs: number): string => {
return _t("Share for %(duration)s", { duration: formatDuration(durationMs) });
};
@ -54,7 +54,7 @@ const LiveDurationDropdown: React.FC<Props> = ({ timeout, onChange }) => {
});
}
const onOptionChange = (key: string) => {
const onOptionChange = (key: string): void => {
// stringified value back to number
onChange(+key);
};

View file

@ -21,14 +21,14 @@ import { IEventRelation } from "matrix-js-sdk/src/models/event";
import { _t } from "../../../languageHandler";
import { CollapsibleButton } from "../rooms/CollapsibleButton";
import { aboveLeftOf, useContextMenu, AboveLeftOf } from "../../structures/ContextMenu";
import { aboveLeftOf, useContextMenu, MenuProps } from "../../structures/ContextMenu";
import { OverflowMenuContext } from "../rooms/MessageComposerButtons";
import LocationShareMenu from "./LocationShareMenu";
interface IProps {
roomId: string;
sender: RoomMember;
menuPosition?: AboveLeftOf;
menuPosition?: MenuProps;
relation?: IEventRelation;
}
@ -36,7 +36,7 @@ export const LocationButton: React.FC<IProps> = ({ roomId, sender, menuPosition,
const overflowMenuCloser = useContext(OverflowMenuContext);
const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu();
const _onFinished = (ev?: SyntheticEvent) => {
const _onFinished = (ev?: SyntheticEvent): void => {
closeMenu(ev);
overflowMenuCloser?.();
};

View file

@ -67,11 +67,11 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
};
}
private getMarkerId = () => {
private getMarkerId = (): string => {
return "mx_MLocationPicker_marker";
};
public componentDidMount() {
public componentDidMount(): void {
this.context.on(ClientEvent.ClientWellKnown, this.updateStyleUrl);
try {
@ -128,14 +128,14 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
}
}
public componentWillUnmount() {
public componentWillUnmount(): void {
this.geolocate?.off("error", this.onGeolocateError);
this.geolocate?.off("geolocate", this.onGeolocate);
this.map?.off("click", this.onClick);
this.context.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
}
private addMarkerToMap = () => {
private addMarkerToMap = (): void => {
this.marker = new maplibregl.Marker({
element: document.getElementById(this.getMarkerId()) ?? undefined,
anchor: "bottom",
@ -145,14 +145,14 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
.addTo(this.map);
};
private updateStyleUrl = (clientWellKnown: IClientWellKnown) => {
private updateStyleUrl = (clientWellKnown: IClientWellKnown): void => {
const style = tileServerFromWellKnown(clientWellKnown)?.["map_style_url"];
if (style) {
this.map?.setStyle(style);
}
};
private onGeolocate = (position: GeolocationPosition) => {
private onGeolocate = (position: GeolocationPosition): void => {
if (!this.marker) {
this.addMarkerToMap();
}
@ -160,7 +160,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
this.marker?.setLngLat(new maplibregl.LngLat(position.coords.longitude, position.coords.latitude));
};
private onClick = (event: MapMouseEvent) => {
private onClick = (event: MapMouseEvent): void => {
if (!this.marker) {
this.addMarkerToMap();
}
@ -174,7 +174,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
});
};
private onGeolocateError = (e: GeolocationPositionError) => {
private onGeolocateError = (e: GeolocationPositionError): void => {
logger.error("Could not fetch location", e);
// close the dialog and show an error when trying to share own location
// pin drop location without permissions is ok
@ -195,7 +195,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
this.setState({ timeout });
};
private onOk = () => {
private onOk = (): void => {
const { timeout, position } = this.state;
this.props.onChoose(
@ -208,7 +208,7 @@ class LocationPicker extends React.Component<ILocationPickerProps, IState> {
this.props.onFinished();
};
public render() {
public render(): JSX.Element {
if (this.state.error) {
return (
<div className="mx_LocationPicker mx_LocationPicker_hasError">

View file

@ -19,7 +19,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { IEventRelation } from "matrix-js-sdk/src/models/event";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import ContextMenu, { AboveLeftOf } from "../../structures/ContextMenu";
import ContextMenu, { MenuProps } from "../../structures/ContextMenu";
import LocationPicker, { ILocationPickerProps } from "./LocationPicker";
import { shareLiveLocation, shareLocation, LocationShareType } from "./shareLocation";
import SettingsStore from "../../../settings/SettingsStore";
@ -32,7 +32,7 @@ import { SettingLevel } from "../../../settings/SettingLevel";
type Props = Omit<ILocationPickerProps, "onChoose" | "shareType"> & {
onFinished: (ev?: SyntheticEvent) => void;
menuPosition: AboveLeftOf;
menuPosition: MenuProps;
openMenu: () => void;
roomId: Room["roomId"];
relation?: IEventRelation;
@ -70,7 +70,7 @@ const LocationShareMenu: React.FC<Props> = ({ menuPosition, onFinished, sender,
? shareLiveLocation(matrixClient, roomId, displayName, openMenu)
: shareLocation(matrixClient, roomId, shareType, relation, openMenu);
const onLiveShareEnableSubmit = () => {
const onLiveShareEnableSubmit = (): void => {
SettingsStore.setValue("feature_location_share_live", undefined, SettingLevel.DEVICE, true);
};

View file

@ -46,15 +46,15 @@ export default class LocationViewDialog extends React.Component<IProps, IState>
};
}
private getBodyId = () => {
private getBodyId = (): string => {
return `mx_LocationViewDialog_${this.props.mxEvent.getId()}`;
};
private onError = (error) => {
private onError = (error: Error): void => {
this.setState({ error });
};
public render() {
public render(): JSX.Element {
const { mxEvent } = this.props;
// only pass member to marker when should render avatar marker

View file

@ -27,7 +27,22 @@ import { tileServerFromWellKnown } from "../../../utils/WellKnownUtils";
import { useMap } from "../../../utils/location/useMap";
import { Bounds } from "../../../utils/beacon/bounds";
const useMapWithStyle = ({ id, centerGeoUri, onError, interactive, bounds }) => {
const useMapWithStyle = ({
id,
centerGeoUri,
onError,
interactive,
bounds,
}: {
id: string;
centerGeoUri?: string;
interactive?: boolean;
bounds?: Bounds;
onError(error: Error): void;
}): {
map: maplibregl.Map;
bodyId: string;
} => {
const bodyId = `mx_Map_${id}`;
// style config
@ -98,7 +113,7 @@ interface MapProps {
const Map: React.FC<MapProps> = ({ bounds, centerGeoUri, children, className, id, interactive, onError, onClick }) => {
const { map, bodyId } = useMapWithStyle({ centerGeoUri, onError, id, interactive, bounds });
const onMapClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const onMapClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>): void => {
// Eat click events when clicking the attribution button
const target = event.target as Element;
if (target.classList.contains("maplibregl-ctrl-attrib-button")) {

View file

@ -44,9 +44,9 @@ const OptionalTooltip: React.FC<{
return <>{children}</>;
}
const show = () => setIsVisible(true);
const hide = () => setIsVisible(false);
const toggleVisibility = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const show = (): void => setIsVisible(true);
const hide = (): void => setIsVisible(false);
const toggleVisibility = (e: React.MouseEvent<HTMLDivElement, MouseEvent>): void => {
// stop map from zooming in on click
e.stopPropagation();
setIsVisible(!isVisible);

View file

@ -26,7 +26,7 @@ import { Icon as LocationIcon } from "../../../../res/img/element-icons/location
import { LocationShareType } from "./shareLocation";
import StyledLiveBeaconIcon from "../beacon/StyledLiveBeaconIcon";
const UserAvatar = () => {
const UserAvatar: React.FC = () => {
const matrixClient = useContext(MatrixClientContext);
const userId = matrixClient.getUserId();
const displayName = OwnProfileStore.instance.displayName;

View file

@ -27,11 +27,11 @@ interface Props {
}
const ZoomButtons: React.FC<Props> = ({ map }) => {
const onZoomIn = () => {
const onZoomIn = (): void => {
map.zoomIn();
};
const onZoomOut = () => {
const onZoomOut = (): void => {
map.zoomOut();
};

View file

@ -107,7 +107,7 @@ const handleShareError = (error: Error, openMenu: () => void, shareType: Locatio
export const shareLiveLocation =
(client: MatrixClient, roomId: string, displayName: string, openMenu: () => void): ShareLocationFn =>
async ({ timeout }) => {
async ({ timeout }): Promise<void> => {
const description = _t(`%(displayName)s's live location`, { displayName });
try {
await OwnBeaconStore.instance.createLiveBeacon(
@ -132,7 +132,7 @@ export const shareLocation =
relation: IEventRelation | undefined,
openMenu: () => void,
): ShareLocationFn =>
async ({ uri, timestamp }) => {
async ({ uri, timestamp }): Promise<void> => {
if (!uri) return;
try {
const threadId = relation?.rel_type === THREAD_RELATION_TYPE.name ? relation.event_id : null;