From 5c5a1fb79906f18560012263239e7bd611ee8d2b Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sat, 13 Feb 2021 16:49:49 +0100 Subject: [PATCH] Add eslint-plugin-spellcheck (#139) --- .eslintrc.js | 26 +++++++++++++++++++- .gitignore | 1 + .vscode/settings.json | 20 ++++++++++++++++ CHANGELOG.md | 4 ++++ examples/multiFunctionExample.js | 6 ++--- examples/multifunctionWorker.js | 4 ++-- package-lock.json | 40 ++++++++++++++++++++++++++++--- package.json | 1 + src/pools/abstract-pool.ts | 19 +++++++++++---- src/pools/cluster/fixed.ts | 6 ++--- src/pools/thread/fixed.ts | 6 ++--- tests/pools/cluster/fixed.test.js | 10 ++++---- tests/pools/thread/fixed.test.js | 10 ++++---- 13 files changed, 124 insertions(+), 29 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.eslintrc.js b/.eslintrc.js index 738e7df9..6c8063c8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,7 +9,13 @@ module.exports = { ecmaVersion: 2020, sourceType: 'module' }, - plugins: ['@typescript-eslint', 'promise', 'prettierx', 'jsdoc'], + plugins: [ + '@typescript-eslint', + 'promise', + 'prettierx', + 'jsdoc', + 'spellcheck' + ], extends: [ 'standard', 'eslint:recommended', @@ -38,6 +44,24 @@ module.exports = { ignoreMemberSort: true, ignoreDeclarationSort: true } + ], + + 'spellcheck/spell-checker': [ + 'warn', + { + skipWords: [ + 'poolifier', + 'pioardi', + 'christopher', + 'ecma', + 'jsdoc', + 'readonly', + 'serializable', + 'unregister', + 'workerpool' + ], + skipIfMatch: ['^@.*', '^plugin:.*'] + } ] }, overrides: [ diff --git a/.gitignore b/.gitignore index 9b6244b7..2e2848ad 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ jspm_packages .vscode/* !.vscode/extensions.json !.vscode/launch.json +!.vscode/settings.json !.vscode/tasks.json # Mac diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..cf389d79 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "cSpell.words": [ + "Alessandro", + "Ardizio", + "Benoit", + "Dependabot", + "Gitter", + "Shinigami", + "lcov", + "loglevel", + "markdownlint", + "piment", + "pioardi", + "poolifier", + "prettierx", + "serializable", + "standardx", + "workerpool" + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a7d9427..ec50e05d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ const { DynamicThreadPool } = require('poolifier') For cluster and thread pools, you can now only send and receive serializable `JSON` data. _This is not a limitation by poolifier but NodeJS._ +#### Public properties renaming + +- Thread Pool's `numWorkers` is now `numberOfWorkers` + #### Internal (protected) methods renaming Those methods are not intended to be used from final users diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 0c4b749e..93d4e78b 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,15 +1,15 @@ const { FixedThreadPool } = require('poolifier') -const pool = new FixedThreadPool(15, './multifunctionWorker.js', { +const pool = new FixedThreadPool(15, './multiFunctionWorker.js', { errorHandler: e => console.error(e), onlineHandler: () => console.log('worker is online') }) pool - .execute({ fname: 'fn0', input: 'hello' }) + .execute({ functionName: 'fn0', input: 'hello' }) .then(res => console.log(res)) .catch(err => console.error(err)) pool - .execute({ fname: 'fn1', input: 'multifunction' }) + .execute({ functionName: 'fn1', input: 'multiple functions' }) .then(res => console.log(res)) .catch(err => console.error(err)) diff --git a/examples/multifunctionWorker.js b/examples/multifunctionWorker.js index 8a1809ac..61369cfa 100644 --- a/examples/multifunctionWorker.js +++ b/examples/multifunctionWorker.js @@ -2,10 +2,10 @@ const { ThreadWorker } = require('poolifier') function yourFunction (data) { - if (data.fname === 'fn0') { + if (data.functionName === 'fn0') { console.log('Executing function 0') return { data: '0 your input was' + data.input } - } else if (data.fname === 'fn1') { + } else if (data.functionName === 'fn1') { console.log('Executing function 1') return { data: '1 your input was' + data.input } } diff --git a/package-lock.json b/package-lock.json index 17506031..e376fccb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -466,9 +466,9 @@ } }, "@istanbuljs/schema": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz", - "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", "dev": true }, "@jest/types": { @@ -1671,6 +1671,34 @@ "integrity": "sha512-bY2sGqyptzFBDLh/GMbAxfdJC+b0f23ME63FOE4+Jao0oZ3E1LEwFtWJX/1pGMJLiTtrSSern2CRM/g+dfc0eQ==", "dev": true }, + "eslint-plugin-spellcheck": { + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/eslint-plugin-spellcheck/-/eslint-plugin-spellcheck-0.0.17.tgz", + "integrity": "sha512-SjEPsqHgAODWgCusCXxzYqTkJHe8krun7UjekzhWkFlGM3ZTPto66ED+kQHBrOB3Mrqkx3oD0qf0sDmxyeCRCA==", + "dev": true, + "requires": { + "globals": "^13.0.0", + "hunspell-spellchecker": "^1.0.2", + "lodash": "^4.17.15" + }, + "dependencies": { + "globals": { + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.5.0.tgz", + "integrity": "sha512-TMJe2Iu/qCIEFnG7IQ62C9N/iKdgX5wSvmGOVuk75+UAGDW+Yv/hH5+Ky6d/8UMqo4WCzhFCy+pHsvv09zhBoQ==", + "dev": true, + "requires": { + "type-fest": "^0.20.2" + } + }, + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + } + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -2249,6 +2277,12 @@ "integrity": "sha512-uE/TxKuyNIcx44cIWnjr/rfIATDH7ZaOMmstu0CwhFG1Dunhlp4OC6/NMbhiwoq5BpW0ubi303qnEk/PZj614w==", "dev": true }, + "hunspell-spellchecker": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/hunspell-spellchecker/-/hunspell-spellchecker-1.0.2.tgz", + "integrity": "sha1-oQsL0voAplq2Kkxrc0zkltMYkQ4=", + "dev": true + }, "ignore": { "version": "5.1.8", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", diff --git a/package.json b/package.json index 4fcf8e7f..529bcf0c 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettierx": "^0.17.1", "eslint-plugin-promise": "^4.3.1", + "eslint-plugin-spellcheck": "0.0.17", "expect": "^26.6.2", "mocha": "^8.3.0", "mocha-lcov-reporter": "^1.3.0", diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 6b29669f..b3198af3 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -103,12 +103,12 @@ export abstract class AbstractPool< /** * Constructs a new poolifier pool. * - * @param numWorkers Number of workers that this pool should manage. + * @param numberOfWorkers Number of workers that this pool should manage. * @param filePath Path to the worker-file. * @param opts Options for the pool. Default: `{ maxTasks: 1000 }` */ public constructor ( - public readonly numWorkers: number, + public readonly numberOfWorkers: number, public readonly filePath: string, public readonly opts: PoolOptions = { maxTasks: 1000 } ) { @@ -122,7 +122,7 @@ export abstract class AbstractPool< this.setupHook() - for (let i = 1; i <= this.numWorkers; i++) { + for (let i = 1; i <= this.numberOfWorkers; i++) { this.internalNewWorker() } @@ -130,7 +130,18 @@ export abstract class AbstractPool< } /** - * Setup hook that can be overridden by a Poolifer pool implementation + * Number of workers that this pool should manage. + * + * @returns Number of workers that this pool manages. + * @deprecated Only here for backward compatibility. + */ + // eslint-disable-next-line spellcheck/spell-checker + public get numWorkers (): number { + return this.numberOfWorkers + } + + /** + * Setup hook that can be overridden by a Poolifier pool implementation * to run code before workers are created in the abstract constructor. */ protected setupHook (): void { diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index f17deed7..601ee532 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -36,16 +36,16 @@ export class FixedClusterPool< /** * Constructs a new poolifier fixed cluster pool. * - * @param numWorkers Number of workers for this pool. + * @param numberOfWorkers Number of workers for this pool. * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. * @param opts Options for this fixed cluster pool. Default: `{ maxTasks: 1000 }` */ public constructor ( - numWorkers: number, + numberOfWorkers: number, filePath: string, public readonly opts: ClusterPoolOptions = { maxTasks: 1000 } ) { - super(numWorkers, filePath, opts) + super(numberOfWorkers, filePath, opts) } protected setupHook (): void { diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 7ef5f84a..ee3d63c1 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -28,16 +28,16 @@ export class FixedThreadPool< /** * Constructs a new poolifier fixed thread pool. * - * @param numThreads Number of threads for this pool. + * @param numberOfThreads Number of threads for this pool. * @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. * @param opts Options for this fixed thread pool. Default: `{ maxTasks: 1000 }` */ public constructor ( - numThreads: number, + numberOfThreads: number, filePath: string, opts: PoolOptions = { maxTasks: 1000 } ) { - super(numThreads, filePath, opts) + super(numberOfThreads, filePath, opts) } protected isMain (): boolean { diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 1a150dac..aae9127f 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -1,9 +1,9 @@ const expect = require('expect') const { FixedClusterPool } = require('../../../lib/index') -const numWorkers = 10 +const numberOfWorkers = 10 const maxTasks = 500 const pool = new FixedClusterPool( - numWorkers, + numberOfWorkers, './tests/worker/cluster/testWorker.js', { errorHandler: e => console.error(e), @@ -42,10 +42,10 @@ const asyncPool = new FixedClusterPool( describe('Fixed cluster pool test suite ', () => { it('Choose worker round robin test', async () => { const results = new Set() - for (let i = 0; i < numWorkers; i++) { + for (let i = 0; i < numberOfWorkers; i++) { results.add(pool.chooseWorker().id) } - expect(results.size).toBe(numWorkers) + expect(results.size).toBe(numberOfWorkers) }) it('Verify that the function is executed in a worker cluster', async () => { @@ -122,7 +122,7 @@ describe('Fixed cluster pool test suite ', () => { }) pool.destroy() await new Promise(resolve => setTimeout(resolve, 200)) - expect(closedWorkers).toBe(numWorkers) + expect(closedWorkers).toBe(numberOfWorkers) }) it('Validations test', () => { diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index ec6a066b..a5ec3f0a 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -1,9 +1,9 @@ const expect = require('expect') const { FixedThreadPool } = require('../../../lib/index') -const numThreads = 10 +const numberOfThreads = 10 const maxTasks = 400 const pool = new FixedThreadPool( - numThreads, + numberOfThreads, './tests/worker/thread/testWorker.js', { errorHandler: e => console.error(e), @@ -29,10 +29,10 @@ const asyncPool = new FixedThreadPool( describe('Fixed thread pool test suite ', () => { it('Choose worker round robin test', async () => { const results = new Set() - for (let i = 0; i < numThreads; i++) { + for (let i = 0; i < numberOfThreads; i++) { results.add(pool.chooseWorker().threadId) } - expect(results.size).toBe(numThreads) + expect(results.size).toBe(numberOfThreads) }) it('Verify that the function is executed in a worker thread', async () => { @@ -95,7 +95,7 @@ describe('Fixed thread pool test suite ', () => { }) }) await pool.destroy() - expect(closedThreads).toBe(numThreads) + expect(closedThreads).toBe(numberOfThreads) }) it('Validations test', () => { -- 2.34.1