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
"object-shorthand": "off",
// WORKING ON
"prefer-rest-params": "off",
"prefer-spread": "off",
// TODO
"consistent-return": "off",
"no-restricted-globals": "off",

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

@ -6,8 +6,7 @@ helpers.valueToString = function (value) {
return String(value);
};
helpers.removeDuplicateValues = function (values) {
const others = Array.prototype.slice.call(arguments, 1);
helpers.removeDuplicateValues = function (values, ...others) {
for (let i = 0; i < values.length; i++) {
if (values.lastIndexOf(values[i]) !== i) {
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
*/
function override(method, name, errorMsg) {
return function () {
return (...args) => {
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 {
method.apply(socket, arguments);
method.apply(socket, args);
} catch (err) {
winston.info(errorMsg, err);
}

@ -78,7 +78,7 @@ async function beforeBuild(targets) {
const allTargets = Object.keys(targetHandlers).filter(name => typeof targetHandlers[name] === 'function');
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) {
await Promise.all(

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

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

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

@ -38,22 +38,22 @@ module.exports = function (theModule, ignoreKeys) {
function wrapCallback(origFn, callbackFn) {
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();
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) {
return function wrapperPromise(...args) {
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
return origFn.apply(null, args);
if (args.length && typeof args[args.length - 1] === 'function') {
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) {
const router = express.Router();
router.render = function () {
app.render.apply(app, arguments);
router.render = function (...args) {
app.render(...args);
};
const ensureLoggedIn = require('connect-ensure-login');

@ -124,9 +124,9 @@ Settings.prototype.persist = function (callback) {
if (typeof conf === 'object') {
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') {
callback.apply(_this, arguments || []);
callback.apply(_this, args || []);
}
});
return this;

@ -33,7 +33,7 @@ module.exports = function (Topics) {
const maxIndex = await Topics.getPostCount(tid);
const indices = await db.sortedSetRanks(`tid:${tid}:posts`, pids);
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);

@ -191,7 +191,7 @@ async function isSelfOrMethod(callerUid, uid, method) {
User.getAdminsandGlobalMods = async function () {
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 () {
@ -200,7 +200,7 @@ User.getAdminsandGlobalModsandModerators = async function () {
groups.getMembers('Global Moderators', 0, -1),
User.getModeratorUids(),
]);
return await User.getUsersData(_.union.apply(_, results));
return await User.getUsersData(_.union(...results));
};
User.getModeratorUids = async function () {

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

Loading…
Cancel
Save