mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 19:15:28 +02:00
chore: eslint prefer-arrow-callback
This commit is contained in:
committed by
Julian Lam
parent
707b55b6a5
commit
b56d9e12b5
@@ -189,7 +189,7 @@ Data.getModules = async function getModules(pluginData) {
|
||||
if (Array.isArray(pluginModules)) {
|
||||
var strip = parseInt(pluginData.modulesStrip, 10) || 0;
|
||||
|
||||
pluginModules = pluginModules.reduce(function (prev, modulePath) {
|
||||
pluginModules = pluginModules.reduce((prev, modulePath) => {
|
||||
var key;
|
||||
if (strip) {
|
||||
key = modulePath.replace(new RegExp(`.?(/[^/]+){${strip}}/`), '');
|
||||
@@ -228,7 +228,7 @@ Data.getLanguageData = async function getLanguageData(pluginData) {
|
||||
const namespaces = [];
|
||||
const languages = [];
|
||||
|
||||
filepaths.forEach(function (p) {
|
||||
filepaths.forEach((p) => {
|
||||
const rel = path.relative(pathToFolder, p).split(/[/\\]/);
|
||||
const language = rel.shift().replace('_', '-').replace('@', '-x-');
|
||||
const namespace = rel.join('/').replace(/\.json$/, '');
|
||||
|
||||
@@ -55,12 +55,12 @@ Hooks.register = function (id, data) {
|
||||
|
||||
if (Array.isArray(data.method) && data.method.every(method => typeof method === 'function' || typeof method === 'string')) {
|
||||
// Go go gadget recursion!
|
||||
data.method.forEach(function (method) {
|
||||
data.method.forEach((method) => {
|
||||
const singularData = { ...data, method: method };
|
||||
Hooks.register(id, singularData);
|
||||
});
|
||||
} else if (typeof data.method === 'string' && data.method.length > 0) {
|
||||
const method = data.method.split('.').reduce(function (memo, prop) {
|
||||
const method = data.method.split('.').reduce((memo, prop) => {
|
||||
if (memo && memo[prop]) {
|
||||
return memo[prop];
|
||||
}
|
||||
@@ -81,9 +81,7 @@ Hooks.register = function (id, data) {
|
||||
|
||||
Hooks.unregister = function (id, hook, method) {
|
||||
var hooks = plugins.loadedHooks[hook] || [];
|
||||
plugins.loadedHooks[hook] = hooks.filter(function (hookData) {
|
||||
return hookData && hookData.id !== id && hookData.method !== method;
|
||||
});
|
||||
plugins.loadedHooks[hook] = hooks.filter(hookData => hookData && hookData.id !== id && hookData.method !== method);
|
||||
};
|
||||
|
||||
Hooks.fire = async function (hook, params) {
|
||||
@@ -116,7 +114,7 @@ async function fireFilterHook(hook, hookList, params) {
|
||||
return params;
|
||||
}
|
||||
|
||||
return await async.reduce(hookList, params, function (params, hookObj, next) {
|
||||
return await async.reduce(hookList, params, (params, hookObj, next) => {
|
||||
if (typeof hookObj.method !== 'function') {
|
||||
if (global.env === 'development') {
|
||||
winston.warn(`[plugins] Expected method for hook '${hook}' in plugin '${hookObj.id}' not found, skipping.`);
|
||||
@@ -155,13 +153,13 @@ async function fireStaticHook(hook, hookList, params) {
|
||||
}
|
||||
// don't bubble errors from these hooks, so bad plugins don't stop startup
|
||||
const noErrorHooks = ['static:app.load', 'static:assets.prepare', 'static:app.preload'];
|
||||
await async.each(hookList, function (hookObj, next) {
|
||||
await async.each(hookList, (hookObj, next) => {
|
||||
if (typeof hookObj.method !== 'function') {
|
||||
return next();
|
||||
}
|
||||
|
||||
let timedOut = false;
|
||||
const timeoutId = setTimeout(function () {
|
||||
const timeoutId = setTimeout(() => {
|
||||
winston.warn(`[plugins] Callback timed out, hook '${hook}' in plugin '${hookObj.id}'`);
|
||||
timedOut = true;
|
||||
next();
|
||||
|
||||
@@ -147,7 +147,7 @@ Plugins.reload = async function () {
|
||||
meta.configs.registerHooks();
|
||||
|
||||
// Lower priority runs earlier
|
||||
Object.keys(Plugins.loadedHooks).forEach(function (hook) {
|
||||
Object.keys(Plugins.loadedHooks).forEach((hook) => {
|
||||
Plugins.loadedHooks[hook].sort((a, b) => a.priority - b.priority);
|
||||
});
|
||||
|
||||
@@ -200,7 +200,7 @@ Plugins.normalise = async function (apiReturn) {
|
||||
const pluginMap = {};
|
||||
const dependencies = require(paths.currentPackage).dependencies;
|
||||
apiReturn = Array.isArray(apiReturn) ? apiReturn : [];
|
||||
apiReturn.forEach(function (packageData) {
|
||||
apiReturn.forEach((packageData) => {
|
||||
packageData.id = packageData.name;
|
||||
packageData.installed = false;
|
||||
packageData.active = false;
|
||||
@@ -211,7 +211,7 @@ Plugins.normalise = async function (apiReturn) {
|
||||
let installedPlugins = await Plugins.showInstalled();
|
||||
installedPlugins = installedPlugins.filter(plugin => plugin && !plugin.system);
|
||||
|
||||
installedPlugins.forEach(function (plugin) {
|
||||
installedPlugins.forEach((plugin) => {
|
||||
// If it errored out because a package.json or plugin.json couldn't be read, no need to do this stuff
|
||||
if (plugin.error) {
|
||||
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
|
||||
@@ -250,7 +250,7 @@ Plugins.normalise = async function (apiReturn) {
|
||||
}
|
||||
}
|
||||
|
||||
pluginArray.sort(function (a, b) {
|
||||
pluginArray.sort((a, b) => {
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
} else if (a.name < b.name) {
|
||||
@@ -290,12 +290,12 @@ Plugins.showInstalled = async function () {
|
||||
|
||||
async function findNodeBBModules(dirs) {
|
||||
const pluginPaths = [];
|
||||
await async.each(dirs, function (dirname, next) {
|
||||
await async.each(dirs, (dirname, next) => {
|
||||
var dirPath = path.join(Plugins.nodeModulesPath, dirname);
|
||||
|
||||
async.waterfall([
|
||||
function (cb) {
|
||||
fs.stat(dirPath, function (err, stats) {
|
||||
fs.stat(dirPath, (err, stats) => {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
return cb(err);
|
||||
}
|
||||
@@ -315,13 +315,13 @@ async function findNodeBBModules(dirs) {
|
||||
});
|
||||
},
|
||||
function (subdirs, cb) {
|
||||
async.each(subdirs, function (subdir, next) {
|
||||
async.each(subdirs, (subdir, next) => {
|
||||
if (!pluginNamePattern.test(subdir)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var subdirPath = path.join(dirPath, subdir);
|
||||
fs.stat(subdirPath, function (err, stats) {
|
||||
fs.stat(subdirPath, (err, stats) => {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -43,13 +43,13 @@ if (process.platform === 'win32') {
|
||||
|
||||
module.exports = function (Plugins) {
|
||||
if (nconf.get('isPrimary')) {
|
||||
pubsub.on('plugins:toggleInstall', function (data) {
|
||||
pubsub.on('plugins:toggleInstall', (data) => {
|
||||
if (data.hostname !== os.hostname()) {
|
||||
toggleInstall(data.id, data.version);
|
||||
}
|
||||
});
|
||||
|
||||
pubsub.on('plugins:upgrade', function (data) {
|
||||
pubsub.on('plugins:upgrade', (data) => {
|
||||
if (data.hostname !== os.hostname()) {
|
||||
upgrade(data.id, data.version);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ module.exports = function (Plugins) {
|
||||
packageManagerCommands[packageManager][command],
|
||||
pkgName + (command === 'install' ? `@${version}` : ''),
|
||||
'--save',
|
||||
], function (err, stdout) {
|
||||
], (err, stdout) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ module.exports = function (Plugins) {
|
||||
|
||||
var methods = {};
|
||||
if (Array.isArray(fields)) {
|
||||
fields.forEach(function (field) {
|
||||
fields.forEach((field) => {
|
||||
methods[field] = handlers[field];
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -12,9 +12,9 @@ const meta = require('../meta');
|
||||
|
||||
module.exports = function (Plugins) {
|
||||
Plugins.startJobs = function () {
|
||||
new cronJob('0 0 0 * * *', function () {
|
||||
new cronJob('0 0 0 * * *', (() => {
|
||||
Plugins.submitUsageData();
|
||||
}, null, true);
|
||||
}), null, true);
|
||||
};
|
||||
|
||||
Plugins.submitUsageData = function () {
|
||||
@@ -31,7 +31,7 @@ module.exports = function (Plugins) {
|
||||
plugins: Plugins.loadedPlugins,
|
||||
},
|
||||
timeout: 5000,
|
||||
}, function (err, res, body) {
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
return winston.error(err.stack);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user