mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
lint: Fix more ESLint errors
This commit is contained in:
parent
1bc52f4913
commit
47f0a7dacf
3 changed files with 30 additions and 35 deletions
|
@ -1,6 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('underscore');
|
|
||||||
const pluginDefs = require('./plugin_defs');
|
const pluginDefs = require('./plugin_defs');
|
||||||
|
|
||||||
// Maps the name of a server-side hook to a string explaining the deprecation
|
// Maps the name of a server-side hook to a string explaining the deprecation
|
||||||
|
@ -24,9 +23,12 @@ const checkDeprecation = (hook) => {
|
||||||
deprecationWarned[hook.hook_fn_name] = true;
|
deprecationWarned[hook.hook_fn_name] = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Flattens the array one level.
|
||||||
|
const flatten1 = (array) => array.reduce((a, b) => a.concat(b), []);
|
||||||
|
|
||||||
exports.bubbleExceptions = true;
|
exports.bubbleExceptions = true;
|
||||||
|
|
||||||
const hookCallWrapper = (hook, hook_name, args, cb) => {
|
const hookCallWrapper = (hook, hookName, args, cb) => {
|
||||||
if (cb === undefined) cb = (x) => x;
|
if (cb === undefined) cb = (x) => x;
|
||||||
|
|
||||||
checkDeprecation(hook);
|
checkDeprecation(hook);
|
||||||
|
@ -36,7 +38,7 @@ const hookCallWrapper = (hook, hook_name, args, cb) => {
|
||||||
if (x === undefined) return [];
|
if (x === undefined) return [];
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
const normalizedhook = () => normalize(hook.hook_fn(hook_name, args, (x) => cb(normalize(x))));
|
const normalizedhook = () => normalize(hook.hook_fn(hookName, args, (x) => cb(normalize(x))));
|
||||||
|
|
||||||
if (exports.bubbleExceptions) {
|
if (exports.bubbleExceptions) {
|
||||||
return normalizedhook();
|
return normalizedhook();
|
||||||
|
@ -44,7 +46,7 @@ const hookCallWrapper = (hook, hook_name, args, cb) => {
|
||||||
try {
|
try {
|
||||||
return normalizedhook();
|
return normalizedhook();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error([hook_name, hook.part.full_name, ex.stack || ex]);
|
console.error([hookName, hook.part.full_name, ex.stack || ex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -204,12 +206,12 @@ const callHookFnSync = (hook, context) => {
|
||||||
exports.callAll = (hookName, context) => {
|
exports.callAll = (hookName, context) => {
|
||||||
if (context == null) context = {};
|
if (context == null) context = {};
|
||||||
const hooks = pluginDefs.hooks[hookName] || [];
|
const hooks = pluginDefs.hooks[hookName] || [];
|
||||||
return _.flatten(hooks.map((hook) => {
|
return flatten1(hooks.map((hook) => {
|
||||||
const ret = callHookFnSync(hook, context);
|
const ret = callHookFnSync(hook, context);
|
||||||
// `undefined` (but not `null`!) is treated the same as [].
|
// `undefined` (but not `null`!) is treated the same as [].
|
||||||
if (ret === undefined) return [];
|
if (ret === undefined) return [];
|
||||||
return ret;
|
return ret;
|
||||||
}), 1);
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls the hook function asynchronously and returns a Promise that either resolves to the hook
|
// Calls the hook function asynchronously and returns a Promise that either resolves to the hook
|
||||||
|
@ -349,26 +351,26 @@ exports.aCallAll = async (hookName, context, cb) => {
|
||||||
let resultsPromise = Promise.all(hooks.map((hook) => callHookFnAsync(hook, context)
|
let resultsPromise = Promise.all(hooks.map((hook) => callHookFnAsync(hook, context)
|
||||||
// `undefined` (but not `null`!) is treated the same as [].
|
// `undefined` (but not `null`!) is treated the same as [].
|
||||||
.then((result) => (result === undefined) ? [] : result)))
|
.then((result) => (result === undefined) ? [] : result)))
|
||||||
.then((results) => _.flatten(results, 1));
|
.then(flatten1);
|
||||||
if (cb != null) resultsPromise = resultsPromise.then((val) => cb(null, val), cb);
|
if (cb != null) resultsPromise = resultsPromise.then((val) => cb(null, val), cb);
|
||||||
return await resultsPromise;
|
return await resultsPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.callFirst = (hook_name, args) => {
|
exports.callFirst = (hookName, args) => {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (pluginDefs.hooks[hook_name] === undefined) return [];
|
if (pluginDefs.hooks[hookName] === undefined) return [];
|
||||||
return exports.syncMapFirst(pluginDefs.hooks[hook_name],
|
return exports.syncMapFirst(pluginDefs.hooks[hookName],
|
||||||
(hook) => hookCallWrapper(hook, hook_name, args));
|
(hook) => hookCallWrapper(hook, hookName, args));
|
||||||
};
|
};
|
||||||
|
|
||||||
const aCallFirst = (hook_name, args, cb, predicate) => {
|
const aCallFirst = (hookName, args, cb, predicate) => {
|
||||||
if (!args) args = {};
|
if (!args) args = {};
|
||||||
if (!cb) cb = () => {};
|
if (!cb) cb = () => {};
|
||||||
if (pluginDefs.hooks[hook_name] === undefined) return cb(null, []);
|
if (pluginDefs.hooks[hookName] === undefined) return cb(null, []);
|
||||||
exports.mapFirst(
|
exports.mapFirst(
|
||||||
pluginDefs.hooks[hook_name],
|
pluginDefs.hooks[hookName],
|
||||||
(hook, cb) => {
|
(hook, cb) => {
|
||||||
hookCallWrapper(hook, hook_name, args, (res) => { cb(null, res); });
|
hookCallWrapper(hook, hookName, args, (res) => { cb(null, res); });
|
||||||
},
|
},
|
||||||
cb,
|
cb,
|
||||||
predicate
|
predicate
|
||||||
|
@ -376,13 +378,13 @@ const aCallFirst = (hook_name, args, cb, predicate) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* return a Promise if cb is not supplied */
|
/* return a Promise if cb is not supplied */
|
||||||
exports.aCallFirst = (hook_name, args, cb, predicate) => {
|
exports.aCallFirst = (hookName, args, cb, predicate) => {
|
||||||
if (cb === undefined) {
|
if (cb === undefined) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
aCallFirst(hook_name, args, (err, res) => err ? reject(err) : resolve(res), predicate);
|
aCallFirst(hookName, args, (err, res) => err ? reject(err) : resolve(res), predicate);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return aCallFirst(hook_name, args, cb, predicate);
|
return aCallFirst(hookName, args, cb, predicate);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
/* global __dirname, __filename, afterEach, beforeEach, describe, it, process, require */
|
'use strict';
|
||||||
|
|
||||||
function m(mod) { return `${__dirname}/../../../src/${mod}`; }
|
|
||||||
|
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
const common = require('../common');
|
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
const hooks = require(m('static/js/pluginfw/hooks'));
|
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
|
||||||
const plugins = require(m('static/js/pluginfw/plugin_defs'));
|
const sinon = require('ep_etherpad-lite/node_modules/sinon');
|
||||||
const sinon = require(m('node_modules/sinon'));
|
|
||||||
|
|
||||||
const logger = common.logger;
|
|
||||||
|
|
||||||
describe(__filename, function () {
|
describe(__filename, function () {
|
||||||
const hookName = 'testHook';
|
const hookName = 'testHook';
|
||||||
|
@ -203,7 +198,7 @@ describe(__filename, function () {
|
||||||
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
|
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
|
||||||
// time, or call the callback and then return a value.)
|
// time, or call the callback and then return a value.)
|
||||||
describe('bad hook function behavior (double settle)', function () {
|
describe('bad hook function behavior (double settle)', function () {
|
||||||
beforeEach(function () {
|
beforeEach(async function () {
|
||||||
sinon.stub(console, 'error');
|
sinon.stub(console, 'error');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -558,7 +553,7 @@ describe(__filename, function () {
|
||||||
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
|
// Test various ways a hook might attempt to settle twice. (Examples: call the callback a second
|
||||||
// time, or call the callback and then return a value.)
|
// time, or call the callback and then return a value.)
|
||||||
describe('bad hook function behavior (double settle)', function () {
|
describe('bad hook function behavior (double settle)', function () {
|
||||||
beforeEach(function () {
|
beforeEach(async function () {
|
||||||
sinon.stub(console, 'error');
|
sinon.stub(console, 'error');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
/* global __dirname, __filename, Buffer, afterEach, before, beforeEach, describe, it, require */
|
'use strict';
|
||||||
|
|
||||||
function m(mod) { return `${__dirname}/../../../src/${mod}`; }
|
|
||||||
|
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const plugins = require(m('static/js/pluginfw/plugin_defs'));
|
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
|
||||||
const settings = require(m('node/utils/Settings'));
|
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
||||||
|
|
||||||
describe(__filename, function () {
|
describe(__filename, function () {
|
||||||
let agent;
|
let agent;
|
||||||
|
@ -402,7 +400,7 @@ describe(__filename, function () {
|
||||||
};
|
};
|
||||||
const handlers = {};
|
const handlers = {};
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(async function () {
|
||||||
failHookNames.forEach((hookName) => {
|
failHookNames.forEach((hookName) => {
|
||||||
const handler = new Handler(hookName);
|
const handler = new Handler(hookName);
|
||||||
handlers[hookName] = handler;
|
handlers[hookName] = handler;
|
||||||
|
|
Loading…
Reference in a new issue