From 4ba1f91a2bf3a33252cbb5e7154ce412f9f11a2c Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Mon, 20 Jul 2020 20:43:49 +0100 Subject: [PATCH] Fix lint issues in new code --- src/@types/global.d.ts | 16 ++++++++-------- src/ContentMessages.tsx | 6 +++--- src/DeviceListener.ts | 4 ++-- src/PlatformPeg.ts | 6 +++--- src/RebrandListener.tsx | 4 ++-- src/createRoom.ts | 4 ++++ src/hooks/useAccountData.ts | 4 ++-- src/integrations/IntegrationManagers.ts | 9 +++++++-- src/notifications/ContentRules.ts | 2 +- src/notifications/types.ts | 3 +++ src/settings/watchers/FontWatcher.ts | 1 - src/stores/ToastStore.ts | 4 ++-- src/stores/room-list/RoomListLayoutStore.ts | 2 +- src/stores/room-list/RoomListStore.ts | 2 +- src/stores/room-list/algorithms/Algorithm.ts | 5 ++++- .../list-ordering/ImportanceAlgorithm.ts | 7 ++++++- .../algorithms/list-ordering/NaturalAlgorithm.ts | 6 +++++- .../algorithms/tag-sorting/RecentAlgorithm.ts | 2 +- yarn.lock | 12 +++++++++++- 19 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 76145c7e67..d79ca75f9f 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -33,14 +33,14 @@ declare global { init: () => Promise; }; - mx_ContentMessages: ContentMessages; - mx_ToastStore: ToastStore; - mx_DeviceListener: DeviceListener; - mx_RebrandListener: RebrandListener; - mx_RoomListStore: RoomListStoreClass; - mx_RoomListLayoutStore: RoomListLayoutStore; - mx_PlatformPeg: PlatformPeg; - mx_IntegrationManagers: typeof IntegrationManagers; + mxContentMessages: ContentMessages; + mxToastStore: ToastStore; + mxDeviceListener: DeviceListener; + mxRebrandListener: RebrandListener; + mxRoomListStore: RoomListStoreClass; + mxRoomListLayoutStore: RoomListLayoutStore; + mxPlatformPeg: PlatformPeg; + mxIntegrationManagers: typeof IntegrationManagers; } // workaround for https://github.com/microsoft/TypeScript/issues/30933 diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 25445b1c74..e0597f5e59 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -621,9 +621,9 @@ export default class ContentMessages { } static sharedInstance() { - if (window.mx_ContentMessages === undefined) { - window.mx_ContentMessages = new ContentMessages(); + if (window.mxContentMessages === undefined) { + window.mxContentMessages = new ContentMessages(); } - return window.mx_ContentMessages; + return window.mxContentMessages; } } diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index e9001d43b4..a37521118f 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -48,8 +48,8 @@ export default class DeviceListener { private displayingToastsForDeviceIds = new Set(); static sharedInstance() { - if (!window.mx_DeviceListener) window.mx_DeviceListener = new DeviceListener(); - return window.mx_DeviceListener; + if (!window.mxDeviceListener) window.mxDeviceListener = new DeviceListener(); + return window.mxDeviceListener; } start() { diff --git a/src/PlatformPeg.ts b/src/PlatformPeg.ts index c14e11145b..1d2b813ebc 100644 --- a/src/PlatformPeg.ts +++ b/src/PlatformPeg.ts @@ -45,7 +45,7 @@ export class PlatformPeg { } } -if (!window.mx_PlatformPeg) { - window.mx_PlatformPeg = new PlatformPeg(); +if (!window.mxPlatformPeg) { + window.mxPlatformPeg = new PlatformPeg(); } -export default window.mx_PlatformPeg; +export default window.mxPlatformPeg; diff --git a/src/RebrandListener.tsx b/src/RebrandListener.tsx index a93ce9e3a5..283f74d743 100644 --- a/src/RebrandListener.tsx +++ b/src/RebrandListener.tsx @@ -67,8 +67,8 @@ export default class RebrandListener { private nagAgainAt?: number = null; static sharedInstance() { - if (!window.mx_RebrandListener) window.mx_RebrandListener = new RebrandListener(); - return window.mx_RebrandListener; + if (!window.mxRebrandListener) window.mxRebrandListener = new RebrandListener(); + return window.mxRebrandListener; } constructor() { diff --git a/src/createRoom.ts b/src/createRoom.ts index c436196c27..ec84ed8316 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -29,6 +29,9 @@ import {getAddressType} from "./UserAddress"; const E2EE_WK_KEY = "im.vector.riot.e2ee"; +// we define a number of interfaces which in effect take their names from the js-sdk +/* eslint-disable camelcase */ + // TODO move these interfaces over to js-sdk once it has been typescripted enough to accept them enum Visibility { Public = "public", @@ -42,6 +45,7 @@ enum Preset { } interface Invite3PID { + id_server: string; id_access_token?: string; // this gets injected by the js-sdk medium: string; diff --git a/src/hooks/useAccountData.ts b/src/hooks/useAccountData.ts index dd0d53f0d3..fe71ed9ecd 100644 --- a/src/hooks/useAccountData.ts +++ b/src/hooks/useAccountData.ts @@ -30,7 +30,7 @@ export const useAccountData = (cli: MatrixClient, eventType: strin const handler = useCallback((event) => { if (event.getType() !== eventType) return; setValue(event.getContent()); - }, [cli, eventType]); + }, [eventType]); useEventEmitter(cli, "accountData", handler); return value || {} as T; @@ -43,7 +43,7 @@ export const useRoomAccountData = (room: Room, eventType: string) const handler = useCallback((event) => { if (event.getType() !== eventType) return; setValue(event.getContent()); - }, [room, eventType]); + }, [eventType]); useEventEmitter(room, "Room.accountData", handler); return value || {} as T; diff --git a/src/integrations/IntegrationManagers.ts b/src/integrations/IntegrationManagers.ts index 4d90d4871d..1791e92514 100644 --- a/src/integrations/IntegrationManagers.ts +++ b/src/integrations/IntegrationManagers.ts @@ -123,7 +123,12 @@ export class IntegrationManagers { const apiUrl = data['api_url']; if (!apiUrl || !uiUrl) return; - const manager = new IntegrationManagerInstance(Kind.Account, apiUrl, uiUrl, w['id'] || w['state_key'] || ''); + const manager = new IntegrationManagerInstance( + Kind.Account, + apiUrl, + uiUrl, + w['id'] || w['state_key'] || '', + ); this.managers.push(manager); }); this.primaryManager = null; // reset primary @@ -245,4 +250,4 @@ export class IntegrationManagers { } // For debugging -window.mx_IntegrationManagers = IntegrationManagers; +window.mxIntegrationManagers = IntegrationManagers; diff --git a/src/notifications/ContentRules.ts b/src/notifications/ContentRules.ts index a3ec017e37..cd574e12b6 100644 --- a/src/notifications/ContentRules.ts +++ b/src/notifications/ContentRules.ts @@ -16,7 +16,7 @@ limitations under the License. */ import {PushRuleVectorState, State} from "./PushRuleVectorState"; -import {IExtendedPushRule, IPushRuleSet, IRuleSets} from "./types"; +import {IExtendedPushRule, IRuleSets} from "./types"; export interface IContentRules { vectorState: State; diff --git a/src/notifications/types.ts b/src/notifications/types.ts index 9622193740..ea46552947 100644 --- a/src/notifications/types.ts +++ b/src/notifications/types.ts @@ -22,10 +22,12 @@ export enum NotificationSetting { } export interface ISoundTweak { + // eslint-disable-next-line camelcase set_tweak: "sound"; value: string; } export interface IHighlightTweak { + // eslint-disable-next-line camelcase set_tweak: "highlight"; value?: boolean; } @@ -86,6 +88,7 @@ export enum RuleIds { export interface IPushRule { enabled: boolean; + // eslint-disable-next-line camelcase rule_id: RuleIds | string; actions: Action[]; default: boolean; diff --git a/src/settings/watchers/FontWatcher.ts b/src/settings/watchers/FontWatcher.ts index 9af5156704..53ef999f9b 100644 --- a/src/settings/watchers/FontWatcher.ts +++ b/src/settings/watchers/FontWatcher.ts @@ -19,7 +19,6 @@ import SettingsStore, {SettingLevel} from '../SettingsStore'; import IWatcher from "./Watcher"; import { toPx } from '../../utils/units'; import { Action } from '../../dispatcher/actions'; -import { UpdateSystemFontPayload } from '../../dispatcher/payloads/UpdateSystemFontPayload'; export class FontWatcher implements IWatcher { public static readonly MIN_SIZE = 8; diff --git a/src/stores/ToastStore.ts b/src/stores/ToastStore.ts index 7063ba541a..afb9fe1f8c 100644 --- a/src/stores/ToastStore.ts +++ b/src/stores/ToastStore.ts @@ -37,8 +37,8 @@ export default class ToastStore extends EventEmitter { private countSeen = 0; static sharedInstance() { - if (!window.mx_ToastStore) window.mx_ToastStore = new ToastStore(); - return window.mx_ToastStore; + if (!window.mxToastStore) window.mxToastStore = new ToastStore(); + return window.mxToastStore; } reset() { diff --git a/src/stores/room-list/RoomListLayoutStore.ts b/src/stores/room-list/RoomListLayoutStore.ts index fbc7d7719d..1443448a64 100644 --- a/src/stores/room-list/RoomListLayoutStore.ts +++ b/src/stores/room-list/RoomListLayoutStore.ts @@ -70,4 +70,4 @@ export default class RoomListLayoutStore extends AsyncStoreWithClient { } } -window.mx_RoomListLayoutStore = RoomListLayoutStore.instance; +window.mxRoomListLayoutStore = RoomListLayoutStore.instance; diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index 0cb1e094b1..28d757bb89 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -606,4 +606,4 @@ export default class RoomListStore { } } -window.mx_RoomListStore = RoomListStore.instance; +window.mxRoomListStore = RoomListStore.instance; diff --git a/src/stores/room-list/algorithms/Algorithm.ts b/src/stores/room-list/algorithms/Algorithm.ts index 62d387c9d9..488dc1d1e5 100644 --- a/src/stores/room-list/algorithms/Algorithm.ts +++ b/src/stores/room-list/algorithms/Algorithm.ts @@ -419,7 +419,9 @@ export class Algorithm extends EventEmitter { if (!updatedTag || updatedTag === sticky.tag) { if (SettingsStore.getValue("advancedRoomListLogging")) { // TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14602 - console.log(`Inserting sticky room ${sticky.room.roomId} at position ${sticky.position} in ${sticky.tag}`); + console.log( + `Inserting sticky room ${sticky.room.roomId} at position ${sticky.position} in ${sticky.tag}`, + ); } this._cachedStickyRooms[sticky.tag].splice(sticky.position, 0, sticky.room); } @@ -823,6 +825,7 @@ export class Algorithm extends EventEmitter { // Flag that we've done something this.recalculateFilteredRoomsForTag(tag); // update filter to re-sort the list this.recalculateStickyRoom(tag); // update sticky room to make sure it appears if needed + changed = true; } if (SettingsStore.getValue("advancedRoomListLogging")) { diff --git a/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts b/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts index 0376c10915..4e9959a5ca 100644 --- a/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts +++ b/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts @@ -218,7 +218,12 @@ export class ImportanceAlgorithm extends OrderingAlgorithm { } // noinspection JSMethodCanBeStatic - private moveRoomIndexes(nRooms: number, fromCategory: NotificationColor, toCategory: NotificationColor, indices: ICategoryIndex) { + private moveRoomIndexes( + nRooms: number, + fromCategory: NotificationColor, + toCategory: NotificationColor, + indices: ICategoryIndex, + ) { // We have to update the index of the category *after* the from/toCategory variables // in order to update the indices correctly. Because the room is moving from/to those // categories, the next category's index will change - not the category we're modifying. diff --git a/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts b/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts index e441bbab92..5759f0c32d 100644 --- a/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts +++ b/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts @@ -56,7 +56,11 @@ export class NaturalAlgorithm extends OrderingAlgorithm { // TODO: Optimize this to avoid useless operations: https://github.com/vector-im/riot-web/issues/14457 // For example, we can skip updates to alphabetic (sometimes) and manually ordered tags - this.cachedOrderedRooms = await sortRoomsWithAlgorithm(this.cachedOrderedRooms, this.tagId, this.sortingAlgorithm); + this.cachedOrderedRooms = await sortRoomsWithAlgorithm( + this.cachedOrderedRooms, + this.tagId, + this.sortingAlgorithm, + ); return true; } finally { diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 0a8beac231..59c04b0665 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -26,7 +26,7 @@ import { EffectiveMembership, getEffectiveMembership } from "../../../../utils/m * useful to the user. */ export class RecentAlgorithm implements IAlgorithm { - public async sortRooms(rooms: Room[], _: TagID): Promise { + public async sortRooms(rooms: Room[], tagID: TagID): Promise { // We cache the timestamp lookup to avoid iterating forever on the timeline // of events. This cache only survives a single sort though. // We wouldn't need this if `.sort()` didn't constantly try and compare all diff --git a/yarn.lock b/yarn.lock index e1181dc22c..f46d7a6c40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1264,11 +1264,21 @@ resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.10.tgz#cc658ca319b6355399efc1f5b9e818f1a24bf999" integrity sha512-1UzDldn9GfYYEsWWnn/P4wkTlkZDH7lDb0wBMGbtIQc9zXEQq7FlKBdZUn6OBqD8sKZZ2RQO2mAjGpXiDGoRmQ== +"@types/color-name@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" + integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== + "@types/counterpart@^0.18.1": version "0.18.1" resolved "https://registry.yarnpkg.com/@types/counterpart/-/counterpart-0.18.1.tgz#b1b784d9e54d9879f0a8cb12f2caedab65430fe8" integrity sha512-PRuFlBBkvdDOtxlIASzTmkEFar+S66Ek48NVVTWMUjtJAdn5vyMSN8y6IZIoIymGpR36q2nZbIYazBWyFxL+IQ== +"@types/eslint-visitor-keys@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" + integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== + "@types/fbemitter@*": version "2.0.32" resolved "https://registry.yarnpkg.com/@types/fbemitter/-/fbemitter-2.0.32.tgz#8ed204da0f54e9c8eaec31b1eec91e25132d082c" @@ -5779,7 +5789,7 @@ lodash.sortby@^4.7.0: resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= -lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.2.1: +lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.2.1: version "4.17.19" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==