lint: Run eslint --fix on src/

This commit is contained in:
Richard Hansen 2020-11-23 13:24:19 -05:00 committed by John McLear
parent b8d07a42eb
commit 8e5fd19db2
109 changed files with 9061 additions and 10572 deletions

View file

@ -1,5 +1,5 @@
var _ = require("underscore");
var defs = require('./plugin_defs');
const _ = require('underscore');
const defs = require('./plugin_defs');
const disabledHookReasons = {
hooks: {
@ -9,70 +9,70 @@ const disabledHookReasons = {
};
function loadFn(path, hookName) {
var functionName
, parts = path.split(":");
let functionName;
const parts = path.split(':');
// on windows: C:\foo\bar:xyz
if (parts[0].length == 1) {
if (parts.length == 3) {
functionName = parts.pop();
}
path = parts.join(":");
path = parts.join(':');
} else {
path = parts[0];
functionName = parts[1];
}
var fn = require(path);
let fn = require(path);
functionName = functionName ? functionName : hookName;
_.each(functionName.split("."), function (name) {
_.each(functionName.split('.'), (name) => {
fn = fn[name];
});
return fn;
};
}
function extractHooks(parts, hook_set_name, normalizer) {
var hooks = {};
_.each(parts,function (part) {
const hooks = {};
_.each(parts, (part) => {
_.chain(part[hook_set_name] || {})
.keys()
.each(function (hook_name) {
var hook_fn_name = part[hook_set_name][hook_name];
.keys()
.each((hook_name) => {
let hook_fn_name = part[hook_set_name][hook_name];
/* On the server side, you can't just
/* On the server side, you can't just
* require("pluginname/whatever") if the plugin is installed as
* a dependency of another plugin! Bah, pesky little details of
* npm... */
if (normalizer) {
hook_fn_name = normalizer(part, hook_fn_name, hook_name);
}
if (normalizer) {
hook_fn_name = normalizer(part, hook_fn_name, hook_name);
}
const disabledReason = (disabledHookReasons[hook_set_name] || {})[hook_name];
if (disabledReason) {
console.error(`Hook ${hook_set_name}/${hook_name} is disabled. Reason: ${disabledReason}`);
console.error(`The hook function ${hook_fn_name} from plugin ${part.plugin} ` +
const disabledReason = (disabledHookReasons[hook_set_name] || {})[hook_name];
if (disabledReason) {
console.error(`Hook ${hook_set_name}/${hook_name} is disabled. Reason: ${disabledReason}`);
console.error(`The hook function ${hook_fn_name} from plugin ${part.plugin} ` +
'will never be called, which may cause the plugin to fail');
console.error(`Please update the ${part.plugin} plugin to not use the ${hook_name} hook`);
return;
}
console.error(`Please update the ${part.plugin} plugin to not use the ${hook_name} hook`);
return;
}
try {
var hook_fn = loadFn(hook_fn_name, hook_name);
if (!hook_fn) {
throw "Not a function";
}
} catch (exc) {
console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + "': " + exc.toString())
}
if (hook_fn) {
if (hooks[hook_name] == null) hooks[hook_name] = [];
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
}
});
try {
var hook_fn = loadFn(hook_fn_name, hook_name);
if (!hook_fn) {
throw 'Not a function';
}
} catch (exc) {
console.error(`Failed to load '${hook_fn_name}' for '${part.full_name}/${hook_set_name}/${hook_name}': ${exc.toString()}`);
}
if (hook_fn) {
if (hooks[hook_name] == null) hooks[hook_name] = [];
hooks[hook_name].push({hook_name, hook_fn, hook_fn_name, part});
}
});
});
return hooks;
};
}
exports.extractHooks = extractHooks;
@ -88,12 +88,12 @@ exports.extractHooks = extractHooks;
* No plugins: []
* Some plugins: [ 'ep_adminpads', 'ep_add_buttons', 'ep_activepads' ]
*/
exports.clientPluginNames = function() {
var client_plugin_names = _.uniq(
defs.parts
.filter(function(part) { return part.hasOwnProperty('client_hooks'); })
.map(function(part) { return 'plugin-' + part['plugin']; })
exports.clientPluginNames = function () {
const client_plugin_names = _.uniq(
defs.parts
.filter((part) => part.hasOwnProperty('client_hooks'))
.map((part) => `plugin-${part.plugin}`),
);
return client_plugin_names;
}
};