chore: eslint prefer-rest-params, prefer-spread

v1.18.x
Peter Jaszkowiak 4 years ago committed by Julian Lam
parent 23f212a4c0
commit 115d19e289

@ -104,10 +104,6 @@
// allow not using object shorthand // allow not using object shorthand
"object-shorthand": "off", "object-shorthand": "off",
// WORKING ON
"prefer-rest-params": "off",
"prefer-spread": "off",
// TODO // TODO
"consistent-return": "off", "consistent-return": "off",
"no-restricted-globals": "off", "no-restricted-globals": "off",

@ -38,8 +38,7 @@ const appPath = path.join(__dirname, 'app.js');
Loader.init = function (callback) { Loader.init = function (callback) {
if (silent) { if (silent) {
console.log = function () { console.log = (...args) => {
const args = Array.prototype.slice.call(arguments);
output.write(`${args.join(' ')}\n`); output.write(`${args.join(' ')}\n`);
}; };
} }

@ -6,8 +6,7 @@ helpers.valueToString = function (value) {
return String(value); return String(value);
}; };
helpers.removeDuplicateValues = function (values) { helpers.removeDuplicateValues = function (values, ...others) {
const others = Array.prototype.slice.call(arguments, 1);
for (let i = 0; i < values.length; i++) { for (let i = 0; i < values.length; i++) {
if (values.lastIndexOf(values[i]) !== i) { if (values.lastIndexOf(values[i]) !== i) {
values.splice(i, 1); values.splice(i, 1);

@ -191,13 +191,13 @@ Logger.io_one = function (socket, uid) {
* This function replaces a socket's .emit/.on functions in order to intercept events * This function replaces a socket's .emit/.on functions in order to intercept events
*/ */
function override(method, name, errorMsg) { function override(method, name, errorMsg) {
return function () { return (...args) => {
if (opts.streams.log.f) { if (opts.streams.log.f) {
opts.streams.log.f.write(Logger.prepare_io_string(name, uid, arguments)); opts.streams.log.f.write(Logger.prepare_io_string(name, uid, args));
} }
try { try {
method.apply(socket, arguments); method.apply(socket, args);
} catch (err) { } catch (err) {
winston.info(errorMsg, err); winston.info(errorMsg, err);
} }

@ -78,7 +78,7 @@ async function beforeBuild(targets) {
const allTargets = Object.keys(targetHandlers).filter(name => typeof targetHandlers[name] === 'function'); const allTargets = Object.keys(targetHandlers).filter(name => typeof targetHandlers[name] === 'function');
async function buildTargets(targets, parallel) { async function buildTargets(targets, parallel) {
const length = Math.max.apply(Math, targets.map(name => name.length)); const length = Math.max(...targets.map(name => name.length));
if (parallel) { if (parallel) {
await Promise.all( await Promise.all(

@ -27,8 +27,7 @@ Plugins.data = require('./data');
Plugins.hooks = require('./hooks'); Plugins.hooks = require('./hooks');
// Backwards compatibility for hooks, remove in v1.18.0 // Backwards compatibility for hooks, remove in v1.18.0
const _deprecate = async function () { const _deprecate = async function (...args) {
const args = Array.from(arguments);
const oldMethod = args.shift(); const oldMethod = args.shift();
const newMethod = args.shift(); const newMethod = args.shift();
const method = args.shift(); const method = args.shift();

@ -12,7 +12,7 @@ const { themeNamePattern } = require('../constants');
module.exports = function (Plugins) { module.exports = function (Plugins) {
async function registerPluginAssets(pluginData, fields) { async function registerPluginAssets(pluginData, fields) {
function add(dest, arr) { function add(dest, arr) {
dest.push.apply(dest, arr || []); dest.push(...(arr || []));
} }
const handlers = { const handlers = {

@ -31,7 +31,7 @@ module.exports = function (Posts) {
return await filterPidsBySingleCid(pids, cid); return await filterPidsBySingleCid(pids, cid);
} }
const pidsArr = await Promise.all(cid.map(c => Posts.filterPidsByCid(pids, c))); const pidsArr = await Promise.all(cid.map(c => Posts.filterPidsByCid(pids, c)));
return _.union.apply(_, pidsArr); return _.union(...pidsArr);
}; };
async function filterPidsBySingleCid(pids, cid) { async function filterPidsBySingleCid(pids, cid) {

@ -38,22 +38,22 @@ module.exports = function (theModule, ignoreKeys) {
function wrapCallback(origFn, callbackFn) { function wrapCallback(origFn, callbackFn) {
return async function wrapperCallback(...args) { return async function wrapperCallback(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { if (args.length && typeof args[args.length - 1] === 'function') {
const cb = args.pop(); const cb = args.pop();
args.push((err, res) => (res !== undefined ? cb(err, res) : cb(err))); args.push((err, res) => (res !== undefined ? cb(err, res) : cb(err)));
return callbackFn.apply(null, args); return callbackFn(...args);
} }
return origFn.apply(null, arguments); return origFn(...args);
}; };
} }
function wrapPromise(origFn, promiseFn) { function wrapPromise(origFn, promiseFn) {
return function wrapperPromise(...args) { return function wrapperPromise(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { if (args.length && typeof args[args.length - 1] === 'function') {
return origFn.apply(null, args); return origFn(...args);
} }
return promiseFn.apply(null, arguments); return promiseFn(...args);
}; };
} }

@ -93,8 +93,8 @@ function groupRoutes(app, middleware, controllers) {
module.exports = async function (app, middleware) { module.exports = async function (app, middleware) {
const router = express.Router(); const router = express.Router();
router.render = function () { router.render = function (...args) {
app.render.apply(app, arguments); app.render(...args);
}; };
const ensureLoggedIn = require('connect-ensure-login'); const ensureLoggedIn = require('connect-ensure-login');

@ -124,9 +124,9 @@ Settings.prototype.persist = function (callback) {
if (typeof conf === 'object') { if (typeof conf === 'object') {
conf = JSON.stringify(conf); conf = JSON.stringify(conf);
} }
meta.settings.set(this.hash, this.createWrapper(this.cfg.v, conf), function () { meta.settings.set(this.hash, this.createWrapper(this.cfg.v, conf), (...args) => {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback.apply(_this, arguments || []); callback.apply(_this, args || []);
} }
}); });
return this; return this;

@ -33,7 +33,7 @@ module.exports = function (Topics) {
const maxIndex = await Topics.getPostCount(tid); const maxIndex = await Topics.getPostCount(tid);
const indices = await db.sortedSetRanks(`tid:${tid}:posts`, pids); const indices = await db.sortedSetRanks(`tid:${tid}:posts`, pids);
const postIndices = indices.map(i => (i === null ? 0 : i + 1)); const postIndices = indices.map(i => (i === null ? 0 : i + 1));
const minIndex = Math.min.apply(Math, postIndices); const minIndex = Math.min(...postIndices);
const bookmarks = await Topics.getTopicBookmarks(tid); const bookmarks = await Topics.getTopicBookmarks(tid);

@ -191,7 +191,7 @@ async function isSelfOrMethod(callerUid, uid, method) {
User.getAdminsandGlobalMods = async function () { User.getAdminsandGlobalMods = async function () {
const results = await groups.getMembersOfGroups(['administrators', 'Global Moderators']); const results = await groups.getMembersOfGroups(['administrators', 'Global Moderators']);
return await User.getUsersData(_.union.apply(_, results)); return await User.getUsersData(_.union(...results));
}; };
User.getAdminsandGlobalModsandModerators = async function () { User.getAdminsandGlobalModsandModerators = async function () {
@ -200,7 +200,7 @@ User.getAdminsandGlobalModsandModerators = async function () {
groups.getMembers('Global Moderators', 0, -1), groups.getMembers('Global Moderators', 0, -1),
User.getModeratorUids(), User.getModeratorUids(),
]); ]);
return await User.getUsersData(_.union.apply(_, results)); return await User.getUsersData(_.union(...results));
}; };
User.getModeratorUids = async function () { User.getModeratorUids = async function () {

@ -283,10 +283,10 @@ function listen(callback) {
throw err; throw err;
} }
server.listen.apply(server, args); server.listen(...args);
}); });
} else { } else {
server.listen.apply(server, args); server.listen(...args);
} }
} }

Loading…
Cancel
Save