Use new eslint-plugin-functional instead of tslint-immutable

This commit is contained in:
Dolan Miu
2022-09-15 20:00:50 +01:00
parent d020d59b11
commit e90d97b813
70 changed files with 321 additions and 436 deletions

View File

@ -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: [
{

View File

@ -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?

392
package-lock.json generated
View File

@ -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"
}

View File

@ -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",

View File

@ -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);
}
}

View File

@ -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<string, IXmlifyedFile | IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(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);
}
}

View File

@ -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) {

View File

@ -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();
});
});

View File

@ -1,5 +1,5 @@
import { File } from "@file/file";
import { Stream } from "stream";
import { File } from "@file/file";
import { Compiler } from "./next-compiler";

View File

@ -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;
}

View File

@ -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(

View File

@ -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 {

View File

@ -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<IColumnsAttributes> {

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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 {

View File

@ -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,

View File

@ -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);

View File

@ -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
}
}

View File

@ -13,6 +13,7 @@ export interface IMediaTransformation {
}
export class Media {
// eslint-disable-next-line functional/prefer-readonly-type
private readonly map: Map<string, IMediaData>;
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");
}
}

View File

@ -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({

View File

@ -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", () => {

View File

@ -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");
}
}

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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");
}
}

View File

@ -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(

View File

@ -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(

View File

@ -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());

View File

@ -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(

View File

@ -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) {

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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) {

View File

@ -12,7 +12,7 @@ export interface ICommentOptions {
}
export interface ICommentsOptions {
readonly children: ICommentOptions[];
readonly children: readonly ICommentOptions[];
}
class CommentAttributes extends XmlAttributeComponent<{

View File

@ -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,

View File

@ -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");
}

View File

@ -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;
}

View File

@ -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);

View File

@ -23,6 +23,7 @@ export class ExternalStylesFactory {
* <w:docDefaults>Or any other element will be parsed to</w:docDefaults>
*
* </w:styles>
*
* @param externalStyles context from styles.xml
*/
public newInstance(xmlData: string): Styles {

View File

@ -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<string, any> => {
const style = {
"w:styles": [
{
_attr: {

View File

@ -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)[];
}
// <xsd:complexType name="CT_Styles">

View File

@ -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.

View File

@ -14,9 +14,7 @@ describe("Table of Contents", () => {
});
it("should construct a TOC with all the options and alias", () => {
const styles = new Array<StyleLevel>();
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",

View File

@ -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));

View File

@ -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 {

View File

@ -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);
}

View File

@ -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<number>(Math.max(...rows.map((row) => row.CellCount))).fill(100),
margins,
indent,

View File

@ -1,11 +1,11 @@
import { BaseXmlComponent, IContext } from "./base";
import { IXmlableObject } from "./xmlable-object";
export type AttributeMap<T> = { [P in keyof T]: string };
export type AttributeMap<T> = { readonly [P in keyof T]: string };
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
export abstract class XmlAttributeComponent<T extends object> extends BaseXmlComponent {
// tslint:disable-next-line:readonly-keyword
protected root: T;
protected readonly root: T;
protected readonly xmlKeys?: AttributeMap<T>;
public constructor(properties: T) {
@ -19,6 +19,7 @@ export abstract class XmlAttributeComponent<T> 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;
}
});

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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);

View File

@ -43,27 +43,21 @@ const hexBinary = (val: string, length: number): string => {
// <xsd:length value="4"/>
// </xsd:restriction>
// </xsd:simpleType>
export const longHexNumber = (val: string): string => {
return hexBinary(val, 4);
};
export const longHexNumber = (val: string): string => hexBinary(val, 4);
// <xsd:simpleType name="ST_ShortHexNumber">
// <xsd:restriction base="xsd:hexBinary">
// <xsd:length value="2"/>
// </xsd:restriction>
// </xsd:simpleType>
export const shortHexNumber = (val: string): string => {
return hexBinary(val, 2);
};
export const shortHexNumber = (val: string): string => hexBinary(val, 2);
// <xsd:simpleType name="ST_UcharHexNumber">
// <xsd:restriction base="xsd:hexBinary">
// <xsd:length value="1"/>
// </xsd:restriction>
// </xsd:simpleType>
export const uCharHexNumber = (val: string): string => {
return hexBinary(val, 1);
};
export const uCharHexNumber = (val: string): string => hexBinary(val, 1);
// <xsd:simpleType name="ST_LongHexNumber">
// <xsd:restriction base="xsd:hexBinary">
@ -129,30 +123,26 @@ export const hexColorValue = (val: string): string => {
// <xsd:simpleType name="ST_SignedTwipsMeasure">
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
// </xsd:simpleType>
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);
// <xsd:simpleType name="ST_HpsMeasure">
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure"/>
// </xsd:simpleType>
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);
// <xsd:simpleType name="ST_SignedHpsMeasure">
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
// </xsd:simpleType>
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);
// <xsd:simpleType name="ST_TwipsMeasure">
// <xsd:union memberTypes="ST_UnsignedDecimalNumber ST_PositiveUniversalMeasure"/>
// </xsd:simpleType>
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);
// <xsd:simpleType name="ST_Percentage">
// <xsd:restriction base="xsd:string">
@ -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();