From 144fa8698c4d8f228250bf3194ca7f22cd4a3278 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Sat, 18 Feb 2017 14:32:35 -0700
Subject: [PATCH] Eslint no-lonely-if
---
.eslintrc | 6 +++---
public/src/ajaxify.js | 6 ++----
public/src/client/chats.js | 26 ++++++++++++--------------
public/src/modules/settings.js | 24 +++++++++++-------------
src/controllers/helpers.js | 12 +++++-------
src/groups/membership.js | 8 +++-----
src/meta/sounds.js | 6 ++----
src/plugins.js | 8 +++-----
src/privileges/users.js | 8 +++-----
src/reset.js | 12 +++++-------
src/socket.io/topics/infinitescroll.js | 8 +++-----
11 files changed, 52 insertions(+), 72 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index e04ea21d3b..e9fc782420 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -51,6 +51,7 @@
"no-script-url": "off",
"no-use-before-define": "off",
"default-case": "off",
+ "new-cap": "off",
// "linebreak-style": "off",
// "one-var": "off",
@@ -67,9 +68,8 @@
"eqeqeq": "off",
"camelcase": "off",
"no-negated-condition": "off",
- "one-var-declaration-per-line": "off",
- "new-cap": "off",
- "no-lonely-if": "off",
+ // "one-var-declaration-per-line": "off",
+ // "no-lonely-if": "off",
// "radix": "off",
// "no-else-return": "off",
// "no-useless-escape": "off",
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index 9cc3711701..322a13bd20 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -351,10 +351,8 @@ $(document).ready(function () {
// Special handling for urls with hashes
if (window.location.pathname === this.pathname && this.hash.length) {
window.location.hash = this.hash;
- } else {
- if (ajaxify.go(pathname)) {
- e.preventDefault();
- }
+ } else if (ajaxify.go(pathname)) {
+ e.preventDefault();
}
} else if (window.location.pathname !== '/outgoing') {
if (config.openOutgoingLinksInNewTab && $.contains(contentEl, this)) {
diff --git a/public/src/client/chats.js b/public/src/client/chats.js
index 4f212b3f77..262f58bbe4 100644
--- a/public/src/client/chats.js
+++ b/public/src/client/chats.js
@@ -311,22 +311,20 @@ define('forum/chats', [
data.message.self = data.self;
messages.appendChatMessage($('.expanded-chat .chat-content'), data.message);
- } else {
- if (ajaxify.currentPage.startsWith('chats')) {
- var roomEl = $('[data-roomid=' + data.roomId + ']');
-
- if (roomEl.length > 0) {
- roomEl.addClass('unread');
- } else {
- var recentEl = components.get('chat/recent');
- templates.parse('partials/chats/recent_room', {
- rooms: { roomId: data.roomId, lastUser: data.message.fromUser, usernames: data.message.fromUser.username, unread: true },
- }, function (html) {
- translator.translate(html, function (translated) {
+ } else if (ajaxify.currentPage.startsWith('chats')) {
+ var roomEl = $('[data-roomid=' + data.roomId + ']');
+
+ if (roomEl.length > 0) {
+ roomEl.addClass('unread');
+ } else {
+ var recentEl = components.get('chat/recent');
+ templates.parse('partials/chats/recent_room', {
+ rooms: { roomId: data.roomId, lastUser: data.message.fromUser, usernames: data.message.fromUser.username, unread: true },
+ }, function (html) {
+ translator.translate(html, function (translated) {
recentEl.prepend(translated);
- });
});
- }
+ });
}
}
});
diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js
index 35ae29eb9b..ecd99a9521 100644
--- a/public/src/modules/settings.js
+++ b/public/src/modules/settings.js
@@ -510,20 +510,18 @@ define('settings', function () {
if (typeof callback === 'function') {
callback(err);
+ } else if (err) {
+ app.alert({
+ title: 'Error while saving settings',
+ type: 'error',
+ timeout: 2500,
+ });
} else {
- if (err) {
- app.alert({
- title: 'Error while saving settings',
- type: 'error',
- timeout: 2500,
- });
- } else {
- app.alert({
- title: 'Settings Saved',
- type: 'success',
- timeout: 2500,
- });
- }
+ app.alert({
+ title: 'Settings Saved',
+ type: 'success',
+ timeout: 2500,
+ });
}
});
}
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js
index 0942cc7b82..773b0e6463 100644
--- a/src/controllers/helpers.js
+++ b/src/controllers/helpers.js
@@ -38,14 +38,12 @@ helpers.notAllowed = function (req, res, error) {
title: '[[global:403.title]]',
});
}
+ } else if (res.locals.isAPI) {
+ req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
+ res.status(401).json('not-authorized');
} else {
- if (res.locals.isAPI) {
- req.session.returnTo = nconf.get('relative_path') + req.url.replace(/^\/api/, '');
- res.status(401).json('not-authorized');
- } else {
- req.session.returnTo = nconf.get('relative_path') + req.url;
- res.redirect(nconf.get('relative_path') + '/login');
- }
+ req.session.returnTo = nconf.get('relative_path') + req.url;
+ res.redirect(nconf.get('relative_path') + '/login');
}
});
};
diff --git a/src/groups/membership.js b/src/groups/membership.js
index b0afbbd9c8..567c5b7dcc 100644
--- a/src/groups/membership.js
+++ b/src/groups/membership.js
@@ -241,12 +241,10 @@ module.exports = function (Groups) {
}
if (Groups.isPrivilegeGroup(groupName) && parseInt(groupData.memberCount, 10) === 0) {
Groups.destroy(groupName, next);
+ } else if (parseInt(groupData.hidden, 10) !== 1) {
+ db.sortedSetAdd('groups:visible:memberCount', groupData.memberCount, groupName, next);
} else {
- if (parseInt(groupData.hidden, 10) !== 1) {
- db.sortedSetAdd('groups:visible:memberCount', groupData.memberCount, groupName, next);
- } else {
- next();
- }
+ next();
}
},
function (next) {
diff --git a/src/meta/sounds.js b/src/meta/sounds.js
index 249d49d49b..0205e56396 100644
--- a/src/meta/sounds.js
+++ b/src/meta/sounds.js
@@ -18,10 +18,8 @@ module.exports = function (Meta) {
Meta.sounds.init = function (callback) {
if (nconf.get('isPrimary') === 'true') {
setupSounds(callback);
- } else {
- if (typeof callback === 'function') {
- callback();
- }
+ } else if (typeof callback === 'function') {
+ callback();
}
};
diff --git a/src/plugins.js b/src/plugins.js
index 99656312e9..84673f635f 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -190,12 +190,10 @@ var middleware;
winston.warn('[plugins] Skipping ' + pluginTemplate + ' by plugin ' + plugin.id);
}
});
+ } else if (err) {
+ winston.error(err);
} else {
- if (err) {
- winston.error(err);
- } else {
- winston.warn('[plugins/' + plugin.id + '] A templates directory was defined for this plugin, but was not found.');
- }
+ winston.warn('[plugins/' + plugin.id + '] A templates directory was defined for this plugin, but was not found.');
}
next(false);
diff --git a/src/privileges/users.js b/src/privileges/users.js
index a73437db75..ed72efb147 100644
--- a/src/privileges/users.js
+++ b/src/privileges/users.js
@@ -28,12 +28,10 @@ module.exports = function (privileges) {
privileges.users.isModerator = function (uid, cid, callback) {
if (Array.isArray(cid)) {
isModeratorOfCategories(cid, uid, callback);
+ } else if (Array.isArray(uid)) {
+ isModeratorsOfCategory(cid, uid, callback);
} else {
- if (Array.isArray(uid)) {
- isModeratorsOfCategory(cid, uid, callback);
- } else {
- isModeratorOfCategory(cid, uid, callback);
- }
+ isModeratorOfCategory(cid, uid, callback);
}
};
diff --git a/src/reset.js b/src/reset.js
index b69f4980dc..a6ed18b32a 100644
--- a/src/reset.js
+++ b/src/reset.js
@@ -133,14 +133,12 @@ function resetPlugin(pluginId, callback) {
], function (err) {
if (err) {
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err.message);
+ } else if (active) {
+ winston.info('[reset] Plugin `%s` disabled', pluginId);
} else {
- if (active) {
- winston.info('[reset] Plugin `%s` disabled', pluginId);
- } else {
- winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
- winston.info('[reset] No action taken.');
- err = new Error('plugin-not-active');
- }
+ winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
+ winston.info('[reset] No action taken.');
+ err = new Error('plugin-not-active');
}
callback(err);
diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.js
index 275fa18895..b0d7407a0a 100644
--- a/src/socket.io/topics/infinitescroll.js
+++ b/src/socket.io/topics/infinitescroll.js
@@ -46,12 +46,10 @@ module.exports = function (SocketTopics) {
if (reverse) {
start = results.topic.postcount - start;
}
+ } else if (reverse) {
+ start = results.topic.postcount - start - infScrollPostsPerPage - 1;
} else {
- if (reverse) {
- start = results.topic.postcount - start - infScrollPostsPerPage - 1;
- } else {
- start = start - infScrollPostsPerPage - 1;
- }
+ start = start - infScrollPostsPerPage - 1;
}
var stop = start + (infScrollPostsPerPage - 1);