From 9f8a1f08be181247e44202e38bd0c8d357aaaf73 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Wed, 15 Aug 2018 09:01:47 +0300 Subject: [PATCH] Update eslint rules --- .eslintrc.json | 41 ++++++++++ .eslintrc.yml | 21 ----- client/src/builtin/E2EE.js | 21 +++-- client/src/builtin/EmoteModule.js | 8 +- client/src/builtin/ReactDevtoolsModule.js | 2 +- client/src/builtin/VueDevToolsModule.js | 2 +- client/src/modules/contentmanager.js | 10 +-- client/src/modules/csseditor.js | 10 +-- client/src/modules/eventhook.js | 4 +- client/src/modules/eventlistener.js | 2 +- client/src/modules/eventswrapper.js | 4 +- client/src/modules/modulemanager.js | 2 +- client/src/modules/pluginapi.js | 14 ++-- client/src/modules/pluginmanager.js | 4 +- client/src/modules/reactcomponents.js | 26 +++---- client/src/modules/settings.js | 4 +- client/src/modules/theme.js | 4 +- client/src/modules/thememanager.js | 10 +-- client/src/modules/webpackmodules.js | 76 +++++++++---------- client/src/structs/discord/channel.js | 18 ++--- client/src/structs/discord/message.js | 18 ++--- client/src/structs/discord/user.js | 4 +- client/src/structs/list.js | 8 +- .../src/structs/settings/settingscategory.js | 10 +-- client/src/structs/settings/settingsscheme.js | 4 +- client/src/structs/settings/settingsset.js | 16 ++-- client/src/structs/settings/types/array.js | 12 +-- .../src/structs/settings/types/basesetting.js | 2 +- client/src/structs/settings/types/file.js | 2 +- client/src/structs/settings/types/guild.js | 6 +- client/src/structs/settings/types/keybind.js | 2 +- client/src/ui/bdmenu.js | 2 +- client/src/ui/classnormaliser.js | 10 +-- client/src/ui/dom.js | 6 +- client/src/ui/modals.js | 14 ++-- client/src/ui/profilebadges.js | 2 +- client/src/ui/reflection.js | 2 +- common/modules/async-eventemitter.js | 2 +- common/modules/bdipc.js | 2 +- common/modules/utils.js | 24 +++--- core/src/main.js | 8 +- core/src/modules/bdipc.js | 2 +- core/src/modules/database.js | 8 +- core/src/sparkplug.js | 2 +- package-lock.json | 4 +- package.json | 1 + 46 files changed, 235 insertions(+), 221 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 .eslintrc.yml diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..6b5a1f49 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,41 @@ +{ + "parserOptions": { + "ecmaVersion": 8, + "sourceType": "module" + }, + "env": { + "browser": true, + "node": true + }, + "plugins": [ + "vue" + ], + "extends": [ + "eslint:recommended", + "plugin:vue/recommended" + ], + "rules": { + "no-unused-vars": "off", + "no-console": "off", + "no-empty": "off", + "quotes": [ + "error", + "single", + { "allowTemplateLiterals": true } + ], + "prefer-template": "warn", + "no-return-await": "error", + "indent": [ "error", 4 ], + "no-lonely-if": "error", + "no-multiple-empty-lines": [ + "warn", + { "max": 1 } + ], + "no-tabs": "error", + "no-trailing-spaces": "error", + "no-unneeded-ternary": "error", + "no-useless-constructor": "warn", + "no-var": "error", + "prefer-const": "error" + } +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 2f68afd1..00000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- - -parserOptions: - ecmaVersion: 8 - sourceType: module - -env: - browser: true - node: true - -plugins: - - vue - -extends: - - eslint:recommended - - plugin:vue/recommended - -rules: - no-unused-vars: 'off' - no-console: 'off' - no-empty: 'off' diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js index da77d0cb..f0babf9a 100644 --- a/client/src/builtin/E2EE.js +++ b/client/src/builtin/E2EE.js @@ -19,8 +19,8 @@ import E2EEComponent from './E2EEComponent.vue'; import E2EEMessageButton from './E2EEMessageButton.vue'; import nodecrypto from 'node-crypto'; -const userMentionPattern = new RegExp(`<@!?([0-9]{10,})>`, "g"); -const roleMentionPattern = new RegExp(`<@&([0-9]{10,})>`, "g"); +const userMentionPattern = new RegExp(`<@!?([0-9]{10,})>`, 'g'); +const roleMentionPattern = new RegExp(`<@&([0-9]{10,})>`, 'g'); const everyoneMentionPattern = new RegExp(`(?:\\s+|^)@everyone(?:\\s+|$)`); const START_DATE = new Date(); @@ -43,7 +43,7 @@ export default new class E2EE extends BuiltinModule { this.setMaster(newMaster); this.patchDispatcher(); this.patchMessageContent(); - const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton'); + const selector = `.${WebpackModules.getClassName('channelTextArea', 'emojiButton')}`; const cta = await ReactComponents.getComponent('ChannelTextArea', { selector }); this.patchChannelTextArea(cta); this.patchChannelTextAreaSubmit(cta); @@ -72,7 +72,6 @@ export default new class E2EE extends BuiltinModule { return ['security', 'default', 'e2ee']; } - get database() { return Settings.getSetting('security', 'e2eedb', 'e2ekvps').value; } @@ -112,8 +111,8 @@ export default new class E2EE extends BuiltinModule { const items = Settings.getSetting('security', 'e2eedb', 'e2ekvps').items; const index = items.findIndex(kvp => kvp.value.key === channelId); if (index > -1) { - items[index].value = {key: channelId, value: key}; - return; + items[index].value = {key: channelId, value: key}; + return; } Settings.getSetting('security', 'e2eedb', 'e2ekvps').addItem({ value: { key: channelId, value: key } }); } @@ -178,7 +177,7 @@ export default new class E2EE extends BuiltinModule { patchDispatcher() { const Dispatcher = WebpackModules.getModuleByName('Dispatcher'); MonkeyPatch('BD:E2EE', Dispatcher).before('dispatch', (_, [event]) => { - if (event.type !== "MESSAGE_CREATE") return; + if (event.type !== 'MESSAGE_CREATE') return; const key = this.getKey(event.message.channel_id); if (!key) return; // We don't have a key for this channel @@ -208,11 +207,11 @@ export default new class E2EE extends BuiltinModule { } async patchMessageContent() { - const selector = '.' + WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited'); + const selector = `.${WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited')}`; const MessageContent = await ReactComponents.getComponent('MessageContent', { selector }); MonkeyPatch('BD:E2EE', MessageContent.component.prototype).before('render', this.beforeRenderMessageContent.bind(this)); MonkeyPatch('BD:E2EE', MessageContent.component.prototype).after('render', this.renderMessageContent.bind(this)); - const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: '.' + WebpackModules.getClassName('imageWrapper') }); + const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: `.${WebpackModules.getClassName('imageWrapper')}` }); MonkeyPatch('BD:E2EE', ImageWrapper.component.prototype).before('render', this.beforeRenderImageWrapper.bind(this)); } @@ -293,13 +292,13 @@ export default new class E2EE extends BuiltinModule { try { const decrypt = Security.decrypt(seed, [this.master, haveKey, cached.image]); component.props.className = 'bd-decryptedImage'; - component.props.src = component.props.original = 'data:;base64,' + decrypt; + component.props.src = component.props.original = `data:;base64,${decrypt}`; } catch (err) { return } finally { component.props.readyState = 'READY' } return; } component.props.readyState = 'LOADING'; - Logger.info('E2EE', 'Decrypting image: ' + src); + Logger.info('E2EE', `Decrypting image: ${src}`); request.get(src, { encoding: 'binary' }).then(res => { (async () => { const arr = new Uint8Array(new ArrayBuffer(res.length)); diff --git a/client/src/builtin/EmoteModule.js b/client/src/builtin/EmoteModule.js index 95921f02..4f0e76e1 100644 --- a/client/src/builtin/EmoteModule.js +++ b/client/src/builtin/EmoteModule.js @@ -58,7 +58,7 @@ export default new class EmoteModule { async load(dataPath) { const emotes = await FileUtils.readJsonFromFile(dataPath); - for (let [index, emote] of emotes.entries()) { + for (const [index, emote] of emotes.entries()) { // Pause every 10000 emotes so the window doesn't freeze if ((index % 10000) === 0) await Utils.wait(); @@ -179,7 +179,7 @@ export default new class EmoteModule { let startIndex = 0; const matching = this.searchCache[key] = []; - for (let emote of this.emotes.values()) { + for (const emote of this.emotes.values()) { if (index >= limit) break; if (regex.test(emote.id)) { if (startIndex < start) { @@ -195,7 +195,7 @@ export default new class EmoteModule { } async patchMessageContent() { - const selector = '.' + WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited'); + const selector = `.${WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited')}`; const MessageContent = await ReactComponents.getComponent('MessageContent', {selector}); this.unpatchRender = MonkeyPatch('BD:EmoteModule', MessageContent.component.prototype).after('render', (component, args, retVal) => { @@ -213,7 +213,7 @@ export default new class EmoteModule { } async patchChannelTextArea() { - const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton'); + const selector = `.${WebpackModules.getClassName('channelTextArea', 'emojiButton')}`; const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector}); this.unpatchChannelTextArea = MonkeyPatch('BD:EmoteModule', ChannelTextArea.component.prototype).after('render', (component, args, retVal) => { diff --git a/client/src/builtin/ReactDevtoolsModule.js b/client/src/builtin/ReactDevtoolsModule.js index 134e00c4..68082612 100644 --- a/client/src/builtin/ReactDevtoolsModule.js +++ b/client/src/builtin/ReactDevtoolsModule.js @@ -42,7 +42,7 @@ export default new class ReactDevtoolsModule extends BuiltinModule { try { const res = electron.remote.BrowserWindow.addDevToolsExtension(path.join(Globals.getPath('ext'), 'extensions', 'rdt')); if (res !== undefined) { - Toasts.success(res + ' Installed'); + Toasts.success(`${res} Installed`); return; } Toasts.error('React Developer Tools install failed'); diff --git a/client/src/builtin/VueDevToolsModule.js b/client/src/builtin/VueDevToolsModule.js index 794042b5..50af44b7 100644 --- a/client/src/builtin/VueDevToolsModule.js +++ b/client/src/builtin/VueDevToolsModule.js @@ -42,7 +42,7 @@ export default new class VueDevtoolsModule extends BuiltinModule { try { const res = electron.remote.BrowserWindow.addDevToolsExtension(path.join(Globals.getPath('ext'), 'extensions', 'vdt')); if (res !== undefined) { - Toasts.success(res + ' Installed'); + Toasts.success(`${res } Installed`); return; } Toasts.error('Vue.js devtools install failed'); diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index ac0b33c3..d00d661e 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -76,7 +76,7 @@ export default class { await FileUtils.ensureDirectory(this.contentPath); const directories = await FileUtils.listDirectory(this.contentPath); - for (let dir of directories) { + for (const dir of directories) { try { await FileUtils.directoryExists(path.join(this.contentPath, dir)); } catch (err) { continue; } @@ -119,7 +119,7 @@ export default class { await FileUtils.ensureDirectory(this.contentPath); const directories = await FileUtils.listDirectory(this.contentPath); - for (let dir of directories) { + for (const dir of directories) { // If content is already loaded this should resolve if (this.getContentByDirName(dir)) continue; @@ -142,7 +142,7 @@ export default class { } } - for (let content of this.localContent) { + for (const content of this.localContent) { if (directories.includes(content.dirName)) continue; try { @@ -219,13 +219,13 @@ export default class { userConfig.config = defaultConfig.clone({ settings: userConfig.config }); userConfig.config.setSaved(); - for (let setting of userConfig.config.findSettings(() => true)) { + for (const setting of userConfig.config.findSettings(() => true)) { // This will load custom settings // Setting the content's path on only the live config (and not the default config) ensures that custom settings will not be loaded on the default settings setting.setContentPath(contentPath); } - for (let scheme of userConfig.config.schemes) { + for (const scheme of userConfig.config.schemes) { scheme.setContentPath(contentPath); } diff --git a/client/src/modules/csseditor.js b/client/src/modules/csseditor.js index c791f2c6..6534532b 100644 --- a/client/src/modules/csseditor.js +++ b/client/src/modules/csseditor.js @@ -119,7 +119,7 @@ export default new class { * @param {String} scss SCSS string */ async compile(scss) { - return await ClientIPC.send('bd-compileSass', { + return ClientIPC.send('bd-compileSass', { data: scss, path: await this.fileExists() ? this.filePath : undefined }); @@ -130,7 +130,7 @@ export default new class { * @return {Promise} */ async recompile() { - return await this.updateScss(this.scss); + return this.updateScss(this.scss); } /** @@ -160,7 +160,7 @@ export default new class { // For some reason this doesn't work // if (!electron.shell.openItem(this.filePath)) - if (!electron.shell.openExternal('file://' + this.filePath)) + if (!electron.shell.openExternal(`file://${this.filePath}`)) throw {message: 'Failed to open system editor.'}; } @@ -267,7 +267,7 @@ export default new class { * @param {Array} files Files to watch */ set watchfiles(files) { - for (let file of files) { + for (const file of files) { if (!this.watchfiles.includes(file)) { this.filewatcher.add(file); this.watchfiles.push(file); @@ -275,7 +275,7 @@ export default new class { } } - for (let index in this.watchfiles) { + for (const index in this.watchfiles) { let file = this.watchfiles[index]; while (file && !files.find(f => f === file)) { this.filewatcher.remove(file); diff --git a/client/src/modules/eventhook.js b/client/src/modules/eventhook.js index 58c29c32..14f6ab47 100644 --- a/client/src/modules/eventhook.js +++ b/client/src/modules/eventhook.js @@ -62,8 +62,8 @@ export default class extends EventListener { */ emit(e, action, data) { switch (e) { - case 'dispatch': - return this.dispatch(action, data); + case 'dispatch': + return this.dispatch(action, data); } } diff --git a/client/src/modules/eventlistener.js b/client/src/modules/eventlistener.js index 042a9697..7ef0ea77 100644 --- a/client/src/modules/eventlistener.js +++ b/client/src/modules/eventlistener.js @@ -14,7 +14,7 @@ import Events from './events'; export default class extends Module { events() { - for (let event of this.eventBindings) { + for (const event of this.eventBindings) { Events.on(event.id, event.callback); } } diff --git a/client/src/modules/eventswrapper.js b/client/src/modules/eventswrapper.js index ac5deacc..79fb14d3 100644 --- a/client/src/modules/eventswrapper.js +++ b/client/src/modules/eventswrapper.js @@ -38,7 +38,7 @@ export default class EventsWrapper { get off() { return this.unsubscribe } unsubscribe(event, callback) { - for (let index in this.eventSubs) { + for (const index in this.eventSubs) { if (this.eventSubs[index].event !== event || (callback && this.eventSubs[index].callback === callback)) continue; eventemitters.get(this).removeListener(event, this.eventSubs[index].boundCallback); this.eventSubs.splice(index, 1); @@ -46,7 +46,7 @@ export default class EventsWrapper { } unsubscribeAll() { - for (let event of this.eventSubs) { + for (const event of this.eventSubs) { eventemitters.get(this).removeListener(event.event, event.boundCallback); } this.eventSubs.splice(0, this.eventSubs.length); diff --git a/client/src/modules/modulemanager.js b/client/src/modules/modulemanager.js index 4b2e25fd..962b7e93 100644 --- a/client/src/modules/modulemanager.js +++ b/client/src/modules/modulemanager.js @@ -37,7 +37,7 @@ export default class { * @return {Promise} */ static async initModules() { - for (let module of this.modules) { + for (const module of this.modules) { try { if (module.init && module.init instanceof Function) module.init(); } catch (err) { diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index e1b9bfc7..368b39fd 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -182,7 +182,7 @@ export default class PluginApi { Utils.removeFromArray(this.menuItems, item); } removeAllMenuItems() { - for (let item of this.menuItems) + for (const item of this.menuItems) BdMenu.items.remove(item); } get BdMenuItems() { @@ -232,7 +232,7 @@ export default class PluginApi { DOM.deleteStyle(styleid); } deleteAllStyles(id) { - for (let id of this.injectedStyles) { + for (const id of this.injectedStyles) { this.deleteStyle(id); } } @@ -273,7 +273,7 @@ export default class PluginApi { } closeAllModals(force) { const promises = []; - for (let modal of this.modalStack) + for (const modal of this.modalStack) promises.push(modal.close(force)); return Promise.all(promises); } @@ -305,7 +305,6 @@ export default class PluginApi { }); } - /** * Toasts */ @@ -335,7 +334,6 @@ export default class PluginApi { }; } - /** * Emotes */ @@ -388,7 +386,7 @@ export default class PluginApi { async getPlugin(plugin_id) { // This should require extra permissions - return await PluginManager.waitForPlugin(plugin_id); + return PluginManager.waitForPlugin(plugin_id); } listPlugins() { return PluginManager.localContent.map(plugin => plugin.id); @@ -406,7 +404,7 @@ export default class PluginApi { async getTheme(theme_id) { // This should require extra permissions - return await ThemeManager.waitForContent(theme_id); + return ThemeManager.waitForContent(theme_id); } listThemes() { return ThemeManager.localContent.map(theme => theme.id); @@ -424,7 +422,7 @@ export default class PluginApi { async getModule(module_id) { // This should require extra permissions - return await ExtModuleManager.waitForContent(module_id); + return ExtModuleManager.waitForContent(module_id); } listModules() { return ExtModuleManager.localContent.map(module => module.id); diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 906b62b0..c18c6aaa 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -41,7 +41,7 @@ export default class extends ContentManager { this.loaded = false; const loadAll = await this.loadAllContent(true); this.loaded = true; - for (let plugin of this.localPlugins) { + for (const plugin of this.localPlugins) { if (!plugin.enabled) continue; plugin.userConfig.enabled = false; @@ -76,7 +76,7 @@ export default class extends ContentManager { static get loadContent() { return this.loadPlugin } static async loadPlugin(paths, configs, info, main, dependencies, permissions, mainExport) { if (permissions && permissions.length > 0) { - for (let perm of permissions) { + for (const perm of permissions) { Logger.log(this.moduleName, `Permission: ${Permissions.permissionText(perm).HEADER} - ${Permissions.permissionText(perm).BODY}`); } try { diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index e8d97cef..6ba75c87 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -50,7 +50,7 @@ class Helpers { const item = parent[key]; yield { item, parent, key, index, count }; if (item && item.props && item.props.children) { - for (let { parent, key, index, count } of this.recursiveArrayCount(item.props, 'children')) { + for (const { parent, key, index, count } of this.recursiveArrayCount(item.props, 'children')) { yield* this.recursiveChildren(parent, key, index, count); } } @@ -58,7 +58,7 @@ class Helpers { } static returnFirst(iterator, process) { - for (let child of iterator) { + for (const child of iterator) { const retVal = process(child); if (retVal !== undefined) return retVal; } @@ -175,7 +175,7 @@ class ReactComponent { forceUpdateAll() { if (!this.important || !this.important.selector) return; - for (let e of document.querySelectorAll(this.important.selector)) { + for (const e of document.querySelectorAll(this.important.selector)) { Reflection(e).forceUpdate(this); } } @@ -237,7 +237,7 @@ export class ReactComponents { if (!elements.length) return; let component, reflect; - for (let element of elements) { + for (const element of elements) { reflect = Reflection(element); component = filter ? reflect.components.find(filter) : reflect.component; if (component) break; @@ -328,7 +328,7 @@ export class ReactAutoPatcher { } static async patchMessage() { - const selector = '.' + WebpackModules.getClassName('message', 'messageCozy', 'messageCompact'); + const selector = `.${WebpackModules.getClassName('message', 'messageCozy', 'messageCompact')}`; this.Message = await ReactComponents.getComponent('Message', {selector}, m => m.prototype && m.prototype.renderCozy); this.unpatchMessageRender = MonkeyPatch('BD:ReactComponents', this.Message.component.prototype).after('render', (component, args, retVal) => { @@ -352,7 +352,7 @@ export class ReactAutoPatcher { } static async patchMessageGroup() { - const selector = '.' + WebpackModules.getClassName('container', 'message', 'messageCozy'); + const selector = `.${WebpackModules.getClassName('container', 'message', 'messageCozy')}`; this.MessageGroup = await ReactComponents.getComponent('MessageGroup', {selector}); this.unpatchMessageGroupRender = MonkeyPatch('BD:ReactComponents', this.MessageGroup.component.prototype).after('render', (component, args, retVal) => { @@ -370,7 +370,7 @@ export class ReactAutoPatcher { } static async patchChannelMember() { - const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity'); + const selector = `.${WebpackModules.getClassName('member', 'memberInner', 'activity')}`; this.ChannelMember = await ReactComponents.getComponent('ChannelMember', {selector}, m => m.prototype.renderActivity); this.unpatchChannelMemberRender = MonkeyPatch('BD:ReactComponents', this.ChannelMember.component.prototype).after('render', (component, args, retVal) => { @@ -423,7 +423,7 @@ export class ReactAutoPatcher { * The GuildTextChannel component represents a text channel in the guild channel list. */ static async patchGuildTextChannel() { - const selector = '.' + WebpackModules.getClassName('containerDefault', 'actionIcon'); + const selector = `.${WebpackModules.getClassName('containerDefault', 'actionIcon')}`; this.GuildTextChannel = await ReactComponents.getComponent('GuildTextChannel', {selector}, c => c.prototype.renderMentionBadge); this.unpatchGuildTextChannel = MonkeyPatch('BD:ReactComponents', this.GuildTextChannel.component.prototype).after('render', this._afterChannelRender); @@ -435,7 +435,7 @@ export class ReactAutoPatcher { * The GuildVoiceChannel component represents a voice channel in the guild channel list. */ static async patchGuildVoiceChannel() { - const selector = '.' + WebpackModules.getClassName('containerDefault', 'actionIcon'); + const selector = `.${WebpackModules.getClassName('containerDefault', 'actionIcon')}`; this.GuildVoiceChannel = await ReactComponents.getComponent('GuildVoiceChannel', {selector}, c => c.prototype.handleVoiceConnect); this.unpatchGuildVoiceChannel = MonkeyPatch('BD:ReactComponents', this.GuildVoiceChannel.component.prototype).after('render', this._afterChannelRender); @@ -469,7 +469,7 @@ export class ReactAutoPatcher { } static async patchUserProfileModal() { - const selector = '.' + WebpackModules.getClassName('root', 'topSectionNormal'); + const selector = `.${WebpackModules.getClassName('root', 'topSectionNormal')}`; this.UserProfileModal = await ReactComponents.getComponent('UserProfileModal', {selector}, Filters.byPrototypeFields(['renderHeader', 'renderBadges'])); this.unpatchUserProfileModal = MonkeyPatch('BD:ReactComponents', this.UserProfileModal.component.prototype).after('render', (component, args, retVal) => { @@ -484,7 +484,7 @@ export class ReactAutoPatcher { } static async patchUserPopout() { - const selector = '.' + WebpackModules.getClassName('userPopout', 'headerNormal'); + const selector = `.${WebpackModules.getClassName('userPopout', 'headerNormal')}`; this.UserPopout = await ReactComponents.getComponent('UserPopout', {selector}); this.unpatchUserPopout = MonkeyPatch('BD:ReactComponents', this.UserPopout.component.prototype).after('render', (component, args, retVal) => { @@ -503,7 +503,7 @@ export class ReactAutoPatcher { } static async patchUploadArea() { - const selector = '.' + WebpackModules.getClassName('uploadArea'); + const selector = `.${WebpackModules.getClassName('uploadArea')}`; this.UploadArea = await ReactComponents.getComponent('UploadArea', {selector}); const reflect = Reflection(selector); @@ -514,7 +514,7 @@ export class ReactAutoPatcher { e.stopPropagation(); e.stopImmediatePropagation(); stateNode.clearDragging(); - Modals.confirm("Function not ready", `You tried to install "${e.dataTransfer.files[0].path}", but installing .bd files isn't ready yet.`) + Modals.confirm('Function not ready', `You tried to install "${e.dataTransfer.files[0].path}", but installing .bd files isn't ready yet.`) // Possibly something like Events.emit('install-file', e.dataTransfer.files[0]); }; diff --git a/client/src/modules/settings.js b/client/src/modules/settings.js index 403df8cc..91f436cf 100644 --- a/client/src/modules/settings.js +++ b/client/src/modules/settings.js @@ -54,7 +54,7 @@ export default new class Settings { const user_config = await FileUtils.readJsonFromFile(settingsPath); const { settings, scss, css, css_editor_files, scss_error, css_editor_bounds, favourite_emotes } = user_config; - for (let set of this.settings) { + for (const set of this.settings) { const newSet = settings.find(s => s.id === set.id); if (!newSet) continue; await set.merge(newSet, {dont_save: true}); @@ -91,7 +91,7 @@ export default new class Settings { favourite_emotes: EmoteModule.favourite_emotes }); - for (let set of this.settings) { + for (const set of this.settings) { set.setSaved(); } } catch (err) { diff --git a/client/src/modules/theme.js b/client/src/modules/theme.js index ec961d2e..05acc613 100644 --- a/client/src/modules/theme.js +++ b/client/src/modules/theme.js @@ -150,7 +150,7 @@ export default class Theme extends Content { set watchfiles(files) { if (!files) files = []; - for (let file of files) { + for (const file of files) { if (!this.watchfiles.includes(file)) { this.filewatcher.add(file); this.watchfiles.push(file); @@ -158,7 +158,7 @@ export default class Theme extends Content { } } - for (let index in this.watchfiles) { + for (const index in this.watchfiles) { let file = this.watchfiles[index]; while (file && !files.find(f => f === file)) { this.filewatcher.remove(file); diff --git a/client/src/modules/thememanager.js b/client/src/modules/thememanager.js index 4914cb05..1a1b5811 100644 --- a/client/src/modules/thememanager.js +++ b/client/src/modules/thememanager.js @@ -80,8 +80,8 @@ export default class ThemeManager extends ContentManager { static async getConfigAsSCSS(settingsset) { const variables = []; - for (let category of settingsset.categories) { - for (let setting of category.settings) { + for (const category of settingsset.categories) { + for (const setting of category.settings) { const setting_scss = await this.parseSetting(setting); if (setting_scss) variables.push(`$${setting_scss[0]}: ${setting_scss[1]};`); } @@ -98,14 +98,14 @@ export default class ThemeManager extends ContentManager { static async getConfigAsSCSSMap(settingsset) { const variables = []; - for (let category of settingsset.categories) { - for (let setting of category.settings) { + for (const category of settingsset.categories) { + for (const setting of category.settings) { const setting_scss = await this.parseSetting(setting); if (setting_scss) variables.push(`${setting_scss[0]}: (${setting_scss[1]})`); } } - return '(' + variables.join(', ') + ')'; + return `(${variables.join(', ')})`; } /** diff --git a/client/src/modules/webpackmodules.js b/client/src/modules/webpackmodules.js index 28a61d8d..5f5b06cc 100644 --- a/client/src/modules/webpackmodules.js +++ b/client/src/modules/webpackmodules.js @@ -21,11 +21,11 @@ const KnownModules = { GuildStore: Filters.byProperties(['getGuild']), SortedGuildStore: Filters.byProperties(['getSortedGuilds']), SelectedGuildStore: Filters.byProperties(['getLastSelectedGuildId']), - GuildSync: Filters.byProperties(["getSyncedGuilds"]), - GuildInfo: Filters.byProperties(["getAcronym"]), + GuildSync: Filters.byProperties(['getSyncedGuilds']), + GuildInfo: Filters.byProperties(['getAcronym']), GuildChannelsStore: Filters.byProperties(['getChannels', 'getDefaultChannel']), GuildMemberStore: Filters.byProperties(['getMember']), - MemberCountStore: Filters.byProperties(["getMemberCounts"]), + MemberCountStore: Filters.byProperties(['getMemberCounts']), GuildEmojiStore: Filters.byProperties(['getEmojis']), GuildActions: Filters.byProperties(['markGuildAsRead']), GuildPermissions: Filters.byProperties(['getGuildPermissions']), @@ -33,20 +33,20 @@ const KnownModules = { /* Channel Store & Actions */ ChannelStore: Filters.byProperties(['getChannels', 'getDMFromUserId']), SelectedChannelStore: Filters.byProperties(['getLastSelectedChannelId']), - ChannelActions: Filters.byProperties(["selectChannel"]), - PrivateChannelActions: Filters.byProperties(["openPrivateChannel"]), - ChannelSelector: Filters.byProperties(["selectGuild", "selectChannel"]), + ChannelActions: Filters.byProperties(['selectChannel']), + PrivateChannelActions: Filters.byProperties(['openPrivateChannel']), + ChannelSelector: Filters.byProperties(['selectGuild', 'selectChannel']), /* Current User Info, State and Settings */ - UserInfoStore: Filters.byProperties(["getToken"]), - UserSettingsStore: Filters.byProperties(["guildPositions"]), + UserInfoStore: Filters.byProperties(['getToken']), + UserSettingsStore: Filters.byProperties(['guildPositions']), AccountManager: Filters.byProperties(['register', 'login']), UserSettingsUpdater: Filters.byProperties(['updateRemoteSettings']), OnlineWatcher: Filters.byProperties(['isOnline']), CurrentUserIdle: Filters.byProperties(['getIdleTime']), RelationshipStore: Filters.byProperties(['isBlocked']), RelationshipManager: Filters.byProperties(['addRelationship']), - MentionStore: Filters.byProperties(["getMentions"]), + MentionStore: Filters.byProperties(['getMentions']), /* User Stores and Utils */ UserStore: Filters.byProperties(['getCurrentUser']), @@ -64,18 +64,18 @@ const KnownModules = { EmojiStore: Filters.byProperties(['getByCategory', 'EMOJI_NAME_RE']), /* Invite Store and Utils */ - InviteStore: Filters.byProperties(["getInvites"]), + InviteStore: Filters.byProperties(['getInvites']), InviteResolver: Filters.byProperties(['findInvite']), InviteActions: Filters.byProperties(['acceptInvite']), /* Discord Objects & Utils */ - DiscordConstants: Filters.byProperties(["Permissions", "ActivityTypes", "StatusTypes"]), + DiscordConstants: Filters.byProperties(['Permissions', 'ActivityTypes', 'StatusTypes']), Permissions: Filters.byProperties(['getHighestRole']), ColorConverter: Filters.byProperties(['hex2int']), ColorShader: Filters.byProperties(['darken']), - ClassResolver: Filters.byProperties(["getClass"]), - ButtonData: Filters.byProperties(["ButtonSizes"]), - IconNames: Filters.byProperties(["IconNames"]), + ClassResolver: Filters.byProperties(['getClass']), + ButtonData: Filters.byProperties(['ButtonSizes']), + IconNames: Filters.byProperties(['IconNames']), NavigationUtils: Filters.byProperties(['transitionTo', 'replaceWith', 'getHistory']), /* Discord Messages */ @@ -94,36 +94,36 @@ const KnownModules = { CurrentExperiment: Filters.byProperties(['getExperimentId']), /* Images, Avatars and Utils */ - ImageResolver: Filters.byProperties(["getUserAvatarURL"]), + ImageResolver: Filters.byProperties(['getUserAvatarURL']), ImageUtils: Filters.byProperties(['getSizedImageSrc']), - AvatarDefaults: Filters.byProperties(["getUserAvatarURL", "DEFAULT_AVATARS"]), + AvatarDefaults: Filters.byProperties(['getUserAvatarURL', 'DEFAULT_AVATARS']), /* Drag & Drop */ - DNDActions: Filters.byProperties(["beginDrag"]), - DNDSources: Filters.byProperties(["addTarget"]), - DNDObjects: Filters.byProperties(["DragSource"]), + DNDActions: Filters.byProperties(['beginDrag']), + DNDSources: Filters.byProperties(['addTarget']), + DNDObjects: Filters.byProperties(['DragSource']), /* Electron & Other Internals with Utils */ - ElectronModule: Filters.byProperties(["_getMainWindow"]), + ElectronModule: Filters.byProperties(['_getMainWindow']), Dispatcher: Filters.byProperties(['dirtyDispatch']), - PathUtils: Filters.byProperties(["hasBasename"]), - NotificationModule: Filters.byProperties(["showNotification"]), - RouterModule: Filters.byProperties(["Router"]), - APIModule: Filters.byProperties(["getAPIBaseURL"]), - AnalyticEvents: Filters.byProperties(["AnalyticEventConfigs"]), + PathUtils: Filters.byProperties(['hasBasename']), + NotificationModule: Filters.byProperties(['showNotification']), + RouterModule: Filters.byProperties(['Router']), + APIModule: Filters.byProperties(['getAPIBaseURL']), + AnalyticEvents: Filters.byProperties(['AnalyticEventConfigs']), KeyGenerator: Filters.byCode(/"binary"/), Buffers: Filters.byProperties(['Buffer', 'kMaxLength']), DeviceStore: Filters.byProperties(['getDevices']), - SoftwareInfo: Filters.byProperties(["os"]), - CurrentContext: Filters.byProperties(["setTagsContext"]), + SoftwareInfo: Filters.byProperties(['os']), + CurrentContext: Filters.byProperties(['setTagsContext']), /* Media Stuff (Audio/Video) */ - MediaDeviceInfo: Filters.byProperties(["Codecs", "SUPPORTED_BROWSERS"]), - MediaInfo: Filters.byProperties(["getOutputVolume"]), + MediaDeviceInfo: Filters.byProperties(['Codecs', 'SUPPORTED_BROWSERS']), + MediaInfo: Filters.byProperties(['getOutputVolume']), MediaEngineInfo: Filters.byProperties(['MediaEngineFeatures']), - VoiceInfo: Filters.byProperties(["EchoCancellation"]), - VideoStream: Filters.byProperties(["getVideoStream"]), - SoundModule: Filters.byProperties(["playSound"]), + VoiceInfo: Filters.byProperties(['EchoCancellation']), + VideoStream: Filters.byProperties(['getVideoStream']), + SoundModule: Filters.byProperties(['playSound']), /* Window, DOM, HTML */ WindowInfo: Filters.byProperties(['isFocused', 'windowSize']), @@ -133,13 +133,13 @@ const KnownModules = { /* Locale/Location and Time */ LocaleManager: Filters.byProperties(['setLocale']), Moment: Filters.byProperties(['parseZone']), - LocationManager: Filters.byProperties(["createLocation"]), - Timestamps: Filters.byProperties(["fromTimestamp"]), + LocationManager: Filters.byProperties(['createLocation']), + Timestamps: Filters.byProperties(['fromTimestamp']), /* Strings and Utils */ - Strings: Filters.byProperties(["TEXT", "TEXTAREA_PLACEHOLDER"]), + Strings: Filters.byProperties(['TEXT', 'TEXTAREA_PLACEHOLDER']), StringFormats: Filters.byProperties(['a', 'z']), - StringUtils: Filters.byProperties(["toASCII"]), + StringUtils: Filters.byProperties(['toASCII']), /* URLs and Utils */ URLParser: Filters.byProperties(['Url', 'parse']), @@ -193,7 +193,7 @@ class WebpackModules { static getModule(filter, first = true, _modules) { const modules = _modules || this.getAllModules(); const rm = []; - for (let index in modules) { + for (const index in modules) { if (!modules.hasOwnProperty(index)) continue; const module = modules[index]; const { exports } = module; @@ -317,7 +317,7 @@ class WebpackModules { this.moduleLoadedEventTimeout = undefined; // Emit a module-loaded event for every module - for (let module of this.modulesLoadingCache) { + for (const module of this.modulesLoadingCache) { Events.emit('module-loaded', module); } diff --git a/client/src/structs/discord/channel.js b/client/src/structs/discord/channel.js index cedbddee..f56ea9af 100644 --- a/client/src/structs/discord/channel.js +++ b/client/src/structs/discord/channel.js @@ -27,12 +27,12 @@ export class Channel { static from(channel) { switch (channel.type) { - default: return new Channel(channel); - case 0: return new GuildTextChannel(channel); - case 1: return new DirectMessageChannel(channel); - case 2: return new GuildVoiceChannel(channel); - case 3: return new GroupChannel(channel); - case 4: return new ChannelCategory(channel); + default: return new Channel(channel); + case 0: return new GuildTextChannel(channel); + case 1: return new DirectMessageChannel(channel); + case 2: return new GuildVoiceChannel(channel); + case 3: return new GroupChannel(channel); + case 4: return new ChannelCategory(channel); } } @@ -156,9 +156,9 @@ export class PermissionOverwrite { static from(data, channel_id) { switch (data.type) { - default: return new PermissionOverwrite(data, channel_id); - case 'role': return new RolePermissionOverwrite(data, channel_id); - case 'member': return new MemberPermissionOverwrite(data, channel_id); + default: return new PermissionOverwrite(data, channel_id); + case 'role': return new RolePermissionOverwrite(data, channel_id); + case 'member': return new MemberPermissionOverwrite(data, channel_id); } } diff --git a/client/src/structs/discord/message.js b/client/src/structs/discord/message.js index 7c2206b8..0c6ae81d 100644 --- a/client/src/structs/discord/message.js +++ b/client/src/structs/discord/message.js @@ -99,15 +99,15 @@ export class Message { static from(data) { switch (data.type) { - default: return new Message(data); - case 0: return new DefaultMessage(data); - case 1: return new RecipientAddMessage(data); - case 2: return new RecipientRemoveMessage(data); - case 3: return new CallMessage(data); - case 4: return new GroupChannelNameChangeMessage(data); - case 5: return new GroupChannelIconChangeMessage(data); - case 6: return new MessagePinnedMessage(data); - case 7: return new GuildMemberJoinMessage(data); + default: return new Message(data); + case 0: return new DefaultMessage(data); + case 1: return new RecipientAddMessage(data); + case 2: return new RecipientRemoveMessage(data); + case 3: return new CallMessage(data); + case 4: return new GroupChannelNameChangeMessage(data); + case 5: return new GroupChannelIconChangeMessage(data); + case 6: return new MessagePinnedMessage(data); + case 7: return new GuildMemberJoinMessage(data); } } diff --git a/client/src/structs/discord/user.js b/client/src/structs/discord/user.js index 1254bdaf..d942ffb2 100644 --- a/client/src/structs/discord/user.js +++ b/client/src/structs/discord/user.js @@ -289,7 +289,7 @@ export class GuildMember { addRole(...roles) { const newRoles = this.roleIds.concat([]); let changed = false; - for (let role of roles) { + for (const role of roles) { if (newRoles.includes(role.id || role)) continue; newRoles.push(role.id || role); changed = true; @@ -306,7 +306,7 @@ export class GuildMember { removeRole(...roles) { const newRoles = this.roleIds.concat([]); let changed = false; - for (let role of roles) { + for (const role of roles) { if (!newRoles.includes(role.id || role)) continue; Utils.removeFromArray(newRoles, role.id || role); changed = true; diff --git a/client/src/structs/list.js b/client/src/structs/list.js index 157f1e9f..da47fdf4 100644 --- a/client/src/structs/list.js +++ b/client/src/structs/list.js @@ -10,14 +10,10 @@ export default class List extends Array { - constructor() { - super(...arguments); - } - get(...filters) { return this.find(item => { - for (let filter of filters) { - for (let key in filter) { + for (const filter of filters) { + for (const key in filter) { if (filter.hasOwnProperty(key)) { if (item[key] !== filter[key]) return false; } diff --git a/client/src/structs/settings/settingscategory.js b/client/src/structs/settings/settingscategory.js index 33f8402d..14ad01f2 100644 --- a/client/src/structs/settings/settingscategory.js +++ b/client/src/structs/settings/settingscategory.js @@ -29,14 +29,14 @@ export default class SettingsCategory extends AsyncEventEmitter { this.args.settings = this.settings.map(setting => new Setting(setting)); - for (let newCategory of merge) { + for (const newCategory of merge) { this._merge(newCategory); } this.__settingUpdated = this.__settingUpdated.bind(this); this.__settingsUpdated = this.__settingsUpdated.bind(this); - for (let setting of this.settings) { + for (const setting of this.settings) { setting.on('setting-updated', this.__settingUpdated); setting.on('settings-updated', this.__settingsUpdated); } @@ -216,7 +216,7 @@ export default class SettingsCategory extends AsyncEventEmitter { _merge(newCategory) { let updatedSettings = []; - for (let newSetting of newCategory.settings) { + for (const newSetting of newCategory.settings) { const setting = this.settings.find(setting => setting.id === newSetting.id); if (!setting) { Logger.warn('SettingsCategory', `Trying to merge setting ${this.id}/${newSetting.id}, which does not exist.`); @@ -243,7 +243,7 @@ export default class SettingsCategory extends AsyncEventEmitter { async merge(newCategory, emit_multi = true) { let updatedSettings = []; - for (let newSetting of newCategory.settings) { + for (const newSetting of newCategory.settings) { const setting = this.settings.find(setting => setting.id === newSetting.id); if (!setting) { Logger.warn('SettingsCategory', `Trying to merge setting ${this.id}/${newSetting.id}, which does not exist.`); @@ -271,7 +271,7 @@ export default class SettingsCategory extends AsyncEventEmitter { * Marks all settings in this set as saved (not changed). */ setSaved() { - for (let setting of this.settings) { + for (const setting of this.settings) { setting.setSaved(); } } diff --git a/client/src/structs/settings/settingsscheme.js b/client/src/structs/settings/settingsscheme.js index 19f9aad6..3c70002c 100644 --- a/client/src/structs/settings/settingsscheme.js +++ b/client/src/structs/settings/settingsscheme.js @@ -86,14 +86,14 @@ export default class SettingsScheme { * @return {Boolean} */ isActive(set) { - for (let schemeCategory of this.categories) { + for (const schemeCategory of this.categories) { const category = set.categories.find(c => c.id === (schemeCategory.id || schemeCategory.category)); if (!category) { Logger.warn('SettingsScheme', `Category ${schemeCategory.id || schemeCategory.category} does not exist`); return false; } - for (let schemeSetting of schemeCategory.settings) { + for (const schemeSetting of schemeCategory.settings) { const setting = category.settings.find(s => s.id === schemeSetting.id); if (!setting) { Logger.warn('SettingsScheme', `Setting ${category.category}/${schemeSetting.id} does not exist`); diff --git a/client/src/structs/settings/settingsset.js b/client/src/structs/settings/settingsset.js index d822ea1a..82789476 100644 --- a/client/src/structs/settings/settingsset.js +++ b/client/src/structs/settings/settingsset.js @@ -31,7 +31,7 @@ export default class SettingsSet extends AsyncEventEmitter { this.args.categories = this.categories.map(category => new SettingsCategory(category)); this.args.schemes = this.schemes.map(scheme => new SettingsScheme(scheme)); - for (let newSet of merge) { + for (const newSet of merge) { this._merge(newSet); } @@ -40,7 +40,7 @@ export default class SettingsSet extends AsyncEventEmitter { this.__addedSetting = this.__addedSetting.bind(this); this.__removedSetting = this.__removedSetting.bind(this); - for (let category of this.categories) { + for (const category of this.categories) { category.on('setting-updated', this.__settingUpdated); category.on('settings-updated', this.__settingsUpdated); category.on('added-setting', this.__addedSetting); @@ -287,7 +287,7 @@ export default class SettingsSet extends AsyncEventEmitter { * @return {Setting} */ findSetting(f) { - for (let category of this.categories) { + for (const category of this.categories) { const setting = category.find(f); if (setting) return setting; } @@ -309,7 +309,7 @@ export default class SettingsSet extends AsyncEventEmitter { * @return {Array} An array of matching Setting objects */ findSettingInCategory(cf, f) { - for (let category of this.categories.filter(cf)) { + for (const category of this.categories.filter(cf)) { const setting = category.find(f); if (setting) return setting; } @@ -323,7 +323,7 @@ export default class SettingsSet extends AsyncEventEmitter { */ findSettingsInCategory(cf, f) { let settings = []; - for (let category of this.categories.filter(cf)) { + for (const category of this.categories.filter(cf)) { settings = settings.concat(category.findSettings(f)); } return settings; @@ -371,7 +371,7 @@ export default class SettingsSet extends AsyncEventEmitter { const categories = newSet && newSet.args ? newSet.args.settings : newSet ? newSet.settings : newSet; if (!categories) return []; - for (let newCategory of categories) { + for (const newCategory of categories) { const category = this.find(category => category.id === (newCategory.id || newCategory.category)); if (!category) { Logger.warn('SettingsSet', `Trying to merge category ${newCategory.id}, which does not exist.`); @@ -402,7 +402,7 @@ export default class SettingsSet extends AsyncEventEmitter { newSet ? newSet.categories || newSet.settings : newSet; if (!categories) return []; - for (let newCategory of categories) { + for (const newCategory of categories) { const category = this.find(category => category.id === (newCategory.id || newCategory.category)); if (!category) { Logger.warn('SettingsSet', `Trying to merge category ${newCategory.id}, which does not exist.`); @@ -432,7 +432,7 @@ export default class SettingsSet extends AsyncEventEmitter { * Marks all settings in this set as saved (not changed). */ setSaved() { - for (let category of this.categories) { + for (const category of this.categories) { category.setSaved(); } } diff --git a/client/src/structs/settings/types/array.js b/client/src/structs/settings/types/array.js index a4095025..c68d2620 100644 --- a/client/src/structs/settings/types/array.js +++ b/client/src/structs/settings/types/array.js @@ -174,7 +174,7 @@ export default class ArraySetting extends Setting { const newItems = []; let error; - for (let newItem of updatedSetting.value) { + for (const newItem of updatedSetting.value) { try { const item = this.items.find(i => i.id && i.id === newItem.id); @@ -200,7 +200,7 @@ export default class ArraySetting extends Setting { } catch (e) { error = e; } } - for (let item of this.items) { + for (const item of this.items) { if (newItems.includes(item)) continue; try { @@ -245,8 +245,8 @@ export default class ArraySetting extends Setting { setContentPath(contentPath) { this.args.path = contentPath; - for (let category of this.categories) { - for (let setting of category.settings) { + for (const category of this.categories) { + for (const setting of category.settings) { setting.setContentPath(contentPath); } } @@ -258,11 +258,11 @@ export default class ArraySetting extends Setting { */ async toSCSS() { const maps = []; - for (let item of this.items) + for (const item of this.items) maps.push(await ThemeManager.getConfigAsSCSSMap(item)); // Final comma ensures the variable is a list - return maps.length ? maps.join(', ') + ',' : '()'; + return maps.length ? `${maps.join(', ')},` : '()'; } } diff --git a/client/src/structs/settings/types/basesetting.js b/client/src/structs/settings/types/basesetting.js index 117f8e25..bb72e4b2 100644 --- a/client/src/structs/settings/types/basesetting.js +++ b/client/src/structs/settings/types/basesetting.js @@ -30,7 +30,7 @@ export default class Setting extends AsyncEventEmitter { if (!this.args.hasOwnProperty('saved_value')) this.args.saved_value = this.args.value; - for (let newSetting of merge) { + for (const newSetting of merge) { this._merge(newSetting); } diff --git a/client/src/structs/settings/types/file.js b/client/src/structs/settings/types/file.js index 914fd848..22a3994e 100644 --- a/client/src/structs/settings/types/file.js +++ b/client/src/structs/settings/types/file.js @@ -49,7 +49,7 @@ export default class FileSetting extends Setting { if (!this.value || !this.value.length) return '()'; const files = []; - for (let filepath of this.value) { + for (const filepath of this.value) { const buffer = await FileUtils.readFileBuffer(path.resolve(this.path, filepath)); const type = await FileUtils.getFileType(buffer); files.push(`(data: ${ThemeManager.toSCSSString(buffer.toString('base64'))}, type: ${ThemeManager.toSCSSString(type.mime)}, url: ${ThemeManager.toSCSSString(await FileUtils.toDataURI(buffer, type.mime))})`); diff --git a/client/src/structs/settings/types/guild.js b/client/src/structs/settings/types/guild.js index 3df82044..0face601 100644 --- a/client/src/structs/settings/types/guild.js +++ b/client/src/structs/settings/types/guild.js @@ -89,7 +89,7 @@ export default class GuildSetting extends Setting { const newGuilds = []; let error; - for (let newGuild of updatedSetting.value) { + for (const newGuild of updatedSetting.value) { try { const guild = updatedSetting.old_value.find(g => g === newGuild); @@ -105,7 +105,7 @@ export default class GuildSetting extends Setting { } catch (e) { error = e; } } - for (let guild_id of updatedSetting.old_value) { + for (const guild_id of updatedSetting.old_value) { if (newGuilds.find(g => g === guild_id)) continue; try { @@ -129,7 +129,7 @@ export default class GuildSetting extends Setting { if (!this.value || !this.value.length) return '()'; const guilds = []; - for (let guild_id of this.value) { + for (const guild_id of this.value) { if (guild_id) guilds.push(guild_id); } diff --git a/client/src/structs/settings/types/keybind.js b/client/src/structs/settings/types/keybind.js index 1a7984da..13e20cd5 100644 --- a/client/src/structs/settings/types/keybind.js +++ b/client/src/structs/settings/types/keybind.js @@ -67,7 +67,7 @@ export default class KeybindSetting extends Setting { } static __event_handler(event, data) { - for (let keybindSetting of instances) { + for (const keybindSetting of instances) { keybindSetting.emit(event, data); } } diff --git a/client/src/ui/bdmenu.js b/client/src/ui/bdmenu.js index fbce0333..97d4ca3d 100644 --- a/client/src/ui/bdmenu.js +++ b/client/src/ui/bdmenu.js @@ -58,7 +58,7 @@ export const BdMenuItems = new class { if (this.items.includes(item)) return item; item.id = items++; - item.contentid = item.contentid || (items++ + ''); + item.contentid = item.contentid || (`${items++}`); item.active = false; item.hidden = item.hidden || false; item._type = item._type || 'button'; diff --git a/client/src/ui/classnormaliser.js b/client/src/ui/classnormaliser.js index c2979ab0..f39e577a 100644 --- a/client/src/ui/classnormaliser.js +++ b/client/src/ui/classnormaliser.js @@ -21,7 +21,7 @@ export default class ClassNormaliser extends Module { } patchClassModules(modules) { - for (let module of modules) { + for (const module of modules) { this.patchClassModule(normalizedPrefix, module); } } @@ -38,7 +38,7 @@ export default class ClassNormaliser extends Module { if (typeof module !== 'object' || Array.isArray(module)) return false; if (module.__esModule) return false; if (!Object.keys(module).length) return false; - for (let baseClassName in module) { + for (const baseClassName in module) { const value = module[baseClassName]; if (typeof value !== 'string') return false; if (this.shouldIgnore(value)) continue; @@ -50,11 +50,11 @@ export default class ClassNormaliser extends Module { } patchClassModule(componentName, classNames) { - for (let baseClassName in classNames) { + for (const baseClassName in classNames) { const value = classNames[baseClassName]; if (this.shouldIgnore(value)) continue; const classList = value.split(' '); - for (let normalClass of classList) { + for (const normalClass of classList) { const match = normalClass.match(randClass)[1]; if (!match) continue; // Shouldn't ever happen since they passed the moduleFilter, but you never know const camelCase = match.split('-').map((s, i) => i ? s[0].toUpperCase() + s.slice(1) : s).join(''); @@ -74,7 +74,7 @@ export default class ClassNormaliser extends Module { element.classList.add(`${normalizedPrefix}-${newClass}`); } - for (let child of element.children) { + for (const child of element.children) { this.normalizeElement(child); } } diff --git a/client/src/ui/dom.js b/client/src/ui/dom.js index 6646a3f7..2428a29c 100644 --- a/client/src/ui/dom.js +++ b/client/src/ui/dom.js @@ -47,7 +47,7 @@ export class DOMObserver { } observerCallback(mutations) { - for (let sub of this.subscriptions) { + for (const sub of this.subscriptions) { try { const filteredMutations = sub.filter ? mutations.filter(sub.filter) : mutations; @@ -55,7 +55,7 @@ export class DOMObserver { if (!filteredMutations.length) continue; sub.callback.call(sub.bind || sub, filteredMutations); } else { - for (let mutation of filteredMutations) sub.callback.call(sub.bind || sub, mutation); + for (const mutation of filteredMutations) sub.callback.call(sub.bind || sub, mutation); } } catch (err) { Logger.warn('DOMObserver', [`Error in observer callback`, err]); @@ -239,7 +239,7 @@ export default class DOM { } static setAttributes(node, attributes) { - for (let attribute of attributes) { + for (const attribute of attributes) { node.setAttribute(attribute.name, attribute.value); } } diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js index cebd89d5..d25189b8 100644 --- a/client/src/ui/modals.js +++ b/client/src/ui/modals.js @@ -128,7 +128,7 @@ export default class Modals { */ static closeAll(force) { const promises = []; - for (let modal of this.stack) + for (const modal of this.stack) promises.push(modal.close(force)); return Promise.all(promises); } @@ -235,14 +235,14 @@ export default class Modals { if (errors.length) { const modal = this.error({ header: - (PluginManager.errors.length && ThemeManager.errors.length ? '' : - (PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName) + ' - ') + + `${(PluginManager.errors.length && ThemeManager.errors.length ? '' : + `${PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName } - `) + (PluginManager.errors.length ? `${PluginManager.errors.length} ${PluginManager.contentType}${PluginManager.errors.length !== 1 ? 's' : ''}` : '') + (PluginManager.errors.length && ThemeManager.errors.length ? ' and ' : '') + - (ThemeManager.errors.length ? `${ThemeManager.errors.length} ${ThemeManager.contentType}${ThemeManager.errors.length !== 1 ? 's' : ''}` : '') + - ' failed to load', + (ThemeManager.errors.length ? `${ThemeManager.errors.length} ${ThemeManager.contentType}${ThemeManager.errors.length !== 1 ? 's' : ''}` : '') + } failed to load`, module: (PluginManager.errors.length && ThemeManager.errors.length ? 'Content Manager' : - (PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName)), + (PluginManager.errors.length ? PluginManager.moduleName : ThemeManager.moduleName)), type: 'err', content: errors }); @@ -294,7 +294,7 @@ export default class Modals { * @return {Modal} */ static contentSettings(content, headertext, options) { - return this.settings(content.settings, headertext ? headertext : content.name + ' Settings', options); + return this.settings(content.settings, headertext ? headertext : `${content.name} Settings`, options); } /** diff --git a/client/src/ui/profilebadges.js b/client/src/ui/profilebadges.js index e6873e1e..efa9b7f9 100644 --- a/client/src/ui/profilebadges.js +++ b/client/src/ui/profilebadges.js @@ -88,7 +88,7 @@ export default class extends Module { async patchNameTag() { if (this.PatchedNameTag) return this.PatchedNameTag; - const selector = '.' + WebpackModules.getClassName('nameTag', 'username', 'discriminator', 'ownerIcon'); + const selector = `.${WebpackModules.getClassName('nameTag', 'username', 'discriminator', 'ownerIcon')}`; const NameTag = await ReactComponents.getComponent('NameTag', {selector}); this.PatchedNameTag = class extends NameTag.component { diff --git a/client/src/ui/reflection.js b/client/src/ui/reflection.js index 18e33c75..653cb72c 100644 --- a/client/src/ui/reflection.js +++ b/client/src/ui/reflection.js @@ -110,7 +110,7 @@ class Reflection { static getComponentStateNode(node, component) { if (component instanceof ReactComponents.ReactComponent) component = component.component; - for (let stateNode of this.getStateNodes(node)) { + for (const stateNode of this.getStateNodes(node)) { if (stateNode instanceof component) return stateNode; } } diff --git a/common/modules/async-eventemitter.js b/common/modules/async-eventemitter.js index f5a8f2b4..92ac4dd8 100644 --- a/common/modules/async-eventemitter.js +++ b/common/modules/async-eventemitter.js @@ -35,7 +35,7 @@ export default class AsyncEventEmitter extends EventEmitter { }]; } - for (let listener of listeners) { + for (const listener of listeners) { await listener.apply(this, data); } } diff --git a/common/modules/bdipc.js b/common/modules/bdipc.js index 09b808af..b687f1a0 100644 --- a/common/modules/bdipc.js +++ b/common/modules/bdipc.js @@ -57,7 +57,7 @@ const ClientIPC = new class ClientIPC { async send(channel, message, error) { channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; - const eid = 'bd-' + Date.now().toString(); + const eid = `bd-${Date.now().toString()}`; ipcRenderer.send(channel, { eid, message, error }); return new Promise((resolve, reject) => { diff --git a/common/modules/utils.js b/common/modules/utils.js index 2a6e7cc7..e8e45366 100644 --- a/common/modules/utils.js +++ b/common/modules/utils.js @@ -72,21 +72,21 @@ export class Utils { */ static findInTree(tree, searchFilter, {walkable = null, ignore = []}) { if (searchFilter(tree)) return tree; - if (typeof tree !== "object" || tree == null) return undefined; - + if (typeof tree !== 'object' || tree == null) return undefined; + let tempReturn = undefined; if (tree instanceof Array) { - for (let value of tree) { + for (const value of tree) { tempReturn = this.findInTree(value, searchFilter, {walkable, ignore}); - if (typeof tempReturn != "undefined") return tempReturn; + if (typeof tempReturn != 'undefined') return tempReturn; } } else { const toWalk = walkable == null ? Object.keys(tree) : walkable; - for (let key of toWalk) { + for (const key of toWalk) { if (!tree.hasOwnProperty(key) || ignore.includes(key)) continue; tempReturn = this.findInTree(tree[key], searchFilter, {walkable, ignore}); - if (typeof tempReturn != "undefined") return tempReturn; + if (typeof tempReturn != 'undefined') return tempReturn; } } return tempReturn; @@ -107,14 +107,14 @@ export class Utils { // Loop through the object and check if everything's the same if (Object.keys(value1).length !== Object.keys(value2).length) return false; - for (let key in value1) { + for (const key in value1) { if (!this.compare(value1[key], value2[key])) return false; } } else if (value1 !== value2) return false; // value1 and value2 contain the same data // Check any more values - for (let value3 of values) { + for (const value3 of values) { if (!this.compare(value1, value3)) return false; } @@ -136,7 +136,7 @@ export class Utils { const clone = Object.assign({}, value); - for (let key in clone) { + for (const key in clone) { clone[key] = this.deepclone(clone[key], exclude); } @@ -157,7 +157,7 @@ export class Utils { if (typeof object === 'object' && object !== null) { const properties = Object.getOwnPropertyNames(object); - for (let property of properties) { + for (const property of properties) { this.deepfreeze(object[property], exclude); } @@ -260,7 +260,7 @@ export class Utils { }); const img = new Image(); img.src = reader.result; - return await new Promise(resolve => { + return new Promise(resolve => { img.onload = () => { resolve(img); } @@ -446,7 +446,7 @@ export class FileUtils { * @return {Promise} */ static async writeJsonToFile(path, json, pretty) { - return this.writeFile(path, JSON.stringify(json, null, pretty ? 4 : 0) + '\n'); + return this.writeFile(path, `${JSON.stringify(json, null, pretty ? 4 : 0)}\n`); } /** diff --git a/core/src/main.js b/core/src/main.js index d6694afc..dabbb572 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -57,9 +57,9 @@ const globals = { const CSP = { 'img-src': ['https://cdn.betterttv.net', 'https://cdn.frankerfacez.com'], 'script-src': [ - "'sha256-fSHKdpQGCHaIqWP3SpJOuUHrLp49jy4dWHzZ/RBJ/p4='", // React Devtools - "'sha256-VFJcfKY5B3EBkFDgQnv3CozPwBlZcxwssfLVWlPFfZU='", // Vue Devtools - "'sha256-VzDmLZ4PxPkOS/KY7ITzLQsSWhfCnvUrNculcj8UNgE=' 'sha256-l6K+77Z1cmldR9gIvaVWlboF/zr5MXCQHcsEHfnr5TU='"] // Vue Detector + '\'sha256-fSHKdpQGCHaIqWP3SpJOuUHrLp49jy4dWHzZ/RBJ/p4=\'', // React Devtools + '\'sha256-VFJcfKY5B3EBkFDgQnv3CozPwBlZcxwssfLVWlPFfZU=\'', // Vue Devtools + '\'sha256-VzDmLZ4PxPkOS/KY7ITzLQsSWhfCnvUrNculcj8UNgE=\' \'sha256-l6K+77Z1cmldR9gIvaVWlboF/zr5MXCQHcsEHfnr5TU=\''] // Vue Detector }; class PatchedBrowserWindow extends BrowserWindow { @@ -255,7 +255,7 @@ export class BetterDiscord { */ static hookSessionRequest() { session.defaultSession.webRequest.onHeadersReceived((details, callback) => { - for (let [header, values] of Object.entries(details.responseHeaders)) { + for (const [header, values] of Object.entries(details.responseHeaders)) { if (!header.match(/^Content-Security-Policy(-Report-Only)?$/i)) continue; details.responseHeaders[header] = values.map(value => { diff --git a/core/src/modules/bdipc.js b/core/src/modules/bdipc.js index 788fe9d4..6fc4403d 100644 --- a/core/src/modules/bdipc.js +++ b/core/src/modules/bdipc.js @@ -58,7 +58,7 @@ export default class BDIpc { static send(window, channel, message, error) { channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; - const eid = 'bd-' + Date.now().toString(); + const eid = `bd-${ Date.now().toString()}`; window.send(channel, { eid, message, error }); return new Promise((resolve, reject) => { diff --git a/core/src/modules/database.js b/core/src/modules/database.js index 744407ec..4daaf030 100644 --- a/core/src/modules/database.js +++ b/core/src/modules/database.js @@ -58,10 +58,10 @@ export default class Database { async exec(cmd) { switch (cmd.action) { - case 'update': - return this.update(cmd); - case 'find': - return this.find(cmd); + case 'update': + return this.update(cmd); + case 'find': + return this.find(cmd); } throw 'Invalid Command'; } diff --git a/core/src/sparkplug.js b/core/src/sparkplug.js index b635414e..0efa10dd 100644 --- a/core/src/sparkplug.js +++ b/core/src/sparkplug.js @@ -20,7 +20,7 @@ import electron, { ipcRenderer } from 'electron'; const currentWindow = electron.remote.getCurrentWindow(); if (currentWindow.__bd_preload) { - for (let preloadScript of currentWindow.__bd_preload) { + for (const preloadScript of currentWindow.__bd_preload) { try { require(preloadScript); } catch (err) { diff --git a/package-lock.json b/package-lock.json index e51cd4ef..5442cc3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5137,8 +5137,8 @@ "dev": true, "optional": true, "requires": { - "abbrev": "1", - "osenv": "^0.1.4" + "abbrev": "1.1.0", + "osenv": "0.1.4" } }, "npmlog": { diff --git a/package.json b/package.json index 457204b4..020354dc 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "build_installer": "npm run build --prefix installer", "watch_installer": "npm run watch --prefix installer", "lint": "eslint -f unix client/src core/src csseditor/src common", + "lint_fix": "eslint -f unix client/src core/src csseditor/src common --fix", "test": "npm run build && npm run lint", "build_node-sass": "node scripts/build-node-sass.js", "build_release": "npm run release --prefix client && npm run build --prefix core && npm run release --prefix csseditor",