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 19, 2017
1 parent edc106d commit f6dd616
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 130 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, always]
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
4 changes: 2 additions & 2 deletions 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 All @@ -29,7 +29,7 @@ function findLinks(text) {
// Check if the scheme of the detected URL matches a common one above.
// In a URL like `foo..http://example.com`, the scheme would be `foo..http`,
// so we need to clean up the end of the scheme and filter out the rest.
const matchedScheme = commonSchemes.find(scheme => parsedScheme.endsWith(scheme));
const matchedScheme = commonSchemes.find((scheme) => parsedScheme.endsWith(scheme));

// A known scheme was found, extract the unknown part from the URL
if (matchedScheme) {
Expand Down
6 changes: 3 additions & 3 deletions client/js/libs/handlebars/ircmessageparser/merge.js
Expand Up @@ -48,10 +48,10 @@ function merge(textParts, styleFragments) {
.sort((a, b) => a.start - b.start);

// Distribute the style fragments within the text parts
return allParts.map(textPart => {
return allParts.map((textPart) => {
textPart.fragments = styleFragments
.filter(fragment => anyIntersection(textPart, fragment))
.map(fragment => assign(textPart, fragment));
.filter((fragment) => anyIntersection(textPart, fragment))
.map((fragment) => assign(textPart, fragment));

return textPart;
});
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -178,7 +177,7 @@ function prepare(text) {
.reduce((prev, curr) => {
if (prev.length) {
const lastEntry = prev[prev.length - 1];
if (properties.every(key => curr[key] === lastEntry[key])) {
if (properties.every((key) => curr[key] === lastEntry[key])) {
lastEntry.text += curr.text;
lastEntry.end += curr.text.length;
return prev;
Expand Down
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -50,7 +50,7 @@ function createFragment(fragment) {
module.exports = function parse(text) {
// Extract the styling information and get the plain text version from it
const styleFragments = parseStyle(text);
const cleanText = styleFragments.map(fragment => fragment.text).join("");
const cleanText = styleFragments.map((fragment) => fragment.text).join("");

// On the plain text, find channels and URLs, returned as "parts". Parts are
// arrays of objects containing start and end markers, as well as metadata
Expand All @@ -67,7 +67,7 @@ module.exports = function parse(text) {

// Merge the styling information with the channels / URLs / text objects and
// generate HTML strings with the resulting fragments
return merge(parts, styleFragments).map(textPart => {
return merge(parts, styleFragments).map((textPart) => {
// Create HTML strings with styling information
const fragments = textPart.fragments.map(createFragment).join("");

Expand Down
48 changes: 23 additions & 25 deletions client/js/lounge.js
Expand Up @@ -52,7 +52,7 @@ $(function() {
id: "emoji",
match: /\B:([-+\w]*):?$/,
search(term, callback) {
callback(Object.keys(emojiMap).filter(name => name.indexOf(term) === 0));
callback(Object.keys(emojiMap).filter((name) => name.indexOf(term) === 0));
},
template(value) {
return `<span class="emoji">${emojiMap[value]}</span> ${value}`;
Expand All @@ -69,7 +69,7 @@ $(function() {
search(term, callback) {
term = term.slice(1);
if (term[0] === "@") {
callback(completeNicks(term.slice(1)).map(val => "@" + val));
callback(completeNicks(term.slice(1)).map((val) => "@" + val));
} else {
callback(completeNicks(term));
}
Expand Down Expand Up @@ -119,7 +119,7 @@ $(function() {
search(term, callback) {
term = term.toLowerCase();
const matchingColorCodes = constants.colorCodeMap
.filter(i => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term));
.filter((i) => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term));

callback(matchingColorCodes);
},
Expand All @@ -138,8 +138,8 @@ $(function() {
search(term, callback, match) {
term = term.toLowerCase();
const matchingColorCodes = constants.colorCodeMap
.filter(i => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term))
.map(pair => pair.concat(match[1])); // Needed to pass fg color to `template`...
.filter((i) => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term))
.map((pair) => pair.concat(match[1])); // Needed to pass fg color to `template`...

callback(matchingColorCodes);
},
Expand Down 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 @@ -1099,7 +1099,7 @@ $(function() {
const fuzzyOptions = {
pre: "<b>",
post: "</b>",
extract: el => $(el).text()
extract: (el) => $(el).text()
};

const result = fuzzy.filter(
Expand Down Expand Up @@ -1438,7 +1438,7 @@ $(function() {

return $.grep(
words,
w => !w.toLowerCase().indexOf(word.toLowerCase())
(w) => !w.toLowerCase().indexOf(word.toLowerCase())
);
}

Expand All @@ -1447,7 +1447,7 @@ $(function() {

return $.grep(
words,
w => !w.toLowerCase().indexOf(word.toLowerCase())
(w) => !w.toLowerCase().indexOf(word.toLowerCase())
);
}

Expand All @@ -1464,7 +1464,7 @@ $(function() {

return $.grep(
words,
w => !w.toLowerCase().indexOf(word.toLowerCase())
(w) => !w.toLowerCase().indexOf(word.toLowerCase())
);
}

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
30 changes: 13 additions & 17 deletions src/client.js
Expand Up @@ -58,7 +58,7 @@ var inputs = [
].reduce(function(plugins, name) {
var path = "./plugins/inputs/" + name;
var plugin = require(path);
plugin.commands.forEach(command => plugins[command] = plugin);
plugin.commands.forEach((command) => plugins[command] = plugin);
return plugins;
}, {});

Expand Down Expand Up @@ -88,7 +88,7 @@ function Client(manager, name, config) {
}

var delay = 0;
(client.config.networks || []).forEach(n => {
(client.config.networks || []).forEach((n) => {
setTimeout(function() {
client.connect(n);
}, delay);
Expand Down Expand Up @@ -155,7 +155,7 @@ Client.prototype.connect = function(args) {
if (args.channels) {
var badName = false;

args.channels.forEach(chan => {
args.channels.forEach((chan) => {
if (!chan.name) {
badName = true;
return;
Expand Down Expand Up @@ -273,7 +273,7 @@ Client.prototype.connect = function(args) {
"znc.in/self-message", // Legacy echo-message for ZNc
]);

events.forEach(plugin => {
events.forEach((plugin) => {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
network.irc,
Expand Down Expand Up @@ -319,7 +319,7 @@ Client.prototype.setPassword = function(hash, callback) {

Client.prototype.input = function(data) {
var client = this;
data.text.split("\n").forEach(line => {
data.text.split("\n").forEach((line) => {
data.text = line;
client.inputLine(data);
});
Expand Down Expand Up @@ -422,12 +422,10 @@ 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});
this.emit("sync_sort", {order: this.networks.map((obj) => obj.id), type: data.type, target: data.target});

break;

Expand All @@ -437,12 +435,10 @@ 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});
this.emit("sync_sort", {order: network.channels.map((obj) => obj.id), type: data.type, target: data.target});

break;
}
Expand Down Expand Up @@ -472,7 +468,7 @@ Client.prototype.quit = function() {
socket.disconnect();
}
}
this.networks.forEach(network => {
this.networks.forEach((network) => {
if (network.irc) {
network.irc.quit("Page closed");
}
Expand All @@ -496,7 +492,7 @@ Client.prototype.clientAttach = function(socketId) {
client.attachedClients[socketId] = client.lastActiveChannel;

// Update old networks to store ip and hostmask
client.networks.forEach(network => {
client.networks.forEach((network) => {
if (!network.ip) {
save = true;
network.ip = (client.config && client.config.ip) || client.ip;
Expand Down Expand Up @@ -539,7 +535,7 @@ Client.prototype.save = _.debounce(function SaveClient() {
}

const client = this;
let json = {};
json.networks = this.networks.map(n => n.export());
const json = {};
json.networks = this.networks.map((n) => n.export());
client.manager.updateUser(client.name, json);
}, 1000, {maxWait: 10000});

0 comments on commit f6dd616

Please sign in to comment.