From 50eceb07c3713782d1d6bbe49d3fe47318e45c93 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sat, 13 Feb 2021 14:06:26 +0100 Subject: [PATCH] Add eslint-plugin-jsdoc (#142) --- .eslintrc.js | 11 +++++++++- package-lock.json | 39 ++++++++++++++++++++++++++++++++--- package.json | 1 + src/pools/abstract-pool.ts | 4 ++++ src/pools/cluster/dynamic.ts | 2 ++ src/pools/thread/dynamic.ts | 2 ++ src/worker/abstract-worker.ts | 1 + 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 04c5b05b..738e7df9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,7 +9,7 @@ module.exports = { ecmaVersion: 2020, sourceType: 'module' }, - plugins: ['@typescript-eslint', 'promise', 'prettierx'], + plugins: ['@typescript-eslint', 'promise', 'prettierx', 'jsdoc'], extends: [ 'standard', 'eslint:recommended', @@ -41,6 +41,15 @@ module.exports = { ] }, overrides: [ + { + files: ['src/**/*.ts'], + extends: 'plugin:jsdoc/recommended', + rules: { + 'jsdoc/no-types': 'error', + 'jsdoc/require-param-type': 'off', + 'jsdoc/require-returns-type': 'off' + } + }, { files: ['*.js'], extends: 'plugin:node/recommended', diff --git a/package-lock.json b/package-lock.json index 30a6abd4..8d016514 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2083,6 +2083,12 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, + "comment-parser": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.1.2.tgz", + "integrity": "sha512-AOdq0i8ghZudnYv8RUnHrhTgafUGs61Rdz9jemU5x2lnZwAWyOq7vySo626K59e1fVKH1xSRorJwPVRLSWOoAQ==", + "dev": true + }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -2382,9 +2388,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.663", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.663.tgz", - "integrity": "sha512-xkVkzHj6k3oRRGlmdgUCCLSLhtFYHDCTH7SeK+LJdJjnsLcrdbpr8EYmfMQhez3V/KPO5UScSpzQ0feYX6Qoyw==", + "version": "1.3.664", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.664.tgz", + "integrity": "sha512-yb8LrTQXQnh9yhnaIHLk6CYugF/An50T20+X0h++hjjhVfgSp1DGoMSYycF8/aD5eiqS4QwaNhiduFvK8rifRg==", "dev": true }, "emoji-regex": { @@ -2657,6 +2663,21 @@ } } }, + "eslint-plugin-jsdoc": { + "version": "31.6.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-31.6.1.tgz", + "integrity": "sha512-5hCV3u+1VSEUMyfdTl+dpWsioD7tqQr2ILQw+KbXrF42AVxCLO8gnNLR6zDCDjqGGpt79V1sgY0RRchCWuCigg==", + "dev": true, + "requires": { + "comment-parser": "1.1.2", + "debug": "^4.3.1", + "jsdoctypeparser": "^9.0.0", + "lodash": "^4.17.20", + "regextras": "^0.7.1", + "semver": "^7.3.4", + "spdx-expression-parse": "^3.0.1" + } + }, "eslint-plugin-node": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", @@ -3762,6 +3783,12 @@ "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "dev": true }, + "jsdoctypeparser": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-9.0.0.tgz", + "integrity": "sha512-jrTA2jJIL6/DAEILBEh2/w9QxCuwmvNXIry39Ay/HVfhE3o2yVV0U44blYkqdHA/OKloJEqvJy0xU+GSdE2SIw==", + "dev": true + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -5091,6 +5118,12 @@ "unicode-match-property-value-ecmascript": "^1.2.0" } }, + "regextras": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/regextras/-/regextras-0.7.1.tgz", + "integrity": "sha512-9YXf6xtW+qzQ+hcMQXx95MOvfqXFgsKDZodX3qZB0x2n5Z94ioetIITsBtvJbiOyxa/6s9AtyweBLCdPmPko/w==", + "dev": true + }, "regjsgen": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.2.tgz", diff --git a/package.json b/package.json index 0a905111..a69e76a7 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "eslint": "^7.20.0", "eslint-config-standard": "^16.0.2", "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsdoc": "^31.6.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettierx": "^0.17.1", "eslint-plugin-promise": "^4.3.1", diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 0763f04f..6b29669f 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -230,6 +230,8 @@ export abstract class AbstractPool< * Choose a worker for the next task. * * The default implementation uses a round robin algorithm to distribute the load. + * + * @returns Worker. */ protected chooseWorker (): Worker { this.nextWorker = @@ -253,6 +255,8 @@ export abstract class AbstractPool< /** * Creates a new worker for this pool and sets it up completely. + * + * @returns New, completely set up worker. */ protected internalNewWorker (): Worker { const worker: Worker = this.newWorker() diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 99fa828d..3d523890 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -42,6 +42,8 @@ export class DynamicClusterPool< * It will first check for and return an idle worker. * If all workers are busy, then it will try to create a new one up to the `max` worker count. * If the max worker count is reached, the emitter will emit a `FullPool` event and it will fall back to using a round robin algorithm to distribute the load. + * + * @returns Cluster worker. */ protected chooseWorker (): Worker { let worker: Worker | undefined diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 77f0a2d5..c8e93850 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -42,6 +42,8 @@ export class DynamicThreadPool< * It will first check for and return an idle thread. * If all threads are busy, then it will try to create a new one up to the `max` thread count. * If the max thread count is reached, the emitter will emit a `FullPool` event and it will fall back to using a round robin algorithm to distribute the load. + * + * @returns Thread worker. */ protected chooseWorker (): ThreadWorkerWithMessageChannel { let worker: ThreadWorkerWithMessageChannel | undefined diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index fd163547..779088c5 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -86,6 +86,7 @@ export abstract class AbstractWorker< * Handle an error and convert it to a string so it can be sent back to the main worker. * * @param e The error raised by the worker. + * @returns Message of the error. */ protected handleError (e: Error | string): string { return (e as unknown) as string -- 2.34.1