Merge pull request #681 from thelounge/xpaw/more-eslint

Enforce more eslint rules
This commit is contained in:
Jérémie Astori 2016-10-09 19:02:04 -04:00 committed by GitHub
commit 7e39ae045f
18 changed files with 144 additions and 125 deletions

View File

@ -11,27 +11,34 @@ parserOptions:
ecmaVersion: 6 ecmaVersion: 6
rules: rules:
block-scoped-var: 2
block-spacing: [2, always] block-spacing: [2, always]
brace-style: [2, 1tbs] brace-style: [2, 1tbs]
comma-dangle: 0 comma-dangle: 0
curly: [2, all] curly: [2, all]
dot-notation: 2
eqeqeq: 2 eqeqeq: 2
handle-callback-err: 2
indent: [2, tab] indent: [2, tab]
key-spacing: [2, {beforeColon: false, afterColon: true}] key-spacing: [2, {beforeColon: false, afterColon: true}]
keyword-spacing: [2, {before: true, after: true}] keyword-spacing: [2, {before: true, after: true}]
linebreak-style: [2, unix] linebreak-style: [2, unix]
no-console: 0 no-console: 0
no-control-regex: 0 no-control-regex: 0
no-inner-declarations: 2 no-else-return: 2
no-invalid-regexp: 2 no-implicit-globals: 2
no-irregular-whitespace: 2 no-multi-spaces: 2
no-shadow: 2
no-template-curly-in-string: 2
no-trailing-spaces: 2 no-trailing-spaces: 2
no-unexpected-multiline: 2 no-unsafe-negation: 2
no-unreachable: 2 no-useless-escape: 2
object-curly-spacing: [2, never] object-curly-spacing: [2, never]
quote-props: [2, as-needed]
quotes: [2, double, avoid-escape] quotes: [2, double, avoid-escape]
semi: [2, always] semi: [2, always]
space-before-blocks: 2 space-before-blocks: 2
space-before-function-paren: [2, never]
space-infix-ops: 2 space-infix-ops: 2
spaced-comment: [2, always] spaced-comment: [2, always]
strict: 2 strict: 2

View File

@ -7,8 +7,8 @@ Handlebars.registerHelper(
if (a !== diff) { if (a !== diff) {
diff = a; diff = a;
return opt.fn(this); return opt.fn(this);
} else { }
return opt.inverse(this); return opt.inverse(this);
} }
}
); );

View File

@ -6,8 +6,8 @@ Handlebars.registerHelper(
b = b.toString(); b = b.toString();
if (a === b) { if (a === b) {
return opt.fn(this); return opt.fn(this);
} else { }
return opt.inverse(this); return opt.inverse(this);
} }
}
); );

View File

@ -33,7 +33,7 @@ function uri(text) {
*/ */
function channels(text) { function channels(text) {
return text.replace( return text.replace(
/(^|\s|\x07|,)((?:#|&)[^\x07\s\,]{1,49})/g, /(^|\s|\x07|,)((?:#|&)[^\x07\s,]{1,49})/g,
'$1<span class="inline-channel" role="button" tabindex="0" data-chan="$2">$2</span>' '$1<span class="inline-channel" role="button" tabindex="0" data-chan="$2">$2</span>'
); );
} }
@ -114,10 +114,10 @@ function colors(line) {
return; return;
} }
result = result.replace(style.keyregex, function(match, text) { result = result.replace(style.keyregex, function(matchedTrash, matchedText) {
return styleTemplate({ return styleTemplate({
"style": style.style, style: style.style,
"text": text text: matchedText
}); });
}); });
}); });

View File

