From a5a3f3089a30353986a900ae93cc7c435a9cff8e Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Sat, 18 Feb 2017 01:51:11 -0700
Subject: [PATCH] ESlint no-mixed-operators
---
.eslintrc | 3 ++-
loader.js | 2 +-
public/src/admin/admin.js | 2 +-
public/src/admin/manage/users.js | 2 +-
public/src/client/account/header.js | 2 +-
public/src/client/chats.js | 2 +-
public/src/modules/chat.js | 2 +-
public/src/modules/navigator.js | 2 +-
public/src/modules/settings.js | 2 +-
public/src/modules/settings/array.js | 2 +-
public/src/modules/settings/object.js | 2 +-
public/src/utils.js | 4 ++--
src/controllers/category.js | 2 +-
src/controllers/topics.js | 2 +-
src/image.js | 2 +-
src/middleware/render.js | 2 +-
src/posts/votes.js | 2 +-
src/privileges/users.js | 2 +-
src/topics/unread.js | 3 ++-
src/user/email.js | 2 +-
src/user/reset.js | 2 +-
src/user/search.js | 2 +-
22 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 7fc8f5ecf8..30c2dddcff 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -15,6 +15,7 @@
"no-underscore-dangle": "off",
"newline-per-chained-call": "off",
"no-console": "off",
+ "no-mixed-operators": ["error", { "allowSamePrecedence": true }],
// ES6
"prefer-rest-params": "off",
@@ -99,7 +100,7 @@
"no-multi-spaces": "off",
"quotes": "off",
"keyword-spacing": "off",
- "no-mixed-operators": "off",
+ // "no-mixed-operators": "off",
// "comma-spacing": "off",
// "no-trailing-spaces": "off",
// "key-spacing": "off",
diff --git a/loader.js b/loader.js
index bcfad1b52c..a8e1bf712e 100644
--- a/loader.js
+++ b/loader.js
@@ -60,7 +60,7 @@ Loader.addWorkerEvents = function (worker) {
Loader.timesStarted = 0;
}, 10000);
} else {
- console.log(numProcs * 3 + ' restarts in 10 seconds, most likely an error on startup. Halting.');
+ console.log((numProcs * 3) + ' restarts in 10 seconds, most likely an error on startup. Halting.');
process.exit();
}
}
diff --git a/public/src/admin/admin.js b/public/src/admin/admin.js
index d492f7d831..45211d9934 100644
--- a/public/src/admin/admin.js
+++ b/public/src/admin/admin.js
@@ -216,7 +216,7 @@
function onOpeningMenu() {
$('#header').css({
- top: $('#panel').position().top * -1 + 'px',
+ top: ($('#panel').position().top * -1) + 'px',
position: 'absolute',
});
}
diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js
index 5e3dddf19a..34cd2476cd 100644
--- a/public/src/admin/manage/users.js
+++ b/public/src/admin/manage/users.js
@@ -99,7 +99,7 @@ define('admin/manage/users', ['translator'], function (translator) {
data[cur.name] = cur.value;
return data;
}, {});
- var until = formData.length ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
+ var until = formData.length ? (Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))) : 0;
socket.emit('user.banUsers', { uids: uids, until: until, reason: formData.reason }, done('[[admin/manage/users:alerts.ban-success]]', '.ban', true));
},
},
diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js
index 9e453e8203..33756e5b6c 100644
--- a/public/src/client/account/header.js
+++ b/public/src/client/account/header.js
@@ -129,7 +129,7 @@ define('forum/account/header', [
data[cur.name] = cur.value;
return data;
}, {});
- var until = parseInt(formData.length, 10) ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
+ var until = parseInt(formData.length, 10) ? (Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))) : 0;
socket.emit('user.banUsers', { uids: [ajaxify.data.theirid], until: until, reason: formData.reason || '' }, function (err) {
if (err) {
diff --git a/public/src/client/chats.js b/public/src/client/chats.js
index d05e9d2e99..82a4354c39 100644
--- a/public/src/client/chats.js
+++ b/public/src/client/chats.js
@@ -355,7 +355,7 @@ define('forum/chats', [
messagesList.height($(window).height() - (fromTop + inputHeight + (margin * 4)));
components.get('chat/recent').height($('.expanded-chat').height() - (searchHeight + searchListHeight));
- $('[component="chat/search/list"]').css('max-height', components.get('chat/recent').height() / 2 + 'px');
+ $('[component="chat/search/list"]').css('max-height', (components.get('chat/recent').height() / 2) + 'px');
}
Chats.setActive();
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index f2e15c57b5..e5d82ba4aa 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -298,7 +298,7 @@ define('chat', [
hideAfter = true;
}
chatModal.css('left', Math.max(0, (($(window).width() - $(chatModal).outerWidth()) / 2) + $(window).scrollLeft()) + 'px');
- chatModal.css('top', Math.max(0, $(window).height() / 2 - $(chatModal).outerHeight() / 2) + 'px');
+ chatModal.css('top', Math.max(0, ($(window).height() / 2) - ($(chatModal).outerHeight() / 2)) + 'px');
if (hideAfter) {
chatModal.addClass('hide');
diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js
index b6f7480027..62d5bbb788 100644
--- a/public/src/modules/navigator.js
+++ b/public/src/modules/navigator.js
@@ -114,7 +114,7 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var scrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
var documentHeight = $(document).height();
- var middleOfViewport = scrollTop + windowHeight / 2;
+ var middleOfViewport = scrollTop + (windowHeight / 2);
var previousDistance = Number.MAX_VALUE;
els.each(function () {
var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top);
diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js
index cc10a7cdf4..cb733b970a 100644
--- a/public/src/modules/settings.js
+++ b/public/src/modules/settings.js
@@ -171,7 +171,7 @@ define('settings', function () {
if (trim && value != null && typeof value.trim === 'function') {
value = value.trim();
}
- if (empty || value !== void 0 && (value == null || value.length !== 0)) {
+ if (empty || (value !== void 0 && (value == null || value.length !== 0))) {
return value;
} else {
return void 0;
diff --git a/public/src/modules/settings/array.js b/public/src/modules/settings/array.js
index 6957b85bc7..368574f68e 100644
--- a/public/src/modules/settings/array.js
+++ b/public/src/modules/settings/array.js
@@ -130,7 +130,7 @@ define('settings/array', function () {
child = $(child);
var val = helper.readValue(child);
var empty = helper.isTrue(child.data('empty'));
- if (empty || val !== void 0 && (val == null || val.length !== 0)) {
+ if (empty || (val !== void 0 && (val == null || val.length !== 0))) {
return values.push(val);
}
});
diff --git a/public/src/modules/settings/object.js b/public/src/modules/settings/object.js
index 11166607e7..8bf7e8400b 100644
--- a/public/src/modules/settings/object.js
+++ b/public/src/modules/settings/object.js
@@ -102,7 +102,7 @@ define('settings/object', function () {
var val = helper.readValue(property);
var prop = property.data('prop');
var empty = helper.isTrue(property.data('empty'));
- if (empty || val !== void 0 && (val == null || val.length !== 0)) {
+ if (empty || (val !== void 0 && (val == null || val.length !== 0))) {
return value[prop] = val;
}
});
diff --git a/public/src/utils.js b/public/src/utils.js
index 93b67dff5c..c80d530b13 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -15,7 +15,7 @@
process.elapsedTimeSince = function (start) {
var diff = process.hrtime(start);
- return diff[0] * 1e3 + diff[1] / 1e6;
+ return (diff[0] * 1e3) + (diff[1] / 1e6);
};
} else {
@@ -27,7 +27,7 @@
generateUUID: function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
- var v = c === 'x' ? r : (r & 0x3 | 0x8);
+ var v = c === 'x' ? r : ((r & 0x3) | 0x8);
return v.toString(16);
});
},
diff --git a/src/controllers/category.js b/src/controllers/category.js
index 70e167b9c7..218c7c3144 100644
--- a/src/controllers/category.js
+++ b/src/controllers/category.js
@@ -87,7 +87,7 @@ categoryController.get = function (req, res, callback) {
set = 'cid:' + cid + ':tids:posts';
}
- var start = (currentPage - 1) * settings.topicsPerPage + topicIndex;
+ var start = ((currentPage - 1) * settings.topicsPerPage) + topicIndex;
var stop = start + settings.topicsPerPage - 1;
var payload = {
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 4b5ef83245..12082fa32e 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -113,7 +113,7 @@ topicsController.get = function (req, res, callback) {
currentPage = Math.max(1, Math.ceil(index / settings.postsPerPage));
}
- var start = (currentPage - 1) * settings.postsPerPage + postIndex;
+ var start = ((currentPage - 1) * settings.postsPerPage) + postIndex;
var stop = start + settings.postsPerPage - 1;
topics.getTopicWithPosts(results.topic, set, req.uid, start, stop, reverse, next);
diff --git a/src/image.js b/src/image.js
index 54777d6c79..82d8886895 100644
--- a/src/image.js
+++ b/src/image.js
@@ -42,7 +42,7 @@ image.resizeImage = function (data, callback) {
crop = async.apply(image.crop.bind(image), x, y, h * desiredRatio, h);
} else {
x = 0; // width is the smaller dimension here
- y = Math.floor(h / 2 - (w * desiredRatio / 2));
+ y = Math.floor((h / 2) - (w * desiredRatio / 2));
crop = async.apply(image.crop.bind(image), x, y, w, w * desiredRatio);
}
} else {
diff --git a/src/middleware/render.js b/src/middleware/render.js
index 8d2c96a4ee..3f565353a1 100644
--- a/src/middleware/render.js
+++ b/src/middleware/render.js
@@ -107,7 +107,7 @@ module.exports = function (middleware) {
}
function translate(str, req, res, next) {
- var language = res.locals.config && res.locals.config.userLang || 'en-GB';
+ var language = (res.locals.config && res.locals.config.userLang) || 'en-GB';
language = req.query.lang ? validator.escape(String(req.query.lang)) : language;
translator.translate(str, language, function (translated) {
next(null, translator.unescape(translated));
diff --git a/src/posts/votes.js b/src/posts/votes.js
index 61ba87b919..d069f0f57a 100644
--- a/src/posts/votes.js
+++ b/src/posts/votes.js
@@ -162,7 +162,7 @@ module.exports = function (Posts) {
var hook;
var current = voteStatus.upvoted ? 'upvote' : 'downvote';
- if (voteStatus.upvoted && command === 'downvote' || voteStatus.downvoted && command === 'upvote') { // e.g. User *has* upvoted, and clicks downvote
+ if ((voteStatus.upvoted && command === 'downvote') || (voteStatus.downvoted && command === 'upvote')) { // e.g. User *has* upvoted, and clicks downvote
hook = command;
} else if (voteStatus.upvoted || voteStatus.downvoted) { // e.g. User *has* upvoted, clicks upvote (so we "unvote")
hook = 'unvote';
diff --git a/src/privileges/users.js b/src/privileges/users.js
index 94426d154c..5dd26f5189 100644
--- a/src/privileges/users.js
+++ b/src/privileges/users.js
@@ -128,7 +128,7 @@ module.exports = function (privileges) {
if (err) {
return callback(err);
}
- if (Array.isArray(uid) && !Array.isArray(data.isModerator) || Array.isArray(cid) && !Array.isArray(data.isModerator)) {
+ if ((Array.isArray(uid) || Array.isArray(cid)) && !Array.isArray(data.isModerator)) {
return callback(new Error('filter:user.isModerator - i/o mismatch'));
}
diff --git a/src/topics/unread.js b/src/topics/unread.js
index e76ee22fda..17c5b701e0 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -64,7 +64,8 @@ module.exports = function (Topics) {
};
Topics.unreadCutoff = function () {
- return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;
+ var cutoff = parseInt(meta.config.unreadCutoff, 10) || 2;
+ return Date.now() - (cutoff * 86400000);
};
Topics.getUnreadTids = function (cid, uid, filter, callback) {
diff --git a/src/user/email.js b/src/user/email.js
index 05a3db8719..2e51da951a 100644
--- a/src/user/email.js
+++ b/src/user/email.js
@@ -57,7 +57,7 @@ var emailer = require('../emailer');
}, next);
},
function (next) {
- db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 24), next);
+ db.expireAt('confirm:' + confirm_code, Math.floor((Date.now() / 1000) + (60 * 60 * 24)), next);
},
function (next) {
user.getUserField(uid, 'username', next);
diff --git a/src/user/reset.js b/src/user/reset.js
index 9b3732c13e..90aa9f072e 100644
--- a/src/user/reset.js
+++ b/src/user/reset.js
@@ -48,7 +48,7 @@ var emailer = require('../emailer');
db.sortedSetScore('reset:issueDate:uid', uid, next);
},
function (score, next) {
- if (score > Date.now() - 1000 * 60) {
+ if (score > Date.now() - (1000 * 60)) {
return next(new Error('[[error:cant-reset-password-more-than-once-a-minute]]'));
}
next();
diff --git a/src/user/search.js b/src/user/search.js
index ee20b48c39..95e5b6ed29 100644
--- a/src/user/search.js
+++ b/src/user/search.js
@@ -156,7 +156,7 @@ module.exports = function (User) {
},
function (users, next) {
var diff = process.hrtime(start);
- var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
+ var timing = ((diff[0] * 1e3) + (diff[1] / 1e6)).toFixed(1);
next(null, {timing: timing, users: users});
},
], callback);