diff --git a/.eslintrc b/.eslintrc index 10219b1d01..cef86e196d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,11 +21,16 @@ "no-mixed-operators": ["error", { "allowSamePrecedence": true }], "strict": ["error", "global"], "consistent-return": "off", + "func-names": "off", + "no-tabs": "off", + "indent": ["error", "tab"], // ES6 "prefer-rest-params": "off", "prefer-spread": "off", "prefer-arrow-callback": "off", + "prefer-template": "off", + "no-var": "off", // TODO "import/no-unresolved": "off", @@ -90,13 +95,9 @@ "no-restricted-module": "off", "no-return-assign": "off", "no-restricted-modules": "off", - "no-tabs": "off", - "indent": "off", - "func-names": "off", "object-curly-spacing": "off", - "no-var": "off", "no-shadow": "off", - "prefer-template": "off", + // "indent": "off", // "padded-blocks": "off", // "eol-last": "off", // "lines-around-directive": "off", diff --git a/loader.js b/loader.js index 5dcc382d47..0eaf9a12df 100644 --- a/loader.js +++ b/loader.js @@ -75,13 +75,13 @@ Loader.addWorkerEvents = function (worker) { worker.on('message', function (message) { if (message && typeof message === 'object' && message.action) { switch (message.action) { - case 'restart': - console.log('[cluster] Restarting...'); - Loader.restart(); + case 'restart': + console.log('[cluster] Restarting...'); + Loader.restart(); break; - case 'reload': - console.log('[cluster] Reloading...'); - Loader.reload(); + case 'reload': + console.log('[cluster] Reloading...'); + Loader.reload(); break; } } diff --git a/minifier.js b/minifier.js index e57c30fb38..a68aca8fde 100644 --- a/minifier.js +++ b/minifier.js @@ -50,9 +50,9 @@ function minifyScripts(scripts, callback) { // Follow along here: https://github.com/mishoo/UglifyJS2/issues/700 try { var minified = uglifyjs.minify(scripts, { - // outSourceMap: "nodebb.min.js.map", - compress: false, - }); + // outSourceMap: "nodebb.min.js.map", + compress: false, + }); callback(minified.code/* , minified.map*/); } catch (err) { diff --git a/public/src/admin/advanced/logs.js b/public/src/admin/advanced/logs.js index c0e9fee0f0..5d13543a40 100644 --- a/public/src/admin/advanced/logs.js +++ b/public/src/admin/advanced/logs.js @@ -15,25 +15,25 @@ define('admin/advanced/logs', function () { var action = btnEl.attr('data-action'); switch (action) { - case 'reload': - socket.emit('admin.logs.get', function (err, logs) { - if (!err) { - logsEl.text(logs); - logsEl.scrollTop(logsEl.prop('scrollHeight')); - } else { - app.alertError(err.message); - } - }); - break; + case 'reload': + socket.emit('admin.logs.get', function (err, logs) { + if (!err) { + logsEl.text(logs); + logsEl.scrollTop(logsEl.prop('scrollHeight')); + } else { + app.alertError(err.message); + } + }); + break; - case 'clear': - socket.emit('admin.logs.clear', function (err) { - if (!err) { - app.alertSuccess('[[admin/advanced/logs:clear-success]]'); - btnEl.prev().click(); - } - }); - break; + case 'clear': + socket.emit('admin.logs.clear', function (err) { + if (!err) { + app.alertSuccess('[[admin/advanced/logs:clear-success]]'); + btnEl.prev().click(); + } + }); + break; } }); }; diff --git a/public/src/admin/extend/plugins.js b/public/src/admin/extend/plugins.js index 6d0a1b7de9..135a9f05e0 100644 --- a/public/src/admin/extend/plugins.js +++ b/public/src/admin/extend/plugins.js @@ -162,7 +162,7 @@ define('admin/extend/plugins', ['jqueryui', 'translator'], function (jqueryui, t function confirmInstall(pluginID, callback) { bootbox.confirm(translator.compile('admin/extend/plugins:alert.possibly-incompatible', pluginID), function (confirm) { - callback(confirm); + callback(confirm); }); } diff --git a/public/src/admin/extend/rewards.js b/public/src/admin/extend/rewards.js index a605b87186..7a40a7ef59 100644 --- a/public/src/admin/extend/rewards.js +++ b/public/src/admin/extend/rewards.js @@ -57,18 +57,18 @@ define('admin/extend/rewards', ['translator'], function (translator) { function select(el) { el.val(el.attr('data-selected')); switch (el.attr('name')) { - case 'rid': - selectReward(el); - break; + case 'rid': + selectReward(el); + break; } } function update(el) { el.attr('data-selected', el.val()); switch (el.attr('name')) { - case 'rid': - selectReward(el); - break; + case 'rid': + selectReward(el); + break; } } @@ -95,15 +95,15 @@ define('admin/extend/rewards', ['translator'], function (translator) { inputs.forEach(function (input) { html += '
'; }); diff --git a/public/src/admin/general/dashboard.js b/public/src/admin/general/dashboard.js index a6600ce93a..cdd12aa5c6 100644 --- a/public/src/admin/general/dashboard.js +++ b/public/src/admin/general/dashboard.js @@ -292,10 +292,10 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s $('[data-action="updateGraph"]').on('click', function () { var until; switch ($(this).attr('data-until')) { - case 'last-month': - var lastMonth = new Date(); - lastMonth.setDate(lastMonth.getDate() - 30); - until = lastMonth.getTime(); + case 'last-month': + var lastMonth = new Date(); + lastMonth.setDate(lastMonth.getDate() - 30); + until = lastMonth.getTime(); } updateTrafficGraph($(this).attr('data-units'), until); }); diff --git a/public/src/admin/manage/category-analytics.js b/public/src/admin/manage/category-analytics.js index 16500d227c..c9d4d55c2e 100644 --- a/public/src/admin/manage/category-analytics.js +++ b/public/src/admin/manage/category-analytics.js @@ -10,11 +10,11 @@ define('admin/manage/category-analytics', ['Chart'], function (Chart) { var topicsCanvas = document.getElementById('topics:daily'); var postsCanvas = document.getElementById('posts:daily'); var hourlyLabels = utils.getHoursArray().map(function (text, idx) { - return idx % 3 ? '' : text; - }); + return idx % 3 ? '' : text; + }); var dailyLabels = utils.getDaysArray().map(function (text, idx) { - return idx % 3 ? '' : text; - }); + return idx % 3 ? '' : text; + }); if (utils.isMobile()) { Chart.defaults.global.tooltips.enabled = false; diff --git a/public/src/admin/manage/group.js b/public/src/admin/manage/group.js index 89985f3ba5..0a7b6e0247 100644 --- a/public/src/admin/manage/group.js +++ b/public/src/admin/manage/group.js @@ -113,36 +113,36 @@ define('admin/manage/group', [ var action = btnEl.attr('data-action'); switch (action) { - case 'toggleOwnership': - socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { - toUid: uid, + case 'toggleOwnership': + socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { + toUid: uid, + groupName: groupName, + }, function (err) { + if (err) { + return app.alertError(err.message); + } + ownerFlagEl.toggleClass('invisible'); + }); + break; + + case 'kick': + bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) { + if (!confirm) { + return; + } + socket.emit('admin.groups.leave', { + uid: uid, groupName: groupName, }, function (err) { if (err) { return app.alertError(err.message); } - ownerFlagEl.toggleClass('invisible'); + userRow.slideUp().remove(); }); - break; - - case 'kick': - bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) { - if (!confirm) { - return; - } - socket.emit('admin.groups.leave', { - uid: uid, - groupName: groupName, - }, function (err) { - if (err) { - return app.alertError(err.message); - } - userRow.slideUp().remove(); - }); - }); - break; - default: - break; + }); + break; + default: + break; } }); diff --git a/public/src/app.js b/public/src/app.js index 37eb41b564..48f65ac752 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -274,25 +274,25 @@ app.cacheBuster = null; function showAlert(type) { switch (messages[type].format) { - case 'alert': - app.alert({ - type: 'success', - title: messages[type].title, - message: messages[type].message, - timeout: 5000, - }); - break; - - case 'modal': - require(['translator'], function (translator) { - translator.translate(messages[type].message, function (translated) { - bootbox.alert({ - title: messages[type].title, - message: translated, - }); + case 'alert': + app.alert({ + type: 'success', + title: messages[type].title, + message: messages[type].message, + timeout: 5000, + }); + break; + + case 'modal': + require(['translator'], function (translator) { + translator.translate(messages[type].message, function (translated) { + bootbox.alert({ + title: messages[type].title, + message: translated, }); }); - break; + }); + break; } } @@ -366,10 +366,10 @@ app.cacheBuster = null; }; var titleObj = { - active: false, - interval: undefined, - titles: [], - }; + active: false, + interval: undefined, + titles: [], + }; app.alternatingTitle = function (title) { if (typeof title !== 'string') { diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index 8159f50458..fe3808ccd8 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -56,13 +56,13 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' } switch (input.attr('type')) { - case 'text': - case 'textarea': - settings[setting] = input.val(); - break; - case 'checkbox': - settings[setting] = input.is(':checked') ? 1 : 0; - break; + case 'text': + case 'textarea': + settings[setting] = input.val(); + break; + case 'checkbox': + settings[setting] = input.is(':checked') ? 1 : 0; + break; } }); diff --git a/public/src/client/groups/details.js b/public/src/client/groups/details.js index 21549ec2a7..e4443ab7ff 100644 --- a/public/src/client/groups/details.js +++ b/public/src/client/groups/details.js @@ -59,61 +59,61 @@ define('forum/groups/details', [ var action = btnEl.attr('data-action'); switch (action) { - case 'toggleOwnership': - socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { - toUid: uid, - groupName: groupName, - }, function (err) { - if (!err) { - ownerFlagEl.toggleClass('invisible'); - } else { - app.alertError(err.message); - } - }); - break; + case 'toggleOwnership': + socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { + toUid: uid, + groupName: groupName, + }, function (err) { + if (!err) { + ownerFlagEl.toggleClass('invisible'); + } else { + app.alertError(err.message); + } + }); + break; - case 'kick': - socket.emit('groups.kick', { - uid: uid, - groupName: groupName, - }, function (err) { - if (!err) { - userRow.slideUp().remove(); - } else { - app.alertError(err.message); - } - }); - break; - - case 'update': - Details.update(); - break; - - case 'delete': - Details.deleteGroup(); - break; - - case 'join': // intentional fall-throughs! - case 'leave': - case 'accept': - case 'reject': - case 'issueInvite': - case 'rescindInvite': - case 'acceptInvite': - case 'rejectInvite': - case 'acceptAll': - case 'rejectAll': - socket.emit('groups.' + action, { - toUid: uid, - groupName: groupName, - }, function (err) { - if (!err) { - ajaxify.refresh(); - } else { - app.alertError(err.message); - } - }); - break; + case 'kick': + socket.emit('groups.kick', { + uid: uid, + groupName: groupName, + }, function (err) { + if (!err) { + userRow.slideUp().remove(); + } else { + app.alertError(err.message); + } + }); + break; + + case 'update': + Details.update(); + break; + + case 'delete': + Details.deleteGroup(); + break; + + case 'join': // intentional fall-throughs! + case 'leave': + case 'accept': + case 'reject': + case 'issueInvite': + case 'rescindInvite': + case 'acceptInvite': + case 'rejectInvite': + case 'acceptAll': + case 'rejectAll': + socket.emit('groups.' + action, { + toUid: uid, + groupName: groupName, + }, function (err) { + if (!err) { + ajaxify.refresh(); + } else { + app.alertError(err.message); + } + }); + break; } }); }; diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index 22d92750eb..206ebe0e6a 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -372,31 +372,31 @@ define('forum/topic/postTools', [ translator.translate('[[topic:stale.warning]]', function (translated) { var warning = bootbox.dialog({ - title: '[[topic:stale.title]]', - message: translated, - buttons: { - reply: { - label: '[[topic:stale.reply_anyway]]', - className: 'btn-link', - callback: function () { - staleReplyAnyway = true; - callback(); - }, + title: '[[topic:stale.title]]', + message: translated, + buttons: { + reply: { + label: '[[topic:stale.reply_anyway]]', + className: 'btn-link', + callback: function () { + staleReplyAnyway = true; + callback(); }, - create: { - label: '[[topic:stale.create]]', - className: 'btn-primary', - callback: function () { - translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) { - $(window).trigger('action:composer.topic.new', { - cid: ajaxify.data.cid, - body: body, - }); + }, + create: { + label: '[[topic:stale.create]]', + className: 'btn-primary', + callback: function () { + translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) { + $(window).trigger('action:composer.topic.new', { + cid: ajaxify.data.cid, + body: body, }); - }, + }); }, }, - }); + }, + }); warning.modal(); }); diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 5711c4513f..88fe8af9b9 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -290,11 +290,11 @@ define('forum/topic/posts', [ var images = components.get('post/content').find('img[data-state="unloaded"]'); var visible = images.filter(function () { - return utils.isElementInViewport(this); - }); + return utils.isElementInViewport(this); + }); var posts = $.unique(visible.map(function () { - return $(this).parents('[component="post"]').get(0); - })); + return $(this).parents('[component="post"]').get(0); + })); var scrollTop = $(window).scrollTop(); var adjusting = false; var adjustQueue = []; diff --git a/public/src/installer/install.js b/public/src/installer/install.js index 463c2f741b..55661cd1b6 100644 --- a/public/src/installer/install.js +++ b/public/src/installer/install.js @@ -99,16 +99,16 @@ $('document').ready(function () { } switch (type) { - case 'admin:username': - return validateUsername(field); - case 'admin:password': - return validatePassword(field); - case 'admin:passwordConfirm': - return validateConfirmPassword(field); - case 'admin:email': - return validateEmail(field); - case 'database': - return switchDatabase(field); + case 'admin:username': + return validateUsername(field); + case 'admin:password': + return validatePassword(field); + case 'admin:passwordConfirm': + return validateConfirmPassword(field); + case 'admin:email': + return validateEmail(field); + case 'database': + return switchDatabase(field); } } diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js index 030e6333e0..729c6e42d4 100644 --- a/public/src/modules/helpers.js +++ b/public/src/modules/helpers.js @@ -214,49 +214,49 @@ var icons = ''; switch (data.platform) { - case 'Linux': - icons += ''; - break; - case 'Microsoft Windows': - icons += ''; - break; - case 'Apple Mac': - icons += ''; - break; - case 'Android': - icons += ''; - break; - case 'iPad': - icons += ''; - break; - case 'iPod': // intentional fall-through - case 'iPhone': - icons += ''; - break; - default: - icons += ''; - break; + case 'Linux': + icons += ''; + break; + case 'Microsoft Windows': + icons += ''; + break; + case 'Apple Mac': + icons += ''; + break; + case 'Android': + icons += ''; + break; + case 'iPad': + icons += ''; + break; + case 'iPod': // intentional fall-through + case 'iPhone': + icons += ''; + break; + default: + icons += ''; + break; } switch (data.browser) { - case 'Chrome': - icons += ''; - break; - case 'Firefox': - icons += ''; - break; - case 'Safari': - icons += ''; - break; - case 'IE': - icons += ''; - break; - case 'Edge': - icons += ''; - break; - default: - icons += ''; - break; + case 'Chrome': + icons += ''; + break; + case 'Firefox': + icons += ''; + break; + case 'Safari': + icons += ''; + break; + case 'IE': + icons += ''; + break; + case 'Edge': + icons += ''; + break; + default: + icons += ''; + break; } return icons; diff --git a/public/src/modules/iconSelect.js b/public/src/modules/iconSelect.js index 3c72303b73..76d457088f 100644 --- a/public/src/modules/iconSelect.js +++ b/public/src/modules/iconSelect.js @@ -24,41 +24,41 @@ define('iconSelect', function () { html.find('.fa-icons').prepend($('')); var picker = bootbox.dialog({ - onEscape: true, - backdrop: true, - show: false, - message: html, - title: 'Select an Icon', - buttons: { - noIcon: { - label: 'No Icon', - className: 'btn-default', - callback: function () { - el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '')); - el.val(''); - el.attr('value', ''); - - onModified(el); - }, + onEscape: true, + backdrop: true, + show: false, + message: html, + title: 'Select an Icon', + buttons: { + noIcon: { + label: 'No Icon', + className: 'btn-default', + callback: function () { + el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '')); + el.val(''); + el.attr('value', ''); + + onModified(el); }, - success: { - label: 'Select', - className: 'btn-primary', - callback: function (confirm) { - var iconClass = $('.bootbox .selected').attr('class'); - var categoryIconClass = $('
').addClass(iconClass).removeClass('fa').removeClass('selected').attr('class'); - - if (categoryIconClass) { - el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '') + categoryIconClass); - el.val(categoryIconClass); - el.attr('value', categoryIconClass); - } - - onModified(el); - }, + }, + success: { + label: 'Select', + className: 'btn-primary', + callback: function (confirm) { + var iconClass = $('.bootbox .selected').attr('class'); + var categoryIconClass = $('
').addClass(iconClass).removeClass('fa').removeClass('selected').attr('class'); + + if (categoryIconClass) { + el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : '') + categoryIconClass); + el.val(categoryIconClass); + el.attr('value', categoryIconClass); + } + + onModified(el); }, }, - }); + }, + }); picker.on('show.bs.modal', function () { var modalEl = $(this); diff --git a/public/src/modules/pictureCropper.js b/public/src/modules/pictureCropper.js index 670f9bf91b..c5b8e155df 100644 --- a/public/src/modules/pictureCropper.js +++ b/public/src/modules/pictureCropper.js @@ -30,7 +30,7 @@ define('pictureCropper', ['translator', 'cropper'], function (translator, croppe }); }; - module.handleImageCrop = function (data, callback) { + module.handleImageCrop = function (data, callback) { $('#crop-picture-modal').remove(); templates.parse('modals/crop_picture', {url: data.url}, function (cropperHtml) { translator.translate(cropperHtml, function (translated) { diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index 9722e51ec8..023225c978 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -491,26 +491,26 @@ // and correct NodeBB language codes to timeago codes, if necessary var languageCode = void 0; switch (config.userLang) { - case 'en-GB': - case 'en-US': - languageCode = 'en'; - break; - - case 'fa-IR': - languageCode = 'fa'; - break; - - case 'pt-BR': - languageCode = 'pt-br'; - break; - - case 'nb': - languageCode = 'no'; - break; - - default: - languageCode = config.userLang; - break; + case 'en-GB': + case 'en-US': + languageCode = 'en'; + break; + + case 'fa-IR': + languageCode = 'fa'; + break; + + case 'pt-BR': + languageCode = 'pt-br'; + break; + + case 'nb': + languageCode = 'no'; + break; + + default: + languageCode = config.userLang; + break; } jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(function () { diff --git a/public/src/sockets.js b/public/src/sockets.js index 50a3c5504f..248ce498aa 100644 --- a/public/src/sockets.js +++ b/public/src/sockets.js @@ -72,29 +72,29 @@ app.isConnected = false; var room; switch (url_parts[0]) { - case 'user': - room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0); + case 'user': + room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0); break; - case 'topic': - room = 'topic_' + url_parts[1]; + case 'topic': + room = 'topic_' + url_parts[1]; break; - case 'category': - room = 'category_' + url_parts[1]; + case 'category': + room = 'category_' + url_parts[1]; break; - case 'recent': - room = 'recent_topics'; + case 'recent': + room = 'recent_topics'; break; - case 'unread': - room = 'unread_topics'; + case 'unread': + room = 'unread_topics'; break; - case 'popular': - room = 'popular_topics'; + case 'popular': + room = 'popular_topics'; break; - case 'admin': - room = 'admin'; + case 'admin': + room = 'admin'; break; - case 'categories': - room = 'categories'; + case 'categories': + room = 'categories'; break; } app.currentRoom = ''; diff --git a/src/controllers/admin/plugins.js b/src/controllers/admin/plugins.js index c55ef4b457..4e8e1a415e 100644 --- a/src/controllers/admin/plugins.js +++ b/src/controllers/admin/plugins.js @@ -30,8 +30,8 @@ pluginsController.get = function (req, res, next) { return next(err); } var compatiblePkgNames = payload.compatible.map(function (pkgData) { - return pkgData.name; - }); + return pkgData.name; + }); res.render('admin/extend/plugins', { installed: payload.compatible.filter(function (plugin) { diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.js index ba8fb4318f..55e5a1dfbf 100644 --- a/src/controllers/admin/settings.js +++ b/src/controllers/admin/settings.js @@ -11,12 +11,12 @@ settingsController.get = function (req, res, next) { var term = req.params.term ? req.params.term : 'general'; switch (req.params.term) { - case 'email': - renderEmail(req, res, next); - break; + case 'email': + renderEmail(req, res, next); + break; - default: - res.render('admin/settings/' + term); + default: + res.render('admin/settings/' + term); } }; diff --git a/src/controllers/api.js b/src/controllers/api.js index 544beed40a..858db57d66 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -124,11 +124,11 @@ apiController.renderWidgets = function (req, res, next) { req, res, function (err, widgets) { - if (err) { - return next(err); - } - res.status(200).json(widgets); - }); + if (err) { + return next(err); + } + res.status(200).json(widgets); + }); }; apiController.getPostData = function (pid, uid, callback) { diff --git a/src/controllers/index.js b/src/controllers/index.js index 1a54a5e8f0..3124355a98 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -419,11 +419,11 @@ Controllers.handleURIErrors = function (err, req, res, next) { Controllers.handleErrors = function (err, req, res, next) { switch (err.code) { - case 'EBADCSRFTOKEN': - winston.error(req.path + '\n', err.message); - return res.sendStatus(403); - case 'blacklisted-ip': - return res.status(403).type('text/plain').send(err.message); + case 'EBADCSRFTOKEN': + winston.error(req.path + '\n', err.message); + return res.sendStatus(403); + case 'blacklisted-ip': + return res.status(403).type('text/plain').send(err.message); } if (parseInt(err.status, 10) === 302 && err.path) { diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 1d93bbcaab..f20e3330a5 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -431,7 +431,7 @@ module.exports = function (db, module) { return item && item.value; }); callback(err, data); - }); + }); } module.sortedSetRemoveRangeByLex = function (key, min, max, callback) { diff --git a/src/groups.js b/src/groups.js index 07d8a2347b..0d2a22c131 100644 --- a/src/groups.js +++ b/src/groups.js @@ -302,8 +302,8 @@ var utils = require('../public/src/utils'); Groups.exists = function (name, callback) { if (Array.isArray(name)) { var slugs = name.map(function (groupName) { - return utils.slugify(groupName); - }); + return utils.slugify(groupName); + }); async.parallel([ function (next) { next(null, slugs.map(function (slug) { diff --git a/src/groups/search.js b/src/groups/search.js index 00bcee3967..680dff11e8 100644 --- a/src/groups/search.js +++ b/src/groups/search.js @@ -38,25 +38,25 @@ module.exports = function (Groups) { Groups.sort = function (strategy, groups, next) { switch (strategy) { - case 'count': - groups = groups.sort(function (a, b) { - return a.slug > b.slug; - }).sort(function (a, b) { - return b.memberCount - a.memberCount; - }); - break; + case 'count': + groups = groups.sort(function (a, b) { + return a.slug > b.slug; + }).sort(function (a, b) { + return b.memberCount - a.memberCount; + }); + break; - case 'date': - groups = groups.sort(function (a, b) { - return b.createtime - a.createtime; - }); - break; + case 'date': + groups = groups.sort(function (a, b) { + return b.createtime - a.createtime; + }); + break; - case 'alpha': // intentional fall-through - default: - groups = groups.sort(function (a, b) { - return a.slug > b.slug ? 1 : -1; - }); + case 'alpha': // intentional fall-through + default: + groups = groups.sort(function (a, b) { + return a.slug > b.slug ? 1 : -1; + }); } next(null, groups); diff --git a/src/messaging.js b/src/messaging.js index 7e74f0bb3b..aa24944c96 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -256,7 +256,7 @@ Messaging.canMessageUser = function (uid, toUid, callback) { return next(); } - next(new Error('[[error:chat-restricted]]')); + next(new Error('[[error:chat-restricted]]')); }, ], callback); }; diff --git a/src/meta/blacklist.js b/src/meta/blacklist.js index a7e81c604b..49213ac92c 100644 --- a/src/meta/blacklist.js +++ b/src/meta/blacklist.js @@ -6,8 +6,8 @@ var async = require('async'); var db = require('../database'); var Blacklist = { - _rules: [], - }; + _rules: [], +}; Blacklist.load = function (callback) { async.waterfall([ diff --git a/src/meta/build.js b/src/meta/build.js index 887d2cb766..cdebd8572e 100644 --- a/src/meta/build.js +++ b/src/meta/build.js @@ -84,37 +84,37 @@ exports.buildTargets = function (targets, callback) { async.eachSeries(targets, function (target, next) { var startTime; switch (target) { - case 'js': - setImmediate(next); - break; - case 'clientCSS': - winston.info('[build] Building client-side CSS'); - startTime = Date.now(); - meta.css.minify('client', step.bind(this, startTime, target, next)); - break; - - case 'acpCSS': - winston.info('[build] Building admin control panel CSS'); - startTime = Date.now(); - meta.css.minify('admin', step.bind(this, startTime, target, next)); - break; - - case 'tpl': - winston.info('[build] Building templates'); - startTime = Date.now(); - meta.templates.compile(step.bind(this, startTime, target, next)); - break; - - case 'lang': - winston.info('[build] Building language files'); - startTime = Date.now(); - meta.languages.build(step.bind(this, startTime, target, next)); - break; - - default: - winston.warn('[build] Unknown build target: \'' + target + '\''); - setImmediate(next); - break; + case 'js': + setImmediate(next); + break; + case 'clientCSS': + winston.info('[build] Building client-side CSS'); + startTime = Date.now(); + meta.css.minify('client', step.bind(this, startTime, target, next)); + break; + + case 'acpCSS': + winston.info('[build] Building admin control panel CSS'); + startTime = Date.now(); + meta.css.minify('admin', step.bind(this, startTime, target, next)); + break; + + case 'tpl': + winston.info('[build] Building templates'); + startTime = Date.now(); + meta.templates.compile(step.bind(this, startTime, target, next)); + break; + + case 'lang': + winston.info('[build] Building language files'); + startTime = Date.now(); + meta.languages.build(step.bind(this, startTime, target, next)); + break; + + default: + winston.warn('[build] Unknown build target: \'' + target + '\''); + setImmediate(next); + break; } }, next); }, diff --git a/src/meta/themes.js b/src/meta/themes.js index da1f5aa16f..e950847421 100644 --- a/src/meta/themes.js +++ b/src/meta/themes.js @@ -134,8 +134,8 @@ module.exports = function (Meta) { var themeId = data.currentThemeId || 'nodebb-theme-persona'; var themeObj = data.themesData.filter(function (themeObj) { - return themeObj.id === themeId; - })[0]; + return themeObj.id === themeId; + })[0]; if (process.env.NODE_ENV === 'development') { winston.info('[themes] Using theme ' + themeId); diff --git a/src/notifications.js b/src/notifications.js index 06ebd64b61..0fad742e1a 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -461,33 +461,33 @@ var utils = require('../public/src/utils'); switch (mergeId) { // intentional fall-through - case 'notifications:upvoted_your_post_in': - case 'notifications:user_started_following_you': - case 'notifications:user_posted_to': - case 'notifications:user_flagged_post_in': - var usernames = set.map(function (notifObj) { - return notifObj && notifObj.user && notifObj.user.username; - }).filter(function (username, idx, array) { - return array.indexOf(username) === idx; - }); - var numUsers = usernames.length; - - var title = S(notifications[modifyIndex].topicTitle || '').decodeHTMLEntities().s; - var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); - titleEscaped = titleEscaped ? (', ' + titleEscaped) : ''; - - if (numUsers === 2) { - notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]'; - } else if (numUsers > 2) { - notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]'; - } + case 'notifications:upvoted_your_post_in': + case 'notifications:user_started_following_you': + case 'notifications:user_posted_to': + case 'notifications:user_flagged_post_in': + var usernames = set.map(function (notifObj) { + return notifObj && notifObj.user && notifObj.user.username; + }).filter(function (username, idx, array) { + return array.indexOf(username) === idx; + }); + var numUsers = usernames.length; + + var title = S(notifications[modifyIndex].topicTitle || '').decodeHTMLEntities().s; + var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ','); + titleEscaped = titleEscaped ? (', ' + titleEscaped) : ''; + + if (numUsers === 2) { + notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]'; + } else if (numUsers > 2) { + notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]'; + } - notifications[modifyIndex].path = set[set.length - 1].path; - break; + notifications[modifyIndex].path = set[set.length - 1].path; + break; - case 'new_register': - notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]'; - break; + case 'new_register': + notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]'; + break; } // Filter out duplicates diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index 2441b24228..ef82046bbf 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -83,18 +83,18 @@ module.exports = function (Plugins) { var hookType = hook.split(':')[0]; switch (hookType) { - case 'filter': - fireFilterHook(hook, hookList, params, callback); - break; - case 'action': - fireActionHook(hook, hookList, params, callback); - break; - case 'static': - fireStaticHook(hook, hookList, params, callback); - break; - default: - winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook); - break; + case 'filter': + fireFilterHook(hook, hookList, params, callback); + break; + case 'action': + fireActionHook(hook, hookList, params, callback); + break; + case 'static': + fireStaticHook(hook, hookList, params, callback); + break; + default: + winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook); + break; } }; diff --git a/src/posts/flags.js b/src/posts/flags.js index f03cb9de59..a1ee62ecd4 100644 --- a/src/posts/flags.js +++ b/src/posts/flags.js @@ -247,18 +247,18 @@ module.exports = function (Posts) { if (prop === 'flag:state') { switch (postObj[prop]) { - case 'open': - postObj.flagData.labelClass = 'info'; - break; - case 'wip': - postObj.flagData.labelClass = 'warning'; - break; - case 'resolved': - postObj.flagData.labelClass = 'success'; - break; - case 'rejected': - postObj.flagData.labelClass = 'danger'; - break; + case 'open': + postObj.flagData.labelClass = 'info'; + break; + case 'wip': + postObj.flagData.labelClass = 'warning'; + break; + case 'resolved': + postObj.flagData.labelClass = 'success'; + break; + case 'rejected': + postObj.flagData.labelClass = 'danger'; + break; } } @@ -324,22 +324,22 @@ module.exports = function (Posts) { changes.forEach(function (property) { switch (property) { - case 'assignee': // intentional fall-through - case 'state': - history.unshift({ - uid: uid, - type: property, - value: flagObj[property], - timestamp: Date.now(), - }); - break; + case 'assignee': // intentional fall-through + case 'state': + history.unshift({ + uid: uid, + type: property, + value: flagObj[property], + timestamp: Date.now(), + }); + break; - case 'notes': - history.unshift({ - uid: uid, - type: property, - timestamp: Date.now(), - }); + case 'notes': + history.unshift({ + uid: uid, + type: property, + timestamp: Date.now(), + }); } }); diff --git a/src/sitemap.js b/src/sitemap.js index 4663c2df9f..dbd881a067 100644 --- a/src/sitemap.js +++ b/src/sitemap.js @@ -21,9 +21,9 @@ var sitemap = { sitemap.render = function (callback) { var numTopics = parseInt(meta.config.sitemapTopics, 10) || 500; var returnData = { - url: nconf.get('url'), - topics: [], - }; + url: nconf.get('url'), + topics: [], + }; var numPages; async.waterfall([ @@ -55,22 +55,22 @@ sitemap.getPages = function (callback) { } var urls = [{ - url: '', - changefreq: 'weekly', - priority: 0.6, - }, { - url: '/recent', - changefreq: 'daily', - priority: 0.4, - }, { - url: '/users', - changefreq: 'daily', - priority: 0.4, - }, { - url: '/groups', - changefreq: 'daily', - priority: 0.4, - }]; + url: '', + changefreq: 'weekly', + priority: 0.6, + }, { + url: '/recent', + changefreq: 'daily', + priority: 0.4, + }, { + url: '/users', + changefreq: 'daily', + priority: 0.4, + }, { + url: '/groups', + changefreq: 'daily', + priority: 0.4, + }]; plugins.fireHook('filter:sitemap.getPages', {urls: urls}, function (err, data) { if (err) { diff --git a/src/socket.io/user/picture.js b/src/socket.io/user/picture.js index b0ddd8cdcd..109b2635e1 100644 --- a/src/socket.io/user/picture.js +++ b/src/socket.io/user/picture.js @@ -26,25 +26,25 @@ module.exports = function (SocketUser) { }, function (next) { switch (type) { - case 'default': - next(null, ''); - break; - case 'uploaded': - user.getUserField(data.uid, 'uploadedpicture', next); - break; - default: - plugins.fireHook('filter:user.getPicture', { - uid: socket.uid, - type: type, - picture: undefined, - }, function (err, returnData) { - if (err) { - return next(err); - } + case 'default': + next(null, ''); + break; + case 'uploaded': + user.getUserField(data.uid, 'uploadedpicture', next); + break; + default: + plugins.fireHook('filter:user.getPicture', { + uid: socket.uid, + type: type, + picture: undefined, + }, function (err, returnData) { + if (err) { + return next(err); + } - next(null, returnData.picture || ''); - }); - break; + next(null, returnData.picture || ''); + }); + break; } }, function (picture, next) { diff --git a/src/start.js b/src/start.js index 489f114f53..652da31128 100644 --- a/src/start.js +++ b/src/start.js @@ -57,21 +57,21 @@ start.start = function () { ], function (err) { if (err) { switch (err.message) { - case 'schema-out-of-date': - winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); - winston.warn(' ./nodebb upgrade'); - break; - case 'dependencies-out-of-date': - winston.warn('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:'); - winston.warn(' ./nodebb upgrade'); - break; - case 'dependencies-missing': - winston.warn('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:'); - winston.warn(' ./nodebb upgrade'); - break; - default: - winston.error(err); - break; + case 'schema-out-of-date': + winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); + winston.warn(' ./nodebb upgrade'); + break; + case 'dependencies-out-of-date': + winston.warn('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:'); + winston.warn(' ./nodebb upgrade'); + break; + case 'dependencies-missing': + winston.warn('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:'); + winston.warn(' ./nodebb upgrade'); + break; + default: + winston.error(err); + break; } // Either way, bad stuff happened. Abort start. @@ -125,8 +125,8 @@ function addProcessHandlers() { var meta = require('./meta'); switch (message.action) { - case 'reload': - meta.reload(); + case 'reload': + meta.reload(); break; } }); diff --git a/src/topics/teaser.js b/src/topics/teaser.js index c18b97c554..9264b4b254 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -30,18 +30,18 @@ module.exports = function (Topics) { } switch (meta.config.teaserPost) { - case 'first': - teaserPids.push(topic.mainPid); - break; - - case 'last-post': - teaserPids.push(topic.teaserPid || topic.mainPid); - break; - - case 'last-reply': // intentional fall-through - default: - teaserPids.push(topic.teaserPid); - break; + case 'first': + teaserPids.push(topic.mainPid); + break; + + case 'last-post': + teaserPids.push(topic.teaserPid || topic.mainPid); + break; + + case 'last-reply': // intentional fall-through + default: + teaserPids.push(topic.teaserPid); + break; } } }); diff --git a/src/topics/unread.js b/src/topics/unread.js index 80dfb0efeb..cc3101ee05 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -121,10 +121,10 @@ module.exports = function (Topics) { return false; } switch (filter) { - case 'new': - return !userRead[recentTopic.value]; - default: - return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value]; + case 'new': + return !userRead[recentTopic.value]; + default: + return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value]; } }).map(function (topic) { return topic.value; diff --git a/src/user/info.js b/src/user/info.js index 6df33f4757..4af1b77f35 100644 --- a/src/user/info.js +++ b/src/user/info.js @@ -119,9 +119,9 @@ module.exports = function (User) { function formatBanData(data) { var reasons = data.reasons.reduce(function (memo, cur) { - memo[cur.score] = cur.value; - return memo; - }, {}); + memo[cur.score] = cur.value; + return memo; + }, {}); data.bans = data.bans.map(function (banObj) { banObj.until = parseInt(banObj.value, 10); diff --git a/test/search-admin.js b/test/search-admin.js index 97316e6639..0d52c8db75 100644 --- a/test/search-admin.js +++ b/test/search-admin.js @@ -5,59 +5,59 @@ var assert = require('assert'); var search = require('../src/admin/search'); describe('admin search', function () { - describe('filterDirectories', function () { - it('should resolve all paths to relative paths', function (done) { - assert.deepEqual(search.filterDirectories([ - 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', - ]), [ - 'admin/gdhgfsdg/sggag', - ]); - done(); - }); - it('should exclude partials', function (done) { - assert.deepEqual(search.filterDirectories([ - 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', - 'dfahdfsgf/admin/partials/hgkfds/fdhsdfh.tpl', - ]), [ - 'admin/gdhgfsdg/sggag', - ]); - done(); - }); - it('should exclude files in the admin directory', function (done) { - assert.deepEqual(search.filterDirectories([ - 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', - 'dfdasg/admin/hjkdfsk.tpl', - ]), [ - 'admin/gdhgfsdg/sggag', - ]); - done(); - }); - }); + describe('filterDirectories', function () { + it('should resolve all paths to relative paths', function (done) { + assert.deepEqual(search.filterDirectories([ + 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', + ]), [ + 'admin/gdhgfsdg/sggag', + ]); + done(); + }); + it('should exclude partials', function (done) { + assert.deepEqual(search.filterDirectories([ + 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', + 'dfahdfsgf/admin/partials/hgkfds/fdhsdfh.tpl', + ]), [ + 'admin/gdhgfsdg/sggag', + ]); + done(); + }); + it('should exclude files in the admin directory', function (done) { + assert.deepEqual(search.filterDirectories([ + 'hfjksfd/fdsgagag/admin/gdhgfsdg/sggag.tpl', + 'dfdasg/admin/hjkdfsk.tpl', + ]), [ + 'admin/gdhgfsdg/sggag', + ]); + done(); + }); + }); - describe('sanitize', function () { - it('should strip out scripts', function (done) { - assert.equal( + describe('sanitize', function () { + it('should strip out scripts', function (done) { + assert.equal( search.sanitize('Pellentesque tristique senectus' + ' habitant morbi'), 'Pellentesque tristique senectus' + ' habitant morbi' ); - done(); - }); - it('should remove all tags', function (done) { - assert.equal( + done(); + }); + it('should remove all tags', function (done) { + assert.equal( search.sanitize('

Pellentesque habitant morbi tristique senectus' + 'Aenean vitae est.Mauris eleifend leo.

'), 'Pellentesque habitant morbi tristique senectus' + 'Aenean vitae est.Mauris eleifend leo.' ); - done(); - }); - }); + done(); + }); + }); - describe('simplify', function () { - it('should remove all mustaches', function (done) { - assert.equal( + describe('simplify', function () { + it('should remove all mustaches', function (done) { + assert.equal( search.simplify( 'Pellentesque tristique {{senectus}}habitant morbi' + 'liquam tincidunt {mauris.eu}risus' @@ -65,10 +65,10 @@ describe('admin search', function () { 'Pellentesque tristique habitant morbi' + 'liquam tincidunt risus' ); - done(); - }); - it('should collapse all whitespace', function (done) { - assert.equal( + done(); + }); + it('should collapse all whitespace', function (done) { + assert.equal( search.simplify( 'Pellentesque tristique habitant morbi' + ' \n\n liquam tincidunt mauris eu risus.' @@ -76,7 +76,7 @@ describe('admin search', function () { 'Pellentesque tristique habitant morbi' + '\nliquam tincidunt mauris eu risus.' ); - done(); - }); - }); + done(); + }); + }); }); diff --git a/test/topics.js b/test/topics.js index ad48e4cc7f..e5190f6d00 100644 --- a/test/topics.js +++ b/test/topics.js @@ -562,11 +562,11 @@ describe('Topic\'s', function () { var originalBookmark = 5; function postReply(next) { topics.reply({uid: topic.userId, content: 'test post ' + replies.length, tid: newTopic.tid}, function (err, result) { - assert.equal(err, null, 'was created with error'); - assert.ok(result); - replies.push(result); - next(); - } + assert.equal(err, null, 'was created with error'); + assert.ok(result); + replies.push(result); + next(); + } ); } diff --git a/test/user.js b/test/user.js index 5573cbe400..672079a322 100644 --- a/test/user.js +++ b/test/user.js @@ -728,7 +728,7 @@ describe('User', function () { it('should send digests', function (done) { User.updateDigestSetting(uid, 'day', function (err) { assert.ifError(err); - User.digest.execute('day', function (err) { + User.digest.execute('day', function (err) { assert.ifError(err); done(); });