Upgrade eslint-plugin-matrix-org to 1.2.1

This upgrade came with a number of new lints that needed to be fixed across the code base. Primarily: explicit return types on functions, and explicit visibility modifiers on class members.
This commit is contained in:
Robin
2023-09-22 18:05:13 -04:00
parent 444a37224b
commit a7624806b2
88 changed files with 735 additions and 433 deletions

View File

@@ -78,7 +78,7 @@ export interface SparseGrid {
export function getPaths(
g: SparseGrid,
dest: number,
avoid: (cell: number) => boolean = () => false
avoid: (cell: number) => boolean = (): boolean => false
): (number | null)[] {
const destRow = row(dest, g);
const destColumn = column(dest, g);
@@ -91,7 +91,7 @@ export function getPaths(
edges[dest] = null;
const heap = new TinyQueue([dest], (i) => distances[i]);
const visit = (curr: number, via: number, distanceVia: number) => {
const visit = (curr: number, via: number, distanceVia: number): void => {
if (distanceVia < distances[curr]) {
distances[curr] = distanceVia;
edges[curr] = via;
@@ -128,7 +128,7 @@ export function getPaths(
return edges;
}
const is1By1 = (c: Cell) => c.columns === 1 && c.rows === 1;
const is1By1 = (c: Cell): boolean => c.columns === 1 && c.rows === 1;
const findLast1By1Index = (g: SparseGrid): number | null =>
findLastIndex(g.cells, (c) => c !== undefined && is1By1(c));
@@ -257,7 +257,7 @@ function getNextGap(
* along the way.
* Precondition: the destination area must consist of only 1×1 tiles.
*/
function moveTileUnchecked(g: SparseGrid, from: number, to: number) {
function moveTileUnchecked(g: SparseGrid, from: number, to: number): void {
const tile = g.cells[from]!;
const fromEnd = areaEnd(from, tile.columns, tile.rows, g);
const toEnd = areaEnd(to, tile.columns, tile.rows, g);
@@ -333,7 +333,7 @@ function pushTileUp(
g: SparseGrid,
from: number,
rows: number,
avoid: (cell: number) => boolean = () => false
avoid: (cell: number) => boolean = (): boolean => false
): number {
const tile = g.cells[from]!;
@@ -359,7 +359,7 @@ function pushTileUp(
return 0;
}
function trimTrailingGaps(g: SparseGrid) {
function trimTrailingGaps(g: SparseGrid): void {
// Shrink the array to remove trailing gaps
const newLength = (findLastIndex(g.cells, (c) => c !== undefined) ?? -1) + 1;
if (newLength !== g.cells.length) g.cells = g.cells.slice(0, newLength);
@@ -485,7 +485,7 @@ export function fillGaps(
export function fillGaps(
g: SparseGrid,
packLargeTiles = true,
ignoreGap: (cell: number) => boolean = () => false
ignoreGap: (cell: number) => boolean = (): boolean => false
): SparseGrid {
const lastGap = findLastIndex(
g.cells,
@@ -785,7 +785,11 @@ export function setTileSize<G extends Grid | SparseGrid>(
gridWithoutTile.cells[i] = undefined;
});
const placeTile = (to: number, toEnd: number, grid: Grid | SparseGrid) => {
const placeTile = (
to: number,
toEnd: number,
grid: Grid | SparseGrid
): void => {
forEachCellInArea(to, toEnd, grid, (_c, i) => {
grid.cells[i] = {
item: fromCell.item,
@@ -904,7 +908,7 @@ export function resize(g: Grid, columns: number): Grid {
/**
* Promotes speakers to the first page of the grid.
*/
export function promoteSpeakers(g: SparseGrid) {
export function promoteSpeakers(g: SparseGrid): void {
// This is all a bit of a hack right now, because we don't know if the designs
// will stick with this approach in the long run
// We assume that 4 rows are probably about 1 page

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { ComponentType, useCallback, useMemo, useRef } from "react";
import { ComponentType, ReactNode, useCallback, useMemo, useRef } from "react";
import type { RectReadOnly } from "react-use-measure";
import { useReactiveState } from "../useReactiveState";
@@ -98,16 +98,33 @@ export const useLayoutStates = (): LayoutStatesMap => {
return layoutStates.current as LayoutStatesMap;
};
interface UseLayout<State, T> {
state: State;
orderedItems: TileDescriptor<T>[];
generation: number;
canDragTile: (tile: TileDescriptor<T>) => boolean;
dragTile: (
from: TileDescriptor<T>,
to: TileDescriptor<T>,
xPositionOnFrom: number,
yPositionOnFrom: number,
xPositionOnTo: number,
yPositionOnTo: number
) => void;
toggleFocus: ((tile: TileDescriptor<T>) => void) | undefined;
slots: ReactNode;
}
/**
* Hook which uses the provided layout system to arrange a set of items into a
* concrete layout state, and provides callbacks for user interaction.
*/
export const useLayout = <State, T>(
export function useLayout<State, T>(
layout: Layout<State>,
items: TileDescriptor<T>[],
bounds: RectReadOnly,
layoutStates: LayoutStatesMap
) => {
): UseLayout<State, T> {
const prevLayout = useRef<Layout<unknown>>();
const prevState = layoutStates.get(layout);
@@ -169,10 +186,10 @@ export const useLayout = <State, T>(
toggleFocus: useMemo(
() =>
layout.toggleFocus &&
((tile: TileDescriptor<T>) =>
((tile: TileDescriptor<T>): void =>
setState((s) => layout.toggleFocus!(s, tile))),
[layout, setState]
),
slots: <layout.Slots s={state} />,
};
};
}

View File

@@ -81,7 +81,7 @@ export function NewVideoGrid<T>({
disableAnimations,
layoutStates,
children,
}: Props<T>) {
}: Props<T>): ReactNode {
// Overview: This component lays out tiles by rendering an invisible template
// grid of "slots" for tiles to go in. Once rendered, it uses the DOM API to
// get the dimensions of each slot, feeding these numbers back into
@@ -210,7 +210,7 @@ export function NewVideoGrid<T>({
springRef.start();
}, [tiles, springRef]);
const animateDraggedTile = (endOfGesture: boolean) => {
const animateDraggedTile = (endOfGesture: boolean): void => {
const { tileId, tileX, tileY, cursorX, cursorY } = dragState.current!;
const tile = tiles.find((t) => t.item.id === tileId)!;
@@ -226,7 +226,8 @@ export function NewVideoGrid<T>({
y: tile.y,
width: tile.width,
height: tile.height,
immediate: disableAnimations || ((key) => key === "zIndex"),
immediate:
disableAnimations || ((key): boolean => key === "zIndex"),
// Allow the tile's position to settle before pushing its
// z-index back down
delay: (key) => (key === "zIndex" ? 500 : 0),
@@ -239,7 +240,8 @@ export function NewVideoGrid<T>({
y: tileY,
immediate:
disableAnimations ||
((key) => key === "zIndex" || key === "x" || key === "y"),
((key): boolean =>
key === "zIndex" || key === "x" || key === "y"),
}
);
@@ -286,7 +288,7 @@ export function NewVideoGrid<T>({
// @ts-ignore
last,
}: Parameters<Handler<"drag", EventTypes["drag"]>>[0]
) => {
): void => {
if (tap) {
const now = Date.now();

View File

@@ -17,6 +17,7 @@ limitations under the License.
import {
ComponentProps,
Key,
MutableRefObject,
ReactNode,
Ref,
useCallback,
@@ -112,7 +113,7 @@ export function useVideoGridLayout(hasScreenshareFeeds: boolean): {
const GAP = 8;
function useIsMounted() {
function useIsMounted(): MutableRefObject<boolean> {
const isMountedRef = useRef<boolean>(false);
useEffect(() => {
@@ -478,7 +479,7 @@ function centerTiles(
gridHeight: number,
offsetLeft: number,
offsetTop: number
) {
): TilePosition[] {
const bounds = getSubGridBoundingBox(positions);
const leftOffset = Math.round((gridWidth - bounds.width) / 2) + offsetLeft;
@@ -493,7 +494,7 @@ function applyTileOffsets(
positions: TilePosition[],
leftOffset: number,
topOffset: number
) {
): TilePosition[] {
for (const position of positions) {
position.x += leftOffset;
position.y += topOffset;
@@ -623,7 +624,7 @@ function getSubGridPositions(
tileAspectRatio: number,
gridWidth: number,
gridHeight: number
) {
): TilePosition[] {
if (tileCount === 0) {
return [];
}
@@ -726,7 +727,11 @@ function displayedTileCount(
// Sets the 'order' property on tiles based on the layout param and
// other properties of the tiles, eg. 'focused' and 'presenter'
function reorderTiles<T>(tiles: Tile<T>[], layout: Layout, displayedTile = -1) {
function reorderTiles<T>(
tiles: Tile<T>[],
layout: Layout,
displayedTile = -1
): void {
// We use a special layout for 1:1 to always put the local tile first.
// We only do this if there are two tiles (obviously) and exactly one
// of them is local: during startup we can have tiles from other users
@@ -841,7 +846,7 @@ export function VideoGrid<T>({
layout,
disableAnimations,
children,
}: VideoGridProps<T>) {
}: VideoGridProps<T>): ReactNode {
// Place the PiP in the bottom right corner by default
const [pipXRatio, setPipXRatio] = useState(1);
const [pipYRatio, setPipYRatio] = useState(1);
@@ -1208,7 +1213,7 @@ export function VideoGrid<T>({
// @ts-ignore
event,
}: Parameters<Handler<"drag", EventTypes["drag"]>>[0]
) => {
): void => {
event.preventDefault();
if (tap) {

View File

@@ -97,12 +97,12 @@ export const VideoTile = forwardRef<HTMLDivElement, Props>(
);
useEffect(() => {
if (member) {
const updateName = () => {
const updateName = (): void => {
setDisplayName(member.rawDisplayName);
};
member!.on(RoomMemberEvent.Name, updateName);
return () => {
return (): void => {
member!.removeListener(RoomMemberEvent.Name, updateName);
};
}

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { ChangeEvent, useState } from "react";
import { ChangeEvent, FC, useState } from "react";
import { useTranslation } from "react-i18next";
import { RemoteParticipant, Track } from "livekit-client";
@@ -29,7 +29,7 @@ interface LocalVolumeProps {
content: TileContent;
}
const LocalVolume: React.FC<LocalVolumeProps> = ({
const LocalVolume: FC<LocalVolumeProps> = ({
participant,
content,
}: LocalVolumeProps) => {
@@ -42,7 +42,7 @@ const LocalVolume: React.FC<LocalVolumeProps> = ({
participant.getVolume(source) ?? 0
);
const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>) => {
const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>): void => {
const value: number = +event.target.value;
setLocalVolume(value);
participant.setVolume(value, source);
@@ -72,7 +72,11 @@ interface Props {
onDismiss: () => void;
}
export const VideoTileSettingsModal = ({ data, open, onDismiss }: Props) => {
export const VideoTileSettingsModal: FC<Props> = ({
data,
open,
onDismiss,
}) => {
const { t } = useTranslation();
return (