From e90d97b81331454c2c8449e2e5acfa4d950b7fc8 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 15 Sep 2022 20:00:50 +0100 Subject: [PATCH] Use new eslint-plugin-functional instead of tslint-immutable --- .eslintrc.js | 31 +- docs/contribution-guidelines.md | 4 +- package-lock.json | 392 +++++++----------- package.json | 2 +- src/export/packer/image-replacer.ts | 4 +- src/export/packer/next-compiler.ts | 14 +- src/export/packer/numbering-replacer.ts | 2 +- src/export/packer/packer.spec.ts | 22 +- src/export/packer/packer.ts | 2 +- src/file/core-properties/properties.ts | 6 +- .../custom-properties/custom-properties.ts | 5 +- src/file/document/body/body.ts | 2 + .../section-properties/properties/columns.ts | 2 +- src/file/drawing/anchor/anchor.spec.ts | 5 +- src/file/drawing/drawing.spec.ts | 5 +- src/file/file.ts | 10 +- src/file/footer-wrapper.spec.ts | 2 +- src/file/footnotes/footnote/footnote.ts | 2 +- src/file/footnotes/footnotes.ts | 2 +- src/file/header-wrapper.spec.ts | 2 +- src/file/header.ts | 10 +- src/file/media/media.ts | 4 +- src/file/numbering/abstract-numbering.ts | 2 +- src/file/numbering/level.spec.ts | 2 +- src/file/numbering/level.ts | 2 +- src/file/numbering/numbering.ts | 34 +- src/file/paragraph/links/bookmark.ts | 4 +- src/file/paragraph/links/hyperlink.ts | 6 +- .../math/brackets/math-angled-brackets.ts | 2 +- .../math/brackets/math-curly-brackets.ts | 2 +- .../math/brackets/math-round-brackets.ts | 2 +- .../math/brackets/math-square-brackets.ts | 2 +- .../math/fraction/math-denominator.ts | 2 +- .../paragraph/math/fraction/math-fraction.ts | 4 +- .../paragraph/math/fraction/math-numerator.ts | 2 +- .../math/function/math-function-name.ts | 2 +- .../paragraph/math/function/math-function.ts | 4 +- src/file/paragraph/math/math.ts | 2 +- src/file/paragraph/math/n-ary/math-base.ts | 2 +- .../paragraph/math/n-ary/math-sub-script.ts | 2 +- src/file/paragraph/math/n-ary/math-sum.ts | 6 +- .../paragraph/math/n-ary/math-super-script.ts | 2 +- .../paragraph/math/radical/math-degree.ts | 2 +- .../paragraph/math/radical/math-radical.ts | 4 +- .../math-pre-sub-super-script-function.ts | 6 +- .../sub-script/math-sub-script-function.ts | 4 +- .../math-sub-super-script-function.ts | 6 +- .../math-super-script-function.ts | 4 +- src/file/paragraph/paragraph.ts | 2 +- src/file/paragraph/properties.spec.ts | 4 +- src/file/paragraph/properties.ts | 3 +- src/file/paragraph/run/comment-run.ts | 2 +- src/file/paragraph/run/image-run.spec.ts | 10 +- src/file/paragraph/run/image-run.ts | 1 + src/file/paragraph/run/run.ts | 2 +- .../styles/external-styles-factory.spec.ts | 6 +- src/file/styles/external-styles-factory.ts | 1 + src/file/styles/sample/default-style.ts | 7 +- src/file/styles/styles.ts | 6 +- .../table-of-contents-properties.ts | 2 +- .../table-of-contents.spec.ts | 4 +- src/file/table/grid.ts | 2 +- src/file/table/table-cell/table-cell.ts | 2 +- src/file/table/table-row/table-row.ts | 4 +- src/file/table/table.ts | 5 +- src/file/xml-components/default-attributes.ts | 7 +- .../xml-components/imported-xml-component.ts | 3 +- src/file/xml-components/xml-component.ts | 4 +- src/tests/utility.ts | 2 +- src/util/values.ts | 36 +- 70 files changed, 321 insertions(+), 436 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f5fd89265a..a4cea40931 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,7 +29,7 @@ module.exports = { "eslint-plugin-jsdoc", "eslint-plugin-prefer-arrow", "@typescript-eslint", - "@typescript-eslint/tslint", + "functional", ], root: true, rules: { @@ -162,6 +162,7 @@ module.exports = { "@typescript-eslint/unified-signatures": "error", "arrow-body-style": "error", complexity: "off", + "consistent-return": "error", "constructor-super": "error", curly: "error", "dot-notation": "off", @@ -232,30 +233,18 @@ module.exports = { "unicorn/prefer-ternary": "error", "use-isnan": "error", "valid-typeof": "off", - "@typescript-eslint/tslint/config": [ + "@typescript-eslint/explicit-function-return-type": "off", + "functional/immutable-data": [ "error", { - rules: { - "no-delete": true, - "no-method-signature": true, - "no-mixed-interface": true, - "readonly-keyword": true, - "return-undefined": true, - whitespace: [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type", - "check-typecast", - "check-type-operator", - "check-rest-spread", - ], - }, + assumeTypes: true, + ignoreImmediateMutation: true, + ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"], }, ], - "@typescript-eslint/explicit-function-return-type": "off", + "functional/no-method-signature": "error", + "functional/no-mixed-type": "error", + "functional/prefer-readonly-type": "error", }, overrides: [ { diff --git a/docs/contribution-guidelines.md b/docs/contribution-guidelines.md index 1923a47341..dede758ecf 100644 --- a/docs/contribution-guidelines.md +++ b/docs/contribution-guidelines.md @@ -8,11 +8,11 @@ - Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin. -- Follow the `TSLint` rules +- Follow the `ESLint` rules ## Always think about the user -Put yourself in their position, and imagine how they would feel about your feature you wrote. +Put yourself in their position, and imagine how they would feel about the feature you wrote. 1. Is it easy to use? 2. Has it been documented well? diff --git a/package-lock.json b/package-lock.json index 3d65052419..9f68c5413f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,13 +26,13 @@ "@types/unzipper": "^0.10.4", "@types/webpack": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.36.1", - "@typescript-eslint/eslint-plugin-tslint": "^5.36.1", "@typescript-eslint/parser": "^5.36.1", "buffer": "^6.0.3", "chai": "^3.5.0", "cspell": "^6.2.2", "docsify-cli": "^4.3.0", "eslint": "^8.23.0", + "eslint-plugin-functional": "^4.3.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsdoc": "^39.3.6", "eslint-plugin-no-null": "^1.0.2", @@ -1507,24 +1507,6 @@ } } }, - "node_modules/@typescript-eslint/eslint-plugin-tslint": { - "version": "5.36.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-5.36.1.tgz", - "integrity": "sha512-cOpdXK60QxSxMMr71Rn0AMLaEK2K6zyqK/Dfb9GxruJ+sHYrPsJFW2cy+XkeY1fL6As4Q8yO13Gkjget45I5aw==", - "dev": true, - "dependencies": { - "@typescript-eslint/utils": "5.36.1", - "lodash": "^4.17.21" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0", - "tslint": "^5.0.0 || ^6.0.0", - "typescript": "*" - } - }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1575,21 +1557,6 @@ "node": ">=10" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -1713,21 +1680,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/@typescript-eslint/type-utils/node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/@typescript-eslint/types": { "version": "5.36.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.36.1.tgz", @@ -1818,21 +1770,6 @@ "node": ">=10" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -2614,16 +2551,6 @@ "node": ">=0.2.0" } }, - "node_modules/builtin-modules": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true, - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/cacheable-request": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", @@ -3003,13 +2930,6 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", - "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", - "dev": true, - "peer": true - }, "node_modules/comment-json": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-4.2.3.tgz", @@ -3641,6 +3561,15 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/deepmerge-ts": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/deepmerge-ts/-/deepmerge-ts-4.2.1.tgz", + "integrity": "sha512-xzJLiUo4z1dD2nggSfaMvHo5qWLoy/JVa9rKuktC6FrQQEBI8Qnj7KwuCYZhqBoGOOpGqs6+3MR2ZhSMcTr4BA==", + "dev": true, + "engines": { + "node": ">=12.4.0" + } + }, "node_modules/default-require-extensions": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.0.tgz", @@ -4307,6 +4236,79 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "node_modules/eslint-plugin-functional": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-functional/-/eslint-plugin-functional-4.3.1.tgz", + "integrity": "sha512-Mlm0A4gtQya2jLg6BvL8FoyHtedMj3gGJNMe9SWIyRhFmIibGFjOldzZ86LxOQYnwLMV9AD5aeLBRfxPFTkkaQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/utils": "^5.10.2", + "deepmerge-ts": "^4.0.3", + "escape-string-regexp": "^4.0.0", + "semver": "^7.3.7" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^8.0.0", + "tsutils": "^3.0.0", + "typescript": "^3.4.1 || ^4.0.0" + }, + "peerDependenciesMeta": { + "tsutils": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, + "node_modules/eslint-plugin-functional/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-plugin-functional/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/eslint-plugin-functional/node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/eslint-plugin-functional/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/eslint-plugin-import": { "version": "2.26.0", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", @@ -10339,79 +10341,19 @@ "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, - "node_modules/tslint": { - "version": "5.20.1", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.20.1.tgz", - "integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==", - "dev": true, - "peer": true, - "dependencies": { - "@babel/code-frame": "^7.0.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^4.0.1", - "glob": "^7.1.1", - "js-yaml": "^3.13.1", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", - "resolve": "^1.3.2", - "semver": "^5.3.0", - "tslib": "^1.8.0", - "tsutils": "^2.29.0" - }, - "bin": { - "tslint": "bin/tslint" - }, - "engines": { - "node": ">=4.8.0" - }, - "peerDependencies": { - "typescript": ">=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev" - } - }, - "node_modules/tslint/node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "peer": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/tslint/node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "peer": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", "dev": true, - "peer": true, "dependencies": { "tslib": "^1.8.1" }, + "engines": { + "node": ">= 6" + }, "peerDependencies": { - "typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >= 3.0.0-dev || >= 3.1.0-dev" + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" } }, "node_modules/tunnel-agent": { @@ -12773,15 +12715,6 @@ "lru-cache": "^6.0.0" } }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -12790,16 +12723,6 @@ } } }, - "@typescript-eslint/eslint-plugin-tslint": { - "version": "5.36.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-5.36.1.tgz", - "integrity": "sha512-cOpdXK60QxSxMMr71Rn0AMLaEK2K6zyqK/Dfb9GxruJ+sHYrPsJFW2cy+XkeY1fL6As4Q8yO13Gkjget45I5aw==", - "dev": true, - "requires": { - "@typescript-eslint/utils": "5.36.1", - "lodash": "^4.17.21" - } - }, "@typescript-eslint/parser": { "version": "5.36.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.36.1.tgz", @@ -12865,15 +12788,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true - }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } } } }, @@ -12931,15 +12845,6 @@ "lru-cache": "^6.0.0" } }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -13548,13 +13453,6 @@ "integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s=", "dev": true }, - "builtin-modules": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true, - "peer": true - }, "cacheable-request": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", @@ -13844,13 +13742,6 @@ "delayed-stream": "~1.0.0" } }, - "commander": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", - "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", - "dev": true, - "peer": true - }, "comment-json": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-4.2.3.tgz", @@ -14345,6 +14236,12 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "deepmerge-ts": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/deepmerge-ts/-/deepmerge-ts-4.2.1.tgz", + "integrity": "sha512-xzJLiUo4z1dD2nggSfaMvHo5qWLoy/JVa9rKuktC6FrQQEBI8Qnj7KwuCYZhqBoGOOpGqs6+3MR2ZhSMcTr4BA==", + "dev": true + }, "default-require-extensions": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.0.tgz", @@ -15062,6 +14959,50 @@ } } }, + "eslint-plugin-functional": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-functional/-/eslint-plugin-functional-4.3.1.tgz", + "integrity": "sha512-Mlm0A4gtQya2jLg6BvL8FoyHtedMj3gGJNMe9SWIyRhFmIibGFjOldzZ86LxOQYnwLMV9AD5aeLBRfxPFTkkaQ==", + "dev": true, + "requires": { + "@typescript-eslint/utils": "^5.10.2", + "deepmerge-ts": "^4.0.3", + "escape-string-regexp": "^4.0.0", + "semver": "^7.3.7" + }, + "dependencies": { + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, "eslint-plugin-import": { "version": "2.26.0", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", @@ -19392,58 +19333,11 @@ "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, - "tslint": { - "version": "5.20.1", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.20.1.tgz", - "integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==", - "dev": true, - "peer": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^4.0.1", - "glob": "^7.1.1", - "js-yaml": "^3.13.1", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", - "resolve": "^1.3.2", - "semver": "^5.3.0", - "tslib": "^1.8.0", - "tsutils": "^2.29.0" - }, - "dependencies": { - "diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "peer": true - }, - "glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "peer": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - } - } - }, "tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", "dev": true, - "peer": true, "requires": { "tslib": "^1.8.1" } diff --git a/package.json b/package.json index 7563d65e5e..7534109d0f 100644 --- a/package.json +++ b/package.json @@ -73,13 +73,13 @@ "@types/unzipper": "^0.10.4", "@types/webpack": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.36.1", - "@typescript-eslint/eslint-plugin-tslint": "^5.36.1", "@typescript-eslint/parser": "^5.36.1", "buffer": "^6.0.3", "chai": "^3.5.0", "cspell": "^6.2.2", "docsify-cli": "^4.3.0", "eslint": "^8.23.0", + "eslint-plugin-functional": "^4.3.1", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsdoc": "^39.3.6", "eslint-plugin-no-null": "^1.0.2", diff --git a/src/export/packer/image-replacer.ts b/src/export/packer/image-replacer.ts index 3dce0de58d..31415877f0 100644 --- a/src/export/packer/image-replacer.ts +++ b/src/export/packer/image-replacer.ts @@ -1,7 +1,7 @@ import { IMediaData, Media } from "@file/media"; export class ImageReplacer { - public replace(xmlData: string, mediaData: IMediaData[], offset: number): string { + public replace(xmlData: string, mediaData: readonly IMediaData[], offset: number): string { let currentXmlData = xmlData; mediaData.forEach((image, i) => { @@ -11,7 +11,7 @@ export class ImageReplacer { return currentXmlData; } - public getMediaData(xmlData: string, media: Media): IMediaData[] { + public getMediaData(xmlData: string, media: Media): readonly IMediaData[] { return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0); } } diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index d81fbc4de8..8fd5f68144 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -20,10 +20,10 @@ interface IXmlifyedFileMapping { readonly Numbering: IXmlifyedFile; readonly Relationships: IXmlifyedFile; readonly FileRelationships: IXmlifyedFile; - readonly Headers: IXmlifyedFile[]; - readonly Footers: IXmlifyedFile[]; - readonly HeaderRelationships: IXmlifyedFile[]; - readonly FooterRelationships: IXmlifyedFile[]; + readonly Headers: readonly IXmlifyedFile[]; + readonly Footers: readonly IXmlifyedFile[]; + readonly HeaderRelationships: readonly IXmlifyedFile[]; + readonly FooterRelationships: readonly IXmlifyedFile[]; readonly ContentTypes: IXmlifyedFile; readonly CustomProperties: IXmlifyedFile; readonly AppProperties: IXmlifyedFile; @@ -47,15 +47,15 @@ export class Compiler { public compile(file: File, prettifyXml?: boolean | PrettifyType): JSZip { const zip = new JSZip(); const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml); - const map = new Map(Object.entries(xmlifiedFileMapping)); + const map = new Map(Object.entries(xmlifiedFileMapping)); for (const [, obj] of map) { if (Array.isArray(obj)) { - for (const subFile of obj) { + for (const subFile of obj as readonly IXmlifyedFile[]) { zip.file(subFile.path, subFile.data); } } else { - zip.file(obj.path, obj.data); + zip.file((obj as IXmlifyedFile).path, (obj as IXmlifyedFile).data); } } diff --git a/src/export/packer/numbering-replacer.ts b/src/export/packer/numbering-replacer.ts index d0416340b1..4391fa9361 100644 --- a/src/export/packer/numbering-replacer.ts +++ b/src/export/packer/numbering-replacer.ts @@ -1,7 +1,7 @@ import { ConcreteNumbering } from "@file/numbering"; export class NumberingReplacer { - public replace(xmlData: string, concreteNumberings: ConcreteNumbering[]): string { + public replace(xmlData: string, concreteNumberings: readonly ConcreteNumbering[]): string { let currentXmlData = xmlData; for (const concreteNumbering of concreteNumberings) { diff --git a/src/export/packer/packer.spec.ts b/src/export/packer/packer.spec.ts index f0ed3d8b94..9dd5d55021 100644 --- a/src/export/packer/packer.spec.ts +++ b/src/export/packer/packer.spec.ts @@ -54,8 +54,8 @@ describe("Packer", () => { assert.isTrue(buffer.byteLength > 0); }); - it("should handle exception if it throws any", () => { - // tslint:disable-next-line:no-any + it("should handle exception if it throws any", async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const compiler = stub((Packer as any).compiler, "compile"); compiler.throwsException(); @@ -65,7 +65,7 @@ describe("Packer", () => { }); after(() => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (Packer as any).compiler.compile.restore(); }); }); @@ -80,7 +80,7 @@ describe("Packer", () => { }); it("should handle exception if it throws any", () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const compiler = stub((Packer as any).compiler, "compile"); compiler.throwsException(); @@ -90,14 +90,14 @@ describe("Packer", () => { }); after(() => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (Packer as any).compiler.compile.restore(); }); }); describe("#toBlob()", () => { it("should create a standard docx file", async () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any stub((Packer as any).compiler, "compile").callsFake(() => ({ // tslint:disable-next-line: no-empty generateAsync: () => mock({}), @@ -108,7 +108,7 @@ describe("Packer", () => { }); it("should handle exception if it throws any", () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const compiler = stub((Packer as any).compiler, "compile"); compiler.throwsException(); @@ -118,14 +118,14 @@ describe("Packer", () => { }); afterEach(() => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (Packer as any).compiler.compile.restore(); }); }); describe("#toStream()", () => { it("should create a standard docx file", async () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any stub((Packer as any).compiler, "compile").callsFake(() => ({ // tslint:disable-next-line: no-empty generateNodeStream: () => ({ @@ -149,7 +149,7 @@ describe("Packer", () => { }); it("should handle exception if it throws any", async () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const compiler = stub((Packer as any).compiler, "compile").callsFake(() => ({ // tslint:disable-next-line: no-empty on: (event: string, cb: () => void) => { @@ -166,7 +166,7 @@ describe("Packer", () => { }); afterEach(() => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (Packer as any).compiler.compile.restore(); }); }); diff --git a/src/export/packer/packer.ts b/src/export/packer/packer.ts index 5d233ec0ef..9e230fda86 100644 --- a/src/export/packer/packer.ts +++ b/src/export/packer/packer.ts @@ -1,5 +1,5 @@ -import { File } from "@file/file"; import { Stream } from "stream"; +import { File } from "@file/file"; import { Compiler } from "./next-compiler"; diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index 8a72bcabf4..264203f753 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -12,7 +12,7 @@ import { Paragraph } from "../paragraph"; import { IStylesOptions } from "../styles"; export interface IPropertiesOptions { - readonly sections: ISectionOptions[]; + readonly sections: readonly ISectionOptions[]; readonly title?: string; readonly subject?: string; readonly creator?: string; @@ -26,7 +26,7 @@ export interface IPropertiesOptions { readonly comments?: ICommentsOptions; readonly footnotes?: { readonly [key: string]: { - readonly children: Paragraph[]; + readonly children: readonly Paragraph[]; }; }; readonly background?: IDocumentBackgroundOptions; @@ -35,7 +35,7 @@ export interface IPropertiesOptions { readonly updateFields?: boolean; }; readonly compatabilityModeVersion?: number; - readonly customProperties?: ICustomPropertyOptions[]; + readonly customProperties?: readonly ICustomPropertyOptions[]; readonly evenAndOddHeaderAndFooters?: boolean; } diff --git a/src/file/custom-properties/custom-properties.ts b/src/file/custom-properties/custom-properties.ts index fbe7160e57..8c15db148f 100644 --- a/src/file/custom-properties/custom-properties.ts +++ b/src/file/custom-properties/custom-properties.ts @@ -3,11 +3,12 @@ import { CustomPropertiesAttributes } from "./custom-properties-attributes"; import { CustomProperty, ICustomPropertyOptions } from "./custom-property"; export class CustomProperties extends XmlComponent { - // tslint:disable-next-line:readonly-keyword + // eslint-disable-next-line functional/prefer-readonly-type private nextId: number; + // eslint-disable-next-line functional/prefer-readonly-type private readonly properties: CustomProperty[] = []; - public constructor(properties: ICustomPropertyOptions[]) { + public constructor(properties: readonly ICustomPropertyOptions[]) { super("Properties"); this.root.push( diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index cdda805405..2d0f81ed49 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -4,6 +4,7 @@ import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components"; import { ISectionPropertiesOptions, SectionProperties } from "./section-properties/section-properties"; export class Body extends XmlComponent { + // eslint-disable-next-line functional/prefer-readonly-type private readonly sections: SectionProperties[] = []; public constructor() { @@ -16,6 +17,7 @@ export class Body extends XmlComponent { * The spec says: * - section element should be in the last paragraph of the section * - last section should be direct child of body + * * @param options new section options */ public addSection(options: ISectionPropertiesOptions): void { diff --git a/src/file/document/body/section-properties/properties/columns.ts b/src/file/document/body/section-properties/properties/columns.ts index 875c806815..dc09e60462 100644 --- a/src/file/document/body/section-properties/properties/columns.ts +++ b/src/file/document/body/section-properties/properties/columns.ts @@ -17,7 +17,7 @@ export interface IColumnsAttributes { readonly count?: number; readonly separate?: boolean; readonly equalWidth?: boolean; - readonly children?: Column[]; + readonly children?: readonly Column[]; } export class ColumnsAttributes extends XmlAttributeComponent { diff --git a/src/file/drawing/anchor/anchor.spec.ts b/src/file/drawing/anchor/anchor.spec.ts index 358f70aa33..17ccb0f165 100644 --- a/src/file/drawing/anchor/anchor.spec.ts +++ b/src/file/drawing/anchor/anchor.spec.ts @@ -6,8 +6,8 @@ import { IDrawingOptions } from "../drawing"; import { TextWrappingType } from "../text-wrap"; import { Anchor } from "./anchor"; -const createAnchor = (drawingOptions: IDrawingOptions): Anchor => { - return new Anchor( +const createAnchor = (drawingOptions: IDrawingOptions): Anchor => + new Anchor( { fileName: "test.png", stream: new Buffer(""), @@ -34,7 +34,6 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor => { }, drawingOptions, ); -}; describe("Anchor", () => { let anchor: Anchor; diff --git a/src/file/drawing/drawing.spec.ts b/src/file/drawing/drawing.spec.ts index d495ef111e..b5b48d80bd 100644 --- a/src/file/drawing/drawing.spec.ts +++ b/src/file/drawing/drawing.spec.ts @@ -6,8 +6,8 @@ import { Drawing, IDrawingOptions } from "./drawing"; const imageBase64Data = `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`; -const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => { - return new Drawing( +const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => + new Drawing( { fileName: "test.jpg", stream: Buffer.from(imageBase64Data, "base64"), @@ -24,7 +24,6 @@ const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => { }, drawingOptions, ); -}; describe("Drawing", () => { let currentBreak: Drawing; diff --git a/src/file/file.ts b/src/file/file.ts index 02eace30a6..aa1b1c64e1 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -33,15 +33,17 @@ export interface ISectionOptions { readonly even?: Footer; }; readonly properties?: ISectionPropertiesOptions; - readonly children: (Paragraph | Table | TableOfContents)[]; + readonly children: readonly (Paragraph | Table | TableOfContents)[]; } export class File { - // tslint:disable-next-line:readonly-keyword + // eslint-disable-next-line functional/immutable-data private currentRelationshipId: number = 1; private readonly documentWrapper: DocumentWrapper; + // eslint-disable-next-line functional/immutable-data private readonly headers: IDocumentHeader[] = []; + // eslint-disable-next-line functional/immutable-data private readonly footers: IDocumentFooter[] = []; private readonly coreProperties: CoreProperties; private readonly numbering: Numbering; @@ -268,11 +270,11 @@ export class File { return this.fileRelationships; } - public get Headers(): HeaderWrapper[] { + public get Headers(): readonly HeaderWrapper[] { return this.headers.map((item) => item.header); } - public get Footers(): FooterWrapper[] { + public get Footers(): readonly FooterWrapper[] { return this.footers.map((item) => item.footer); } diff --git a/src/file/footer-wrapper.spec.ts b/src/file/footer-wrapper.spec.ts index 8978541d21..91187474cd 100644 --- a/src/file/footer-wrapper.spec.ts +++ b/src/file/footer-wrapper.spec.ts @@ -41,7 +41,7 @@ describe("FooterWrapper", () => { it("should call the underlying footer's addChildElement", () => { const file = new FooterWrapper(new Media(), 1); const spy = sinon.spy(file.View, "addChildElement"); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.addChildElement({} as any); expect(spy.called).to.equal(true); diff --git a/src/file/footnotes/footnote/footnote.ts b/src/file/footnotes/footnote/footnote.ts index 4edd5b0419..a2983e0211 100644 --- a/src/file/footnotes/footnote/footnote.ts +++ b/src/file/footnotes/footnote/footnote.ts @@ -12,7 +12,7 @@ export enum FootnoteType { export interface IFootnoteOptions { readonly id: number; readonly type?: FootnoteType; - readonly children: Paragraph[]; + readonly children: readonly Paragraph[]; } export class Footnote extends XmlComponent { diff --git a/src/file/footnotes/footnotes.ts b/src/file/footnotes/footnotes.ts index a963b9cf82..cf215d5aac 100644 --- a/src/file/footnotes/footnotes.ts +++ b/src/file/footnotes/footnotes.ts @@ -67,7 +67,7 @@ export class FootNotes extends XmlComponent { this.root.push(spacing); } - public createFootNote(id: number, paragraph: Paragraph[]): void { + public createFootNote(id: number, paragraph: readonly Paragraph[]): void { const footnote = new Footnote({ id: id, children: paragraph, diff --git a/src/file/header-wrapper.spec.ts b/src/file/header-wrapper.spec.ts index f224743470..9731513537 100644 --- a/src/file/header-wrapper.spec.ts +++ b/src/file/header-wrapper.spec.ts @@ -41,7 +41,7 @@ describe("HeaderWrapper", () => { it("should call the underlying header's addChildElement", () => { const file = new HeaderWrapper(new Media(), 1); const spy = sinon.spy(file.View, "addChildElement"); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.addChildElement({} as any); expect(spy.called).to.equal(true); diff --git a/src/file/header.ts b/src/file/header.ts index 1d9c3a4f9a..d9dd2166f5 100644 --- a/src/file/header.ts +++ b/src/file/header.ts @@ -2,13 +2,17 @@ import { Paragraph } from "./paragraph"; import { Table } from "./table"; export interface IHeaderOptions { - readonly children: (Paragraph | Table)[]; + readonly children: readonly (Paragraph | Table)[]; } export class Header { - public constructor(public readonly options: IHeaderOptions = { children: [] }) {} + public constructor(public readonly options: IHeaderOptions = { children: [] }) { + // noop + } } export class Footer { - public constructor(public readonly options: IHeaderOptions = { children: [] }) {} + public constructor(public readonly options: IHeaderOptions = { children: [] }) { + // noop + } } diff --git a/src/file/media/media.ts b/src/file/media/media.ts index 4daf8d60f1..6b16495809 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -13,6 +13,7 @@ export interface IMediaTransformation { } export class Media { + // eslint-disable-next-line functional/prefer-readonly-type private readonly map: Map; public constructor() { @@ -68,9 +69,8 @@ export class Media { .map((c) => c.charCodeAt(0)), ); } else { - /* eslint @typescript-eslint/no-require-imports: 0 */ + // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires const b = require("buf" + "fer"); - /* eslint @typescript-eslint/no-require-imports: 2 */ return new b.Buffer(dataURI, "base64"); } } diff --git a/src/file/numbering/abstract-numbering.ts b/src/file/numbering/abstract-numbering.ts index b3e5be265b..24bd1c9842 100644 --- a/src/file/numbering/abstract-numbering.ts +++ b/src/file/numbering/abstract-numbering.ts @@ -32,7 +32,7 @@ class AbstractNumberingAttributes extends XmlAttributeComponent<{ export class AbstractNumbering extends XmlComponent { public readonly id: number; - public constructor(id: number, levelOptions: ILevelsOptions[]) { + public constructor(id: number, levelOptions: readonly ILevelsOptions[]) { super("w:abstractNum"); this.root.push( new AbstractNumberingAttributes({ diff --git a/src/file/numbering/level.spec.ts b/src/file/numbering/level.spec.ts index 9cf033eb28..2216dc1555 100644 --- a/src/file/numbering/level.spec.ts +++ b/src/file/numbering/level.spec.ts @@ -2,8 +2,8 @@ import { expect } from "chai"; import { Formatter } from "@export/formatter"; -import { Level, LevelFormat, LevelSuffix } from "./level"; import { AlignmentType } from ".."; +import { Level, LevelFormat, LevelSuffix } from "./level"; describe("Level", () => { describe("#constructor", () => { diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index c1f7a5d805..0bf575ada1 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -118,7 +118,7 @@ class Suffix extends XmlComponent { // http://officeopenxml.com/WPnumbering-isLgl.php // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.islegalnumberingstyle?view=openxml-2.8.1 class IsLegalNumberingStyle extends XmlComponent { - constructor() { + public constructor() { super("w:isLgl"); } } diff --git a/src/file/numbering/numbering.ts b/src/file/numbering/numbering.ts index 6e0e61836d..233fbeb95a 100644 --- a/src/file/numbering/numbering.ts +++ b/src/file/numbering/numbering.ts @@ -10,8 +10,8 @@ import { ILevelsOptions, LevelFormat } from "./level"; import { ConcreteNumbering } from "./num"; export interface INumberingOptions { - readonly config: { - readonly levels: ILevelsOptions[]; + readonly config: readonly { + readonly levels: readonly ILevelsOptions[]; readonly reference: string; }[]; } @@ -203,33 +203,33 @@ export class Numbering extends XmlComponent { return; } + const referenceConfigLevels = this.referenceConfigMap.get(reference); + const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start; + const concreteNumberingSettings = { numId: uniqueNumericId(), abstractNumId: abstractNumbering.id, reference, instance, - overrideLevel: { - num: 0, - start: 1, - }, + overrideLevel: + firstLevelStartNumber && Number.isInteger(firstLevelStartNumber) + ? { + num: 0, + start: firstLevelStartNumber, + } + : { + num: 0, + start: 1, + }, }; - const referenceConfigLevels = this.referenceConfigMap.get(reference); - const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start; - if (firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)) { - concreteNumberingSettings.overrideLevel = { - num: 0, - start: firstLevelStartNumber, - }; - } - this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings)); } - public get ConcreteNumbering(): ConcreteNumbering[] { + public get ConcreteNumbering(): readonly ConcreteNumbering[] { return Array.from(this.concreteNumberingMap.values()); } - public get ReferenceConfig(): object[] { + public get ReferenceConfig(): readonly object[] { return Array.from(this.referenceConfigMap.values()); } } diff --git a/src/file/paragraph/links/bookmark.ts b/src/file/paragraph/links/bookmark.ts index 6addd8c306..5a74cb1c5d 100644 --- a/src/file/paragraph/links/bookmark.ts +++ b/src/file/paragraph/links/bookmark.ts @@ -7,10 +7,10 @@ import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attri export class Bookmark { public readonly start: BookmarkStart; - public readonly children: ParagraphChild[]; + public readonly children: readonly ParagraphChild[]; public readonly end: BookmarkEnd; - public constructor(options: { readonly id: string; readonly children: ParagraphChild[] }) { + public constructor(options: { readonly id: string; readonly children: readonly ParagraphChild[] }) { const linkId = uniqueNumericId(); this.start = new BookmarkStart(options.id, linkId); diff --git a/src/file/paragraph/links/hyperlink.ts b/src/file/paragraph/links/hyperlink.ts index f1c98503a5..18380fb805 100644 --- a/src/file/paragraph/links/hyperlink.ts +++ b/src/file/paragraph/links/hyperlink.ts @@ -13,7 +13,7 @@ export enum HyperlinkType { export class ConcreteHyperlink extends XmlComponent { public readonly linkId: string; - public constructor(children: ParagraphChild[], relationshipId: string, anchor?: string) { + public constructor(children: readonly ParagraphChild[], relationshipId: string, anchor?: string) { super("w:hyperlink"); this.linkId = relationshipId; @@ -33,13 +33,13 @@ export class ConcreteHyperlink extends XmlComponent { } export class InternalHyperlink extends ConcreteHyperlink { - public constructor(options: { readonly children: ParagraphChild[]; readonly anchor: string }) { + public constructor(options: { readonly children: readonly ParagraphChild[]; readonly anchor: string }) { super(options.children, uniqueId(), options.anchor); } } export class ExternalHyperlink extends XmlComponent { - public constructor(public readonly options: { readonly children: ParagraphChild[]; readonly link: string }) { + public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) { super("w:externalHyperlink"); } } diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.ts b/src/file/paragraph/math/brackets/math-angled-brackets.ts index 82c426d4b4..efef05ea1b 100644 --- a/src/file/paragraph/math/brackets/math-angled-brackets.ts +++ b/src/file/paragraph/math/brackets/math-angled-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathAngledBrackets extends XmlComponent { - public constructor(options: { readonly children: MathComponent[] }) { + public constructor(options: { readonly children: readonly MathComponent[] }) { super("m:d"); this.root.push( diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.ts b/src/file/paragraph/math/brackets/math-curly-brackets.ts index d260f08012..d7336a7297 100644 --- a/src/file/paragraph/math/brackets/math-curly-brackets.ts +++ b/src/file/paragraph/math/brackets/math-curly-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathCurlyBrackets extends XmlComponent { - public constructor(options: { readonly children: MathComponent[] }) { + public constructor(options: { readonly children: readonly MathComponent[] }) { super("m:d"); this.root.push( diff --git a/src/file/paragraph/math/brackets/math-round-brackets.ts b/src/file/paragraph/math/brackets/math-round-brackets.ts index d3cb54627c..249d931ec2 100644 --- a/src/file/paragraph/math/brackets/math-round-brackets.ts +++ b/src/file/paragraph/math/brackets/math-round-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathRoundBrackets extends XmlComponent { - public constructor(options: { readonly children: MathComponent[] }) { + public constructor(options: { readonly children: readonly MathComponent[] }) { super("m:d"); this.root.push(new MathBracketProperties()); diff --git a/src/file/paragraph/math/brackets/math-square-brackets.ts b/src/file/paragraph/math/brackets/math-square-brackets.ts index e4c8079b72..6b27005d36 100644 --- a/src/file/paragraph/math/brackets/math-square-brackets.ts +++ b/src/file/paragraph/math/brackets/math-square-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathSquareBrackets extends XmlComponent { - public constructor(options: { readonly children: MathComponent[] }) { + public constructor(options: { readonly children: readonly MathComponent[] }) { super("m:d"); this.root.push( diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts index 4d7eacd093..f7052d135e 100644 --- a/src/file/paragraph/math/fraction/math-denominator.ts +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathDenominator extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:den"); for (const child of children) { diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts index 7f92c3455a..e18d92d985 100644 --- a/src/file/paragraph/math/fraction/math-fraction.ts +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -5,8 +5,8 @@ import { MathDenominator } from "./math-denominator"; import { MathNumerator } from "./math-numerator"; export interface IMathFractionOptions { - readonly numerator: MathComponent[]; - readonly denominator: MathComponent[]; + readonly numerator: readonly MathComponent[]; + readonly denominator: readonly MathComponent[]; } export class MathFraction extends XmlComponent { diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts index 67bad39fb5..7a54de7f79 100644 --- a/src/file/paragraph/math/fraction/math-numerator.ts +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathNumerator extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:num"); for (const child of children) { diff --git a/src/file/paragraph/math/function/math-function-name.ts b/src/file/paragraph/math/function/math-function-name.ts index b480747112..c6984bce02 100644 --- a/src/file/paragraph/math/function/math-function-name.ts +++ b/src/file/paragraph/math/function/math-function-name.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathFunctionName extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:fName"); for (const child of children) { diff --git a/src/file/paragraph/math/function/math-function.ts b/src/file/paragraph/math/function/math-function.ts index e9457975e6..307c8c4390 100644 --- a/src/file/paragraph/math/function/math-function.ts +++ b/src/file/paragraph/math/function/math-function.ts @@ -7,8 +7,8 @@ import { MathFunctionName } from "./math-function-name"; import { MathFunctionProperties } from "./math-function-properties"; export interface IMathFunctionOptions { - readonly children: MathComponent[]; - readonly name: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly name: readonly MathComponent[]; } export class MathFunction extends XmlComponent { diff --git a/src/file/paragraph/math/math.ts b/src/file/paragraph/math/math.ts index a46856c0a2..d0d3bcca41 100644 --- a/src/file/paragraph/math/math.ts +++ b/src/file/paragraph/math/math.ts @@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "./math-component"; export interface IMathOptions { - readonly children: MathComponent[]; + readonly children: readonly MathComponent[]; } export class Math extends XmlComponent { diff --git a/src/file/paragraph/math/n-ary/math-base.ts b/src/file/paragraph/math/n-ary/math-base.ts index ba017f6a85..0b95eed36d 100644 --- a/src/file/paragraph/math/n-ary/math-base.ts +++ b/src/file/paragraph/math/n-ary/math-base.ts @@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathBase extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:e"); for (const child of children) { diff --git a/src/file/paragraph/math/n-ary/math-sub-script.ts b/src/file/paragraph/math/n-ary/math-sub-script.ts index 89a796fd76..69ed2035b2 100644 --- a/src/file/paragraph/math/n-ary/math-sub-script.ts +++ b/src/file/paragraph/math/n-ary/math-sub-script.ts @@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathSubScriptElement extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:sub"); for (const child of children) { diff --git a/src/file/paragraph/math/n-ary/math-sum.ts b/src/file/paragraph/math/n-ary/math-sum.ts index 5d2c169f11..b5d0995147 100644 --- a/src/file/paragraph/math/n-ary/math-sum.ts +++ b/src/file/paragraph/math/n-ary/math-sum.ts @@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script"; import { MathSuperScriptElement } from "./math-super-script"; export interface IMathSumOptions { - readonly children: MathComponent[]; - readonly subScript?: MathComponent[]; - readonly superScript?: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly subScript?: readonly MathComponent[]; + readonly superScript?: readonly MathComponent[]; } export class MathSum extends XmlComponent { diff --git a/src/file/paragraph/math/n-ary/math-super-script.ts b/src/file/paragraph/math/n-ary/math-super-script.ts index 40fbd6d029..e2d6becf3c 100644 --- a/src/file/paragraph/math/n-ary/math-super-script.ts +++ b/src/file/paragraph/math/n-ary/math-super-script.ts @@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathSuperScriptElement extends XmlComponent { - public constructor(children: MathComponent[]) { + public constructor(children: readonly MathComponent[]) { super("m:sup"); for (const child of children) { diff --git a/src/file/paragraph/math/radical/math-degree.ts b/src/file/paragraph/math/radical/math-degree.ts index 4a1673284b..3942159674 100644 --- a/src/file/paragraph/math/radical/math-degree.ts +++ b/src/file/paragraph/math/radical/math-degree.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathComponent } from "../math-component"; export class MathDegree extends XmlComponent { - public constructor(children?: MathComponent[]) { + public constructor(children?: readonly MathComponent[]) { super("m:deg"); if (!!children) { diff --git a/src/file/paragraph/math/radical/math-radical.ts b/src/file/paragraph/math/radical/math-radical.ts index bbdcc9fb92..1684024dc1 100644 --- a/src/file/paragraph/math/radical/math-radical.ts +++ b/src/file/paragraph/math/radical/math-radical.ts @@ -7,8 +7,8 @@ import { MathDegree } from "./math-degree"; import { MathRadicalProperties } from "./math-radical-properties"; export interface IMathRadicalOptions { - readonly children: MathComponent[]; - readonly degree?: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly degree?: readonly MathComponent[]; } export class MathRadical extends XmlComponent { diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts index 686d24f0cd..293a308a36 100644 --- a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts @@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n- import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; export interface IMathPreSubSuperScriptOptions { - readonly children: MathComponent[]; - readonly subScript: MathComponent[]; - readonly superScript: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly subScript: readonly MathComponent[]; + readonly superScript: readonly MathComponent[]; } export class MathPreSubSuperScript extends XmlComponent { diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts index fbc54287db..e0f70b2089 100644 --- a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts @@ -6,8 +6,8 @@ import { MathBase, MathSubScriptElement } from "../../n-ary"; import { MathSubScriptProperties } from "./math-sub-script-function-properties"; export interface IMathSubScriptOptions { - readonly children: MathComponent[]; - readonly subScript: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly subScript: readonly MathComponent[]; } export class MathSubScript extends XmlComponent { diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts index b0545324ed..20699561c6 100644 --- a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts @@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n- import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; export interface IMathSubSuperScriptOptions { - readonly children: MathComponent[]; - readonly subScript: MathComponent[]; - readonly superScript: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly subScript: readonly MathComponent[]; + readonly superScript: readonly MathComponent[]; } export class MathSubSuperScript extends XmlComponent { diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.ts index 4d61afb655..148b64d2fe 100644 --- a/src/file/paragraph/math/script/super-script/math-super-script-function.ts +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.ts @@ -6,8 +6,8 @@ import { MathBase, MathSuperScriptElement } from "../../n-ary"; import { MathSuperScriptProperties } from "./math-super-script-function-properties"; export interface IMathSuperScriptOptions { - readonly children: MathComponent[]; - readonly superScript: MathComponent[]; + readonly children: readonly MathComponent[]; + readonly superScript: readonly MathComponent[]; } export class MathSuperScript extends XmlComponent { diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 38642d5be3..6d8074ffa8 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -36,7 +36,7 @@ export type ParagraphChild = export interface IParagraphOptions extends IParagraphPropertiesOptions { readonly text?: string; - readonly children?: ParagraphChild[]; + readonly children?: readonly ParagraphChild[]; } export class Paragraph extends XmlComponent { diff --git a/src/file/paragraph/properties.spec.ts b/src/file/paragraph/properties.spec.ts index 9d466bc33c..86ecbbf62b 100644 --- a/src/file/paragraph/properties.spec.ts +++ b/src/file/paragraph/properties.spec.ts @@ -26,9 +26,7 @@ describe("ParagraphProperties", () => { // tslint:disable-next-line: no-object-literal-type-assertion file: { Numbering: { - createConcreteNumberingInstance: (_: string, __: number) => { - return; - }, + createConcreteNumberingInstance: (_: string, __: number) => undefined, }, } as File, // tslint:disable-next-line: no-object-literal-type-assertion diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 098fee0ccf..6f0088ac98 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -41,7 +41,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp readonly heading?: HeadingLevel; readonly bidirectional?: boolean; readonly pageBreakBefore?: boolean; - readonly tabStops?: { + readonly tabStops?: readonly { readonly position: number | TabStopPosition; readonly type: TabStopType; readonly leader?: LeaderType; @@ -57,6 +57,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp } export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { + // eslint-disable-next-line functional/prefer-readonly-type private readonly numberingReferences: { readonly reference: string; readonly instance: number }[] = []; public constructor(options?: IParagraphPropertiesOptions) { diff --git a/src/file/paragraph/run/comment-run.ts b/src/file/paragraph/run/comment-run.ts index f4f95b80dd..626f4ccba9 100644 --- a/src/file/paragraph/run/comment-run.ts +++ b/src/file/paragraph/run/comment-run.ts @@ -12,7 +12,7 @@ export interface ICommentOptions { } export interface ICommentsOptions { - readonly children: ICommentOptions[]; + readonly children: readonly ICommentOptions[]; } class CommentAttributes extends XmlAttributeComponent<{ diff --git a/src/file/paragraph/run/image-run.spec.ts b/src/file/paragraph/run/image-run.spec.ts index 972080b49a..7887d4b0cd 100644 --- a/src/file/paragraph/run/image-run.spec.ts +++ b/src/file/paragraph/run/image-run.spec.ts @@ -40,7 +40,7 @@ describe("ImageRun", () => { const tree = new Formatter().format(currentImageRun, { file: { Media: { - // tslint:disable-next-line: no-empty + // eslint-disable-next-line @typescript-eslint/no-empty-function addImage: () => {}, }, } as unknown as File, @@ -290,7 +290,7 @@ describe("ImageRun", () => { const tree = new Formatter().format(currentImageRun, { file: { Media: { - // tslint:disable-next-line: no-empty + // eslint-disable-next-line @typescript-eslint/no-empty-function addImage: () => {}, }, } as unknown as File, @@ -519,6 +519,7 @@ describe("ImageRun", () => { }); it("should return UInt8Array if atob is present", () => { + // eslint-disable-next-line functional/immutable-data global.atob = () => "atob result"; const currentImageRun = new ImageRun({ @@ -542,7 +543,7 @@ describe("ImageRun", () => { const tree = new Formatter().format(currentImageRun, { file: { Media: { - // tslint:disable-next-line: no-empty + // eslint-disable-next-line @typescript-eslint/no-empty-function addImage: () => {}, }, } as unknown as File, @@ -775,6 +776,7 @@ describe("ImageRun", () => { }); it("should use data as is if its not a string", () => { + // eslint-disable-next-line functional/immutable-data global.atob = () => "atob result"; const currentImageRun = new ImageRun({ @@ -798,7 +800,7 @@ describe("ImageRun", () => { const tree = new Formatter().format(currentImageRun, { file: { Media: { - // tslint:disable-next-line: no-empty + // eslint-disable-next-line @typescript-eslint/no-empty-function addImage: () => {}, }, } as unknown as File, diff --git a/src/file/paragraph/run/image-run.ts b/src/file/paragraph/run/image-run.ts index 59dc64fef7..849f7c6306 100644 --- a/src/file/paragraph/run/image-run.ts +++ b/src/file/paragraph/run/image-run.ts @@ -62,6 +62,7 @@ export class ImageRun extends Run { .map((c) => c.charCodeAt(0)), ); } else { + // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires const b = require("buf" + "fer"); return new b.Buffer(dataURI, "base64"); } diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index 49e895bf09..e5344e0e54 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -12,7 +12,7 @@ import { Text } from "./run-components/text"; import { TextAttributes } from "./text-attributes"; export interface IRunOptions extends IRunPropertiesOptions { - readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[]; + readonly children?: readonly (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[]; readonly break?: number; readonly text?: string; } diff --git a/src/file/styles/external-styles-factory.spec.ts b/src/file/styles/external-styles-factory.spec.ts index 9db766008b..2931b67fdd 100644 --- a/src/file/styles/external-styles-factory.spec.ts +++ b/src/file/styles/external-styles-factory.spec.ts @@ -48,7 +48,7 @@ describe("External styles factory", () => { describe("#parse", () => { it("should parse w:styles attributes", () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any; expect(importedStyle.rootKey).to.equal("w:styles"); @@ -59,7 +59,7 @@ describe("External styles factory", () => { }); it("should parse other child elements of w:styles", () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any; expect(importedStyle.root[1]).to.deep.equal({ root: [ @@ -147,7 +147,7 @@ describe("External styles factory", () => { }); it("should parse styles elements", () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any; expect(importedStyle.root.length).to.equal(5); diff --git a/src/file/styles/external-styles-factory.ts b/src/file/styles/external-styles-factory.ts index b40a0bff46..19dc396378 100644 --- a/src/file/styles/external-styles-factory.ts +++ b/src/file/styles/external-styles-factory.ts @@ -23,6 +23,7 @@ export class ExternalStylesFactory { * Or any other element will be parsed to * * + * * @param externalStyles context from styles.xml */ public newInstance(xmlData: string): Styles { diff --git a/src/file/styles/sample/default-style.ts b/src/file/styles/sample/default-style.ts index 7a3421c201..4796968a7c 100644 --- a/src/file/styles/sample/default-style.ts +++ b/src/file/styles/sample/default-style.ts @@ -1,4 +1,4 @@ -const createLsdException = (name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) => { +const createLsdException = (name: string, uiPriority?: number, qFormat?: number, semiHidden?: number, unhideWhenUsed?: number) => { "use strict"; return [ @@ -14,8 +14,9 @@ const createLsdException = (name, uiPriority, qFormat?, semiHidden?, unhideWhenU ]; }; -export const DefaultStyle = () => { - var style = { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const DefaultStyle = (): Record => { + const style = { "w:styles": [ { _attr: { diff --git a/src/file/styles/styles.ts b/src/file/styles/styles.ts index d61fcd7746..eff550ade4 100644 --- a/src/file/styles/styles.ts +++ b/src/file/styles/styles.ts @@ -7,9 +7,9 @@ import { IParagraphStyleOptions } from "./style/paragraph-style"; export interface IStylesOptions { readonly default?: IDefaultStylesOptions; readonly initialStyles?: BaseXmlComponent; - readonly paragraphStyles?: IParagraphStyleOptions[]; - readonly characterStyles?: ICharacterStyleOptions[]; - readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[]; + readonly paragraphStyles?: readonly IParagraphStyleOptions[]; + readonly characterStyles?: readonly ICharacterStyleOptions[]; + readonly importedStyles?: readonly (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[]; } // diff --git a/src/file/table-of-contents/table-of-contents-properties.ts b/src/file/table-of-contents/table-of-contents-properties.ts index a45a40b0cf..f53299d795 100644 --- a/src/file/table-of-contents/table-of-contents-properties.ts +++ b/src/file/table-of-contents/table-of-contents-properties.ts @@ -98,7 +98,7 @@ export interface ITableOfContentsOptions { * with each doublet being a comma-separated set of style name and table of content level. * \t can be combined with \o. */ - readonly stylesWithLevels?: StyleLevel[]; + readonly stylesWithLevels?: readonly StyleLevel[]; /** * \u Uses the applied paragraph outline level. diff --git a/src/file/table-of-contents/table-of-contents.spec.ts b/src/file/table-of-contents/table-of-contents.spec.ts index aba9647dc4..bd55661a41 100644 --- a/src/file/table-of-contents/table-of-contents.spec.ts +++ b/src/file/table-of-contents/table-of-contents.spec.ts @@ -14,9 +14,7 @@ describe("Table of Contents", () => { }); it("should construct a TOC with all the options and alias", () => { - const styles = new Array(); - styles.push(new StyleLevel("SL", 1)); - styles.push(new StyleLevel("SL", 2)); + const styles = [new StyleLevel("SL", 1), new StyleLevel("SL", 2)]; const props = { captionLabel: "A", diff --git a/src/file/table/grid.ts b/src/file/table/grid.ts index dc32154a23..719253b8b2 100644 --- a/src/file/table/grid.ts +++ b/src/file/table/grid.ts @@ -13,7 +13,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { twipsMeasureValue } from "@util/values"; export class TableGrid extends XmlComponent { - public constructor(widths: number[] | string[]) { + public constructor(widths: readonly number[] | readonly string[]) { super("w:tblGrid"); for (const width of widths) { this.root.push(new GridCol(width)); diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index c030edb308..f9547d9ba5 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -6,7 +6,7 @@ import { Table } from "../table"; import { ITableCellPropertiesOptions, TableCellProperties } from "./table-cell-properties"; export interface ITableCellOptions extends ITableCellPropertiesOptions { - readonly children: (Paragraph | Table)[]; + readonly children: readonly (Paragraph | Table)[]; } export class TableCell extends XmlComponent { diff --git a/src/file/table/table-row/table-row.ts b/src/file/table/table-row/table-row.ts index 7eba4c4134..863274bccf 100644 --- a/src/file/table/table-row/table-row.ts +++ b/src/file/table/table-row/table-row.ts @@ -3,7 +3,7 @@ import { TableCell } from "../table-cell"; import { ITableRowPropertiesOptions, TableRowProperties } from "./table-row-properties"; export interface ITableRowOptions extends ITableRowPropertiesOptions { - readonly children: TableCell[]; + readonly children: readonly TableCell[]; } export class TableRow extends XmlComponent { @@ -20,7 +20,7 @@ export class TableRow extends XmlComponent { return this.options.children.length; } - public get cells(): TableCell[] { + public get cells(): readonly TableCell[] { return this.root.filter((xmlComponent) => xmlComponent instanceof TableCell); } diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 236d56084a..7f272dfe3e 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -21,9 +21,9 @@ import { ITableWidthProperties } from "./table-width"; algorithm will expand columns to fit its content */ export interface ITableOptions { - readonly rows: TableRow[]; + readonly rows: readonly TableRow[]; readonly width?: ITableWidthProperties; - readonly columnWidths?: number[]; + readonly columnWidths?: readonly number[]; readonly margins?: ITableCellMarginOptions; readonly indent?: ITableWidthProperties; readonly float?: ITableFloatOptions; @@ -38,6 +38,7 @@ export class Table extends XmlComponent { public constructor({ rows, width, + // eslint-disable-next-line functional/immutable-data columnWidths = Array(Math.max(...rows.map((row) => row.CellCount))).fill(100), margins, indent, diff --git a/src/file/xml-components/default-attributes.ts b/src/file/xml-components/default-attributes.ts index 3e865c0b1d..bf84e95eef 100644 --- a/src/file/xml-components/default-attributes.ts +++ b/src/file/xml-components/default-attributes.ts @@ -1,11 +1,11 @@ import { BaseXmlComponent, IContext } from "./base"; import { IXmlableObject } from "./xmlable-object"; -export type AttributeMap = { [P in keyof T]: string }; +export type AttributeMap = { readonly [P in keyof T]: string }; -export abstract class XmlAttributeComponent extends BaseXmlComponent { +export abstract class XmlAttributeComponent extends BaseXmlComponent { // tslint:disable-next-line:readonly-keyword - protected root: T; + protected readonly root: T; protected readonly xmlKeys?: AttributeMap; public constructor(properties: T) { @@ -19,6 +19,7 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent { const value = this.root[key]; if (value !== undefined) { const newKey = (this.xmlKeys && this.xmlKeys[key]) || key; + // eslint-disable-next-line functional/immutable-data attrs[newKey] = value; } }); diff --git a/src/file/xml-components/imported-xml-component.ts b/src/file/xml-components/imported-xml-component.ts index 6eca0c261b..5385e8a9b6 100644 --- a/src/file/xml-components/imported-xml-component.ts +++ b/src/file/xml-components/imported-xml-component.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-any +// eslint-disable @typescript-eslint/no-explicit-any import { Element as XmlElement, xml2js } from "xml-js"; import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "@file/xml-components"; @@ -7,6 +7,7 @@ import { IContext } from "./base"; /** * Converts the given xml element (in json format) into XmlComponent. + * * @param element the xml element in json presentation */ diff --git a/src/file/xml-components/xml-component.ts b/src/file/xml-components/xml-component.ts index 60fc67d2b9..878931224b 100644 --- a/src/file/xml-components/xml-component.ts +++ b/src/file/xml-components/xml-component.ts @@ -4,7 +4,7 @@ import { IXmlableObject } from "./xmlable-object"; export const EMPTY_OBJECT = Object.seal({}); export abstract class XmlComponent extends BaseXmlComponent { - // tslint:disable-next-line:readonly-keyword no-any + // eslint-disable-next-line functional/prefer-readonly-type, @typescript-eslint/no-explicit-any protected root: (BaseXmlComponent | string | any)[]; public constructor(rootKey: string) { @@ -46,5 +46,7 @@ export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent { if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) { return result; } + + return undefined; } } diff --git a/src/tests/utility.ts b/src/tests/utility.ts index c43d0f6cc3..bfc0d90299 100644 --- a/src/tests/utility.ts +++ b/src/tests/utility.ts @@ -1,5 +1,5 @@ export class Utility { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any public static jsonify(obj: object): any { const stringifiedJson = JSON.stringify(obj); return JSON.parse(stringifiedJson); diff --git a/src/util/values.ts b/src/util/values.ts index 67e8031a43..fa666bd084 100644 --- a/src/util/values.ts +++ b/src/util/values.ts @@ -43,27 +43,21 @@ const hexBinary = (val: string, length: number): string => { // // // -export const longHexNumber = (val: string): string => { - return hexBinary(val, 4); -}; +export const longHexNumber = (val: string): string => hexBinary(val, 4); // // // // // -export const shortHexNumber = (val: string): string => { - return hexBinary(val, 2); -}; +export const shortHexNumber = (val: string): string => hexBinary(val, 2); // // // // // -export const uCharHexNumber = (val: string): string => { - return hexBinary(val, 1); -}; +export const uCharHexNumber = (val: string): string => hexBinary(val, 1); // // @@ -129,30 +123,26 @@ export const hexColorValue = (val: string): string => { // // // -export const signedTwipsMeasureValue = (val: string | number): string | number => { - return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val); -}; +export const signedTwipsMeasureValue = (val: string | number): string | number => + typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val); // // // -export const hpsMeasureValue = (val: string | number): string | number => { - return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val); -}; +export const hpsMeasureValue = (val: string | number): string | number => + typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val); // // // -export const signedHpsMeasureValue = (val: string | number): string | number => { - return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val); -}; +export const signedHpsMeasureValue = (val: string | number): string | number => + typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val); // // // -export const twipsMeasureValue = (val: string | number): string | number => { - return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val); -}; +export const twipsMeasureValue = (val: string | number): string | number => + typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val); // // @@ -222,6 +212,4 @@ export const pointMeasureValue = unsignedDecimalNumber; // // Luckily, js has this format built in already. See: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString -export const dateTimeValue = (val: Date): string => { - return val.toISOString(); -}; +export const dateTimeValue = (val: Date): string => val.toISOString();