Skip to content

Commit

Permalink
chore: eslint prefer-arrow-callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pitaj authored and julianlam committed Feb 8, 2021
1 parent 707b55b commit b56d9e1
Show file tree
Hide file tree
Showing 334 changed files with 4,997 additions and 5,184 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
// WORKING ON
"prefer-rest-params": "off",
"prefer-spread": "off",
"prefer-arrow-callback": "off",
"no-var": "off",
"vars-on-top": "off",

Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = function (grunt) {
grunt.task.run('init');

grunt.event.removeAllListeners('watch');
grunt.event.on('watch', function update(action, filepath, target) {
grunt.event.on('watch', (action, filepath, target) => {
var compiling;
if (target === 'styleUpdated_Client') {
compiling = 'clientCSS';
Expand All @@ -183,7 +183,7 @@ module.exports = function (grunt) {
return run();
}

require('./src/meta/build').build([compiling], function (err) {
require('./src/meta/build').build([compiling], (err) => {
if (err) {
winston.error(err.stack);
}
Expand Down
12 changes: 5 additions & 7 deletions install/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ web.install = async function (port) {
winston.info(`Launching web installer on port ${port}`);

app.use(express.static('public', {}));
app.engine('tpl', function (filepath, options, callback) {
app.engine('tpl', (filepath, options, callback) => {
filepath = filepath.replace(/\.tpl$/, '.js');

Benchpress.__express(filepath, options, callback);
Expand All @@ -99,7 +99,7 @@ web.install = async function (port) {


function launchExpress(port) {
server = app.listen(port, function () {
server = app.listen(port, () => {
winston.info('Web installer listening on http://%s:%s', '0.0.0.0', port);
});
}
Expand All @@ -118,10 +118,8 @@ function ping(req, res) {

function welcome(req, res) {
var dbs = ['redis', 'mongo', 'postgres'];
var databases = dbs.map(function (databaseName) {
var questions = require(`../src/database/${databaseName}`).questions.filter(function (question) {
return question && !question.hideOnWebInstall;
});
var databases = dbs.map((databaseName) => {
var questions = require(`../src/database/${databaseName}`).questions.filter(question => question && !question.hideOnWebInstall);

return {
name: databaseName,
Expand Down Expand Up @@ -180,7 +178,7 @@ function install(req, res) {
env: setupEnvVars,
});

child.on('close', function (data) {
child.on('close', (data) => {
installing = false;
success = data === 0;
error = data !== 0;
Expand Down
18 changes: 9 additions & 9 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Loader.displayStartupMessages = function (callback) {
};

Loader.addWorkerEvents = function (worker) {
worker.on('exit', function (code, signal) {
worker.on('exit', (code, signal) => {
if (code !== 0) {
if (Loader.timesStarted < numProcs * 3) {
Loader.timesStarted += 1;
if (Loader.crashTimer) {
clearTimeout(Loader.crashTimer);
}
Loader.crashTimer = setTimeout(function () {
Loader.crashTimer = setTimeout(() => {
Loader.timesStarted = 0;
}, 10000);
} else {
Expand All @@ -84,20 +84,20 @@ Loader.addWorkerEvents = function (worker) {
}
});

worker.on('message', function (message) {
worker.on('message', (message) => {
if (message && typeof message === 'object' && message.action) {
switch (message.action) {
case 'restart':
console.log('[cluster] Restarting...');
Loader.restart();
break;
case 'pubsub':
workers.forEach(function (w) {
workers.forEach((w) => {
w.send(message);
});
break;
case 'socket.io':
workers.forEach(function (w) {
workers.forEach((w) => {
if (w !== worker) {
w.send(message);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ Loader.restart = function () {
nconf.remove('file');
nconf.use('file', { file: pathToConfig });

fs.readFile(pathToConfig, { encoding: 'utf-8' }, function (err, configFile) {
fs.readFile(pathToConfig, { encoding: 'utf-8' }, (err, configFile) => {
if (err) {
console.error('Error reading config');
throw err;
Expand Down Expand Up @@ -201,13 +201,13 @@ Loader.stop = function () {
};

function killWorkers() {
workers.forEach(function (worker) {
workers.forEach((worker) => {
worker.suicide = true;
worker.kill();
});
}

fs.open(pathToConfig, 'r', function (err) {
fs.open(pathToConfig, 'r', (err) => {
if (err) {
// No config detected, kickstart web installer
fork('app');
Expand Down Expand Up @@ -238,7 +238,7 @@ fs.open(pathToConfig, 'r', function (err) {
Loader.init,
Loader.displayStartupMessages,
Loader.start,
], function (err) {
], (err) => {
if (err) {
console.error('[loader] Error during startup');
throw err;
Expand Down
22 changes: 10 additions & 12 deletions src/admin/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ const file = require('../file');
const Translator = require('../translator').Translator;

function filterDirectories(directories) {
return directories.map(function (dir) {
return directories.map(
// get the relative path
// convert dir to use forward slashes
return dir.replace(/^.*(admin.*?).tpl$/, '$1').split(path.sep).join('/');
}).filter(function (dir) {
dir => dir.replace(/^.*(admin.*?).tpl$/, '$1').split(path.sep).join('/')
).filter(
// exclude .js files
// exclude partials
// only include subpaths
// exclude category.tpl, group.tpl, category-analytics.tpl
return !dir.endsWith('.js') &&
dir => (
!dir.endsWith('.js') &&
!dir.includes('/partials/') &&
/\/.*\//.test(dir) &&
!/manage\/(category|group|category-analytics)$/.test(dir);
});
!/manage\/(category|group|category-analytics)$/.test(dir)
)
);
}

async function getAdminNamespaces() {
Expand All @@ -50,9 +52,7 @@ function simplify(translations) {
}

function nsToTitle(namespace) {
return namespace.replace('admin/', '').split('/').map(function (str) {
return str[0].toUpperCase() + str.slice(1);
}).join(' > ')
return namespace.replace('admin/', '').split('/').map(str => str[0].toUpperCase() + str.slice(1)).join(' > ')
.replace(/[^a-zA-Z> ]/g, ' ');
}

Expand Down Expand Up @@ -97,9 +97,7 @@ async function buildNamespace(language, namespace) {
return await fallback(namespace);
}
// join all translations into one string separated by newlines
let str = Object.keys(translations).map(function (key) {
return translations[key];
}).join('\n');
let str = Object.keys(translations).map(key => translations[key]).join('\n');
str = sanitize(str);

let title = namespace;
Expand Down
2 changes: 1 addition & 1 deletion src/admin/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getLatestVersion(callback) {
json: true,
headers: headers,
timeout: 2000,
}, function (err, res, latestRelease) {
}, (err, res, latestRelease) => {
if (err) {
return callback(err);
}
Expand Down
10 changes: 5 additions & 5 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ Analytics.init = async function () {
maxAge: 0,
});

new cronJob('*/10 * * * * *', function () {
new cronJob('*/10 * * * * *', (() => {
Analytics.writeData();
}, null, true);
}), null, true);
};

Analytics.increment = function (keys, callback) {
keys = Array.isArray(keys) ? keys : [keys];

plugins.hooks.fire('action:analytics.increment', { keys: keys });

keys.forEach(function (key) {
keys.forEach((key) => {
counters[key] = counters[key] || 0;
counters[key] += 1;
});
Expand Down Expand Up @@ -163,14 +163,14 @@ Analytics.getHourlyStatsForSet = async function (set, hour, numHours) {

const counts = await db.sortedSetScores(set, hoursArr);

hoursArr.forEach(function (term, index) {
hoursArr.forEach((term, index) => {
terms[term] = parseInt(counts[index], 10) || 0;
});

const termsArr = [];

hoursArr.reverse();
hoursArr.forEach(function (hour) {
hoursArr.forEach((hour) => {
termsArr.push(terms[hour]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports.doTopicAction = async function (action, event, caller, { tids }) {

const uids = await user.getUidsFromSet('users:online', 0, -1);

await Promise.all(tids.map(async function (tid) {
await Promise.all(tids.map(async (tid) => {
const title = await topics.getTopicField(tid, 'title');
const data = await topics.tools[action](tid, caller.uid);
const notifyUids = await privileges.categories.filterUids('topics:read', data.cid, uids);
Expand Down
6 changes: 3 additions & 3 deletions src/cacheCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ module.exports = function (opts) {
cache.misses = 0;
}

pubsub.on(`${cache.name}:cache:reset`, function () {
pubsub.on(`${cache.name}:cache:reset`, () => {
localReset();
});

pubsub.on(`${cache.name}:cache:del`, function (keys) {
pubsub.on(`${cache.name}:cache:del`, (keys) => {
if (Array.isArray(keys)) {
keys.forEach(key => cacheDel.apply(cache, [key]));
}
Expand All @@ -71,7 +71,7 @@ module.exports = function (opts) {
}
let data;
let isCached;
const unCachedKeys = keys.filter(function (key) {
const unCachedKeys = keys.filter((key) => {
data = cache.get(key);
isCached = data !== undefined;
if (isCached) {
Expand Down
4 changes: 2 additions & 2 deletions src/categories/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = function (Categories) {

children = children[0];

children.forEach(function (child) {
children.forEach((child) => {
child.parentCid = parentCid;
child.cloneFromCid = child.cid;
child.cloneChildren = true;
Expand Down Expand Up @@ -195,7 +195,7 @@ module.exports = function (Categories) {

const currentMembers = await db.getSortedSetsMembers(toGroups.concat(fromGroups));
const copyGroups = _.uniq(_.flatten(currentMembers));
await async.each(copyGroups, async function (group) {
await async.each(copyGroups, async (group) => {
await copyPrivilegesByGroup(privileges, fromCid, toCid, group);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/categories/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var cache = require('../cache');

module.exports = function (Categories) {
Categories.purge = async function (cid, uid) {
await batch.processSortedSet(`cid:${cid}:tids`, async function (tids) {
await async.eachLimit(tids, 10, async function (tid) {
await batch.processSortedSet(`cid:${cid}:tids`, async (tids) => {
await async.eachLimit(tids, 10, async (tid) => {
await topics.purgePostsAndTopic(tid, uid);
});
}, { alwaysStartAt: 0 });

const pinnedTids = await db.getSortedSetRevRange(`cid:${cid}:tids:pinned`, 0, -1);
await async.eachLimit(pinnedTids, 10, async function (tid) {
await async.eachLimit(pinnedTids, 10, async (tid) => {
await topics.purgePostsAndTopic(tid, uid);
});
const categoryData = await Categories.getCategoryData(cid);
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = function (Categories) {
]);

const bulkAdd = [];
const childrenKeys = children.map(function (cid) {
const childrenKeys = children.map((cid) => {
bulkAdd.push(['cid:0:children', cid, cid]);
return `category:${cid}`;
});
Expand Down
14 changes: 7 additions & 7 deletions src/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ Categories.getModerators = async function (cid) {
};

Categories.getModeratorUids = async function (cids) {
const groupNames = cids.reduce(function (memo, cid) {
const groupNames = cids.reduce((memo, cid) => {
memo.push(`cid:${cid}:privileges:moderate`);
memo.push(`cid:${cid}:privileges:groups:moderate`);
return memo;
}, []);

const memberSets = await groups.getMembersOfGroups(groupNames);
// Every other set is actually a list of user groups, not uids, so convert those to members
const sets = memberSets.reduce(function (memo, set, idx) {
const sets = memberSets.reduce((memo, set, idx) => {
if (idx % 2) {
memo.groupNames.push(set);
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ Categories.getCategories = async function (cids, uid) {
Categories.getTagWhitelist(cids),
Categories.hasReadCategories(cids, uid),
]);
categories.forEach(function (category, i) {
categories.forEach((category, i) => {
if (category) {
category.tagWhitelist = tagWhitelist[i];
category['unread-class'] = (category.topic_count === 0 || (hasRead[i] && uid !== 0)) ? '' : 'unread';
Expand Down Expand Up @@ -180,7 +180,7 @@ function calculateTopicPostCount(category) {
let postCount = category.post_count;
let topicCount = category.topic_count;
if (Array.isArray(category.children)) {
category.children.forEach(function (child) {
category.children.forEach((child) => {
calculateTopicPostCount(child);
postCount += parseInt(child.totalPostCount, 10) || 0;
topicCount += parseInt(child.totalTopicCount, 10) || 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ async function getChildrenTree(category, uid) {
childrenData = childrenData.filter(Boolean);
childrenCids = childrenData.map(child => child.cid);
const hasRead = await Categories.hasReadCategories(childrenCids, uid);
childrenData.forEach(function (child, i) {
childrenData.forEach((child, i) => {
child['unread-class'] = (child.topic_count === 0 || (hasRead[i] && uid !== 0)) ? '' : 'unread';
});
Categories.getTree([category].concat(childrenData), category.parentCid);
Expand Down Expand Up @@ -270,7 +270,7 @@ Categories.getChildrenCids = async function (rootCid) {
};

Categories.flattenCategories = function (allCategories, categoryData) {
categoryData.forEach(function (category) {
categoryData.forEach((category) => {
if (category) {
allCategories.push(category);

Expand Down Expand Up @@ -302,7 +302,7 @@ Categories.getTree = function (categories, parentCid) {

const tree = [];

categories.forEach(function (category) {
categories.forEach((category) => {
if (category) {
category.children = category.children || [];
if (!category.cid) {
Expand Down

0 comments on commit b56d9e1

Please sign in to comment.