Skip to content

Commit

Permalink
Merge pull request #681 from thelounge/xpaw/more-eslint
Browse files Browse the repository at this point in the history
Enforce more eslint rules
  • Loading branch information
astorije committed Oct 9, 2016
2 parents 6b597d3 + aa02fd5 commit 7e39ae0
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 121 deletions.
17 changes: 12 additions & 5 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client/js/libs/handlebars/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Handlebars.registerHelper(
if (a !== diff) {
diff = a;
return opt.fn(this);
} else {
return opt.inverse(this);
}

return opt.inverse(this);
}
);
4 changes: 2 additions & 2 deletions client/js/libs/handlebars/equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Handlebars.registerHelper(
b = b.toString();
if (a === b) {
return opt.fn(this);
} else {
return opt.inverse(this);
}

return opt.inverse(this);
}
);
8 changes: 4 additions & 4 deletions client/js/libs/handlebars/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>'
);
}
Expand Down Expand Up @@ -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
});
});
});
Expand Down
145 changes: 72 additions & 73 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ $(function() {

socket.on("auth", function(data) {
var login = $("#sign-in");
var token;

login.find(".btn").prop("disabled", false);

Expand All @@ -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});
Expand Down Expand Up @@ -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,
Expand All @@ -494,73 +495,75 @@ $(function() {
userStyles: userStyles.text(),
}, JSON.parse(window.localStorage.getItem("settings")));

for (var i in options) {
if (i === "userStyles") {
if (!/[\?&]nocss/.test(window.location.search)) {
$(document.head).find("#user-specified-css").html(options[i]);
(function SettingsScope() {
var settings = $("#settings");

for (var i in options) {
if (i === "userStyles") {
if (!/[\?&]nocss/.test(window.location.search)) {
$(document.head).find("#user-specified-css").html(options[i]);
}
settings.find("#user-specified-css-input").val(options[i]);
} else if (i === "highlights") {
settings.find("input[name=" + i + "]").val(options[i]);
} else if (i === "theme") {
$("#theme").attr("href", "themes/" + options[i] + ".css");
settings.find("select[name=" + i + "]").val(options[i]);
} else if (options[i]) {
settings.find("input[name=" + i + "]").prop("checked", true);
}
settings.find("#user-specified-css-input").val(options[i]);
} else if (i === "highlights") {
settings.find("input[name=" + i + "]").val(options[i]);
} else if (i === "theme") {
$("#theme").attr("href", "themes/" + options[i] + ".css");
settings.find("select[name=" + i + "]").val(options[i]);
} else if (options[i]) {
settings.find("input[name=" + i + "]").prop("checked", true);
}
}

var highlights = [];

settings.on("change", "input, select, textarea", function() {
var self = $(this);
var name = self.attr("name");

if (self.attr("type") === "checkbox") {
options[name] = self.prop("checked");
} else {
options[name] = self.val();
}
settings.on("change", "input, select, textarea", function() {
var self = $(this);
var name = self.attr("name");

setLocalStorageItem("settings", JSON.stringify(options));
if (self.attr("type") === "checkbox") {
options[name] = self.prop("checked");
} else {
options[name] = self.val();
}

if ([
"join",
"mode",
"motd",
"nick",
"part",
"quit",
"notifyAllMessages",
].indexOf(name) !== -1) {
chat.toggleClass("hide-" + name, !self.prop("checked"));
} else if (name === "coloredNicks") {
chat.toggleClass("colored-nicks", self.prop("checked"));
} else if (name === "theme") {
$("#theme").attr("href", "themes/" + options[name] + ".css");
} else if (name === "userStyles") {
$(document.head).find("#user-specified-css").html(options[name]);
} else if (name === "highlights") {
var highlightString = options[name];
highlights = highlightString.split(",").map(function(h) {
return h.trim();
}).filter(function(h) {
// Ensure we don't have empty string in the list of highlights
// otherwise, users get notifications for everything
return h !== "";
});
}
}).find("input")
.trigger("change");
setLocalStorageItem("settings", JSON.stringify(options));

if ([
"join",
"mode",
"motd",
"nick",
"part",
"quit",
"notifyAllMessages",
].indexOf(name) !== -1) {
chat.toggleClass("hide-" + name, !self.prop("checked"));
} else if (name === "coloredNicks") {
chat.toggleClass("colored-nicks", self.prop("checked"));
} else if (name === "theme") {
$("#theme").attr("href", "themes/" + options[name] + ".css");
} else if (name === "userStyles") {
userStyles.html(options[name]);
} else if (name === "highlights") {
var highlightString = options[name];
highlights = highlightString.split(",").map(function(h) {
return h.trim();
}).filter(function(h) {
// Ensure we don't have empty string in the list of highlights
// otherwise, users get notifications for everything
return h !== "";
});
}
}).find("input")
.trigger("change");

$("#desktopNotifications").on("change", function() {
var self = $(this);
if (self.prop("checked")) {
if (Notification.permission !== "granted") {
Notification.requestPermission(updateDesktopNotificationStatus);
$("#desktopNotifications").on("change", function() {
var self = $(this);
if (self.prop("checked")) {
if (Notification.permission !== "granted") {
Notification.requestPermission(updateDesktopNotificationStatus);
}
}
}
});
});
}());

var viewport = $("#viewport");
var sidebarSlide = window.slideoutMenu(viewport[0], sidebar[0]);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -804,7 +805,7 @@ $(function() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type !== "Control") {
} else if (document.selection && document.selection.type !== "Control") {
text = document.selection.createRange().text;
}
if (!text) {
Expand Down Expand Up @@ -1027,30 +1028,28 @@ $(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();
}
});

var windows = $("#windows");
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();
Expand Down
10 changes: 5 additions & 5 deletions scripts/build-fontawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ 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) {
fs.copy(srcDir + font, destDir + font, function (err) {
fonts.forEach(function(font) {
fs.copy(srcDir + font, destDir + font, function(err) {
if (err) {
console.error(err);
} else {
Expand Down
14 changes: 9 additions & 5 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -134,9 +134,9 @@ Client.prototype.find = function(id) {
network: network,
chan: chan
};
} else {
return false;
}

return false;
};

Client.prototype.connect = function(args) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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"));
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/clientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/command-line/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var server = require("../server");
var Helper = require("../helper");

program
.option("-H, --host <ip>" , "host")
.option("-P, --port <port>" , "port")
.option("-B, --bind <ip>" , "bind")
.option(" --public" , "mode")
.option(" --private" , "mode")
.option("-H, --host <ip>", "host")
.option("-P, --port <port>", "port")
.option("-B, --bind <ip>", "bind")
.option(" --public", "mode")
.option(" --private", "mode")
.command("start")
.description("Start the server")
.action(function() {
Expand Down

0 comments on commit 7e39ae0

Please sign in to comment.