Enforce object literal shorthand syntax with ESLint

This commit is contained in:
Jérémie Astori 2018-03-04 19:59:16 -05:00
parent f07a6db7ab
commit 00bca229f0
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
23 changed files with 77 additions and 104 deletions

View File

@ -47,6 +47,10 @@ rules:
no-use-before-define: [error, {functions: false}] no-use-before-define: [error, {functions: false}]
no-var: error no-var: error
object-curly-spacing: [error, never] object-curly-spacing: [error, never]
object-shorthand:
- error
- methods
- avoidExplicitReturnArrows: true
padded-blocks: [error, never] padded-blocks: [error, never]
padding-line-between-statements: padding-line-between-statements:
- error - error

View File

@ -14,7 +14,7 @@ let enabled = false;
module.exports = { module.exports = {
enable: enableAutocomplete, enable: enableAutocomplete,
disable: () => { disable() {
if (enabled) { if (enabled) {
input.off("input.tabcomplete"); input.off("input.tabcomplete");
Mousetrap(input.get(0)).off("tab", "keydown"); Mousetrap(input.get(0)).off("tab", "keydown");

View File

@ -79,6 +79,7 @@ const condensedTypes = [
"kick", "kick",
"mode", "mode",
]; ];
const condensedTypesQuery = "." + condensedTypes.join(", .");
const timeFormats = { const timeFormats = {
msgDefault: "HH:mm", msgDefault: "HH:mm",
@ -86,9 +87,9 @@ const timeFormats = {
}; };
module.exports = { module.exports = {
colorCodeMap: colorCodeMap, colorCodeMap,
commands: commands, commands,
condensedTypes: condensedTypes, condensedTypes,
condensedTypesQuery: "." + condensedTypes.join(", ."), condensedTypesQuery,
timeFormats: timeFormats, timeFormats,
}; };

View File

@ -30,9 +30,7 @@ Mousetrap.bind([
scrollTop = Math.ceil(scrollTop + offset); scrollTop = Math.ceil(scrollTop + offset);
} }
container.animate({ container.animate({scrollTop}, 200);
scrollTop: scrollTop,
}, 200);
return false; return false;
}); });

View File

@ -8,12 +8,9 @@ function assign(textPart, fragment) {
const fragStart = fragment.start; const fragStart = fragment.start;
const start = Math.max(fragment.start, textPart.start); const start = Math.max(fragment.start, textPart.start);
const end = Math.min(fragment.end, textPart.end); const end = Math.min(fragment.end, textPart.end);
const text = fragment.text.slice(start - fragStart, end - fragStart);
return Object.assign({}, fragment, { return Object.assign({}, fragment, {start, end, text});
start: start,
end: end,
text: fragment.text.slice(start - fragStart, end - fragStart),
});
} }
// Merge the style fragments withing the text parts, taking into account // Merge the style fragments withing the text parts, taking into account

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
module.exports = { module.exports = {
set: function(key, value) { set(key, value) {
try { try {
window.localStorage.setItem(key, value); window.localStorage.setItem(key, value);
} catch (e) { } catch (e) {
@ -10,10 +10,10 @@ module.exports = {
// available. See http://stackoverflow.com/q/14555347/1935861. // available. See http://stackoverflow.com/q/14555347/1935861.
} }
}, },
get: function(key) { get(key) {
return window.localStorage.getItem(key); return window.localStorage.getItem(key);
}, },
remove: function(key, value) { remove(key, value) {
window.localStorage.removeItem(key, value); window.localStorage.removeItem(key, value);
}, },
}; };

View File

@ -242,6 +242,7 @@ $(function() {
$("#form").on("submit", function(e) { $("#form").on("submit", function(e) {
e.preventDefault(); e.preventDefault();
utils.forceFocus(); utils.forceFocus();
const target = chat.data("id");
const text = input.val(); const text = input.val();
if (text.length === 0) { if (text.length === 0) {
@ -260,10 +261,7 @@ $(function() {
} }
} }
socket.emit("input", { socket.emit("input", {target, text});
target: chat.data("id"),
text: text,
});
}); });
$("button#set-nick").on("click", function() { $("button#set-nick").on("click", function() {
@ -520,29 +518,29 @@ $(function() {
}); });
const contextMenuActions = { const contextMenuActions = {
join: function(itemData) { join(itemData) {
const network = $(`#join-channel-${itemData}`).closest(".network"); const network = $(`#join-channel-${itemData}`).closest(".network");
JoinChannel.openForm(network); JoinChannel.openForm(network);
}, },
close: function(itemData) { close(itemData) {
closeChan($(`.networks .chan[data-target="${itemData}"]`)); closeChan($(`.networks .chan[data-target="${itemData}"]`));
}, },
focusChan: function(itemData) { focusChan(itemData) {
$(`.networks .chan[data-target="${itemData}"]`).trigger("click"); $(`.networks .chan[data-target="${itemData}"]`).trigger("click");
}, },
list: function(itemData) { list(itemData) {
socket.emit("input", { socket.emit("input", {
target: itemData, target: itemData,
text: "/list", text: "/list",
}); });
}, },
banlist: function(itemData) { banlist(itemData) {
socket.emit("input", { socket.emit("input", {
target: itemData, target: itemData,
text: "/banlist", text: "/banlist",
}); });
}, },
whois: function(itemData) { whois(itemData) {
const chan = utils.findCurrentNetworkChan(itemData); const chan = utils.findCurrentNetworkChan(itemData);
if (chan.length) { if (chan.length) {
@ -556,7 +554,7 @@ $(function() {
$(`.channel.active .userlist .user[data-name="${itemData}"]`).trigger("click"); $(`.channel.active .userlist .user[data-name="${itemData}"]`).trigger("click");
}, },
query: function(itemData) { query(itemData) {
const chan = utils.findCurrentNetworkChan(itemData); const chan = utils.findCurrentNetworkChan(itemData);
if (chan.length) { if (chan.length) {
@ -568,7 +566,7 @@ $(function() {
text: "/query " + itemData, text: "/query " + itemData,
}); });
}, },
kick: function(itemData) { kick(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: $("#chat").data("id"),
text: "/kick " + itemData, text: "/kick " + itemData,

View File

@ -70,11 +70,11 @@ if (typeof userSettings.theme === "string" && $theme.attr("href") !== `themes/${
userSettings = null; userSettings = null;
module.exports = { module.exports = {
alwaysSync: alwaysSync, alwaysSync,
noSync: noSync, noSync,
initialized: false, initialized: false,
highlightsRE: null, highlightsRE: null,
settings: settings, settings,
shouldOpenMessagePreview, shouldOpenMessagePreview,
noServerSettings, noServerSettings,
processSetting, processSetting,
@ -166,10 +166,7 @@ function applySetting(name, value) {
} }
function settingSetEmit(name, value) { function settingSetEmit(name, value) {
socket.emit("setting:set", { socket.emit("setting:set", {name, value});
name: name,
value: value,
});
} }
// When sync is `true` the setting will also be send to the backend for syncing. // When sync is `true` the setting will also be send to the backend for syncing.

View File

@ -17,7 +17,7 @@ function renderPreview(preview, msg) {
preview.shown = preview.shown && options.shouldOpenMessagePreview(preview.type); 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"); const image = template.find("img:first");
if (image.length === 0) { if (image.length === 0) {
@ -61,7 +61,7 @@ function appendPreview(preview, msg, template) {
msg.find(`.text a[href="${escapedLink}"]`) msg.find(`.text a[href="${escapedLink}"]`)
.first() .first()
.after(templates.msg_preview_toggle({preview: preview}).trim()); .after(templates.msg_preview_toggle({preview}).trim());
previewContainer.append(template); previewContainer.append(template);

View File

@ -65,12 +65,8 @@ socket.on("auth", function(data) {
if (token) { if (token) {
$("#loading-page-message, #connection-error").text("Authorizing…"); $("#loading-page-message, #connection-error").text("Authorizing…");
const lastMessage = utils.lastMessageId;
socket.emit("auth", { socket.emit("auth", {user, token, lastMessage});
user: user,
token: token,
lastMessage: utils.lastMessageId,
});
} }
} }

View File

@ -3,11 +3,10 @@
const $ = require("jquery"); const $ = require("jquery");
const io = require("socket.io-client"); const io = require("socket.io-client");
const utils = require("./utils"); const utils = require("./utils");
const path = window.location.pathname + "socket.io/";
const socket = io({ const socket = io({
transports: $(document.body).data("transports"), transports: $(document.body).data("transports"),
path: path, path: window.location.pathname + "socket.io/",
autoConnect: false, autoConnect: false,
reconnection: !$(document.body).hasClass("public"), reconnection: !$(document.body).hasClass("public"),
}); });

View File

@ -17,18 +17,18 @@ module.exports = function() {
forcePlaceholderSize: true, forcePlaceholderSize: true,
tolerance: "pointer", // Use the pointer to figure out where the network is in the list tolerance: "pointer", // Use the pointer to figure out where the network is in the list
update: function() { update() {
const order = []; const order = [];
sidebar.find(".network").each(function() { sidebar.find(".network").each(function() {
const id = $(this).data("id"); const id = $(this).data("id");
order.push(id); order.push(id);
}); });
socket.emit(
"sort", { socket.emit("sort", {
type: "networks", type: "networks",
order: order, order: order,
} });
);
options.settings.ignoreSortSync = true; options.settings.ignoreSortSync = true;
}, },
@ -43,20 +43,20 @@ module.exports = function() {
forcePlaceholderSize: true, forcePlaceholderSize: true,
tolerance: "pointer", // Use the pointer to figure out where the channel is in the list 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 order = [];
const network = ui.item.parent(); const network = ui.item.parent();
network.find(".chan").each(function() { network.find(".chan").each(function() {
const id = $(this).data("id"); const id = $(this).data("id");
order.push(id); order.push(id);
}); });
socket.emit(
"sort", { socket.emit("sort", {
type: "channels", type: "channels",
target: network.data("id"), target: network.data("id"),
order: order, order: order,
} });
);
options.settings.ignoreSortSync = true; options.settings.ignoreSortSync = true;
}, },

View File

@ -142,7 +142,7 @@ function requestIdleCallback(callback, timeout) {
if (window.requestIdleCallback) { if (window.requestIdleCallback) {
// During an idle period the user agent will run idle callbacks in FIFO order // 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. // 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 { } else {
callback(); callback();
} }

View File

@ -132,10 +132,7 @@ Client.prototype.find = function(channelId) {
} }
if (network && chan) { if (network && chan) {
return { return {network, chan};
network: network,
chan: chan,
};
} }
return false; return false;
@ -557,10 +554,8 @@ Client.prototype.clientAttach = function(socketId, token) {
}); });
} }
client.attachedClients[socketId] = { const openChannel = client.lastActiveChannel;
token: token, client.attachedClients[socketId] = {token, openChannel};
openChannel: client.lastActiveChannel,
};
// Update old networks to store ip and hostmask // Update old networks to store ip and hostmask
client.networks.forEach((network) => { client.networks.forEach((network) => {

View File

@ -51,7 +51,7 @@ ClientManager.prototype.autoloadUsers = function() {
// Existing users removed since last time users were loaded // Existing users removed since last time users were loaded
_.difference(loaded, updatedUsers).forEach((name) => { _.difference(loaded, updatedUsers).forEach((name) => {
const client = _.find(this.clients, {name: name}); const client = _.find(this.clients, {name});
if (client) { if (client) {
client.quit(true); client.quit(true);

View File

@ -69,7 +69,7 @@ class Identification {
addSocket(socket, user) { addSocket(socket, user) {
const id = ++this.connectionId; const id = ++this.connectionId;
this.connections.set(id, {socket: socket, user: user}); this.connections.set(id, {socket, user});
if (this.oidentdFile) { if (this.oidentdFile) {
this.refresh(); this.refresh();

View File

@ -43,13 +43,11 @@ Chan.prototype.destroy = function() {
}; };
Chan.prototype.pushMessage = function(client, msg, increasesUnread) { Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
const obj = { const chan = this.id;
chan: this.id, const obj = {chan, msg};
msg: msg,
};
// If this channel is open in any of the clients, do not increase unread counter // 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) { if ((increasesUnread || msg.highlight) && !isOpen) {
obj.unread = ++this.unread; obj.unread = ++this.unread;
@ -131,7 +129,7 @@ Chan.prototype.findUser = function(nick) {
}; };
Chan.prototype.getUser = 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) { Chan.prototype.setUser = function(user) {

View File

@ -31,11 +31,8 @@ exports.input = function({irc}, chan, cmd, args) {
port = port.substring(1); port = port.substring(1);
} }
this.connect({ const host = args[0];
host: args[0], this.connect({host, port, tls});
port: port,
tls: tls,
});
return true; return true;
}; };

View File

@ -269,10 +269,8 @@ function emitPreview(client, msg, preview) {
} }
} }
client.emit("msg:preview", { const id = msg.id;
id: msg.id, client.emit("msg:preview", {id, preview});
preview: preview,
});
} }
function getRequestHeaders(language) { function getRequestHeaders(language) {
@ -349,11 +347,8 @@ function fetch(uri, {language}, cb) {
type = req.response.headers["content-type"].split(/ *; */).shift(); type = req.response.headers["content-type"].split(/ *; */).shift();
} }
cb({ const data = Buffer.concat(buffers, length);
data: Buffer.concat(buffers, length), cb({data, type, size});
type: type,
size: size,
});
}); });
} }

View File

@ -58,11 +58,9 @@ function makePackageThemeObject(moduleName, module) {
} }
const modulePath = Helper.getPackageModulePath(moduleName); const modulePath = Helper.getPackageModulePath(moduleName);
const displayName = module.name || moduleName;
const filename = path.join(modulePath, module.css);
return { return {
displayName: displayName, displayName: module.name || moduleName,
filename: filename, filename: path.join(modulePath, module.css),
name: moduleName, name: moduleName,
}; };
} }

View File

@ -20,7 +20,7 @@ describe("Commands", function() {
lastCommand: null, lastCommand: null,
nick: "xPaw", nick: "xPaw",
irc: { irc: {
raw: function(...args) { raw(...args) {
testableNetwork.lastCommand = args.join(" "); testableNetwork.lastCommand = args.join(" ");
}, },
}, },

View File

@ -90,7 +90,7 @@ describe("Chan", function() {
const chan = new Chan(); const chan = new Chan();
[ [
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", "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([ expect(chan.getSortedUsers().map((u) => u.nick)).to.deep.equal([
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P",
@ -101,7 +101,7 @@ describe("Chan", function() {
const chan = new Chan(); const chan = new Chan();
[ [
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", "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([ expect(getUserNames(chan)).to.deep.equal([
"astorije", "JocelynD", "Max-P", "xPaw", "YaManicKill", "astorije", "JocelynD", "Max-P", "xPaw", "YaManicKill",
@ -138,7 +138,7 @@ describe("Chan", function() {
const chan = new Chan(); const chan = new Chan();
[ [
"aB", "Ad", "AA", "ac", "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"]); 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)", "{foo}", "<foo>", "_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([ expect(getUserNames(chan)).to.deep.equal([
"!foo", "&foo", "(foo)", "+foo", "<foo>", "@foo", "[foo", "]foo", "!foo", "&foo", "(foo)", "+foo", "<foo>", "@foo", "[foo", "]foo",

View File

@ -37,10 +37,10 @@ function mockLogger(callback) {
} }
module.exports = { module.exports = {
createClient: function() { createClient() {
return new MockClient(); return new MockClient();
}, },
createNetwork: function() { createNetwork() {
return new Network({ return new Network({
host: "example.com", host: "example.com",
channels: [new Chan({ channels: [new Chan({
@ -48,7 +48,7 @@ module.exports = {
})], })],
}); });
}, },
createWebserver: function() { createWebserver() {
return express(); return express();
}, },
mockLogger, mockLogger,