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:
@@ -22,7 +22,7 @@ import { TimelineRenderingType } from "../contexts/RoomContext";
|
||||
import type { ICompletion, ISelectionRange } from "./Autocompleter";
|
||||
|
||||
export interface ICommand {
|
||||
command: string | null;
|
||||
command: RegExpExecArray | null;
|
||||
range: {
|
||||
start: number;
|
||||
end: number;
|
||||
@@ -59,7 +59,7 @@ export default abstract class AutocompleteProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
public destroy(): void {
|
||||
// stub
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export default abstract class AutocompleteProvider {
|
||||
* @param {boolean} force True if the user is forcing completion
|
||||
* @return {object} { command, range } where both objects fields are null if no match
|
||||
*/
|
||||
public getCurrentCommand(query: string, selection: ISelectionRange, force = false) {
|
||||
public getCurrentCommand(query: string, selection: ISelectionRange, force = false): ICommand {
|
||||
let commandRegex = this.commandRegex;
|
||||
|
||||
if (force && this.shouldForceComplete()) {
|
||||
@@ -83,7 +83,7 @@ export default abstract class AutocompleteProvider {
|
||||
|
||||
commandRegex.lastIndex = 0;
|
||||
|
||||
let match;
|
||||
let match: RegExpExecArray;
|
||||
while ((match = commandRegex.exec(query)) !== null) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class Autocompleter {
|
||||
});
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
public destroy(): void {
|
||||
this.providers.forEach((p) => {
|
||||
p.destroy();
|
||||
});
|
||||
@@ -88,7 +88,7 @@ export default class Autocompleter {
|
||||
*/
|
||||
// list of results from each provider, each being a list of completions or null if it times out
|
||||
const completionsList: ICompletion[][] = await Promise.all(
|
||||
this.providers.map(async (provider) => {
|
||||
this.providers.map(async (provider): Promise<ICompletion[] | null> => {
|
||||
return timeout(
|
||||
provider.getCompletions(query, selection, force, limit),
|
||||
null,
|
||||
|
||||
@@ -100,7 +100,7 @@ export default class CommandProvider extends AutocompleteProvider {
|
||||
});
|
||||
}
|
||||
|
||||
public getName() {
|
||||
public getName(): string {
|
||||
return "*️⃣ " + _t("Commands");
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ const SORTED_EMOJI: ISortedEmoji[] = EMOJI.sort((a, b) => {
|
||||
_orderBy: index,
|
||||
}));
|
||||
|
||||
function score(query, space) {
|
||||
function score(query: string, space: string): number {
|
||||
const index = space.indexOf(query);
|
||||
if (index === -1) {
|
||||
return Infinity;
|
||||
@@ -154,7 +154,7 @@ export default class EmojiProvider extends AutocompleteProvider {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getName() {
|
||||
public getName(): string {
|
||||
return "😃 " + _t("Emoji");
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export default class NotifProvider extends AutocompleteProvider {
|
||||
return [];
|
||||
}
|
||||
|
||||
public getName() {
|
||||
public getName(): string {
|
||||
return "❗️ " + _t("Room Notification");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export default class QueryMatcher<T extends {}> {
|
||||
}
|
||||
}
|
||||
|
||||
public setObjects(objects: T[]) {
|
||||
public setObjects(objects: T[]): void {
|
||||
this._items = new Map();
|
||||
|
||||
for (const object of objects) {
|
||||
|
||||
@@ -37,7 +37,15 @@ function canonicalScore(displayedAlias: string, room: Room): number {
|
||||
return displayedAlias === room.getCanonicalAlias() ? 0 : 1;
|
||||
}
|
||||
|
||||
function matcherObject(room: Room, displayedAlias: string, matchName = "") {
|
||||
function matcherObject(
|
||||
room: Room,
|
||||
displayedAlias: string,
|
||||
matchName = "",
|
||||
): {
|
||||
room: Room;
|
||||
matchName: string;
|
||||
displayedAlias: string;
|
||||
} {
|
||||
return {
|
||||
room,
|
||||
matchName,
|
||||
@@ -46,7 +54,7 @@ function matcherObject(room: Room, displayedAlias: string, matchName = "") {
|
||||
}
|
||||
|
||||
export default class RoomProvider extends AutocompleteProvider {
|
||||
protected matcher: QueryMatcher<Room>;
|
||||
protected matcher: QueryMatcher<ReturnType<typeof matcherObject>>;
|
||||
|
||||
public constructor(room: Room, renderingType?: TimelineRenderingType) {
|
||||
super({ commandRegex: ROOM_REGEX, renderingType });
|
||||
@@ -55,7 +63,7 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||
});
|
||||
}
|
||||
|
||||
protected getRooms() {
|
||||
protected getRooms(): Room[] {
|
||||
const cli = MatrixClientPeg.get();
|
||||
|
||||
// filter out spaces here as they get their own autocomplete provider
|
||||
@@ -68,7 +76,6 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||
force = false,
|
||||
limit = -1,
|
||||
): Promise<ICompletion[]> {
|
||||
let completions = [];
|
||||
const { command, range } = this.getCurrentCommand(query, selection, force);
|
||||
if (command) {
|
||||
// the only reason we need to do this is because Fuse only matches on properties
|
||||
@@ -96,15 +103,15 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||
|
||||
this.matcher.setObjects(matcherObjects);
|
||||
const matchedString = command[0];
|
||||
completions = this.matcher.match(matchedString, limit);
|
||||
let completions = this.matcher.match(matchedString, limit);
|
||||
completions = sortBy(completions, [
|
||||
(c) => canonicalScore(c.displayedAlias, c.room),
|
||||
(c) => c.displayedAlias.length,
|
||||
]);
|
||||
completions = uniqBy(completions, (match) => match.room);
|
||||
completions = completions
|
||||
.map((room) => {
|
||||
return {
|
||||
return completions
|
||||
.map(
|
||||
(room): ICompletion => ({
|
||||
completion: room.displayedAlias,
|
||||
completionId: room.room.roomId,
|
||||
type: "room",
|
||||
@@ -116,14 +123,14 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||
</PillCompletion>
|
||||
),
|
||||
range,
|
||||
};
|
||||
})
|
||||
}),
|
||||
)
|
||||
.filter((completion) => !!completion.completion && completion.completion.length > 0);
|
||||
}
|
||||
return completions;
|
||||
return [];
|
||||
}
|
||||
|
||||
public getName() {
|
||||
public getName(): string {
|
||||
return _t("Rooms");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import React from "react";
|
||||
|
||||
import { _t } from "../languageHandler";
|
||||
@@ -21,13 +22,13 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import RoomProvider from "./RoomProvider";
|
||||
|
||||
export default class SpaceProvider extends RoomProvider {
|
||||
protected getRooms() {
|
||||
protected getRooms(): Room[] {
|
||||
return MatrixClientPeg.get()
|
||||
.getVisibleRooms()
|
||||
.filter((r) => r.isSpaceRoom());
|
||||
}
|
||||
|
||||
public getName() {
|
||||
public getName(): string {
|
||||
return _t("Spaces");
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||
MatrixClientPeg.get().on(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
public destroy(): void {
|
||||
if (MatrixClientPeg.get()) {
|
||||
MatrixClientPeg.get().removeListener(RoomEvent.Timeline, this.onRoomTimeline);
|
||||
MatrixClientPeg.get().removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
@@ -77,7 +77,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||
toStartOfTimeline: boolean,
|
||||
removed: boolean,
|
||||
data: IRoomTimelineData,
|
||||
) => {
|
||||
): void => {
|
||||
if (!room) return; // notification timeline, we'll get this event again with a room specific timeline
|
||||
if (removed) return;
|
||||
if (room.roomId !== this.room.roomId) return;
|
||||
@@ -93,7 +93,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||
this.onUserSpoke(ev.sender);
|
||||
};
|
||||
|
||||
private onRoomStateUpdate = (state: RoomState) => {
|
||||
private onRoomStateUpdate = (state: RoomState): void => {
|
||||
// ignore updates in other rooms
|
||||
if (state.roomId !== this.room.roomId) return;
|
||||
|
||||
@@ -150,7 +150,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||
return _t("Users");
|
||||
}
|
||||
|
||||
private makeUsers() {
|
||||
private makeUsers(): void {
|
||||
const events = this.room.getLiveTimeline().getEvents();
|
||||
const lastSpoken = {};
|
||||
|
||||
@@ -167,7 +167,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||
this.matcher.setObjects(this.users);
|
||||
}
|
||||
|
||||
public onUserSpoke(user: RoomMember) {
|
||||
public onUserSpoke(user: RoomMember): void {
|
||||
if (!this.users) return;
|
||||
if (!user) return;
|
||||
if (user.userId === MatrixClientPeg.get().credentials.userId) return;
|
||||
|
||||
Reference in New Issue
Block a user