Skip to content

Commit

Permalink
Update to eslint 4 and enforce extra rules
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Jun 16, 2017
1 parent 1a6f2fc commit f560084
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 50 deletions.
16 changes: 13 additions & 3 deletions .eslintrc.yml
Expand Up @@ -9,22 +9,28 @@ env:
node: true

rules:
arrow-body-style: 2
arrow-parens: [2, as-needed]
arrow-spacing: 2
block-scoped-var: 2
block-spacing: [2, always]
brace-style: [2, 1tbs]
comma-dangle: 0
curly: [2, all]
dot-location: [2, property]
dot-notation: 2
eol-last: 2
eqeqeq: 2
handle-callback-err: 2
indent: [2, tab, { "MemberExpression": 1 }]
indent: [2, tab]
key-spacing: [2, {beforeColon: false, afterColon: true}]
keyword-spacing: [2, {before: true, after: true}]
linebreak-style: [2, unix]
no-compare-neg-zero: 2
no-catch-shadow: 2
no-confusing-arrow: 2
no-console: 0
no-control-regex: 0
no-duplicate-imports: 2
no-else-return: 2
no-implicit-globals: 2
no-multi-spaces: 2
Expand All @@ -33,19 +39,23 @@ rules:
no-template-curly-in-string: 2
no-trailing-spaces: 2
no-unsafe-negation: 2
no-useless-escape: 2
no-useless-computed-key: 2
no-useless-return: 2
object-curly-spacing: [2, never]
padded-blocks: [2, never]
prefer-const: 2
quote-props: [2, as-needed]
quotes: [2, double, avoid-escape]
semi-style: [2, last]
semi: [2, always]
space-before-blocks: 2
space-before-function-paren: [2, never]
space-in-parens: [2, never]
space-infix-ops: 2
spaced-comment: [2, always]
strict: 2
template-curly-spacing: 2
yoda: 2

globals:
log: false
Expand Down
2 changes: 1 addition & 1 deletion client/js/libs/handlebars/ircmessageparser/findLinks.js
Expand Up @@ -16,7 +16,7 @@ const commonSchemes = [
];

