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

View File

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

View File

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

View File

@ -33,7 +33,7 @@ function uri(text) {
*/
function channels(text) {
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>'
);
}
@ -114,10 +114,10 @@ function colors(line) {
return;
}
result = result.replace(style.keyregex, function(match, text) {
result = result.replace(style.keyregex, function(matchedTrash, matchedText) {
return styleTemplate({
"style": style.style,
"text": text
style: style.style,
text: matchedText
});
});
});

View File

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

View File

@ -9,9 +9,9 @@ var fonts = [
"fontawesome-webfont.woff2"
];
fs.ensureDir(destDir, function (err) {
if (err) {
console.error(err);
fs.ensureDir(destDir, function(dirErr) {
if (dirErr) {
console.error(dirErr);
}
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 chan = null;
for (var i in this.networks) {
var n = this.networks[i];
chan = _.find(n.channels, {id: id});
chan = _.find(n.channels, {id: channelId});
if (chan) {
network = n;
break;
@ -134,9 +134,9 @@ Client.prototype.find = function(id) {
network: network,
chan: chan
};
} else {
return false;
}
return false;
};
Client.prototype.connect = function(args) {
@ -168,7 +168,7 @@ Client.prototype.connect = function(args) {
// also used by the "connect" window
} else if (args.join) {
channels = args.join
.replace(/\,/g, " ")
.replace(/,/g, " ")
.split(/\s+/g)
.map(function(chan) {
return new Chan({
@ -278,6 +278,10 @@ Client.prototype.updateToken = function(callback) {
var client = this;
crypto.randomBytes(48, function(err, buf) {
if (err) {
throw err;
}
callback(client.config.token = buf.toString("hex"));
});
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,12 +6,13 @@ var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("nick", function(data) {
let msg;
var self = false;
if (data.nick === irc.user.nick) {
network.setNick(data.new_nick);
var lobby = network.channels[0];
var msg = new Msg({
msg = new Msg({
text: "You're now known as " + data.new_nick,
});
lobby.pushMessage(client, msg);
@ -33,7 +34,7 @@ module.exports = function(irc, network) {
client.emit("users", {
chan: chan.id
});
var msg = new Msg({
msg = new Msg({
time: data.time,
type: Msg.Type.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) {
if (err) {
throw err;
}
var data = _.merge(
pkg,
Helper.config
);
data.gitCommit = gitCommit;
data.themes = fs.readdirSync("client/themes/").filter(function(file) {
return file.endsWith(".css");
data.themes = fs.readdirSync("client/themes/").filter(function(themeFile) {
return themeFile.endsWith(".css");
}).map(function(css) {
return css.slice(0, -4);
});
@ -317,7 +321,7 @@ function auth(data) {
manager.loadUser(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);
} else {
init(socket, client, token);

View File

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

View File

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