From 00bca229f01b2f7a78655224589b4c374334650d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sun, 4 Mar 2018 19:59:16 -0500 Subject: [PATCH] Enforce object literal shorthand syntax with ESLint --- .eslintrc.yml | 4 +++ client/js/autocompletion.js | 2 +- client/js/constants.js | 11 +++---- client/js/keybinds.js | 4 +-- .../libs/handlebars/ircmessageparser/merge.js | 7 ++--- client/js/localStorage.js | 6 ++-- client/js/lounge.js | 22 +++++++------- client/js/options.js | 11 +++---- client/js/renderPreview.js | 4 +-- client/js/socket-events/auth.js | 8 ++--- client/js/socket.js | 3 +- client/js/sorting.js | 30 +++++++++---------- client/js/utils.js | 2 +- src/client.js | 11 ++----- src/clientManager.js | 2 +- src/identification.js | 2 +- src/models/chan.js | 10 +++---- src/plugins/inputs/connect.js | 7 ++--- src/plugins/irc-events/link.js | 13 +++----- src/plugins/packages/themes.js | 6 ++-- test/commands/mode.js | 2 +- test/models/chan.js | 8 ++--- test/util.js | 6 ++-- 23 files changed, 77 insertions(+), 104 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index bc4d24d6..8df76f47 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -47,6 +47,10 @@ rules: no-use-before-define: [error, {functions: false}] no-var: error object-curly-spacing: [error, never] + object-shorthand: + - error + - methods + - avoidExplicitReturnArrows: true padded-blocks: [error, never] padding-line-between-statements: - error diff --git a/client/js/autocompletion.js b/client/js/autocompletion.js index 1be83fa2..9e22b1e6 100644 --- a/client/js/autocompletion.js +++ b/client/js/autocompletion.js @@ -14,7 +14,7 @@ let enabled = false; module.exports = { enable: enableAutocomplete, - disable: () => { + disable() { if (enabled) { input.off("input.tabcomplete"); Mousetrap(input.get(0)).off("tab", "keydown"); diff --git a/client/js/constants.js b/client/js/constants.js index 1ce2f9e5..05ff6b3d 100644 --- a/client/js/constants.js +++ b/client/js/constants.js @@ -79,6 +79,7 @@ const condensedTypes = [ "kick", "mode", ]; +const condensedTypesQuery = "." + condensedTypes.join(", ."); const timeFormats = { msgDefault: "HH:mm", @@ -86,9 +87,9 @@ const timeFormats = { }; module.exports = { - colorCodeMap: colorCodeMap, - commands: commands, - condensedTypes: condensedTypes, - condensedTypesQuery: "." + condensedTypes.join(", ."), - timeFormats: timeFormats, + colorCodeMap, + commands, + condensedTypes, + condensedTypesQuery, + timeFormats, }; diff --git a/client/js/keybinds.js b/client/js/keybinds.js index c2dccb10..e71ab3ce 100644 --- a/client/js/keybinds.js +++ b/client/js/keybinds.js @@ -30,9 +30,7 @@ Mousetrap.bind([ scrollTop = Math.ceil(scrollTop + offset); } - container.animate({ - scrollTop: scrollTop, - }, 200); + container.animate({scrollTop}, 200); return false; }); diff --git a/client/js/libs/handlebars/ircmessageparser/merge.js b/client/js/libs/handlebars/ircmessageparser/merge.js index 34a7d00f..fd1a6877 100644 --- a/client/js/libs/handlebars/ircmessageparser/merge.js +++ b/client/js/libs/handlebars/ircmessageparser/merge.js @@ -8,12 +8,9 @@ function assign(textPart, fragment) { const fragStart = fragment.start; const start = Math.max(fragment.start, textPart.start); const end = Math.min(fragment.end, textPart.end); + const text = fragment.text.slice(start - fragStart, end - fragStart); - return Object.assign({}, fragment, { - start: start, - end: end, - text: fragment.text.slice(start - fragStart, end - fragStart), - }); + return Object.assign({}, fragment, {start, end, text}); } // Merge the style fragments withing the text parts, taking into account diff --git a/client/js/localStorage.js b/client/js/localStorage.js index 32c2c13d..728a6c9f 100644 --- a/client/js/localStorage.js +++ b/client/js/localStorage.js @@ -1,7 +1,7 @@ "use strict"; module.exports = { - set: function(key, value) { + set(key, value) { try { window.localStorage.setItem(key, value); } catch (e) { @@ -10,10 +10,10 @@ module.exports = { // available. See http://stackoverflow.com/q/14555347/1935861. } }, - get: function(key) { + get(key) { return window.localStorage.getItem(key); }, - remove: function(key, value) { + remove(key, value) { window.localStorage.removeItem(key, value); }, }; diff --git a/client/js/lounge.js b/client/js/lounge.js index dfbebd57..3f35d757 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -242,6 +242,7 @@ $(function() { $("#form").on("submit", function(e) { e.preventDefault(); utils.forceFocus(); + const target = chat.data("id"); const text = input.val(); if (text.length === 0) { @@ -260,10 +261,7 @@ $(function() { } } - socket.emit("input", { - target: chat.data("id"), - text: text, - }); + socket.emit("input", {target, text}); }); $("button#set-nick").on("click", function() { @@ -520,29 +518,29 @@ $(function() { }); const contextMenuActions = { - join: function(itemData) { + join(itemData) { const network = $(`#join-channel-${itemData}`).closest(".network"); JoinChannel.openForm(network); }, - close: function(itemData) { + close(itemData) { closeChan($(`.networks .chan[data-target="${itemData}"]`)); }, - focusChan: function(itemData) { + focusChan(itemData) { $(`.networks .chan[data-target="${itemData}"]`).trigger("click"); }, - list: function(itemData) { + list(itemData) { socket.emit("input", { target: itemData, text: "/list", }); }, - banlist: function(itemData) { + banlist(itemData) { socket.emit("input", { target: itemData, text: "/banlist", }); }, - whois: function(itemData) { + whois(itemData) { const chan = utils.findCurrentNetworkChan(itemData); if (chan.length) { @@ -556,7 +554,7 @@ $(function() { $(`.channel.active .userlist .user[data-name="${itemData}"]`).trigger("click"); }, - query: function(itemData) { + query(itemData) { const chan = utils.findCurrentNetworkChan(itemData); if (chan.length) { @@ -568,7 +566,7 @@ $(function() { text: "/query " + itemData, }); }, - kick: function(itemData) { + kick(itemData) { socket.emit("input", { target: $("#chat").data("id"), text: "/kick " + itemData, diff --git a/client/js/options.js b/client/js/options.js index 7985818c..b4eaaaa1 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -70,11 +70,11 @@ if (typeof userSettings.theme === "string" && $theme.attr("href") !== `themes/${ userSettings = null; module.exports = { - alwaysSync: alwaysSync, - noSync: noSync, + alwaysSync, + noSync, initialized: false, highlightsRE: null, - settings: settings, + settings, shouldOpenMessagePreview, noServerSettings, processSetting, @@ -166,10 +166,7 @@ function applySetting(name, value) { } function settingSetEmit(name, value) { - socket.emit("setting:set", { - name: name, - value: value, - }); + socket.emit("setting:set", {name, value}); } // When sync is `true` the setting will also be send to the backend for syncing. diff --git a/client/js/renderPreview.js b/client/js/renderPreview.js index cce42131..faccf26e 100644 --- a/client/js/renderPreview.js +++ b/client/js/renderPreview.js @@ -17,7 +17,7 @@ function renderPreview(preview, msg) { preview.shown = preview.shown && options.shouldOpenMessagePreview(preview.type); - const template = $(templates.msg_preview({preview: preview})); + const template = $(templates.msg_preview({preview})); const image = template.find("img:first"); if (image.length === 0) { @@ -61,7 +61,7 @@ function appendPreview(preview, msg, template) { msg.find(`.text a[href="${escapedLink}"]`) .first() - .after(templates.msg_preview_toggle({preview: preview}).trim()); + .after(templates.msg_preview_toggle({preview}).trim()); previewContainer.append(template); diff --git a/client/js/socket-events/auth.js b/client/js/socket-events/auth.js index 3dfb48e4..3a59530e 100644 --- a/client/js/socket-events/auth.js +++ b/client/js/socket-events/auth.js @@ -65,12 +65,8 @@ socket.on("auth", function(data) { if (token) { $("#loading-page-message, #connection-error").text("Authorizing…"); - - socket.emit("auth", { - user: user, - token: token, - lastMessage: utils.lastMessageId, - }); + const lastMessage = utils.lastMessageId; + socket.emit("auth", {user, token, lastMessage}); } } diff --git a/client/js/socket.js b/client/js/socket.js index 5b3dfc85..77008f51 100644 --- a/client/js/socket.js +++ b/client/js/socket.js @@ -3,11 +3,10 @@ const $ = require("jquery"); const io = require("socket.io-client"); const utils = require("./utils"); -const path = window.location.pathname + "socket.io/"; const socket = io({ transports: $(document.body).data("transports"), - path: path, + path: window.location.pathname + "socket.io/", autoConnect: false, reconnection: !$(document.body).hasClass("public"), }); diff --git a/client/js/sorting.js b/client/js/sorting.js index 54f4d457..2375f594 100644 --- a/client/js/sorting.js +++ b/client/js/sorting.js @@ -17,18 +17,18 @@ module.exports = function() { forcePlaceholderSize: true, tolerance: "pointer", // Use the pointer to figure out where the network is in the list - update: function() { + update() { const order = []; + sidebar.find(".network").each(function() { const id = $(this).data("id"); order.push(id); }); - socket.emit( - "sort", { - type: "networks", - order: order, - } - ); + + socket.emit("sort", { + type: "networks", + order: order, + }); options.settings.ignoreSortSync = true; }, @@ -43,20 +43,20 @@ module.exports = function() { forcePlaceholderSize: true, tolerance: "pointer", // Use the pointer to figure out where the channel is in the list - update: function(e, ui) { + update(e, ui) { const order = []; const network = ui.item.parent(); + network.find(".chan").each(function() { const id = $(this).data("id"); order.push(id); }); - socket.emit( - "sort", { - type: "channels", - target: network.data("id"), - order: order, - } - ); + + socket.emit("sort", { + type: "channels", + target: network.data("id"), + order: order, + }); options.settings.ignoreSortSync = true; }, diff --git a/client/js/utils.js b/client/js/utils.js index e7db6d53..9e0bc37c 100644 --- a/client/js/utils.js +++ b/client/js/utils.js @@ -142,7 +142,7 @@ function requestIdleCallback(callback, timeout) { if (window.requestIdleCallback) { // During an idle period the user agent will run idle callbacks in FIFO order // until either the idle period ends or there are no more idle callbacks eligible to be run. - window.requestIdleCallback(callback, {timeout: timeout}); + window.requestIdleCallback(callback, {timeout}); } else { callback(); } diff --git a/src/client.js b/src/client.js index 62dcdc05..058ff66b 100644 --- a/src/client.js +++ b/src/client.js @@ -132,10 +132,7 @@ Client.prototype.find = function(channelId) { } if (network && chan) { - return { - network: network, - chan: chan, - }; + return {network, chan}; } return false; @@ -557,10 +554,8 @@ Client.prototype.clientAttach = function(socketId, token) { }); } - client.attachedClients[socketId] = { - token: token, - openChannel: client.lastActiveChannel, - }; + const openChannel = client.lastActiveChannel; + client.attachedClients[socketId] = {token, openChannel}; // Update old networks to store ip and hostmask client.networks.forEach((network) => { diff --git a/src/clientManager.js b/src/clientManager.js index 5ca4b282..6d158cfc 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -51,7 +51,7 @@ ClientManager.prototype.autoloadUsers = function() { // Existing users removed since last time users were loaded _.difference(loaded, updatedUsers).forEach((name) => { - const client = _.find(this.clients, {name: name}); + const client = _.find(this.clients, {name}); if (client) { client.quit(true); diff --git a/src/identification.js b/src/identification.js index 39eabb6d..e6feec9b 100644 --- a/src/identification.js +++ b/src/identification.js @@ -69,7 +69,7 @@ class Identification { addSocket(socket, user) { const id = ++this.connectionId; - this.connections.set(id, {socket: socket, user: user}); + this.connections.set(id, {socket, user}); if (this.oidentdFile) { this.refresh(); diff --git a/src/models/chan.js b/src/models/chan.js index c82b7f6a..f573712a 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -43,13 +43,11 @@ Chan.prototype.destroy = function() { }; Chan.prototype.pushMessage = function(client, msg, increasesUnread) { - const obj = { - chan: this.id, - msg: msg, - }; + const chan = this.id; + const obj = {chan, msg}; // If this channel is open in any of the clients, do not increase unread counter - const isOpen = _.find(client.attachedClients, {openChannel: this.id}) !== undefined; + const isOpen = _.find(client.attachedClients, {openChannel: chan}) !== undefined; if ((increasesUnread || msg.highlight) && !isOpen) { obj.unread = ++this.unread; @@ -131,7 +129,7 @@ Chan.prototype.findUser = function(nick) { }; Chan.prototype.getUser = function(nick) { - return this.findUser(nick) || new User({nick: nick}); + return this.findUser(nick) || new User({nick}); }; Chan.prototype.setUser = function(user) { diff --git a/src/plugins/inputs/connect.js b/src/plugins/inputs/connect.js index 95d7e1f0..76dc19a7 100644 --- a/src/plugins/inputs/connect.js +++ b/src/plugins/inputs/connect.js @@ -31,11 +31,8 @@ exports.input = function({irc}, chan, cmd, args) { port = port.substring(1); } - this.connect({ - host: args[0], - port: port, - tls: tls, - }); + const host = args[0]; + this.connect({host, port, tls}); return true; }; diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 9339e1cd..d5687e5e 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -269,10 +269,8 @@ function emitPreview(client, msg, preview) { } } - client.emit("msg:preview", { - id: msg.id, - preview: preview, - }); + const id = msg.id; + client.emit("msg:preview", {id, preview}); } function getRequestHeaders(language) { @@ -349,11 +347,8 @@ function fetch(uri, {language}, cb) { type = req.response.headers["content-type"].split(/ *; */).shift(); } - cb({ - data: Buffer.concat(buffers, length), - type: type, - size: size, - }); + const data = Buffer.concat(buffers, length); + cb({data, type, size}); }); } diff --git a/src/plugins/packages/themes.js b/src/plugins/packages/themes.js index aba7269d..7900b08b 100644 --- a/src/plugins/packages/themes.js +++ b/src/plugins/packages/themes.js @@ -58,11 +58,9 @@ function makePackageThemeObject(moduleName, module) { } const modulePath = Helper.getPackageModulePath(moduleName); - const displayName = module.name || moduleName; - const filename = path.join(modulePath, module.css); return { - displayName: displayName, - filename: filename, + displayName: module.name || moduleName, + filename: path.join(modulePath, module.css), name: moduleName, }; } diff --git a/test/commands/mode.js b/test/commands/mode.js index 0b2646f6..f1d75795 100644 --- a/test/commands/mode.js +++ b/test/commands/mode.js @@ -20,7 +20,7 @@ describe("Commands", function() { lastCommand: null, nick: "xPaw", irc: { - raw: function(...args) { + raw(...args) { testableNetwork.lastCommand = args.join(" "); }, }, diff --git a/test/models/chan.js b/test/models/chan.js index c6d55148..34053ddf 100644 --- a/test/models/chan.js +++ b/test/models/chan.js @@ -90,7 +90,7 @@ describe("Chan", function() { const chan = new Chan(); [ "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", - ].forEach((nick) => chan.setUser(new User({nick: nick}))); + ].forEach((nick) => chan.setUser(new User({nick}))); expect(chan.getSortedUsers().map((u) => u.nick)).to.deep.equal([ "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", @@ -101,7 +101,7 @@ describe("Chan", function() { const chan = new Chan(); [ "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", - ].forEach((nick) => chan.setUser(new User({nick: nick}, prefixLookup))); + ].forEach((nick) => chan.setUser(new User({nick}, prefixLookup))); expect(getUserNames(chan)).to.deep.equal([ "astorije", "JocelynD", "Max-P", "xPaw", "YaManicKill", @@ -138,7 +138,7 @@ describe("Chan", function() { const chan = new Chan(); [ "aB", "Ad", "AA", "ac", - ].forEach((nick) => chan.setUser(new User({nick: nick}, prefixLookup))); + ].forEach((nick) => chan.setUser(new User({nick}, prefixLookup))); expect(getUserNames(chan)).to.deep.equal(["AA", "aB", "ac", "Ad"]); }); @@ -148,7 +148,7 @@ describe("Chan", function() { [ "[foo", "]foo", "(foo)", "{foo}", "", "_foo", "@foo", "^foo", "&foo", "!foo", "+foo", "Foo", - ].forEach((nick) => chan.setUser(new User({nick: nick}, prefixLookup))); + ].forEach((nick) => chan.setUser(new User({nick}, prefixLookup))); expect(getUserNames(chan)).to.deep.equal([ "!foo", "&foo", "(foo)", "+foo", "", "@foo", "[foo", "]foo", diff --git a/test/util.js b/test/util.js index 6f820736..bf9f3c25 100644 --- a/test/util.js +++ b/test/util.js @@ -37,10 +37,10 @@ function mockLogger(callback) { } module.exports = { - createClient: function() { + createClient() { return new MockClient(); }, - createNetwork: function() { + createNetwork() { return new Network({ host: "example.com", channels: [new Chan({ @@ -48,7 +48,7 @@ module.exports = { })], }); }, - createWebserver: function() { + createWebserver() { return express(); }, mockLogger,