@ -88,6 +88,7 @@ $(function() {
socket.on("auth", function(data) { socket.on("auth", function(data) {
var login = $("#sign-in"); var login = $("#sign-in");
var token;
login.find(".btn").prop("disabled", false); login.find(".btn").prop("disabled", false);
@ -99,7 +100,7 @@ $(function() {
error.hide(); error.hide();
}); });
} else { } else {
var token = window.localStorage.getItem("token"); token = window.localStorage.getItem("token");
if (token) { if (token) {
$("#loading-page-message").text("Authorizing…"); $("#loading-page-message").text("Authorizing…");
socket.emit("auth", {token: token}); socket.emit("auth", {token: token});
@ -476,7 +477,7 @@ $(function() {
socket.on("names", renderChannelUsers); socket.on("names", renderChannelUsers);
var userStyles = $("#user-specified-css"); var userStyles = $("#user-specified-css");
var settings = $("#settings"); var highlights = [];
var options = $.extend({ var options = $.extend({
coloredNicks: true, coloredNicks: true,
desktopNotifications: false, desktopNotifications: false,
@ -494,6 +495,9 @@ $(function() {
userStyles: userStyles.text(), userStyles: userStyles.text(),
}, JSON.parse(window.localStorage.getItem("settings"))); }, JSON.parse(window.localStorage.getItem("settings")));
(function SettingsScope() {
var settings = $("#settings");
for (var i in options) { for (var i in options) {
if (i === "userStyles") { if (i === "userStyles") {
if (!/[\?&]nocss/.test(window.location.search)) { if (!/[\?&]nocss/.test(window.location.search)) {
@ -510,8 +514,6 @@ $(function() {
} }
} }
var highlights = [];
settings.on("change", "input, select, textarea", function() { settings.on("change", "input, select, textarea", function() {
var self = $(this); var self = $(this);
var name = self.attr("name"); var name = self.attr("name");
@ -539,7 +541,7 @@ $(function() {
} else if (name === "theme") { } else if (name === "theme") {
$("#theme").attr("href", "themes/" + options[name] + ".css"); $("#theme").attr("href", "themes/" + options[name] + ".css");
} else if (name === "userStyles") { } else if (name === "userStyles") {
$(document.head).find("#user-specified-css").html(options[name]); userStyles.html(options[name]);
} else if (name === "highlights") { } else if (name === "highlights") {
var highlightString = options[name]; var highlightString = options[name];
highlights = highlightString.split(",").map(function(h) { highlights = highlightString.split(",").map(function(h) {
@ -561,6 +563,7 @@ $(function() {
} }
} }
}); });
}());
var viewport = $("#viewport"); var viewport = $("#viewport");
var sidebarSlide = window.slideoutMenu(viewport[0], sidebar[0]); var sidebarSlide = window.slideoutMenu(viewport[0], sidebar[0]);
@ -676,9 +679,7 @@ $(function() {
}) })
.tab(complete, {hint: false}); .tab(complete, {hint: false});
var form = $("#form"); $("#form").on("submit", function(e) {
form.on("submit", function(e) {
e.preventDefault(); e.preventDefault();
var text = input.val(); var text = input.val();
@ -1027,20 +1028,20 @@ $(function() {
chat.on("click", ".toggle-button", function() { chat.on("click", ".toggle-button", function() {
var self = $(this); var self = $(this);
var chat = self.closest(".chat"); var localChat = self.closest(".chat");
var bottom = chat.isScrollBottom(); var bottom = localChat.isScrollBottom();
var content = self.parent().next(".toggle-content"); var content = self.parent().next(".toggle-content");
if (bottom && !content.hasClass("show")) { if (bottom && !content.hasClass("show")) {
var img = content.find("img"); var img = content.find("img");
if (img.length !== 0 && !img.width()) { if (img.length !== 0 && !img.width()) {
img.on("load", function() { img.on("load", function() {
chat.scrollBottom(); localChat.scrollBottom();
}); });
} }
} }
content.toggleClass("show"); content.toggleClass("show");
if (bottom) { if (bottom) {
chat.scrollBottom(); localChat.scrollBottom();
} }
}); });
@ -1048,9 +1049,7 @@ $(function() {
var forms = $("#sign-in, #connect, #change-password"); var forms = $("#sign-in, #connect, #change-password");
windows.on("show", "#sign-in", function() { windows.on("show", "#sign-in", function() {
var self = $(this); $(this).find("input").each(function() {
var inputs = self.find("input");
inputs.each(function() {
var self = $(this); var self = $(this);
if (self.val() === "") { if (self.val() === "") {
self.focus(); self.focus();

View File

@ -9,9 +9,9 @@ var fonts = [
"fontawesome-webfont.woff2" "fontawesome-webfont.woff2"
]; ];
fs.ensureDir(destDir, function (err) { fs.ensureDir(destDir, function(dirErr) {
if (err) { if (dirErr) {
console.error(err); console.error(dirErr);
} }
fonts.forEach(function(font) { fonts.forEach(function(font) {

View File

@ -118,12 +118,12 @@ Client.prototype.emit = function(event, data) {
} }
}; };
Client.prototype.find = function(id) { Client.prototype.find = function(channelId) {
var network = null; var network = null;
var chan = null; var chan = null;
for (var i in this.networks) { for (var i in this.networks) {
var n = this.networks[i]; var n = this.networks[i];
chan = _.find(n.channels, {id: id}); chan = _.find(n.channels, {id: channelId});
if (chan) { if (chan) {
network = n; network = n;
break; break;
@ -134,9 +134,9 @@ Client.prototype.find = function(id) {
network: network, network: network,
chan: chan chan: chan
}; };
} else {
return false;
} }
return false;
}; };
Client.prototype.connect = function(args) { Client.prototype.connect = function(args) {
@ -168,7 +168,7 @@ Client.prototype.connect = function(args) {
// also used by the "connect" window // also used by the "connect" window
} else if (args.join) { } else if (args.join) {
channels = args.join channels = args.join
.replace(/\,/g, " ") .replace(/,/g, " ")
.split(/\s+/g) .split(/\s+/g)
.map(function(chan) { .map(function(chan) {
return new Chan({ return new Chan({
@ -278,6 +278,10 @@ Client.prototype.updateToken = function(callback) {
var client = this; var client = this;
crypto.randomBytes(48, function(err, buf) { crypto.randomBytes(48, function(err, buf) {
if (err) {
throw err;
}
callback(client.config.token = buf.toString("hex")); callback(client.config.token = buf.toString("hex"));
}); });
}; };

View File

@ -34,8 +34,9 @@ ClientManager.prototype.loadUsers = function() {
}; };
ClientManager.prototype.loadUser = function(name) { ClientManager.prototype.loadUser = function(name) {
let json;
try { try {
var json = this.readUserConfig(name); json = this.readUserConfig(name);
} catch (e) { } catch (e) {
log.error("Failed to read user config", e); log.error("Failed to read user config", e);
return; return;

View File

@ -78,9 +78,9 @@ Chan.prototype.getMode = function(name) {
var user = _.find(this.users, {name: name}); var user = _.find(this.users, {name: name});
if (user) { if (user) {
return user.mode; return user.mode;
} else {
return "";
} }
return "";
}; };
Chan.prototype.toJSON = function() { Chan.prototype.toJSON = function() {

View File

@ -12,10 +12,10 @@ exports.input = function(network, chan, cmd, args) {
if (cmd !== "mode") { if (cmd !== "mode") {
user = args[0]; user = args[0];
mode = { mode = {
"op": "+o", op: "+o",
"voice": "+v", voice: "+v",
"deop": "-o", deop: "-o",
"devoice": "-v" devoice: "-v"
}[cmd]; }[cmd];
} else if (args.length === 1) { } else if (args.length === 1) {
return true; return true;

View File

@ -90,8 +90,9 @@ function parse(msg, url, res, client) {
} }
function fetch(url, cb) { function fetch(url, cb) {
let req;
try { try {
var req = request.get({ req = request.get({
url: url, url: url,
maxRedirects: 5, maxRedirects: 5,
timeout: 5000, timeout: 5000,

View File

@ -34,8 +34,9 @@ module.exports = function(irc, network) {
}); });
function handleMessage(data) { function handleMessage(data) {
var highlight = false; let chan;
var self = data.nick === irc.user.nick; let highlight = false;
const self = data.nick === irc.user.nick;
// Server messages go to server window, no questions asked // Server messages go to server window, no questions asked
if (data.from_server) { if (data.from_server) {
@ -48,7 +49,7 @@ module.exports = function(irc, network) {
target = data.nick; target = data.nick;
} }
var chan = network.getChannel(target); chan = network.getChannel(target);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
// Send notices that are not targeted at us into the server window // Send notices that are not targeted at us into the server window
if (data.type === Msg.Type.NOTICE) { if (data.type === Msg.Type.NOTICE) {

View File

@ -6,12 +6,13 @@ var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("nick", function(data) { irc.on("nick", function(data) {
let msg;
var self = false; var self = false;
if (data.nick === irc.user.nick) { if (data.nick === irc.user.nick) {
network.setNick(data.new_nick); network.setNick(data.new_nick);
var lobby = network.channels[0]; var lobby = network.channels[0];
var msg = new Msg({ msg = new Msg({
text: "You're now known as " + data.new_nick, text: "You're now known as " + data.new_nick,
}); });
lobby.pushMessage(client, msg); lobby.pushMessage(client, msg);
@ -33,7 +34,7 @@ module.exports = function(irc, network) {
client.emit("users", { client.emit("users", {
chan: chan.id chan: chan.id
}); });
var msg = new Msg({ msg = new Msg({
time: data.time, time: data.time,
type: Msg.Type.NICK, type: Msg.Type.NICK,
mode: chan.getMode(data.new_nick), mode: chan.getMode(data.new_nick),

View File

@ -127,13 +127,17 @@ function index(req, res, next) {
} }
return fs.readFile("client/index.html", "utf-8", function(err, file) { return fs.readFile("client/index.html", "utf-8", function(err, file) {
if (err) {
throw err;
}
var data = _.merge( var data = _.merge(
pkg, pkg,
Helper.config Helper.config
); );
data.gitCommit = gitCommit; data.gitCommit = gitCommit;
data.themes = fs.readdirSync("client/themes/").filter(function(file) { data.themes = fs.readdirSync("client/themes/").filter(function(themeFile) {
return file.endsWith(".css"); return themeFile.endsWith(".css");
}).map(function(css) { }).map(function(css) {
return css.slice(0, -4); return css.slice(0, -4);
}); });
@ -317,7 +321,7 @@ function auth(data) {
manager.loadUser(data.user); manager.loadUser(data.user);
client = manager.findClient(data.user); client = manager.findClient(data.user);
} }
if (Helper.config.webirc !== null && !client.config["ip"]) { if (Helper.config.webirc !== null && !client.config.ip) {
reverseDnsLookup(socket, client); reverseDnsLookup(socket, client);
} else { } else {
init(socket, client, token); init(socket, client, token);

View File

@ -6,8 +6,9 @@ var moment = require("moment");
var Helper = require("./helper"); var Helper = require("./helper");
module.exports.write = function(user, network, chan, msg) { module.exports.write = function(user, network, chan, msg) {
const path = Helper.getUserLogsPath(user, network);
try { try {
var path = Helper.getUserLogsPath(user, network);
fsextra.ensureDirSync(path); fsextra.ensureDirSync(path);
} catch (e) { } catch (e) {
log.error("Unabled to create logs directory", e); log.error("Unabled to create logs directory", e);

View File

@ -29,8 +29,8 @@ describe("Network", function() {
ip: null, ip: null,
hostname: null, hostname: null,
channels: [ channels: [
{"name": "#thelounge"}, {name: "#thelounge"},
{"name": "&foobar"}, {name: "&foobar"},
] ]
}); });
}); });