function findLinks(text) {
let result = [];
const result = [];

// URI.withinString() identifies URIs within text, e.g. to translate them to
// <a>-Tags.
Expand Down
1 change: 0 additions & 1 deletion client/js/libs/handlebars/ircmessageparser/parseStyle.js
Expand Up @@ -84,7 +84,6 @@ function parseStyle(text) {
// encountered since the previous styling character.
while (position < text.length) {
switch (text[position]) {

case RESET:
emitFragment();
resetStyle();
Expand Down
2 changes: 1 addition & 1 deletion client/js/libs/handlebars/parse.js
Expand Up @@ -8,7 +8,7 @@ const merge = require("./ircmessageparser/merge");

// Create an HTML `span` with styling information for a given fragment
function createFragment(fragment) {
let classes = [];
const classes = [];
if (fragment.bold) {
classes.push("irc-bold");
}
Expand Down
30 changes: 14 additions & 16 deletions client/js/lounge.js
Expand Up @@ -476,7 +476,7 @@ $(function() {
$(container).empty();
}

// Check if date changed
// Check if date changed
var prevMsg = $(container.find(".msg")).last();
var prevMsgTime = new Date(prevMsg.attr("data-time"));
var msgTime = new Date(msg.attr("data-time"));
Expand All @@ -490,7 +490,7 @@ $(function() {
prevMsg.after(templates.date_marker({msgDate: msgTime}));
}

// Add message to the container
// Add message to the container
container
.append(msg)
.trigger("msg", [
Expand Down Expand Up @@ -1628,19 +1628,17 @@ $(function() {
// Only start opening socket.io connection after all events have been registered
socket.open();

window.addEventListener(
"popstate",
(e) => {
const {state} = e;
if (!state) {
return;
}
const {clickTarget} = state;
if (clickTarget) {
$(clickTarget).trigger("click", {
pushState: false
});
}
window.addEventListener("popstate", e => {
const {state} = e;
if (!state) {
return;
}
);

const {clickTarget} = state;
if (clickTarget) {
$(clickTarget).trigger("click", {
pushState: false
});
}
});
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -63,7 +63,7 @@
"babel-loader": "7.0.0",
"babel-preset-env": "1.5.2",
"chai": "4.0.2",
"eslint": "3.19.0",
"eslint": "4.0.0",
"font-awesome": "4.7.0",
"fuzzy": "0.1.3",
"handlebars": "4.0.10",
Expand Down
10 changes: 3 additions & 7 deletions src/client.js
Expand Up @@ -422,9 +422,7 @@ Client.prototype.sort = function(data) {

switch (data.type) {
case "networks":
this.networks.sort((a, b) => {
return order.indexOf(a.id) - order.indexOf(b.id);
});
this.networks.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));

// Sync order to connected clients
this.emit("sync_sort", {order: this.networks.map(obj => obj.id), type: data.type, target: data.target});
Expand All @@ -437,9 +435,7 @@ Client.prototype.sort = function(data) {
return;
}

network.channels.sort((a, b) => {
return order.indexOf(a.id) - order.indexOf(b.id);
});
network.channels.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));

// Sync order to connected clients
this.emit("sync_sort", {order: network.channels.map(obj => obj.id), type: data.type, target: data.target});
Expand Down Expand Up @@ -539,7 +535,7 @@ Client.prototype.save = _.debounce(function SaveClient() {
}

const client = this;
let json = {};
const json = {};
json.networks = this.networks.map(n => n.export());
client.manager.updateUser(client.name, json);
}, 1000, {maxWait: 10000});
4 changes: 2 additions & 2 deletions src/clientManager.js
Expand Up @@ -127,7 +127,7 @@ ClientManager.prototype.updateUser = function(name, opts, callback) {
return false;
}

let user = this.readUserConfig(name);
const user = this.readUserConfig(name);
const currentUser = JSON.stringify(user, null, "\t");
_.assign(user, opts);
const newUser = JSON.stringify(user, null, "\t");
Expand All @@ -137,7 +137,7 @@ ClientManager.prototype.updateUser = function(name, opts, callback) {
return callback ? callback() : true;
}

fs.writeFile(Helper.getUserConfigPath(name), newUser, (err) => {
fs.writeFile(Helper.getUserConfigPath(name), newUser, err => {
if (err) {
log.error("Failed to update user", err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/identification.js
Expand Up @@ -89,7 +89,7 @@ class Identification {
refresh() {
let file = "# Warning: file generated by The Lounge: changes will be overwritten!\n";

this.connections.forEach((connection) => {
this.connections.forEach(connection => {
file += "to " + connection.socket.remoteAddress
+ " lport " + connection.socket.localPort
+ " from " + connection.socket.localAddress
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/irc-events/banlist.js
Expand Up @@ -36,7 +36,7 @@ module.exports = function(irc, network) {
chan.pushMessage(client,
new Msg({
type: Msg.Type.BANLIST,
bans: bans.map((data) => ({
bans: bans.map(data => ({
hostmask: data.banned,
banned_by: data.banned_by,
banned_at: data.banned_at * 1000
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/irc-events/link.js
Expand Up @@ -22,7 +22,7 @@ module.exports = function(client, chan, originalMsg) {
return;
}

let msg = new Msg({
const msg = new Msg({
type: Msg.Type.TOGGLE,
time: originalMsg.time,
self: originalMsg.self,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/irc-events/mode.js
Expand Up @@ -46,7 +46,7 @@ module.exports = function(irc, network) {
}

let usersUpdated;
let userModeSortPriority = {};
const userModeSortPriority = {};
const supportsMultiPrefix = network.irc.network.cap.isEnabled("multi-prefix");

irc.network.options.PREFIX.forEach((prefix, index) => {
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/irc-events/names.js
Expand Up @@ -10,12 +10,10 @@ module.exports = function(irc, network) {
return;
}

chan.users = data.users.map(user => {
return new User({
nick: user.nick,
modes: user.modes,
}, network.prefixLookup);
});
chan.users = data.users.map(user => new User({
nick: user.nick,
modes: user.modes,
}, network.prefixLookup));

chan.sortUsers(irc);

Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Expand Up @@ -108,7 +108,7 @@ in ${config.public ? "public" : "private"} mode`);

manager = new ClientManager();

new Identification((identHandler) => {
new Identification(identHandler => {
manager.init(identHandler, sockets);
});
};
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/link.js
Expand Up @@ -21,7 +21,7 @@ describe("Link plugin", function() {
});

it("should be able to fetch basic information about URLs", function(done) {
let message = this.irc.createMessage({
const message = this.irc.createMessage({
text: "http://localhost:9002/basic"
});

Expand Down
10 changes: 5 additions & 5 deletions test/tests/passwords.js
Expand Up @@ -8,7 +8,7 @@ describe("Client passwords", function() {

it("hashed password should match", function() {
// Generated with third party tool to test implementation
let comparedPassword = Helper.password.compare(inputPassword, "$2a$11$zrPPcfZ091WNfs6QrRHtQeUitlgrJcecfZhxOFiQs0FWw7TN3Q1oS");
const comparedPassword = Helper.password.compare(inputPassword, "$2a$11$zrPPcfZ091WNfs6QrRHtQeUitlgrJcecfZhxOFiQs0FWw7TN3Q1oS");

return comparedPassword.then(result => {
expect(result).to.be.true;
Expand All @@ -17,18 +17,18 @@ describe("Client passwords", function() {

it("wrong hashed password should not match", function() {
// Compare against a fake hash
let comparedPassword = Helper.password.compare(inputPassword, "$2a$11$zrPPcfZ091WRONGPASSWORDitlgrJcecfZhxOFiQs0FWw7TN3Q1oS");
const comparedPassword = Helper.password.compare(inputPassword, "$2a$11$zrPPcfZ091WRONGPASSWORDitlgrJcecfZhxOFiQs0FWw7TN3Q1oS");

return comparedPassword.then(result => {
expect(result).to.be.false;
});
});

it("freshly hashed password should match", function() {
let hashedPassword = Helper.password.hash(inputPassword);
let comparedPassword = Helper.password.compare(inputPassword, hashedPassword);
const hashedPassword = Helper.password.hash(inputPassword);
const comparedPassword = Helper.password.compare(inputPassword, hashedPassword);

return comparedPassword.then((result) => {
return comparedPassword.then(result => {
expect(result).to.be.true;
});
});
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Expand Up @@ -7,7 +7,7 @@ const path = require("path");
// Common configuration
// ********************

let config = {
const config = {
entry: {
"js/bundle.js": path.resolve(__dirname, "client/js/lounge.js"),
"js/bundle.vendor.js": [
Expand Down

0 comments on commit f560084

Please sign in to comment.