From 504bc84bac31e594c656f9af399ffe169db8a1b3 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Oct 2023 11:33:37 +0100 Subject: [PATCH 1/3] chore(tsconfig): use es2022 lib --- API.md | 17 ++++++++++++++++- tsconfig.json | 2 +- types/index.d.ts | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index e54fb8d..32dd497 100644 --- a/API.md +++ b/API.md @@ -5,6 +5,9 @@ * [UnRTF](#UnRTF) * [new UnRTF([binPath])](#new_UnRTF_new) + * [.unrtfPath](#UnRTF+unrtfPath) : string \| undefined + * [.unrtfVersion](#UnRTF+unrtfVersion) : string \| undefined + * [.unrtfAcceptedOptions](#UnRTF+unrtfAcceptedOptions) : object * [.convert(file, [options])](#UnRTF+convert) ⇒ Promise.<string> @@ -13,8 +16,20 @@ | Param | Type | Description | | --- | --- | --- | -| [binPath] | string | Path of UnRTF binary. | +| [binPath] | string | Path of UnRTF binary. If not provided, the constructor will attempt to find the binary in the PATH environment variable. For `win32`, a binary is bundled with the package and will be used if a local installation is not found. | + + +### unRTF.unrtfPath : string \| undefined +**Kind**: instance property of [UnRTF](#UnRTF) + + +### unRTF.unrtfVersion : string \| undefined +**Kind**: instance property of [UnRTF](#UnRTF) + + +### unRTF.unrtfAcceptedOptions : object +**Kind**: instance property of [UnRTF](#UnRTF) ### unRTF.convert(file, [options]) ⇒ Promise.<string> diff --git a/tsconfig.json b/tsconfig.json index 168db9c..4e1a958 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "checkJs": true, "declaration": true, "emitDeclarationOnly": true, - "lib": ["ES2023"], + "lib": ["ES2022"], "module": "NodeNext", "moduleResolution": "NodeNext", "outDir": "types", diff --git a/types/index.d.ts b/types/index.d.ts index 32f7e21..63422f2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,8 +1,20 @@ export default UnRTF; export class UnRTF { - /** @param {string} [binPath] - Path of UnRTF binary. */ + /** + * @param {string} [binPath] - Path of UnRTF binary. + * If not provided, the constructor will attempt to find the binary + * in the PATH environment variable. + * + * For `win32`, a binary is bundled with the package and will be used + * if a local installation is not found. + */ constructor(binPath?: string); - unrtfPath: string; + /** @type {string|undefined} */ + unrtfPath: string | undefined; + /** @type {string|undefined} */ + unrtfVersion: string | undefined; + /** @type {object} */ + unrtfAcceptedOptions: object; /** * @author Frazer Smith * @description Converts an RTF file to HTML/LaTeX/RTF/TXT. From 879578f29ae840871a0a4acacc642f09fb57269f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Oct 2023 12:09:58 +0100 Subject: [PATCH 2/3] chore(.vscode): add gitlens to recommended extensions --- .vscode/extensions.json | 1 + .vscode/settings.json | 1 + 2 files changed, 2 insertions(+) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index bf78e64..061d897 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,7 @@ // for the documentation about the extensions.json format "recommendations": [ "dbaeumer.vscode-eslint", + "eamodio.gitlens", "esbenp.prettier-vscode", "redhat.vscode-yaml" ] diff --git a/.vscode/settings.json b/.vscode/settings.json index cf7b796..906f3b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "files.eol": "\n", + "gitlens.telemetry.enabled": false, "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, From 5e286336f7afdddcfef3523be78ee5388d3ed1a9 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Oct 2023 12:11:33 +0100 Subject: [PATCH 3/3] build(deps-dev): add eslint-community/eslint-plugin-eslint-comments --- .eslintrc.js | 5 ++++- package.json | 1 + scripts/license-checker.js | 3 --- src/index.js | 4 ++-- src/index.test.js | 8 ++++---- test_resources/utils/bt-power-set.js | 2 -- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f8193f7..0feb469 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,6 +7,7 @@ module.exports = { }, extends: [ "airbnb-base", + "plugin:@eslint-community/eslint-comments/recommended", "plugin:jsdoc/recommended", "plugin:promise/recommended", "plugin:regexp/recommended", @@ -49,10 +50,12 @@ module.exports = { ], root: true, rules: { + "@eslint-community/eslint-comments/disable-enable-pair": "off", + "@eslint-community/eslint-comments/no-unused-disable": "error", + "@eslint-community/eslint-comments/require-description": "error", "import/no-extraneous-dependencies": "error", "jsdoc/check-syntax": "error", "jsdoc/require-hyphen-before-param-description": "error", - "no-console": "off", "no-multiple-empty-lines": ["error", { max: 1 }], "prefer-destructuring": ["error", { object: true, array: false }], "promise/prefer-await-to-callbacks": "warn", diff --git a/package.json b/package.json index 3d88a4b..7f06d26 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "devDependencies": { "@commitlint/cli": "^17.7.1", "@commitlint/config-conventional": "^17.7.0", + "@eslint-community/eslint-plugin-eslint-comments": "^4.1.0", "@types/jest": "^29.5.5", "eslint": "^8.50.0", "eslint-config-airbnb-base": "^15.0.0", diff --git a/scripts/license-checker.js b/scripts/license-checker.js index 08ad25b..f503de6 100644 --- a/scripts/license-checker.js +++ b/scripts/license-checker.js @@ -1,6 +1,3 @@ -/* eslint-disable security/detect-object-injection */ -/* eslint-disable security-node/detect-crlf */ - "use strict"; const { promisify } = require("node:util"); diff --git a/src/index.js b/src/index.js index ab5778a..369d549 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ function parseOptions(acceptedOptions, options, version) { const invalidArgs = []; Object.keys(options).forEach((key) => { if (Object.hasOwn(acceptedOptions, key)) { - // eslint-disable-next-line valid-typeof + // eslint-disable-next-line valid-typeof -- `type` is a string if (typeof options[key] === acceptedOptions[key].type) { // Skip boolean options if false if (acceptedOptions[key].type === "boolean" && !options[key]) { @@ -203,7 +203,7 @@ class UnRTF { */ let buff; try { - // eslint-disable-next-line security/detect-non-literal-fs-filename + // eslint-disable-next-line security/detect-non-literal-fs-filename -- File read is wanted buff = await readFile(normalizeTrim(file)); } catch { throw new Error("File missing"); diff --git a/src/index.test.js b/src/index.test.js index 909b613..3528643 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -1,4 +1,5 @@ -/* eslint-disable global-require, jest/no-conditional-expect */ +/* eslint-disable global-require, security/detect-child-process -- Mocking child_process */ +/* eslint-disable jest/no-conditional-expect -- Depends on the version of the binary */ "use strict"; @@ -63,7 +64,7 @@ describe("Constructor", () => { * @todo Fix this test, mocking of "node:" scheme not supported yet * @see {@link https://github.com/jestjs/jest/pull/14297 | Jest PR #14297} */ - // eslint-disable-next-line jest/no-disabled-tests + // eslint-disable-next-line jest/no-disabled-tests -- Blocked by Jest PR #14297 it.skip("Throws an Error if the binary path is not found", () => { Object.defineProperty(process, "platform", { value: "mockOS", @@ -78,13 +79,12 @@ describe("Constructor", () => { }, })), })); - // eslint-disable-next-line security/detect-child-process require("node:child_process"); const { UnRTF: UnRTFMock } = require("./index"); expect.assertions(1); try { - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars -- This is intentional const unRtf = new UnRTFMock(); } catch (err) { expect(err.message).toBe( diff --git a/test_resources/utils/bt-power-set.js b/test_resources/utils/bt-power-set.js index 73db8e0..8d3fee8 100644 --- a/test_resources/utils/bt-power-set.js +++ b/test_resources/utils/bt-power-set.js @@ -1,5 +1,3 @@ -/* eslint-disable security/detect-object-injection */ - "use strict"; /**