mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
ESlint no-useless-escape, no-else-return
This commit is contained in:
@@ -71,8 +71,8 @@
|
||||
"new-cap": "off",
|
||||
"no-lonely-if": "off",
|
||||
"radix": "off",
|
||||
"no-else-return": "off",
|
||||
"no-useless-escape": "off",
|
||||
// "no-else-return": "off",
|
||||
// "no-useless-escape": "off",
|
||||
// "block-scoped-var": "off",
|
||||
// "operator-assignment": "off",
|
||||
// "yoda": "off",
|
||||
|
||||
@@ -165,9 +165,8 @@ define('admin/manage/flags', [
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
} else {
|
||||
app.alertSuccess('[[topic:flag_manage_saved]]');
|
||||
}
|
||||
app.alertSuccess('[[topic:flag_manage_saved]]');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -377,9 +377,8 @@ $(document).ready(function () {
|
||||
if ($(this).attr('data-ajaxify') === 'false') {
|
||||
if (!internalLink) {
|
||||
return;
|
||||
} else {
|
||||
return e.preventDefault();
|
||||
}
|
||||
return e.preventDefault();
|
||||
}
|
||||
|
||||
// Default behaviour for rss feeds
|
||||
|
||||
@@ -166,7 +166,7 @@ define('forum/account/edit', ['forum/account/header', 'translator', 'components'
|
||||
if ($('#confirm-username').val() !== app.user.username) {
|
||||
app.alertError('[[error:invalid-username]]');
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
socket.emit('user.deleteAccount', {}, function (err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
@@ -174,7 +174,6 @@ define('forum/account/edit', ['forum/account/header', 'translator', 'components'
|
||||
|
||||
window.location.href = config.relative_path + '/';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
modal.on('shown.bs.modal', function () {
|
||||
|
||||
@@ -45,9 +45,8 @@ $('document').ready(function () {
|
||||
$('html, body').animate({ scrollTop: '0px' }, 400);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
$('#submit .fa-spin').removeClass('hide');
|
||||
}
|
||||
$('#submit .fa-spin').removeClass('hide');
|
||||
}
|
||||
|
||||
function activate(type, el) {
|
||||
|
||||
@@ -7,9 +7,8 @@ define('components', function () {
|
||||
'topic/teaser': function (tid) {
|
||||
if (tid) {
|
||||
return $('[component="category/topic"][data-tid="' + tid + '"] [component="topic/teaser"]');
|
||||
} else {
|
||||
return $('[component="topic/teaser"]');
|
||||
}
|
||||
return $('[component="topic/teaser"]');
|
||||
},
|
||||
topic: function (name, value) {
|
||||
return $('[component="topic"][data-' + name + '="' + value + '"]');
|
||||
@@ -61,9 +60,8 @@ define('components', function () {
|
||||
|
||||
if (components.core[arguments[0]] && args.length) {
|
||||
return components.core[arguments[0]].apply(this, args);
|
||||
} else {
|
||||
return $('[component="' + arguments[0] + '"]');
|
||||
}
|
||||
return $('[component="' + arguments[0] + '"]');
|
||||
};
|
||||
|
||||
return components;
|
||||
|
||||
@@ -56,18 +56,16 @@
|
||||
helpers.escape = function (str) {
|
||||
if (typeof utils !== 'undefined') {
|
||||
return utils.escapeHTML(str);
|
||||
} else {
|
||||
return require('../utils').escapeHTML(str);
|
||||
}
|
||||
return require('../utils').escapeHTML(str);
|
||||
};
|
||||
|
||||
helpers.stripTags = function (str) {
|
||||
if (typeof window !== 'undefined' && window.S) {
|
||||
return window.S(String(str)).stripTags().s;
|
||||
} else {
|
||||
}
|
||||
var S = require('string');
|
||||
return S(String(str)).stripTags().s;
|
||||
}
|
||||
};
|
||||
|
||||
helpers.generateCategoryBackground = function (category) {
|
||||
@@ -157,9 +155,8 @@
|
||||
return '<button class="btn btn-link" data-action="rejectInvite" data-group="' + groupObj.displayName + '">[[groups:membership.reject]]</button><button class="btn btn-success" data-action="acceptInvite" data-group="' + groupObj.name + '"><i class="fa fa-plus"></i> [[groups:membership.accept-invitation]]</button>';
|
||||
} else if (!groupObj.disableJoinRequests && groupObj.name !== 'administrators') {
|
||||
return '<button class="btn btn-success" data-action="join" data-group="' + groupObj.displayName + '"><i class="fa fa-plus"></i> [[groups:membership.join-group]]</button>';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
helpers.spawnPrivilegeStates = function (member, privileges) {
|
||||
@@ -184,25 +181,21 @@
|
||||
helpers.renderTopicImage = function (topicObj) {
|
||||
if (topicObj.thumb) {
|
||||
return '<img src="' + topicObj.thumb + '" class="img-circle user-img" title="' + topicObj.user.username + '" />';
|
||||
} else {
|
||||
return '<img component="user/picture" data-uid="' + topicObj.user.uid + '" src="' + topicObj.user.picture + '" class="user-img" title="' + topicObj.user.username + '" />';
|
||||
}
|
||||
return '<img component="user/picture" data-uid="' + topicObj.user.uid + '" src="' + topicObj.user.picture + '" class="user-img" title="' + topicObj.user.username + '" />';
|
||||
};
|
||||
|
||||
helpers.renderDigestAvatar = function (block) {
|
||||
if (block.teaser) {
|
||||
if (block.teaser.user.picture) {
|
||||
return '<img style="vertical-align: middle; width: 16px; height: 16px; padding-right: 1em;" src="' + block.teaser.user.picture + '" title="' + block.teaser.user.username + '" />';
|
||||
} else {
|
||||
}
|
||||
return '<div style="width: 16px; height: 16px; line-height: 16px; font-size: 10px; margin-right: 1em; background-color: ' + block.teaser.user['icon:bgColor'] + '; color: white; text-align: center; display: inline-block;">' + block.teaser.user['icon:text'] + '</div>';
|
||||
}
|
||||
} else {
|
||||
if (block.user.picture) {
|
||||
return '<img style="vertical-align: middle; width: 16px; height: 16px; padding-right: 1em;" src="' + block.user.picture + '" title="' + block.user.username + '" />';
|
||||
} else {
|
||||
}
|
||||
return '<div style="width: 16px; height: 16px; line-height: 16px; font-size: 10px; margin-right: 1em; background-color: ' + block.user['icon:bgColor'] + '; color: white; text-align: center; display: inline-block;">' + block.user['icon:text'] + '</div>';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
helpers.userAgentIcons = function (data) {
|
||||
|
||||
@@ -36,9 +36,8 @@ define('settings', function () {
|
||||
hook = plugin[name];
|
||||
if (typeof hook === 'function') {
|
||||
return hook;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
helper = {
|
||||
@@ -48,9 +47,8 @@ define('settings', function () {
|
||||
deepClone: function (obj) {
|
||||
if (typeof obj === 'object') {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
/**
|
||||
Creates a new Element with given data.
|
||||
@@ -169,7 +167,7 @@ define('settings', function () {
|
||||
value = element.val();
|
||||
var array = (value != null && value.split(split || ',')) || [];
|
||||
return helper.cleanArray(array, trim, empty);
|
||||
} else {
|
||||
}
|
||||
value = element.val();
|
||||
if (trim && value != null && typeof value.trim === 'function') {
|
||||
value = value.trim();
|
||||
@@ -177,7 +175,6 @@ define('settings', function () {
|
||||
if (empty || (value !== undefined && (value == null || value.length !== 0))) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
Calls the set-hook of the given element.
|
||||
|
||||
@@ -78,9 +78,8 @@ define('settings/key', function () {
|
||||
return String.fromCharCode(code).toUpperCase();
|
||||
} else if (code >= 112 && code <= 123) {
|
||||
return 'F' + (code - 111);
|
||||
} else {
|
||||
return keyMap[code] || ('#' + code);
|
||||
}
|
||||
return keyMap[code] || ('#' + code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,9 +98,8 @@ define('settings/key', function () {
|
||||
if (!key.char) {
|
||||
if (human) {
|
||||
return 'Enter a key';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
if (!separator || /CtrlAShifMea#/.test(separator)) {
|
||||
separator = human ? ' + ' : '+';
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
tag = tag.trim().toLowerCase();
|
||||
// see https://github.com/NodeBB/NodeBB/issues/4378
|
||||
tag = tag.replace(/\u202E/gi, '');
|
||||
tag = tag.replace(/[,\/#!$%\^\*;:{}=_`<>'"~()?\|]/g, '');
|
||||
tag = tag.replace(/[,/#!$%^*;:{}=_`<>'"~()?|]/g, '');
|
||||
tag = tag.substr(0, maxLength || 15).trim();
|
||||
var matches = tag.match(/^[.-]*(.+?)[.-]*$/);
|
||||
if (matches && matches.length > 1) {
|
||||
@@ -121,7 +121,7 @@
|
||||
},
|
||||
|
||||
removePunctuation: function (str) {
|
||||
return str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`<>'"~()?]/g, '');
|
||||
return str.replace(/[.,-/#!$%^&*;:{}=\-_`<>'"~()?]/g, '');
|
||||
},
|
||||
|
||||
isEmailValid: function (email) {
|
||||
@@ -129,7 +129,7 @@
|
||||
},
|
||||
|
||||
isUserNameValid: function (name) {
|
||||
return (name && name !== '' && (/^['"\s\-\+.*0-9\u00BF-\u1FFF\u2C00-\uD7FF\w]+$/.test(name)));
|
||||
return (name && name !== '' && (/^['"\s\-+.*0-9\u00BF-\u1FFF\u2C00-\uD7FF\w]+$/.test(name)));
|
||||
},
|
||||
|
||||
isPasswordValid: function (password) {
|
||||
@@ -390,7 +390,7 @@
|
||||
var type = typeof str;
|
||||
if (type !== 'string') {
|
||||
return str;
|
||||
} else {
|
||||
}
|
||||
var nb = parseFloat(str);
|
||||
if (!isNaN(nb) && isFinite(str)) {
|
||||
return nb;
|
||||
@@ -407,7 +407,6 @@
|
||||
} catch (e) {}
|
||||
|
||||
return str;
|
||||
}
|
||||
},
|
||||
|
||||
// Safely get/set chained properties on an object
|
||||
|
||||
@@ -19,7 +19,7 @@ function filterDirectories(directories) {
|
||||
// exclude category.tpl, group.tpl, category-analytics.tpl
|
||||
return !dir.includes('/partials/') &&
|
||||
/\/.*\//.test(dir) &&
|
||||
!/manage\/(category|group|category\-analytics)$/.test(dir);
|
||||
!/manage\/(category|group|category-analytics)$/.test(dir);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ function sanitize(html) {
|
||||
function simplify(translations) {
|
||||
return translations
|
||||
// remove all mustaches
|
||||
.replace(/(?:\{{1,2}[^\}]*?\}{1,2})/g, '')
|
||||
.replace(/(?:\{{1,2}[^}]*?\}{1,2})/g, '')
|
||||
// collapse whitespace
|
||||
.replace(/(?:[ \t]*[\n\r]+[ \t]*)+/g, '\n')
|
||||
.replace(/[\t ]+/g, ' ');
|
||||
|
||||
@@ -46,9 +46,8 @@ sessionController.revoke = function (req, res, next) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return res.status(500).send(err.message);
|
||||
} else {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
return res.sendStatus(200);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -113,11 +113,10 @@ function registerAndLoginUser(req, res, userData, callback) {
|
||||
|
||||
if (!deferRegistration) {
|
||||
return next();
|
||||
} else {
|
||||
}
|
||||
userData.register = true;
|
||||
req.session.registration = userData;
|
||||
return res.json({ referrer: nconf.get('relative_path') + '/register/complete' });
|
||||
}
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
|
||||
@@ -131,9 +131,8 @@ Controllers.login = function (req, res, next) {
|
||||
return helpers.redirect(res, {
|
||||
external: data.authentication[0].url,
|
||||
});
|
||||
} else {
|
||||
return res.redirect(nconf.get('relative_path') + data.authentication[0].url);
|
||||
}
|
||||
return res.redirect(nconf.get('relative_path') + data.authentication[0].url);
|
||||
}
|
||||
if (req.uid) {
|
||||
user.getUserFields(req.uid, ['username', 'email'], function (err, user) {
|
||||
|
||||
@@ -207,10 +207,10 @@ module.exports = function (redisClient, module) {
|
||||
maxmax = '+';
|
||||
}
|
||||
|
||||
if (min !== minmin && !min.match(/^[\[\(]/)) {
|
||||
if (min !== minmin && !min.match(/^[[(]/)) {
|
||||
min = '[' + min;
|
||||
}
|
||||
if (max !== maxmax && !max.match(/^[\[\(]/)) {
|
||||
if (max !== maxmax && !max.match(/^[[(]/)) {
|
||||
max = '[' + max;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,9 +121,8 @@ module.exports = function (Groups) {
|
||||
return -1;
|
||||
} else if (!a.isOwner && b.isOwner) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
next(null, results);
|
||||
},
|
||||
|
||||
@@ -132,9 +132,8 @@ var opts = {
|
||||
*/
|
||||
if (meta.config.loggerStatus > 0) {
|
||||
return opts.express.ofn(req, res, next);
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
return next();
|
||||
};
|
||||
|
||||
Logger.prepare_io_string = function (_type, _uid, _args) {
|
||||
|
||||
@@ -44,7 +44,7 @@ function getTranslationTree(callback) {
|
||||
// pull languages and namespaces from paths
|
||||
function extrude(languageDir, paths) {
|
||||
paths.forEach(function (p) {
|
||||
var rel = p.split(languageDir)[1].split(/[\/\\]/).slice(1);
|
||||
var rel = p.split(languageDir)[1].split(/[/\\]/).slice(1);
|
||||
var language = rel.shift().replace('_', '-').replace('@', '-x-');
|
||||
var namespace = rel.join('/').replace(/\.json$/, '');
|
||||
|
||||
|
||||
@@ -64,9 +64,8 @@ middleware.ensureSelfOrGlobalPrivilege = function (req, res, next) {
|
||||
return next(err);
|
||||
} else if (ok) {
|
||||
return next();
|
||||
} else {
|
||||
controllers.helpers.notAllowed(req, res);
|
||||
}
|
||||
controllers.helpers.notAllowed(req, res);
|
||||
});
|
||||
} else {
|
||||
controllers.helpers.notAllowed(req, res);
|
||||
@@ -121,11 +120,10 @@ middleware.prepareAPI = function (req, res, next) {
|
||||
middleware.routeTouchIcon = function (req, res) {
|
||||
if (meta.config['brand:touchIcon'] && validator.isURL(meta.config['brand:touchIcon'])) {
|
||||
return res.redirect(meta.config['brand:touchIcon']);
|
||||
} else {
|
||||
}
|
||||
return res.sendFile(path.join(__dirname, '../../public', meta.config['brand:touchIcon'] || '/logo.png'), {
|
||||
maxAge: req.app.enabled('cache') ? 5184000000 : 0,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
middleware.privateTagListing = function (req, res, next) {
|
||||
|
||||
@@ -148,12 +148,11 @@ module.exports = function (middleware) {
|
||||
// If the user's session contains registration data, redirect the user to complete registration
|
||||
if (!req.session.hasOwnProperty('registration')) {
|
||||
return next();
|
||||
} else {
|
||||
}
|
||||
if (!req.path.endsWith('/register/complete')) {
|
||||
controllers.helpers.redirect(res, '/register/complete');
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -316,9 +316,8 @@ var middleware;
|
||||
return 1;
|
||||
} else if (a.name < b.name) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
callback(null, pluginArray);
|
||||
|
||||
@@ -57,10 +57,9 @@ module.exports = function (Plugins) {
|
||||
method = data.method.split('.').reduce(function (memo, prop) {
|
||||
if (memo && memo[prop]) {
|
||||
return memo[prop];
|
||||
} else {
|
||||
}
|
||||
// Couldn't find method by path, aborting
|
||||
return null;
|
||||
}
|
||||
}, Plugins.libraries[data.id]);
|
||||
|
||||
// Write the actual method reference to the hookObj
|
||||
|
||||
@@ -225,7 +225,7 @@ module.exports = function (Plugins) {
|
||||
|
||||
pluginData.modules.forEach(function (file) {
|
||||
if (strip) {
|
||||
modules[file.replace(new RegExp('\.?(\/[^\/]+){' + strip + '}\/'), '')] = path.join('./node_modules/', pluginData.id, file);
|
||||
modules[file.replace(new RegExp('.?(/[^/]+){' + strip + '}/'), '')] = path.join('./node_modules/', pluginData.id, file);
|
||||
} else {
|
||||
modules[path.basename(file)] = path.join('./node_modules/', pluginData.id, file);
|
||||
}
|
||||
@@ -268,13 +268,12 @@ module.exports = function (Plugins) {
|
||||
if (!atRootLevel && relPath) {
|
||||
winston.verbose('[plugins/load] File not found: ' + fullPath + ' (Ascending)');
|
||||
return resolveModulePath(path.join(__dirname, '../..', relPath));
|
||||
} else {
|
||||
}
|
||||
// Already at root level, file was simply not found
|
||||
winston.warn('[plugins/load] File not found: ' + fullPath + ' (Ignoring)');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Plugins.loadPluginInfo = function (pluginPath, callback) {
|
||||
async.parallel({
|
||||
|
||||
@@ -83,9 +83,8 @@ function onMessage(socket, payload) {
|
||||
var methodToCall = parts.reduce(function (prev, cur) {
|
||||
if (prev !== null && prev[cur]) {
|
||||
return prev[cur];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}, Namespaces);
|
||||
|
||||
if (!methodToCall) {
|
||||
|
||||
@@ -93,9 +93,9 @@ function rateLimitExceeded(socket) {
|
||||
var delay = meta.config.hasOwnProperty('chatMessageDelay') ? parseInt(meta.config.chatMessageDelay, 10) : 200;
|
||||
if (now - socket.lastChatMessageTime < delay) {
|
||||
return true;
|
||||
} else {
|
||||
socket.lastChatMessageTime = now;
|
||||
}
|
||||
socket.lastChatMessageTime = now;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,8 @@ module.exports = function (Topics) {
|
||||
tids = results.topicData.filter(function (topic) {
|
||||
if (topic) {
|
||||
return results.ignoredCids.indexOf(topic.cid.toString()) === -1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}).map(function (topic) {
|
||||
return topic.tid;
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('Utility Methods', function () {
|
||||
|
||||
describe('cleanUpTag', function () {
|
||||
it('should cleanUp a tag', function (done) {
|
||||
var cleanedTag = utils.cleanUpTag(',\/#!$%\^\*;TaG1:{}=_`<>\'"~()?\|');
|
||||
var cleanedTag = utils.cleanUpTag(',/#!$%^*;TaG1:{}=_`<>\'"~()?|');
|
||||
assert.equal(cleanedTag, 'tag1');
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user