Switch from eslint to oxlint (#34166)
* Fix type imports * Fix jsdoc * Fixup types * Fix stray awaits on non-thenables * Fixup imports * Fix splats * Fix this-context on callbacks * Memoise react contexts * Prefer find/flatMap * Make oxlint happier about our React keys * Avoid unsafe default function params * Fixup jsdoc * Fixup contexts * Switch from eslint to oxlint * Some oxlint-related tweaks * Iterate * Partial revert to defer some changes and shrink diff * Iterate * Add eslint-plugin-element-call and enable the copyright rule * Set strictStorePkgContentCheck * Iterate * Make sonar happy * Fix new lints
This commit is contained in:
@@ -162,11 +162,11 @@ export default class DMRoomMap {
|
||||
commonRooms = commonRooms.filter((r) => userRooms.includes(r));
|
||||
}
|
||||
|
||||
const joinedRooms = commonRooms
|
||||
.map((r) => this.matrixClient.getRoom(r))
|
||||
.filter((r) => r && r.getMyMembership() === KnownMembership.Join);
|
||||
|
||||
return joinedRooms[0];
|
||||
return (
|
||||
commonRooms
|
||||
.map((r) => this.matrixClient.getRoom(r))
|
||||
.find((r) => r && r.getMyMembership() === KnownMembership.Join) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public getUserIdForRoomId(roomId: string): string | undefined {
|
||||
|
||||
@@ -31,7 +31,7 @@ export function downloadLabelForFile(content: MediaEventContent, withSize = true
|
||||
* @param {string} fallbackText The fallback text
|
||||
* @param {boolean} withSize Whether to include size information. Default true.
|
||||
* @param {boolean} shortened Ensure the extension of the file name is visible. Default false.
|
||||
* @return {string} the human-readable link text for the attachment.
|
||||
* @returns {string} the human-readable link text for the attachment.
|
||||
*/
|
||||
export function presentableTextForFile(
|
||||
content: MediaEventContent,
|
||||
|
||||
@@ -40,7 +40,7 @@ describe("LruCache", () => {
|
||||
});
|
||||
|
||||
it("delete() should not raise an error", () => {
|
||||
cache.delete("a");
|
||||
expect(() => cache.delete("a")).not.toThrow();
|
||||
});
|
||||
|
||||
describe("when the cache contains 2 items", () => {
|
||||
@@ -87,8 +87,8 @@ describe("LruCache", () => {
|
||||
cache.set("c", "c value");
|
||||
});
|
||||
|
||||
it("deleting an unkonwn item should not raise an error", () => {
|
||||
cache.delete("unknown");
|
||||
it("deleting an unknown item should not raise an error", () => {
|
||||
expect(() => cache.delete("unknown")).not.toThrow();
|
||||
});
|
||||
|
||||
it("deleting the first item should work", () => {
|
||||
|
||||
@@ -131,6 +131,7 @@ export class LruCache<K, V> {
|
||||
|
||||
/**
|
||||
* Returns an iterator over the cached values.
|
||||
* @yields each value in the cache
|
||||
*/
|
||||
public *values(): IterableIterator<V> {
|
||||
for (const item of this.map.values()) {
|
||||
|
||||
@@ -35,7 +35,7 @@ function cryptoFailMsg(): string {
|
||||
*
|
||||
* @param {ArrayBuffer} data file to decrypt
|
||||
* @param {String} password
|
||||
* @return {Promise<String>} promise for decrypted output
|
||||
* @returns {Promise<String>} promise for decrypted output
|
||||
*
|
||||
*
|
||||
*/
|
||||
@@ -103,7 +103,7 @@ export async function decryptMegolmKeyFile(data: ArrayBuffer, password: string):
|
||||
* @param {Object=} options
|
||||
* @param {Number=} options.kdf_rounds Number of iterations to perform of the
|
||||
* key-derivation function.
|
||||
* @return {Promise<ArrayBuffer>} promise for encrypted output
|
||||
* @returns {Promise<ArrayBuffer>} promise for encrypted output
|
||||
*/
|
||||
export async function encryptMegolmKeyFile(
|
||||
data: string,
|
||||
@@ -178,7 +178,7 @@ export async function encryptMegolmKeyFile(
|
||||
* @param {Unit8Array} salt salt for pbkdf
|
||||
* @param {Number} iterations number of pbkdf iterations
|
||||
* @param {String} password password
|
||||
* @return {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]
|
||||
* @returns {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]
|
||||
*/
|
||||
async function deriveKeys(
|
||||
salt: Uint8Array<ArrayBuffer>,
|
||||
@@ -251,7 +251,7 @@ const TRAILER_LINE = "-----END MEGOLM SESSION DATA-----";
|
||||
* Strips the header and trailer lines, and unbase64s the content
|
||||
*
|
||||
* @param {ArrayBuffer} data input file
|
||||
* @return {Uint8Array} unbase64ed content
|
||||
* @returns {Uint8Array} unbase64ed content
|
||||
*/
|
||||
function unpackMegolmKeyFile(data: ArrayBuffer): Uint8Array<ArrayBuffer> {
|
||||
// parse the file as a great big String. This should be safe, because there
|
||||
@@ -306,7 +306,7 @@ function unpackMegolmKeyFile(data: ArrayBuffer): Uint8Array<ArrayBuffer> {
|
||||
* base64s the content, and adds header and trailer lines
|
||||
*
|
||||
* @param {Uint8Array} data raw data
|
||||
* @return {ArrayBuffer} formatted file
|
||||
* @returns {ArrayBuffer} formatted file
|
||||
*/
|
||||
function packMegolmKeyFile(data: Uint8Array): ArrayBuffer {
|
||||
// we split into lines before base64ing, because encodeBase64 doesn't deal
|
||||
@@ -329,7 +329,7 @@ function packMegolmKeyFile(data: Uint8Array): ArrayBuffer {
|
||||
/**
|
||||
* Encode a typed array of uint8 as base64.
|
||||
* @param {Uint8Array} uint8Array The data to encode.
|
||||
* @return {string} The base64.
|
||||
* @returns {string} The base64.
|
||||
*/
|
||||
function encodeBase64(uint8Array: Uint8Array): string {
|
||||
// Misinterpt the Uint8Array as Latin-1.
|
||||
@@ -342,7 +342,7 @@ function encodeBase64(uint8Array: Uint8Array): string {
|
||||
/**
|
||||
* Decode a base64 string to a typed array of uint8.
|
||||
* @param {string} base64 The base64 to decode.
|
||||
* @return {Uint8Array} The decoded data.
|
||||
* @returns {Uint8Array} The decoded data.
|
||||
*/
|
||||
function decodeBase64(base64: string): Uint8Array<ArrayBuffer> {
|
||||
// window.atob returns a unicode string with codepoints in the range 0-255.
|
||||
|
||||
@@ -246,7 +246,7 @@ function renderDifferenceInDOM(originalRootNode: Node, diff: IDiff, diffMathPatc
|
||||
* Renders a message with the changes made in an edit shown visually.
|
||||
* @param {IContent} originalContent the content for the base message
|
||||
* @param {IContent} editContent the content for the edit message
|
||||
* @return {JSX.Element} a react element similar to what `bodyToHtml` returns
|
||||
* @returns {JSX.Element} a react element similar to what `bodyToHtml` returns
|
||||
*/
|
||||
export function editBodyDiffToHtml(originalContent: IContent, editContent: IContent): JSX.Element {
|
||||
// wrap the body in a div, DiffDOM needs a root element
|
||||
|
||||
@@ -33,7 +33,7 @@ export default class PinningUtils {
|
||||
* Determines if the given event can be pinned.
|
||||
* This is a simple check to see if the event is of a type that can be pinned.
|
||||
* @param {MatrixEvent} event The event to check.
|
||||
* @return {boolean} True if the event may be pinned, false otherwise.
|
||||
* @returns {boolean} True if the event may be pinned, false otherwise.
|
||||
*/
|
||||
public static isPinnable(event: MatrixEvent): boolean {
|
||||
if (event.isRedacted()) return false;
|
||||
@@ -43,7 +43,7 @@ export default class PinningUtils {
|
||||
/**
|
||||
* Determines if the given event may be unpinned.
|
||||
* @param {MatrixEvent} event The event to check.
|
||||
* @return {boolean} True if the event may be unpinned, false otherwise.
|
||||
* @returns {boolean} True if the event may be unpinned, false otherwise.
|
||||
*/
|
||||
public static isUnpinnable(event: MatrixEvent): boolean {
|
||||
if (!event) return false;
|
||||
|
||||
@@ -85,7 +85,7 @@ export function shouldDisplayReply(event: MatrixEvent): boolean {
|
||||
|
||||
export function addReplyToMessageContent(content: IContent, replyToEvent: MatrixEvent): void {
|
||||
content["m.relates_to"] = {
|
||||
...(content["m.relates_to"] || {}),
|
||||
...content["m.relates_to"],
|
||||
...makeReplyMixIn(replyToEvent),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ export async function upgradeRoom(
|
||||
parent.roomId,
|
||||
EventType.SpaceChild,
|
||||
{
|
||||
...(currentEv?.getContent() || {}), // copy existing attributes like suggested
|
||||
...currentEv?.getContent(), // copy existing attributes like suggested
|
||||
via: [cli.getDomain()!],
|
||||
},
|
||||
newRoomId,
|
||||
|
||||
@@ -105,7 +105,7 @@ export default class Timer {
|
||||
/**
|
||||
*promise that will resolve when the timer elapses,
|
||||
*or is rejected when abort is called
|
||||
*@return {Promise}
|
||||
*@returns {Promise}
|
||||
*/
|
||||
public finished(): Promise<void> {
|
||||
return this.deferred.promise;
|
||||
|
||||
@@ -44,7 +44,7 @@ export default class WidgetUtils {
|
||||
* (Does not apply to non-room-based / user widgets)
|
||||
* @param client The matrix client of the logged-in user
|
||||
* @param roomId -- The ID of the room to check
|
||||
* @return Boolean -- true if the user can modify widgets in this room
|
||||
* @returns Boolean -- true if the user can modify widgets in this room
|
||||
* @throws Error -- specifies the error reason
|
||||
*/
|
||||
public static canUserModifyWidgets(client: MatrixClient, roomId?: string): boolean {
|
||||
@@ -84,7 +84,7 @@ export default class WidgetUtils {
|
||||
* Returns true if specified url is a scalar URL, typically https://scalar.vector.im/api
|
||||
* @param matrixClient The matrix client of the logged-in user
|
||||
* @param {[type]} testUrlString URL to check
|
||||
* @return {Boolean} True if specified URL is a scalar URL
|
||||
* @returns {Boolean} True if specified URL is a scalar URL
|
||||
*/
|
||||
public static isScalarUrl(testUrlString?: string): boolean {
|
||||
if (!testUrlString) {
|
||||
@@ -339,7 +339,7 @@ export default class WidgetUtils {
|
||||
/**
|
||||
* Get room specific widgets
|
||||
* @param {Room} room The room to get widgets force
|
||||
* @return {[object]} Array containing current / active room widgets
|
||||
* @returns {[object]} Array containing current / active room widgets
|
||||
*/
|
||||
public static getRoomWidgets(room: Room): MatrixEvent[] {
|
||||
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
|
||||
@@ -356,7 +356,7 @@ export default class WidgetUtils {
|
||||
/**
|
||||
* Get user specific widgets (not linked to a specific room)
|
||||
* @param client The matrix client of the logged-in user
|
||||
* @return {object} Event content object containing current / active user widgets
|
||||
* @returns {object} Event content object containing current / active user widgets
|
||||
*/
|
||||
public static getUserWidgets(client: MatrixClient | undefined): Record<string, UserWidget> {
|
||||
if (!client) {
|
||||
@@ -372,7 +372,7 @@ export default class WidgetUtils {
|
||||
/**
|
||||
* Get user specific widgets (not linked to a specific room) as an array
|
||||
* @param client The matrix client of the logged-in user
|
||||
* @return {[object]} Array containing current / active user widgets
|
||||
* @returns {[object]} Array containing current / active user widgets
|
||||
*/
|
||||
public static getUserWidgetsArray(client: MatrixClient | undefined): UserWidget[] {
|
||||
return Object.values(WidgetUtils.getUserWidgets(client));
|
||||
@@ -381,7 +381,7 @@ export default class WidgetUtils {
|
||||
/**
|
||||
* Get active stickerpicker widgets (stickerpickers are user widgets by nature)
|
||||
* @param client The matrix client of the logged-in user
|
||||
* @return {[object]} Array containing current / active stickerpicker widgets
|
||||
* @returns {[object]} Array containing current / active stickerpicker widgets
|
||||
*/
|
||||
public static getStickerpickerWidgets(client: MatrixClient | undefined): UserWidget[] {
|
||||
const widgets = WidgetUtils.getUserWidgetsArray(client);
|
||||
@@ -401,7 +401,7 @@ export default class WidgetUtils {
|
||||
/**
|
||||
* Remove all stickerpicker widgets (stickerpickers are user widgets by nature)
|
||||
* @param client The matrix client of the logged-in user
|
||||
* @return {Promise} Resolves on account data updated
|
||||
* @returns {Promise} Resolves on account data updated
|
||||
*/
|
||||
public static async removeStickerpickerWidgets(client: MatrixClient | undefined): Promise<void> {
|
||||
if (!client) {
|
||||
|
||||
@@ -38,7 +38,7 @@ const MAX_HEIGHT = 600;
|
||||
* @param {number} inputHeight the width of the image in the input element.
|
||||
* @param {string} mimeType The mimeType to save the blob as.
|
||||
* @param {boolean} calculateBlurhash Whether to calculate a blurhash of the given image too.
|
||||
* @return {Promise} A promise that resolves with an object with an info key
|
||||
* @returns {Promise} A promise that resolves with an object with an info key
|
||||
* and a thumbnail key.
|
||||
*/
|
||||
export async function createThumbnail(
|
||||
|
||||
@@ -124,7 +124,7 @@ export async function waitForRoomReadyAndApplyAfterCreateCallbacks(
|
||||
*/
|
||||
async function applyAfterCreateCallbacks(localRoom: LocalRoom, roomId: string): Promise<void> {
|
||||
for (const afterCreateCallback of localRoom.afterCreateCallbacks) {
|
||||
await afterCreateCallback(roomId);
|
||||
afterCreateCallback(roomId);
|
||||
}
|
||||
|
||||
localRoom.afterCreateCallbacks = [];
|
||||
|
||||
@@ -102,7 +102,7 @@ export function attachMentions(
|
||||
export function attachRelation(content: IContent, relation?: IEventRelation): void {
|
||||
if (relation) {
|
||||
content["m.relates_to"] = {
|
||||
...(content["m.relates_to"] || {}),
|
||||
...content["m.relates_to"],
|
||||
...relation,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface EncryptedPickleKey {
|
||||
*
|
||||
* @param {string} userId The user ID who owns the pickle key.
|
||||
* @param {string} deviceId The device ID which owns the pickle key.
|
||||
* @return {Uint8Array} The additional data as a Uint8Array.
|
||||
* @returns {Uint8Array} The additional data as a Uint8Array.
|
||||
*/
|
||||
export function getPickleAdditionalData(userId: string, deviceId: string): Uint8Array<ArrayBuffer> {
|
||||
const additionalData = new Uint8Array(userId.length + deviceId.length + 1);
|
||||
|
||||
Reference in New Issue
Block a user