From f4b4416ea52d564bc2dbe543a82084ed98843ccc Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Fri, 30 Jul 2021 10:54:54 +0200 Subject: chore: migrate from tslint to @typescript-eslint (#1706) - update .eslintrc to work for .js and .ts - update devDependencies - lint properly both root /src and nested /packages - update webhint recommended setting for tsconfig.json to shrink output - Manage all eslint rules from the repo root - escape single quotes in scripts to please windows build Co-authored-by: Vijay A --- src/stores/AppStore.js | 105 +++++++++++++++++++++++--------------- src/stores/NewsStore.js | 2 +- src/stores/RecipePreviewsStore.js | 2 +- src/stores/RecipesStore.js | 8 +-- src/stores/ServicesStore.js | 44 ++++++++-------- src/stores/UIStore.js | 2 +- src/stores/UserStore.js | 4 +- src/stores/lib/CachedRequest.js | 4 +- src/stores/lib/Reaction.js | 4 +- src/stores/lib/Request.js | 2 +- src/stores/lib/Store.js | 6 +-- 11 files changed, 104 insertions(+), 79 deletions(-) (limited to 'src/stores') diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index bbb5e6305..6b5ca7c9a 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -1,6 +1,11 @@ import { ipcRenderer, shell } from 'electron'; import { - app, screen, powerMonitor, nativeTheme, getCurrentWindow, process as remoteProcess, + app, + screen, + powerMonitor, + nativeTheme, + getCurrentWindow, + process as remoteProcess, } from '@electron/remote'; import { action, computed, observable } from 'mobx'; import moment from 'moment'; @@ -14,13 +19,20 @@ import Store from './lib/Store'; import Request from './lib/Request'; import { CHECK_INTERVAL } from '../config'; import { - DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion, osRelease, + DEFAULT_APP_SETTINGS, + isMac, + ferdiVersion, + electronVersion, + osRelease, } from '../environment'; import locales from '../i18n/translations'; import { onVisibilityChange } from '../helpers/visibility-helper'; import { getLocale } from '../helpers/i18n-helpers'; -import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; +import { + getServiceIdsFromPartitions, + removeServicePartitionDirectory, +} from '../helpers/service-helpers'; import { isValidExternalURL } from '../helpers/url-helpers'; import { sleep } from '../helpers/async-helpers'; @@ -49,7 +61,10 @@ export default class AppStore extends Store { @observable healthCheckRequest = new Request(this.api.app, 'health'); - @observable getAppCacheSizeRequest = new Request(this.api.local, 'getAppCacheSize'); + @observable getAppCacheSizeRequest = new Request( + this.api.local, + 'getAppCacheSize', + ); @observable clearAppCacheRequest = new Request(this.api.local, 'clearCache'); @@ -93,7 +108,9 @@ export default class AppStore extends Store { this.actions.app.openExternalUrl.listen(this._openExternalUrl.bind(this)); this.actions.app.checkForUpdates.listen(this._checkForUpdates.bind(this)); this.actions.app.installUpdate.listen(this._installUpdate.bind(this)); - this.actions.app.resetUpdateStatus.listen(this._resetUpdateStatus.bind(this)); + this.actions.app.resetUpdateStatus.listen( + this._resetUpdateStatus.bind(this), + ); this.actions.app.healthCheck.listen(this._healthCheck.bind(this)); this.actions.app.muteApp.listen(this._muteApp.bind(this)); this.actions.app.toggleMuteApp.listen(this._toggleMuteApp.bind(this)); @@ -183,9 +200,7 @@ export default class AppStore extends Store { // Handle deep linking (ferdi://) ipcRenderer.on('navigateFromDeepLink', (event, data) => { debug('Navigate from deep link', data); - let { - url, - } = data; + let { url } = data; if (!url) return; url = url.replace(/\/$/, ''); @@ -221,7 +236,10 @@ export default class AppStore extends Store { debug('System resumed, last suspended on', this.timeSuspensionStart); this.actions.service.resetLastPollTimer(); - if (this.timeSuspensionStart.add(10, 'm').isBefore(moment()) && this.stores.settings.app.get('reloadAfterResume')) { + if ( + this.timeSuspensionStart.add(10, 'm').isBefore(moment()) + && this.stores.settings.app.get('reloadAfterResume') + ) { debug('Reloading services, user info and features'); setInterval(() => { @@ -266,15 +284,15 @@ export default class AppStore extends Store { ferdi: { version: ferdiVersion, electron: electronVersion, - installedRecipes: this.stores.recipes.all.map(recipe => ({ + installedRecipes: this.stores.recipes.all.map((recipe) => ({ id: recipe.id, version: recipe.version, })), - devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ + devRecipes: this.stores.recipePreviews.dev.map((recipe) => ({ id: recipe.id, version: recipe.version, })), - services: this.stores.services.all.map(service => ({ + services: this.stores.services.all.map((service) => ({ id: service.id, recipe: service.recipe.id, isAttached: service.isAttached, @@ -285,11 +303,13 @@ export default class AppStore extends Store { isDarkModeEnabled: service.isDarkModeEnabled, })), messages: this.stores.globalError.messages, - workspaces: this.stores.workspaces.workspaces.map(workspace => ({ + workspaces: this.stores.workspaces.workspaces.map((workspace) => ({ id: workspace.id, services: workspace.services, })), - windowSettings: readJsonSync(path.join(app.getPath('userData'), 'window-state.json')), + windowSettings: readJsonSync( + path.join(app.getPath('userData'), 'window-state.json'), + ), settings, features: this.stores.features.features, user: this.stores.user.data.id, @@ -299,10 +319,7 @@ export default class AppStore extends Store { // Actions @action _notify({ - title, - options, - notificationId, - serviceId = null, + title, options, notificationId, serviceId = null, }) { if (this.stores.settings.all.app.isAppMuted) return; @@ -339,15 +356,15 @@ export default class AppStore extends Store { }; } - @action _setBadge({ - unreadDirectMessageCount, - unreadIndirectMessageCount, - }) { + @action _setBadge({ unreadDirectMessageCount, unreadIndirectMessageCount }) { let indicator = unreadDirectMessageCount; if (indicator === 0 && unreadIndirectMessageCount !== 0) { indicator = '•'; - } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) { + } else if ( + unreadDirectMessageCount === 0 + && unreadIndirectMessageCount === 0 + ) { indicator = 0; } else { indicator = parseInt(indicator, 10); @@ -358,9 +375,7 @@ export default class AppStore extends Store { }); } - @action _launchOnStartup({ - enable, - }) { + @action _launchOnStartup({ enable }) { this.autoLaunchOnStart = enable; try { @@ -376,9 +391,7 @@ export default class AppStore extends Store { } } - @action _openExternalUrl({ - url, - }) { + @action _openExternalUrl({ url }) { const parsedUrl = new URL(url); debug('open external url', parsedUrl); @@ -414,10 +427,7 @@ export default class AppStore extends Store { this.healthCheckRequest.execute(); } - @action _muteApp({ - isMuted, - overrideSystemMute = true, - }) { + @action _muteApp({ isMuted, overrideSystemMute = true }) { this.isSystemMuteOverridden = overrideSystemMute; this.actions.settings.update({ type: 'app', @@ -437,16 +447,24 @@ export default class AppStore extends Store { this.isClearingAllCache = true; const clearAppCache = this.clearAppCacheRequest.execute(); const allServiceIds = await getServiceIdsFromPartitions(); - const allOrphanedServiceIds = allServiceIds.filter(id => !this.stores.services.all.find(s => id.replace('service-', '') === s.id)); + const allOrphanedServiceIds = allServiceIds.filter( + (id) => !this.stores.services.all.find( + (s) => id.replace('service-', '') === s.id, + ), + ); try { - await Promise.all(allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id))); + await Promise.all( + allOrphanedServiceIds.map((id) => removeServicePartitionDirectory(id)), + ); } catch (ex) { console.log('Error while deleting service partition directory - ', ex); } - await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ - serviceId: s.id, - }))); + await Promise.all( + this.stores.services.all.map((s) => this.actions.service.clearCache({ + serviceId: s.id, + })), + ); await clearAppCache._promise; @@ -476,7 +494,11 @@ export default class AppStore extends Store { locale = this.stores.user.data.locale; } - if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { + if ( + locale + && Object.prototype.hasOwnProperty.call(locales, locale) + && locale !== this.locale + ) { this.locale = locale; } else if (!locale) { this.locale = this._getDefaultLocale(); @@ -553,7 +575,10 @@ export default class AppStore extends Store { const dnd = await ipcRenderer.invoke('get-dnd'); debug('Do not disturb mode is', dnd); // ipcRenderer.on('autoUpdate', (event, data) => { - if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { + if ( + dnd !== this.stores.settings.all.app.isAppMuted + && !this.isSystemMuteOverridden + ) { this.actions.app.muteApp({ isMuted: dnd, overrideSystemMute: false, diff --git a/src/stores/NewsStore.js b/src/stores/NewsStore.js index 86e092592..66a17cb29 100644 --- a/src/stores/NewsStore.js +++ b/src/stores/NewsStore.js @@ -38,7 +38,7 @@ export default class NewsStore extends Store { this.latestNewsRequest.invalidate().patch((result) => { // TODO: check if we can use mobx.array remove - remove(result, n => n.id === newsId); + remove(result, (n) => n.id === newsId); }); } diff --git a/src/stores/RecipePreviewsStore.js b/src/stores/RecipePreviewsStore.js index 989e1124a..10c170e81 100644 --- a/src/stores/RecipePreviewsStore.js +++ b/src/stores/RecipePreviewsStore.js @@ -31,7 +31,7 @@ export default class RecipePreviewsStore extends Store { } @computed get dev() { - return this.stores.recipes.all.filter(r => r.local); + return this.stores.recipes.all.filter((r) => r.local); } // Actions diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index b49fb72d9..c7c4c1deb 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js @@ -54,11 +54,11 @@ export default class RecipesStore extends Store { } @computed get recipeIdForServices() { - return this.stores.services.all.map(s => s.recipe.id); + return this.stores.services.all.map((s) => s.recipe.id); } one(id) { - return this.all.find(recipe => recipe.id === id); + return this.all.find((recipe) => recipe.id === id); } isInstalled(id) { @@ -78,7 +78,7 @@ export default class RecipesStore extends Store { const recipes = {}; // Hackfix, reference this.all to fetch services - debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); + debug(`Check Recipe updates for ${this.all.map((recipe) => recipe.id)}`); recipeIds.forEach((r) => { const recipe = this.one(r); @@ -98,7 +98,7 @@ export default class RecipesStore extends Store { const version = recipes[recipe]; // Find recipe in local recipe repository - const localRecipe = allJson.find(r => r.id === recipe); + const localRecipe = allJson.find((r) => r.id === recipe); if (localRecipe && semver.lt(version, localRecipe.version)) { localUpdates.push(recipe); diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index fa31dc292..fefcb5080 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -216,7 +216,7 @@ export default class ServicesStore extends Store { } @computed get enabled() { - return this.all.filter(service => service.isEnabled); + return this.all.filter((service) => service.isEnabled); } @computed get allDisplayed() { @@ -229,7 +229,7 @@ export default class ServicesStore extends Store { const { showDisabledServices } = this.stores.settings.all.app; const { keepAllWorkspacesLoaded } = this.stores.workspaces.settings; const services = this.allServicesRequest.execute().result || []; - const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled); + const filteredServices = showDisabledServices ? services : services.filter((service) => service.isEnabled); let displayedServices; if (keepAllWorkspacesLoaded) { @@ -244,8 +244,8 @@ export default class ServicesStore extends Store { // Check if workspace needs to be kept loaded if (workspace.services.includes(KEEP_WS_LOADED_USID)) { // Get services for workspace - const serviceIDs = workspace.services.filter(i => i !== KEEP_WS_LOADED_USID); - const wsServices = filteredServices.filter(service => serviceIDs.includes(service.id)); + const serviceIDs = workspace.services.filter((i) => i !== KEEP_WS_LOADED_USID); + const wsServices = filteredServices.filter((service) => serviceIDs.includes(service.id)); displayedServices = [ ...displayedServices, @@ -262,11 +262,11 @@ export default class ServicesStore extends Store { } @computed get filtered() { - return this.all.filter(service => service.name.toLowerCase().includes(this.filterNeedle.toLowerCase())); + return this.all.filter((service) => service.name.toLowerCase().includes(this.filterNeedle.toLowerCase())); } @computed get active() { - return this.all.find(service => service.isActive); + return this.all.find((service) => service.isActive); } @computed get activeSettings() { @@ -284,7 +284,7 @@ export default class ServicesStore extends Store { } @computed get isTodosServiceAdded() { - return this.allDisplayed.find(service => service.isTodosService && service.isEnabled) || false; + return this.allDisplayed.find((service) => service.isTodosService && service.isEnabled) || false; } @computed get isTodosServiceActive() { @@ -292,7 +292,7 @@ export default class ServicesStore extends Store { } one(id) { - return this.all.find(service => service.id === id); + return this.all.find((service) => service.id === id); } async _showAddServiceInterface({ recipeId }) { @@ -400,7 +400,7 @@ export default class ServicesStore extends Store { newData.iconUrl = data.customIconUrl; } - Object.assign(result.find(c => c.id === serviceId), newData); + Object.assign(result.find((c) => c.id === serviceId), newData); }); await request._promise; @@ -434,7 +434,7 @@ export default class ServicesStore extends Store { } this.allServicesRequest.patch((result) => { - remove(result, c => c.id === serviceId); + remove(result, (c) => c.id === serviceId); }); await request._promise; @@ -493,7 +493,7 @@ export default class ServicesStore extends Store { } // Update list of last used services - this.lastUsedServices = this.lastUsedServices.filter(id => id !== serviceId); + this.lastUsedServices = this.lastUsedServices.filter((id) => id !== serviceId); this.lastUsedServices.unshift(serviceId); this._focusActiveService(); @@ -505,7 +505,7 @@ export default class ServicesStore extends Store { } @action _setActiveNext() { - const nextIndex = this._wrapIndex(this.allDisplayed.findIndex(service => service.isActive), 1, this.allDisplayed.length); + const nextIndex = this._wrapIndex(this.allDisplayed.findIndex((service) => service.isActive), 1, this.allDisplayed.length); // TODO: simplify this; this.all.forEach((s, index) => { @@ -515,7 +515,7 @@ export default class ServicesStore extends Store { } @action _setActivePrev() { - const prevIndex = this._wrapIndex(this.allDisplayed.findIndex(service => service.isActive), -1, this.allDisplayed.length); + const prevIndex = this._wrapIndex(this.allDisplayed.findIndex((service) => service.isActive), -1, this.allDisplayed.length); // TODO: simplify this; this.all.forEach((s, index) => { @@ -689,7 +689,7 @@ export default class ServicesStore extends Store { } @action _sendIPCMessageToAllServices({ channel, args }) { - this.all.forEach(s => this.actions.service.sendIPCMessage({ + this.all.forEach((s) => this.actions.service.sendIPCMessage({ serviceId: s.id, channel, args, @@ -740,7 +740,7 @@ export default class ServicesStore extends Store { } @action _reloadAll() { - this.enabled.forEach(s => this._reload({ + this.enabled.forEach((s) => this._reload({ serviceId: s.id, })); } @@ -859,7 +859,7 @@ export default class ServicesStore extends Store { }; if (!serviceId) { - this.allDisplayed.forEach(service => resetTimer(service)); + this.allDisplayed.forEach((service) => resetTimer(service)); } else { const service = this.one(serviceId); if (service) { @@ -893,7 +893,7 @@ export default class ServicesStore extends Store { _mapActiveServiceToServiceModelReaction() { const { activeService } = this.stores.settings.all.service; if (this.allDisplayed.length) { - this.allDisplayed.map(service => Object.assign(service, { + this.allDisplayed.map((service) => Object.assign(service, { isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, })); } @@ -904,13 +904,13 @@ export default class ServicesStore extends Store { const { showMessageBadgesEvenWhenMuted } = this.stores.ui; const unreadDirectMessageCount = this.allDisplayed - .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) - .map(s => s.unreadDirectMessageCount) + .filter((s) => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) + .map((s) => s.unreadDirectMessageCount) .reduce((a, b) => a + b, 0); const unreadIndirectMessageCount = this.allDisplayed - .filter(s => (showMessageBadgeWhenMuted && showMessageBadgesEvenWhenMuted) && (s.isBadgeEnabled && s.isIndirectMessageBadgeEnabled)) - .map(s => s.unreadIndirectMessageCount) + .filter((s) => (showMessageBadgeWhenMuted && showMessageBadgesEvenWhenMuted) && (s.isBadgeEnabled && s.isIndirectMessageBadgeEnabled)) + .map((s) => s.unreadIndirectMessageCount) .reduce((a, b) => a + b, 0); // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases @@ -975,7 +975,7 @@ export default class ServicesStore extends Store { return; } - if (this.allDisplayed.findIndex(service => service.isActive) === -1 && this.allDisplayed.length !== 0) { + if (this.allDisplayed.findIndex((service) => service.isActive) === -1 && this.allDisplayed.length !== 0) { debug('No active service found, setting active service to index 0'); this._setActive({ serviceId: this.allDisplayed[0].id }); diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js index 0ca61046a..adcd776c1 100644 --- a/src/stores/UIStore.js +++ b/src/stores/UIStore.js @@ -71,7 +71,7 @@ export default class UIStore extends Store { @computed get theme() { const themeId = (this.isDarkThemeActive || this.stores.settings.app.darkMode) ? 'dark' : 'default'; - const accentColor = this.stores.settings.app.accentColor; + const { accentColor } = this.stores.settings.app; return theme(themeId, accentColor); } diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 8a525c2ef..2e009893a 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js @@ -205,7 +205,7 @@ export default class UserStore extends Store { } @action async _invite({ invites }) { - const data = invites.filter(invite => invite.email !== ''); + const data = invites.filter((invite) => invite.email !== ''); const response = await this.inviteRequest.execute(data)._promise; @@ -250,7 +250,7 @@ export default class UserStore extends Store { this.isImportLegacyServicesExecuting = true; // Reduces recipe duplicates - const recipes = services.filter((obj, pos, arr) => arr.map(mapObj => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map(s => s.recipe.id); + const recipes = services.filter((obj, pos, arr) => arr.map((mapObj) => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map((s) => s.recipe.id); // Install recipes for (const recipe of recipes) { // eslint-disable-line no-unused-vars diff --git a/src/stores/lib/CachedRequest.js b/src/stores/lib/CachedRequest.js index 31c7ce241..94f615144 100644 --- a/src/stores/lib/CachedRequest.js +++ b/src/stores/lib/CachedRequest.js @@ -92,7 +92,7 @@ export default class CachedRequest extends Request { } removeCacheForCallWith(...args) { - remove(this._apiCalls, c => isEqual(c.args, args)); + remove(this._apiCalls, (c) => isEqual(c.args, args)); } _addApiCall(args) { @@ -102,6 +102,6 @@ export default class CachedRequest extends Request { } _findApiCall(args) { - return this._apiCalls.find(c => isEqual(c.args, args)); + return this._apiCalls.find((c) => isEqual(c.args, args)); } } diff --git a/src/stores/lib/Reaction.js b/src/stores/lib/Reaction.js index f8009b7f6..7e1bc685e 100644 --- a/src/stores/lib/Reaction.js +++ b/src/stores/lib/Reaction.js @@ -26,6 +26,6 @@ export default class Reaction { } } -export const createReactions = reactions => ( - reactions.map(r => new Reaction(r)) +export const createReactions = (reactions) => ( + reactions.map((r) => new Reaction(r)) ); diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index cfc857c2e..32ffe4367 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js @@ -107,7 +107,7 @@ export default class Request { } _triggerHooks() { - Request._hooks.forEach(hook => hook(this)); + Request._hooks.forEach((hook) => hook(this)); } reset = () => { diff --git a/src/stores/lib/Store.js b/src/stores/lib/Store.js index 8d2fb4066..b03a7e725 100644 --- a/src/stores/lib/Store.js +++ b/src/stores/lib/Store.js @@ -28,18 +28,18 @@ export default class Store { } registerReactions(reactions) { - reactions.forEach(reaction => this._reactions.push(new Reaction(reaction))); + reactions.forEach((reaction) => this._reactions.push(new Reaction(reaction))); } setup() {} initialize() { this.setup(); - this._reactions.forEach(reaction => reaction.start()); + this._reactions.forEach((reaction) => reaction.start()); } teardown() { - this._reactions.forEach(reaction => reaction.stop()); + this._reactions.forEach((reaction) => reaction.stop()); } resetStatus() { -- cgit v1.2.3-54-g00ecf