Skip to content

Commit aaa53b7

Browse files
Americaskurayama
authored andcommitted
Update linting rules
1 parent 762cb37 commit aaa53b7

7 files changed

Lines changed: 588 additions & 728 deletions

File tree

.eslintrc.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
extends:
2-
- seegno
3-
4-
env:
5-
jasmine: true
6-
jest: true
2+
- uphold
73

84
rules:
95
no-process-env: 0

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
test:
77
strategy:
88
matrix:
9-
nodeVersion: [10, 12, 14, 16]
9+
nodeVersion: [14, 16, 18]
1010

1111
name: Tests
1212
runs-on: ubuntu-latest

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@
2727
},
2828
"devDependencies": {
2929
"@uphold/github-changelog-generator": "^0.4.1",
30-
"eslint": "^3.12.2",
31-
"eslint-config-seegno": "^8.0.1",
30+
"eslint": "~8.7.0",
31+
"eslint-config-uphold": "^3.0.0",
3232
"jest": "^27.5.1",
33-
"pre-commit": "^1.2.2"
33+
"pre-commit": "^1.2.2",
34+
"prettier": "^2.6.2"
3435
},
3536
"jest": {
3637
"restoreMocks": true,
3738
"testEnvironment": "node"
3839
},
3940
"engines": {
40-
"node": ">=7.6"
41+
"node": ">=14"
4142
},
4243
"pre-commit": {
4344
"run": [

src/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class TimeoutError extends Error {}
1818
*/
1919

2020
class ProcessManager {
21-
2221
/**
2322
* Constructor.
2423
*/
@@ -37,7 +36,12 @@ class ProcessManager {
3736
*/
3837

3938
addHook({ type, handler, name = 'a handler' }) {
40-
this.hooks.push({ handler, name, timeoutError: new TimeoutError(`${name} took too long to complete ${type} hook`), type });
39+
this.hooks.push({
40+
handler,
41+
name,
42+
timeoutError: new TimeoutError(`${name} took too long to complete ${type} hook`),
43+
type
44+
});
4145

4246
log.info(`New handler added for hook ${type}`);
4347
}
@@ -83,10 +87,7 @@ class ProcessManager {
8387
}
8488

8589
const promises = hooks.map(({ handler, timeoutError }) => {
86-
return Promise.race([
87-
utils.reflect(handler, args),
88-
utils.timeout(this.timeout, timeoutError)
89-
]);
90+
return Promise.race([utils.reflect(handler, args), utils.timeout(this.timeout, timeoutError)]);
9091
});
9192

9293
return Promise.all(promises).then(results => {
@@ -142,14 +143,16 @@ class ProcessManager {
142143
}
143144

144145
const id = Symbol();
145-
const chain = utils.reflect(fn, args)
146-
.then(error => {
147-
this.running.splice(this.running.findIndex(chain => chain.id === id), 1);
148-
149-
if (error || exit) {
150-
this.shutdown({ error });
151-
}
152-
});
146+
const chain = utils.reflect(fn, args).then(error => {
147+
this.running.splice(
148+
this.running.findIndex(chain => chain.id === id),
149+
1
150+
);
151+
152+
if (error || exit) {
153+
this.shutdown({ error });
154+
}
155+
});
153156

154157
chain.id = id;
155158

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Creates a deferred promise.
55
*/
66

7-
module.exports.deferred = function() {
7+
module.exports.deferred = function () {
88
const deferred = {};
99

1010
deferred.promise = new Promise((resolve, reject) => {
@@ -19,15 +19,15 @@ module.exports.deferred = function() {
1919
* Creates promise that will resolve after the given time (in ms).
2020
*/
2121

22-
module.exports.timeout = function(ms, returnValue) {
22+
module.exports.timeout = function (ms, returnValue) {
2323
return new Promise(resolve => setTimeout(() => resolve(returnValue), ms));
2424
};
2525

2626
/**
2727
* Wraps a function and makes it return undefined on success or an error if it throws.
2828
*/
2929

30-
module.exports.reflect = async function(thenable, args) {
30+
module.exports.reflect = async function (thenable, args) {
3131
try {
3232
await thenable(...args);
3333
} catch (error) {

test/index.test.js

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ describe('ProcessManager', () => {
1919
describe('constructor()', () => {
2020
test('sets the initial state', () => {
2121
expect(processManager.errors).toEqual([]);
22-
expect(processManager.forceShutdown).toMatchObject({ promise: expect.any(Promise), reject: expect.any(Function), resolve: expect.any(Function) });
22+
expect(processManager.forceShutdown).toMatchObject({
23+
promise: expect.any(Promise),
24+
reject: expect.any(Function),
25+
resolve: expect.any(Function)
26+
});
2327
expect(processManager.hooks).toEqual([]);
2428
expect(processManager.running).toEqual([]);
2529
expect(processManager.terminating).toEqual(false);
@@ -36,7 +40,14 @@ describe('ProcessManager', () => {
3640

3741
processManager.addHook({ handler, type });
3842

39-
expect(processManager.hooks).toMatchObject([{ handler, name: 'a handler', timeoutError: { message: 'a handler took too long to complete disconnect hook' }, type }]);
43+
expect(processManager.hooks).toMatchObject([
44+
{
45+
handler,
46+
name: 'a handler',
47+
timeoutError: { message: 'a handler took too long to complete disconnect hook' },
48+
type
49+
}
50+
]);
4051
});
4152

4253
test('identifies the hook if `name` is provided', () => {
@@ -45,7 +56,9 @@ describe('ProcessManager', () => {
4556

4657
processManager.addHook({ handler, name: 'foobar', type });
4758

48-
expect(processManager.hooks).toMatchObject([{ handler, name: 'foobar', timeoutError: { message: 'foobar took too long to complete disconnect hook' }, type }]);
59+
expect(processManager.hooks).toMatchObject([
60+
{ handler, name: 'foobar', timeoutError: { message: 'foobar took too long to complete disconnect hook' }, type }
61+
]);
4962
});
5063
});
5164

@@ -171,7 +184,12 @@ describe('ProcessManager', () => {
171184
test('adds handler errors to `processManager.errors`', async () => {
172185
const type = 'disconnect';
173186

174-
processManager.addHook({ handler: () => { throw new Error(); }, type });
187+
processManager.addHook({
188+
handler: () => {
189+
throw new Error();
190+
},
191+
type
192+
});
175193
processManager.configure({ timeout: 1 });
176194

177195
expect(processManager.errors).toHaveLength(0);
@@ -309,7 +327,7 @@ describe('ProcessManager', () => {
309327

310328
let i = 0;
311329

312-
await processManager.loop(async () => {
330+
await processManager.loop(() => {
313331
fn();
314332

315333
if (++i === 3) {
@@ -325,7 +343,9 @@ describe('ProcessManager', () => {
325343

326344
jest.spyOn(processManager, 'shutdown');
327345

328-
await processManager.loop(async () => { throw error; });
346+
await processManager.loop(() => {
347+
throw error;
348+
});
329349

330350
expect(processManager.shutdown).toHaveBeenCalledWith({ error });
331351
});
@@ -335,7 +355,7 @@ describe('ProcessManager', () => {
335355
test('calls the given function', async () => {
336356
const fn = jest.fn();
337357

338-
const on = processManager.on(async () => fn());
358+
const on = processManager.on(() => fn());
339359

340360
await on();
341361

@@ -345,7 +365,7 @@ describe('ProcessManager', () => {
345365
test('passes arguments to the given function', async () => {
346366
const fn = jest.fn();
347367

348-
const on = processManager.on(async value => fn(value));
368+
const on = processManager.on(value => fn(value));
349369

350370
await on('foo');
351371

@@ -358,7 +378,7 @@ describe('ProcessManager', () => {
358378

359379
jest.spyOn(processManager, 'shutdown');
360380

361-
const on = processManager.on(async () => fn());
381+
const on = processManager.on(() => fn());
362382

363383
let i = 0;
364384
const onArray = [];
@@ -378,7 +398,7 @@ describe('ProcessManager', () => {
378398
test('calls the given function', async () => {
379399
const fn = jest.fn();
380400

381-
await processManager.once(async () => fn());
401+
await processManager.once(() => fn());
382402

383403
expect(fn).toHaveBeenCalled();
384404
});
@@ -390,7 +410,7 @@ describe('ProcessManager', () => {
390410

391411
processManager.terminating = true;
392412

393-
const result = processManager.run(async () => fn());
413+
const result = processManager.run(() => fn());
394414

395415
expect(fn).not.toHaveBeenCalled();
396416
expect(result).toBeUndefined();
@@ -401,7 +421,7 @@ describe('ProcessManager', () => {
401421
done();
402422
});
403423

404-
const chain = processManager.run(async () => {});
424+
const chain = processManager.run(() => {});
405425

406426
expect(chain.then).toBeDefined();
407427
expect(typeof chain.id).toBe('symbol');
@@ -412,15 +432,17 @@ describe('ProcessManager', () => {
412432

413433
jest.spyOn(processManager, 'shutdown');
414434

415-
await processManager.run(async () => { throw error; });
435+
await processManager.run(() => {
436+
throw error;
437+
});
416438

417439
expect(processManager.shutdown).toHaveBeenCalledWith({ error });
418440
});
419441

420442
test('calls `shutdown` after running the function', async () => {
421443
jest.spyOn(processManager, 'shutdown');
422444

423-
await processManager.run(async () => {});
445+
await processManager.run(() => {});
424446

425447
expect(processManager.shutdown).toHaveBeenCalledWith({ error: undefined });
426448
});
@@ -437,7 +459,7 @@ describe('ProcessManager', () => {
437459
test('it handles `uncaughtException` events', () => {
438460
processManager.configure({ timeout: 1 });
439461

440-
const uncaughtExceptionEventFunction = process.on.mock.calls.find(([event]) => event === 'uncaughtException')[1];
462+
const [, uncaughtExceptionEventFunction] = process.on.mock.calls.find(([event]) => event === 'uncaughtException');
441463

442464
jest.spyOn(processManager, 'shutdown');
443465

@@ -451,7 +473,9 @@ describe('ProcessManager', () => {
451473
test('it handles `unhandledRejection` events', () => {
452474
processManager.configure({ timeout: 1 });
453475

454-
const unhandledRejectionEventFunction = process.on.mock.calls.find(([event]) => event === 'unhandledRejection')[1];
476+
const [, unhandledRejectionEventFunction] = process.on.mock.calls.find(
477+
([event]) => event === 'unhandledRejection'
478+
);
455479

456480
jest.spyOn(processManager, 'shutdown');
457481

@@ -465,7 +489,7 @@ describe('ProcessManager', () => {
465489
test('it handles `SIGINT` events', () => {
466490
processManager.configure({ timeout: 1 });
467491

468-
const sigintEventFunction = process.on.mock.calls.find(([event]) => event === 'SIGINT')[1];
492+
const [, sigintEventFunction] = process.on.mock.calls.find(([event]) => event === 'SIGINT');
469493

470494
jest.spyOn(processManager, 'shutdown');
471495

@@ -481,7 +505,7 @@ describe('ProcessManager', () => {
481505
test('it handles `SIGTERM` events', () => {
482506
processManager.configure({ timeout: 1 });
483507

484-
const sigtermEventFunction = process.on.mock.calls.find(([event]) => event === 'SIGTERM')[1];
508+
const [, sigtermEventFunction] = process.on.mock.calls.find(([event]) => event === 'SIGTERM');
485509

486510
jest.spyOn(processManager, 'shutdown');
487511

0 commit comments

Comments
 (0)