@nr1e/commons 0.1.0-alpha.1 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +19 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +4 -0
- package/.git/COMMIT_EDITMSG +5 -0
- package/.git/FETCH_HEAD +1 -0
- package/.git/HEAD +1 -0
- package/.git/config +18 -0
- package/.git/config.worktree +5 -0
- package/.git/description +1 -0
- package/.git/hooks/applypatch-msg.sample +15 -0
- package/.git/hooks/commit-msg.sample +24 -0
- package/.git/hooks/fsmonitor-watchman.sample +174 -0
- package/.git/hooks/post-update.sample +8 -0
- package/.git/hooks/pre-applypatch.sample +14 -0
- package/.git/hooks/pre-commit.sample +49 -0
- package/.git/hooks/pre-merge-commit.sample +13 -0
- package/.git/hooks/pre-push.sample +53 -0
- package/.git/hooks/pre-rebase.sample +169 -0
- package/.git/hooks/pre-receive.sample +24 -0
- package/.git/hooks/prepare-commit-msg.sample +42 -0
- package/.git/hooks/push-to-checkout.sample +78 -0
- package/.git/hooks/sendemail-validate.sample +77 -0
- package/.git/hooks/update.sample +128 -0
- package/.git/index +0 -0
- package/.git/info/exclude +6 -0
- package/.git/logs/HEAD +2 -0
- package/.git/logs/refs/heads/develop +2 -0
- package/.git/logs/refs/remotes/origin/develop +2 -0
- package/.git/objects/07/c0af7cd711cab6a55ad3dc349ac8c70775623c +0 -0
- package/.git/objects/09/8fb5a5ff070a1ee3ea11db1a3568af3fea6fa2 +0 -0
- package/.git/objects/0d/698432e2c44311c17b845cc63093a898972b95 +0 -0
- package/.git/objects/10/ba4a7d64968326293182d571a9c73f5e041fb6 +3 -0
- package/.git/objects/12/069a5aa45479564e00749f730582627a276a55 +3 -0
- package/.git/objects/14/5ab9cf82c40696a07ab42f117ba199acb2a50b +4 -0
- package/.git/objects/17/7b0dc4bf884f8ae0403b4aad053e76baafd632 +2 -0
- package/.git/objects/1d/a517ce3527df45a4f28e52ff2c0d9d1c8179f6 +0 -0
- package/.git/objects/26/d9a4912af870ce319f5cb5102651d49baac4ab +1 -0
- package/.git/objects/27/50076ed23b5211a52ef834f40f183ddecb917a +0 -0
- package/.git/objects/2a/96e4bb57fa4bd69c719dca224b17b569e94e82 +2 -0
- package/.git/objects/2b/38c26b4ec43b8f5574acb164d2ba64bca8e230 +0 -0
- package/.git/objects/2c/61d463bee185f04e7c2bd1d2a15ad1117c589e +0 -0
- package/.git/objects/2d/22dbc836cfd75c8d7640ebe5a4fe90bd2c23c6 +0 -0
- package/.git/objects/38/0be191ee415827a1217f46626fea4fefba48e5 +0 -0
- package/.git/objects/4c/bb28de66d7aaeb4d7737cc2be955adc0c886b5 +0 -0
- package/.git/objects/50/150b739272269be2ede552448013eba65323da +0 -0
- package/.git/objects/53/2b7b796ffd3223f913a5a5e1e17743ee3591fe +0 -0
- package/.git/objects/54/f13d9d62fbedd19b41134ba17153c4328de95b +0 -0
- package/.git/objects/5d/4aa0709f62f1bc1fa80251208b570cb3b89d9c +0 -0
- package/.git/objects/63/1c43e00d4c34ba914c510f4fe2e6df15b8b06e +0 -0
- package/.git/objects/63/9900d13c6182e452e33a3bd638e70a0146c785 +2 -0
- package/.git/objects/64/3fa02661c3a1b54205729a75d2fb5f013833af +0 -0
- package/.git/objects/6c/59086d862516d2fffa5da2035e5003100fb5c7 +0 -0
- package/.git/objects/6c/b74f90a0c799eea1c54a04d8d6a8a9e9691cca +2 -0
- package/.git/objects/6d/f39e776d6a89628ce4a005a011911298651635 +0 -0
- package/.git/objects/70/0e093acb1c1e55d523507411b7940a01a3bb65 +0 -0
- package/.git/objects/74/c82ffe8eb71efecbccfdf67b590949c944dd1a +0 -0
- package/.git/objects/76/1413a07839108abb46ef0e4490bd1c1444b4fc +0 -0
- package/.git/objects/77/96f8282f2c553ecdde72bc976478eb3a8a948e +0 -0
- package/.git/objects/79/ee123c2b23e069e35ed634d687e17f731cc702 +0 -0
- package/.git/objects/7d/80af9735f0527db35ecc79ae3c887e445cb3e0 +0 -0
- package/.git/objects/85/1d8d26c2a946ccfd5461a2573665c1fb7d71f7 +0 -0
- package/.git/objects/85/c5f24b8c55496f82a2680f94a7d3fa32887ea0 +0 -0
- package/.git/objects/87/00b3833597b600e6f0ffcfbaf622fd8cfaa9c3 +1 -0
- package/.git/objects/87/f31d3df8e7edbf96e45d80126f878b8e0c243f +0 -0
- package/.git/objects/8d/d819967bdc8457f04c1b5498bce89380d6552b +7 -0
- package/.git/objects/92/608c4e069a4301d466d8d18daecbe7abc9500e +0 -0
- package/.git/objects/94/a25f7f4cb416c083d265558da75d457237d671 +0 -0
- package/.git/objects/9c/69411050eac81b5dce09314516a30b38c41a20 +3 -0
- package/.git/objects/9f/54b5b21769da383f12fb9c7bd364bdb05e13a9 +0 -0
- package/.git/objects/a5/886c22eb68b152bb95ec5151504676d8e78ae1 +0 -0
- package/.git/objects/a6/582c9510e264f3b46fc3b20597a16923a03523 +0 -0
- package/.git/objects/a9/d7db9c0a81b2db47ca92e4e180b30090b27632 +0 -0
- package/.git/objects/aa/8ae6a0af7014d738cc551d1ffebeb4e19e6b73 +0 -0
- package/.git/objects/ad/c418f9105db9ec488de6831584b82e3929eaef +0 -0
- package/.git/objects/ae/14b04cdf65ade0f70577cdea2f85203f4c1bde +0 -0
- package/.git/objects/b0/c1c68fbbad6b190434cd2bb0e807796bd56fca +0 -0
- package/.git/objects/b1/0f0d0ef3bc5aaf3a91be0b991cb6fe0fcadc40 +0 -0
- package/.git/objects/b1/3c15806ef3856ecd8660b0bb36f39830daa3c2 +0 -0
- package/.git/objects/b6/3b642cfb4254fc0f7058903abc5b481895c4ef +0 -0
- package/.git/objects/b8/a2c461d7ffed9d4ba242c58a52341832b99e0a +0 -0
- package/.git/objects/bc/91e0079eb00d56dcde16714748f36a10dbd525 +0 -0
- package/.git/objects/c1/beeb895b71b709e48560460199db11b3fc18af +0 -0
- package/.git/objects/c5/166c2aeebaeb0a0f7654223c843c50cd4c8953 +0 -0
- package/.git/objects/d4/0a2096fc36c1fd9c7a9263c458d5e8a4a5bee7 +0 -0
- package/.git/objects/e8/019be9e978a8e2f094e748cbb6ce0c7163adee +0 -0
- package/.git/objects/eb/1d744c4e9b47bc902647298424320078e32980 +0 -0
- package/.git/objects/ee/15af38be7f3c3862229e59c6b5688f8e0f6099 +0 -0
- package/.git/objects/f1/9e0f429f231c34432784f9e33b92ac1d598c17 +0 -0
- package/.git/objects/f9/86f2fe82493e85651396b6d5886316d1c890dd +0 -0
- package/.git/refs/heads/develop +1 -0
- package/.git/refs/remotes/origin/develop +1 -0
- package/.git/shallow +1 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/ci.yml +12 -0
- package/.github/workflows/issues.yml +13 -0
- package/.github/workflows/publish.yml +20 -0
- package/.gitignore +13 -0
- package/.idea/.gitignore +10 -0
- package/.idea/aws.xml +11 -0
- package/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/commons-js.iml +14 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/.npmrc +1 -0
- package/.prettierignore +7 -0
- package/.prettierrc.cjs +3 -0
- package/LICENSE +26 -0
- package/README.md +14 -0
- package/coverage/base.css +224 -0
- package/coverage/bitsnbytes/b64.mts.html +559 -0
- package/coverage/bitsnbytes/index.html +131 -0
- package/coverage/bitsnbytes/index.mts.html +88 -0
- package/coverage/clover.xml +1003 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/errors/errors.mts.html +898 -0
- package/coverage/errors/index.html +131 -0
- package/coverage/errors/index.mts.html +88 -0
- package/coverage/favicon.png +0 -0
- package/coverage/http/http-method.mts.html +112 -0
- package/coverage/http/http-status-code.mts.html +211 -0
- package/coverage/http/index.html +146 -0
- package/coverage/http/index.mts.html +91 -0
- package/coverage/index.html +191 -0
- package/coverage/lang/index.html +146 -0
- package/coverage/lang/index.mts.html +91 -0
- package/coverage/lang/sleep.mts.html +109 -0
- package/coverage/lang/type-functions.mts.html +124 -0
- package/coverage/oauth/crypto-functions.mts.html +217 -0
- package/coverage/oauth/index.html +131 -0
- package/coverage/oauth/index.mts.html +88 -0
- package/coverage/prettify.css +1 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/validator/index.html +131 -0
- package/coverage/validator/index.mts.html +88 -0
- package/coverage/validator/validators.mts.html +1237 -0
- package/dist/package.json +72 -0
- package/node_modules/@eslint/eslintrc/LICENSE +19 -0
- package/node_modules/@eslint/eslintrc/README.md +115 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4344 -0
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
- package/node_modules/@eslint/eslintrc/package.json +82 -0
- package/node_modules/@eslint/eslintrc/universal.js +9 -0
- package/node_modules/@eslint/js/LICENSE +19 -0
- package/node_modules/@eslint/js/README.md +57 -0
- package/node_modules/@eslint/js/package.json +31 -0
- package/node_modules/@eslint/js/src/index.js +17 -0
- package/node_modules/@eslint-community/eslint-utils/LICENSE +21 -0
- package/node_modules/@eslint-community/eslint-utils/README.md +37 -0
- package/node_modules/@eslint-community/eslint-utils/index.js +2068 -0
- package/node_modules/@eslint-community/eslint-utils/index.js.map +1 -0
- package/node_modules/@eslint-community/eslint-utils/index.mjs +2027 -0
- package/node_modules/@eslint-community/eslint-utils/index.mjs.map +1 -0
- package/node_modules/@eslint-community/eslint-utils/package.json +73 -0
- package/node_modules/@eslint-community/regexpp/LICENSE +21 -0
- package/node_modules/@eslint-community/regexpp/README.md +177 -0
- package/node_modules/@eslint-community/regexpp/index.d.ts +1065 -0
- package/node_modules/@eslint-community/regexpp/index.js +2747 -0
- package/node_modules/@eslint-community/regexpp/index.js.map +1 -0
- package/node_modules/@eslint-community/regexpp/index.mjs +2737 -0
- package/node_modules/@eslint-community/regexpp/index.mjs.map +1 -0
- package/node_modules/@eslint-community/regexpp/package.json +93 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/package.json +217 -0
- package/node_modules/@typescript-eslint/eslint-plugin/LICENSE +21 -0
- package/node_modules/@typescript-eslint/eslint-plugin/README.md +10 -0
- package/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +23 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/README.md +23 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/TEMPLATE.md +26 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/adjacent-overload-signatures.md +93 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/array-type.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/await-thenable.md +40 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-ts-comment.md +148 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-tslint-comment.md +39 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/ban-types.md +183 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/block-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/brace-style.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/camelcase.md +10 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/class-literal-property-style.md +114 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/comma-dangle.md +22 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/comma-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-generic-constructors.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-indexed-object-style.md +80 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-assertions.md +108 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-definitions.md +82 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-exports.md +100 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/consistent-type-imports.md +105 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/default-param-last.md +48 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/dot-notation.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-function-return-type.md +319 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-member-accessibility.md +331 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/explicit-module-boundary-types.md +250 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/func-call-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/indent.md +20 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/init-declarations.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/key-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/keyword-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/lines-around-comment.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/lines-between-class-members.md +63 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/member-delimiter-style.md +161 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/member-ordering.md +1360 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/method-signature-style.md +110 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/naming-convention.md +706 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-array-constructor.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-base-to-string.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md +56 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-confusing-void-expression.md +116 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-dupe-class-members.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-enum-values.md +50 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-imports.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-duplicate-type-constituents.md +61 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-dynamic-delete.md +53 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-empty-function.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-empty-interface.md +70 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-explicit-any.md +174 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-non-null-assertion.md +52 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-parens.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extra-semi.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-extraneous-class.md +294 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-floating-promises.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-for-in-array.md +56 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-implicit-any-catch.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-implied-eval.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-import-type-side-effects.md +75 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-inferrable-types.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-invalid-this.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-invalid-void-type.md +113 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-loop-func.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-loss-of-precision.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-magic-numbers.md +131 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-meaningless-void-operator.md +47 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-misused-new.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-misused-promises.md +245 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-mixed-enums.md +88 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-namespace.md +129 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md +49 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-non-null-assertion.md +42 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-parameter-properties.md +406 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-redeclare.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-redundant-type-constituents.md +78 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-require-imports.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-restricted-imports.md +63 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-shadow.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-this-alias.md +38 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-throw-literal.md +111 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-type-alias.md +602 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md +133 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-condition.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-qualifier.md +51 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md +73 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md +55 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-argument.md +83 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-assignment.md +86 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-call.md +58 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-declaration-merging.md +54 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-enum-comparison.md +75 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-member-access.md +64 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unsafe-return.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unused-expressions.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-unused-vars.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-use-before-define.md +97 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-useless-constructor.md +21 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-useless-empty-export.md +43 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/no-var-requires.md +37 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md +41 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/object-curly-spacing.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/padding-line-between-statements.md +35 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/parameter-properties.md +485 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-as-const.md +44 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-enum-initializers.md +62 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-for-of.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-function-type.md +92 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-includes.md +77 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-literal-enum-member.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-namespace-keyword.md +47 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-nullish-coalescing.md +164 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-optional-chain.md +71 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md +268 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-readonly.md +87 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md +58 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-regexp-exec.md +46 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-return-this-type.md +87 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md +57 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-ts-expect-error.md +69 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/promise-function-async.md +59 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/quotes.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/require-array-sort-compare.md +78 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/require-await.md +24 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/restrict-plus-operands.md +208 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/restrict-template-expressions.md +117 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/return-await.md +216 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/semi.md +16 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/sort-type-constituents.md +101 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/sort-type-union-intersection-members.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-before-blocks.md +42 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-before-function-paren.md +12 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/space-infix-ops.md +16 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/strict-boolean-expressions.md +183 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/switch-exhaustiveness-check.md +106 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/triple-slash-reference.md +61 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/type-annotation-spacing.md +303 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/typedef.md +320 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/unbound-method.md +103 -0
- package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/unified-signatures.md +70 -0
- package/node_modules/@typescript-eslint/eslint-plugin/index.d.ts +4 -0
- package/node_modules/@typescript-eslint/eslint-plugin/package.json +87 -0
- package/node_modules/@typescript-eslint/parser/LICENSE +22 -0
- package/node_modules/@typescript-eslint/parser/README.md +10 -0
- package/node_modules/@typescript-eslint/parser/dist/index.js +17 -0
- package/node_modules/@typescript-eslint/parser/package.json +75 -0
- package/node_modules/@typescript-eslint/scope-manager/LICENSE +21 -0
- package/node_modules/@typescript-eslint/scope-manager/README.md +8 -0
- package/node_modules/@typescript-eslint/scope-manager/dist/index.js +31 -0
- package/node_modules/@typescript-eslint/scope-manager/package.json +67 -0
- package/node_modules/@typescript-eslint/type-utils/LICENSE +21 -0
- package/node_modules/@typescript-eslint/type-utils/README.md +12 -0
- package/node_modules/@typescript-eslint/type-utils/dist/index.js +36 -0
- package/node_modules/@typescript-eslint/type-utils/package.json +71 -0
- package/node_modules/@typescript-eslint/types/LICENSE +21 -0
- package/node_modules/@typescript-eslint/types/README.md +12 -0
- package/node_modules/@typescript-eslint/types/dist/index.js +24 -0
- package/node_modules/@typescript-eslint/types/package.json +84 -0
- package/node_modules/@typescript-eslint/typescript-estree/LICENSE +26 -0
- package/node_modules/@typescript-eslint/typescript-estree/README.md +10 -0
- package/node_modules/@typescript-eslint/typescript-estree/dist/index.js +38 -0
- package/node_modules/@typescript-eslint/typescript-estree/package.json +85 -0
- package/node_modules/@typescript-eslint/utils/LICENSE +21 -0
- package/node_modules/@typescript-eslint/utils/README.md +10 -0
- package/node_modules/@typescript-eslint/utils/dist/index.js +41 -0
- package/node_modules/@typescript-eslint/utils/package.json +70 -0
- package/node_modules/@typescript-eslint/visitor-keys/LICENSE +21 -0
- package/node_modules/@typescript-eslint/visitor-keys/README.md +10 -0
- package/node_modules/@typescript-eslint/visitor-keys/dist/index.js +8 -0
- package/node_modules/@typescript-eslint/visitor-keys/package.json +60 -0
- package/node_modules/@vitest/coverage-v8/LICENSE +21 -0
- package/node_modules/@vitest/coverage-v8/dist/index.js +54 -0
- package/node_modules/@vitest/coverage-v8/package.json +72 -0
- package/package.json +6 -6
- package/pnpm-lock.yaml +3277 -0
- package/src/bitsnbytes/b64.mts +158 -0
- package/src/bitsnbytes/b64.test.mts +78 -0
- package/src/bitsnbytes/index.mts +1 -0
- package/src/errors/errors.mts +271 -0
- package/src/errors/errors.test.mts +74 -0
- package/src/errors/index.mts +1 -0
- package/src/http/http-method.mts +9 -0
- package/src/http/http-status-code.mts +42 -0
- package/src/http/index.mts +2 -0
- package/src/lang/index.mts +2 -0
- package/src/lang/sleep.mts +8 -0
- package/src/lang/type-functions.mts +13 -0
- package/src/oauth/crypto-functions.mts +44 -0
- package/src/oauth/crypto-functions.test.mts +48 -0
- package/src/oauth/index.mts +1 -0
- package/src/validator/index.mts +1 -0
- package/src/validator/validators.mts +384 -0
- package/src/validator/validators.test.mts +245 -0
- package/tsconfig.json +18 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.mjs.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/b64.test.mjs.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.d.mts +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.d.mts.map +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.mjs +0 -0
- /package/{bitsnbytes → dist/bitsnbytes}/index.mjs.map +0 -0
- /package/{errors → dist/errors}/errors.d.mts +0 -0
- /package/{errors → dist/errors}/errors.d.mts.map +0 -0
- /package/{errors → dist/errors}/errors.mjs +0 -0
- /package/{errors → dist/errors}/errors.mjs.map +0 -0
- /package/{errors → dist/errors}/errors.test.d.mts +0 -0
- /package/{errors → dist/errors}/errors.test.d.mts.map +0 -0
- /package/{errors → dist/errors}/errors.test.mjs +0 -0
- /package/{errors → dist/errors}/errors.test.mjs.map +0 -0
- /package/{errors → dist/errors}/index.d.mts +0 -0
- /package/{errors → dist/errors}/index.d.mts.map +0 -0
- /package/{errors → dist/errors}/index.mjs +0 -0
- /package/{errors → dist/errors}/index.mjs.map +0 -0
- /package/{http → dist/http}/http-method.d.mts +0 -0
- /package/{http → dist/http}/http-method.d.mts.map +0 -0
- /package/{http → dist/http}/http-method.mjs +0 -0
- /package/{http → dist/http}/http-method.mjs.map +0 -0
- /package/{http → dist/http}/http-status-code.d.mts +0 -0
- /package/{http → dist/http}/http-status-code.d.mts.map +0 -0
- /package/{http → dist/http}/http-status-code.mjs +0 -0
- /package/{http → dist/http}/http-status-code.mjs.map +0 -0
- /package/{http → dist/http}/index.d.mts +0 -0
- /package/{http → dist/http}/index.d.mts.map +0 -0
- /package/{http → dist/http}/index.mjs +0 -0
- /package/{http → dist/http}/index.mjs.map +0 -0
- /package/{lang → dist/lang}/index.d.mts +0 -0
- /package/{lang → dist/lang}/index.d.mts.map +0 -0
- /package/{lang → dist/lang}/index.mjs +0 -0
- /package/{lang → dist/lang}/index.mjs.map +0 -0
- /package/{lang → dist/lang}/sleep.d.mts +0 -0
- /package/{lang → dist/lang}/sleep.d.mts.map +0 -0
- /package/{lang → dist/lang}/sleep.mjs +0 -0
- /package/{lang → dist/lang}/sleep.mjs.map +0 -0
- /package/{lang → dist/lang}/type-functions.d.mts +0 -0
- /package/{lang → dist/lang}/type-functions.d.mts.map +0 -0
- /package/{lang → dist/lang}/type-functions.mjs +0 -0
- /package/{lang → dist/lang}/type-functions.mjs.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.d.mts +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.mjs +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.mjs.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.d.mts +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.mjs +0 -0
- /package/{oauth → dist/oauth}/crypto-functions.test.mjs.map +0 -0
- /package/{oauth → dist/oauth}/index.d.mts +0 -0
- /package/{oauth → dist/oauth}/index.d.mts.map +0 -0
- /package/{oauth → dist/oauth}/index.mjs +0 -0
- /package/{oauth → dist/oauth}/index.mjs.map +0 -0
- /package/{validator → dist/validator}/index.d.mts +0 -0
- /package/{validator → dist/validator}/index.d.mts.map +0 -0
- /package/{validator → dist/validator}/index.mjs +0 -0
- /package/{validator → dist/validator}/index.mjs.map +0 -0
- /package/{validator → dist/validator}/validators.d.mts +0 -0
- /package/{validator → dist/validator}/validators.d.mts.map +0 -0
- /package/{validator → dist/validator}/validators.mjs +0 -0
- /package/{validator → dist/validator}/validators.mjs.map +0 -0
- /package/{validator → dist/validator}/validators.test.d.mts +0 -0
- /package/{validator → dist/validator}/validators.test.d.mts.map +0 -0
- /package/{validator → dist/validator}/validators.test.mjs +0 -0
- /package/{validator → dist/validator}/validators.test.mjs.map +0 -0
package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-readonly-parameter-types** for documentation.
|
|
8
|
+
|
|
9
|
+
Mutating function arguments can lead to confusing, hard to debug behavior.
|
|
10
|
+
Whilst it's easy to implicitly remember to not modify function arguments, explicitly typing arguments as readonly provides clear contract to consumers.
|
|
11
|
+
This contract makes it easier for a consumer to reason about if a function has side-effects.
|
|
12
|
+
|
|
13
|
+
This rule allows you to enforce that function parameters resolve to readonly types.
|
|
14
|
+
A type is considered readonly if:
|
|
15
|
+
|
|
16
|
+
- it is a primitive type (`string`, `number`, `boolean`, `symbol`, or an enum),
|
|
17
|
+
- it is a function signature type,
|
|
18
|
+
- it is a readonly array type whose element type is considered readonly.
|
|
19
|
+
- it is a readonly tuple type whose elements are all considered readonly.
|
|
20
|
+
- it is an object type whose properties are all marked as readonly, and whose values are all considered readonly.
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
<!--tabs-->
|
|
25
|
+
|
|
26
|
+
### ❌ Incorrect
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
function array1(arg: string[]) {} // array is not readonly
|
|
30
|
+
function array2(arg: readonly string[][]) {} // array element is not readonly
|
|
31
|
+
function array3(arg: [string, number]) {} // tuple is not readonly
|
|
32
|
+
function array4(arg: readonly [string[], number]) {} // tuple element is not readonly
|
|
33
|
+
// the above examples work the same if you use ReadonlyArray<T> instead
|
|
34
|
+
|
|
35
|
+
function object1(arg: { prop: string }) {} // property is not readonly
|
|
36
|
+
function object2(arg: { readonly prop: string; prop2: string }) {} // not all properties are readonly
|
|
37
|
+
function object3(arg: { readonly prop: { prop2: string } }) {} // nested property is not readonly
|
|
38
|
+
// the above examples work the same if you use Readonly<T> instead
|
|
39
|
+
|
|
40
|
+
interface CustomArrayType extends ReadonlyArray<string> {
|
|
41
|
+
prop: string; // note: this property is mutable
|
|
42
|
+
}
|
|
43
|
+
function custom1(arg: CustomArrayType) {}
|
|
44
|
+
|
|
45
|
+
interface CustomFunction {
|
|
46
|
+
(): void;
|
|
47
|
+
prop: string; // note: this property is mutable
|
|
48
|
+
}
|
|
49
|
+
function custom2(arg: CustomFunction) {}
|
|
50
|
+
|
|
51
|
+
function union(arg: string[] | ReadonlyArray<number[]>) {} // not all types are readonly
|
|
52
|
+
|
|
53
|
+
// rule also checks function types
|
|
54
|
+
interface Foo {
|
|
55
|
+
(arg: string[]): void;
|
|
56
|
+
}
|
|
57
|
+
interface Foo {
|
|
58
|
+
new (arg: string[]): void;
|
|
59
|
+
}
|
|
60
|
+
const x = { foo(arg: string[]): void; };
|
|
61
|
+
function foo(arg: string[]);
|
|
62
|
+
type Foo = (arg: string[]) => void;
|
|
63
|
+
interface Foo {
|
|
64
|
+
foo(arg: string[]): void;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### ✅ Correct
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
function array1(arg: readonly string[]) {}
|
|
72
|
+
function array2(arg: readonly (readonly string[])[]) {}
|
|
73
|
+
function array3(arg: readonly [string, number]) {}
|
|
74
|
+
function array4(arg: readonly [readonly string[], number]) {}
|
|
75
|
+
// the above examples work the same if you use ReadonlyArray<T> instead
|
|
76
|
+
|
|
77
|
+
function object1(arg: { readonly prop: string }) {}
|
|
78
|
+
function object2(arg: { readonly prop: string; readonly prop2: string }) {}
|
|
79
|
+
function object3(arg: { readonly prop: { readonly prop2: string } }) {}
|
|
80
|
+
// the above examples work the same if you use Readonly<T> instead
|
|
81
|
+
|
|
82
|
+
interface CustomArrayType extends ReadonlyArray<string> {
|
|
83
|
+
readonly prop: string;
|
|
84
|
+
}
|
|
85
|
+
function custom1(arg: Readonly<CustomArrayType>) {}
|
|
86
|
+
// interfaces that extend the array types are not considered arrays, and thus must be made readonly.
|
|
87
|
+
|
|
88
|
+
interface CustomFunction {
|
|
89
|
+
(): void;
|
|
90
|
+
readonly prop: string;
|
|
91
|
+
}
|
|
92
|
+
function custom2(arg: CustomFunction) {}
|
|
93
|
+
|
|
94
|
+
function union(arg: readonly string[] | ReadonlyArray<number[]>) {}
|
|
95
|
+
|
|
96
|
+
function primitive1(arg: string) {}
|
|
97
|
+
function primitive2(arg: number) {}
|
|
98
|
+
function primitive3(arg: boolean) {}
|
|
99
|
+
function primitive4(arg: unknown) {}
|
|
100
|
+
function primitive5(arg: null) {}
|
|
101
|
+
function primitive6(arg: undefined) {}
|
|
102
|
+
function primitive7(arg: any) {}
|
|
103
|
+
function primitive8(arg: never) {}
|
|
104
|
+
function primitive9(arg: string | number | undefined) {}
|
|
105
|
+
|
|
106
|
+
function fnSig(arg: () => void) {}
|
|
107
|
+
|
|
108
|
+
enum Foo { a, b }
|
|
109
|
+
function enum(arg: Foo) {}
|
|
110
|
+
|
|
111
|
+
function symb1(arg: symbol) {}
|
|
112
|
+
const customSymbol = Symbol('a');
|
|
113
|
+
function symb2(arg: typeof customSymbol) {}
|
|
114
|
+
|
|
115
|
+
// function types
|
|
116
|
+
interface Foo {
|
|
117
|
+
(arg: readonly string[]): void;
|
|
118
|
+
}
|
|
119
|
+
interface Foo {
|
|
120
|
+
new (arg: readonly string[]): void;
|
|
121
|
+
}
|
|
122
|
+
const x = { foo(arg: readonly string[]): void; };
|
|
123
|
+
function foo(arg: readonly string[]);
|
|
124
|
+
type Foo = (arg: readonly string[]) => void;
|
|
125
|
+
interface Foo {
|
|
126
|
+
foo(arg: readonly string[]): void;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Options
|
|
131
|
+
|
|
132
|
+
### `checkParameterProperties`
|
|
133
|
+
|
|
134
|
+
This option allows you to enable or disable the checking of parameter properties.
|
|
135
|
+
Because parameter properties create properties on the class, it may be undesirable to force them to be readonly.
|
|
136
|
+
|
|
137
|
+
Examples of code for this rule with `{checkParameterProperties: true}`:
|
|
138
|
+
|
|
139
|
+
<!--tabs-->
|
|
140
|
+
|
|
141
|
+
#### ❌ Incorrect
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
class Foo {
|
|
145
|
+
constructor(private paramProp: string[]) {}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### ✅ Correct
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
class Foo {
|
|
153
|
+
constructor(private paramProp: readonly string[]) {}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
<!--/tabs-->
|
|
158
|
+
|
|
159
|
+
Examples of **correct** code for this rule with `{checkParameterProperties: false}`:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
class Foo {
|
|
163
|
+
constructor(
|
|
164
|
+
private paramProp1: string[],
|
|
165
|
+
private paramProp2: readonly string[],
|
|
166
|
+
) {}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `ignoreInferredTypes`
|
|
171
|
+
|
|
172
|
+
This option allows you to ignore parameters which don't explicitly specify a type. This may be desirable in cases where an external dependency specifies a callback with mutable parameters, and manually annotating the callback's parameters is undesirable.
|
|
173
|
+
|
|
174
|
+
Examples of code for this rule with `{ignoreInferredTypes: true}`:
|
|
175
|
+
|
|
176
|
+
<!--tabs-->
|
|
177
|
+
|
|
178
|
+
#### ❌ Incorrect
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { acceptsCallback, CallbackOptions } from 'external-dependency';
|
|
182
|
+
|
|
183
|
+
acceptsCallback((options: CallbackOptions) => {});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
<details>
|
|
187
|
+
<summary>external-dependency.d.ts</summary>
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
export interface CallbackOptions {
|
|
191
|
+
prop: string;
|
|
192
|
+
}
|
|
193
|
+
type Callback = (options: CallbackOptions) => void;
|
|
194
|
+
type AcceptsCallback = (callback: Callback) => void;
|
|
195
|
+
|
|
196
|
+
export const acceptsCallback: AcceptsCallback;
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</details>
|
|
200
|
+
|
|
201
|
+
#### ✅ Correct
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { acceptsCallback } from 'external-dependency';
|
|
205
|
+
|
|
206
|
+
acceptsCallback(options => {});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
<details>
|
|
210
|
+
<summary>external-dependency.d.ts</summary>
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
export interface CallbackOptions {
|
|
214
|
+
prop: string;
|
|
215
|
+
}
|
|
216
|
+
type Callback = (options: CallbackOptions) => void;
|
|
217
|
+
type AcceptsCallback = (callback: Callback) => void;
|
|
218
|
+
|
|
219
|
+
export const acceptsCallback: AcceptsCallback;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
</details>
|
|
223
|
+
|
|
224
|
+
### `treatMethodsAsReadonly`
|
|
225
|
+
|
|
226
|
+
This option allows you to treat all mutable methods as though they were readonly. This may be desirable when you are never reassigning methods.
|
|
227
|
+
|
|
228
|
+
Examples of code for this rule with `{treatMethodsAsReadonly: false}`:
|
|
229
|
+
|
|
230
|
+
<!--tabs-->
|
|
231
|
+
|
|
232
|
+
#### ❌ Incorrect
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
type MyType = {
|
|
236
|
+
readonly prop: string;
|
|
237
|
+
method(): string; // note: this method is mutable
|
|
238
|
+
};
|
|
239
|
+
function foo(arg: MyType) {}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### ✅ Correct
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
type MyType = Readonly<{
|
|
246
|
+
prop: string;
|
|
247
|
+
method(): string;
|
|
248
|
+
}>;
|
|
249
|
+
function foo(arg: MyType) {}
|
|
250
|
+
|
|
251
|
+
type MyOtherType = {
|
|
252
|
+
readonly prop: string;
|
|
253
|
+
readonly method: () => string;
|
|
254
|
+
};
|
|
255
|
+
function bar(arg: MyOtherType) {}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
<!--/tabs-->
|
|
259
|
+
|
|
260
|
+
Examples of **correct** code for this rule with `{treatMethodsAsReadonly: true}`:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
type MyType = {
|
|
264
|
+
readonly prop: string;
|
|
265
|
+
method(): string; // note: this method is mutable
|
|
266
|
+
};
|
|
267
|
+
function foo(arg: MyType) {}
|
|
268
|
+
```
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Require private members to be marked as `readonly` if they're never modified outside of the constructor."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-readonly** for documentation.
|
|
8
|
+
|
|
9
|
+
Member variables with the privacy `private` are never permitted to be modified outside of their declaring class.
|
|
10
|
+
If that class never modifies their value, they may safely be marked as `readonly`.
|
|
11
|
+
|
|
12
|
+
This rule reports on private members are marked as `readonly` if they're never modified outside of the constructor.
|
|
13
|
+
|
|
14
|
+
## Examples
|
|
15
|
+
|
|
16
|
+
<!--tabs-->
|
|
17
|
+
|
|
18
|
+
### ❌ Incorrect
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
class Container {
|
|
22
|
+
// These member variables could be marked as readonly
|
|
23
|
+
private neverModifiedMember = true;
|
|
24
|
+
private onlyModifiedInConstructor: number;
|
|
25
|
+
|
|
26
|
+
public constructor(
|
|
27
|
+
onlyModifiedInConstructor: number,
|
|
28
|
+
// Private parameter properties can also be marked as readonly
|
|
29
|
+
private neverModifiedParameter: string,
|
|
30
|
+
) {
|
|
31
|
+
this.onlyModifiedInConstructor = onlyModifiedInConstructor;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### ✅ Correct
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
class Container {
|
|
40
|
+
// Public members might be modified externally
|
|
41
|
+
public publicMember: boolean;
|
|
42
|
+
|
|
43
|
+
// Protected members might be modified by child classes
|
|
44
|
+
protected protectedMember: number;
|
|
45
|
+
|
|
46
|
+
// This is modified later on by the class
|
|
47
|
+
private modifiedLater = 'unchanged';
|
|
48
|
+
|
|
49
|
+
public mutate() {
|
|
50
|
+
this.modifiedLater = 'mutated';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Options
|
|
56
|
+
|
|
57
|
+
### `onlyInlineLambdas`
|
|
58
|
+
|
|
59
|
+
You may pass `"onlyInlineLambdas": true` as a rule option within an object to restrict checking only to members immediately assigned a lambda value.
|
|
60
|
+
|
|
61
|
+
```jsonc
|
|
62
|
+
{
|
|
63
|
+
"@typescript-eslint/prefer-readonly": ["error", { "onlyInlineLambdas": true }]
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Example of code for the `{ "onlyInlineLambdas": true }` options:
|
|
68
|
+
|
|
69
|
+
<!--tabs-->
|
|
70
|
+
|
|
71
|
+
#### ❌ Incorrect
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
class Container {
|
|
75
|
+
private onClick = () => {
|
|
76
|
+
/* ... */
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### ✅ Correct
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
class Container {
|
|
85
|
+
private neverModifiedPrivate = 'unchanged';
|
|
86
|
+
}
|
|
87
|
+
```
|
package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Enforce using type parameter when calling `Array#reduce` instead of casting.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-reduce-type-parameter** for documentation.
|
|
8
|
+
|
|
9
|
+
It's common to call `Array#reduce` with a generic type, such as an array or object, as the initial value.
|
|
10
|
+
Since these values are empty, their types are not usable:
|
|
11
|
+
|
|
12
|
+
- `[]` has type `never[]`, which can't have items pushed into it as nothing is type `never`
|
|
13
|
+
- `{}` has type `{}`, which doesn't have an index signature and so can't have properties added to it
|
|
14
|
+
|
|
15
|
+
A common solution to this problem is to use an `as` assertion on the initial value.
|
|
16
|
+
While this will work, it's not the most optimal solution as type assertions have subtle effects on the underlying types that can allow bugs to slip in.
|
|
17
|
+
|
|
18
|
+
A better solution is to pass the type in as a generic type argument to `Array#reduce` explicitly.
|
|
19
|
+
This means that TypeScript doesn't have to try to infer the type, and avoids the common pitfalls that come with casting.
|
|
20
|
+
|
|
21
|
+
This rule looks for calls to `Array#reduce`, and reports if an initial value is being passed & asserted.
|
|
22
|
+
It will suggest instead pass the asserted type to `Array#reduce` as a generic type argument.
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
<!--tabs-->
|
|
27
|
+
|
|
28
|
+
### ❌ Incorrect
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
[1, 2, 3].reduce((arr, num) => arr.concat(num * 2), [] as number[]);
|
|
32
|
+
|
|
33
|
+
['a', 'b'].reduce(
|
|
34
|
+
(accum, name) => ({
|
|
35
|
+
...accum,
|
|
36
|
+
[name]: true,
|
|
37
|
+
}),
|
|
38
|
+
{} as Record<string, boolean>,
|
|
39
|
+
);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### ✅ Correct
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
[1, 2, 3].reduce<number[]>((arr, num) => arr.concat(num * 2), []);
|
|
46
|
+
|
|
47
|
+
['a', 'b'].reduce<Record<string, boolean>>(
|
|
48
|
+
(accum, name) => ({
|
|
49
|
+
...accum,
|
|
50
|
+
[name]: true,
|
|
51
|
+
}),
|
|
52
|
+
{},
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## When Not To Use It
|
|
57
|
+
|
|
58
|
+
If you don't want to use typechecking in your linting, you can't use this rule.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Enforce `RegExp#exec` over `String#match` if no global flag is provided.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-regexp-exec** for documentation.
|
|
8
|
+
|
|
9
|
+
`String#match` is defined to work the same as `RegExp#exec` when the regular expression does not include the `g` flag.
|
|
10
|
+
Keeping to consistently using one of the two can help improve code readability.
|
|
11
|
+
|
|
12
|
+
This rule reports when a `String#match` call can be replaced with an equivalent `RegExp#exec`.
|
|
13
|
+
|
|
14
|
+
> `RegExp#exec` may also be slightly faster than `String#match`; this is the reason to choose it as the preferred usage.
|
|
15
|
+
|
|
16
|
+
## Examples
|
|
17
|
+
|
|
18
|
+
<!--tabs-->
|
|
19
|
+
|
|
20
|
+
### ❌ Incorrect
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
'something'.match(/thing/);
|
|
24
|
+
|
|
25
|
+
'some things are just things'.match(/thing/);
|
|
26
|
+
|
|
27
|
+
const text = 'something';
|
|
28
|
+
const search = /thing/;
|
|
29
|
+
text.match(search);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### ✅ Correct
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
/thing/.exec('something');
|
|
36
|
+
|
|
37
|
+
'some things are just things'.match(/thing/g);
|
|
38
|
+
|
|
39
|
+
const text = 'something';
|
|
40
|
+
const search = /thing/;
|
|
41
|
+
search.exec(text);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## When Not To Use It
|
|
45
|
+
|
|
46
|
+
If you prefer consistent use of `String#match` for both with `g` flag and without it, you can turn this rule off.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Enforce that `this` is used when only `this` type is returned.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-return-this-type** for documentation.
|
|
8
|
+
|
|
9
|
+
[Method chaining](https://en.wikipedia.org/wiki/Method_chaining) is a common pattern in OOP languages and TypeScript provides a special [polymorphic `this` type](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types) to facilitate it.
|
|
10
|
+
Class methods that explicitly declare a return type of the class name instead of `this` make it harder for extending classes to call that method: the returned object will be typed as the base class, not the derived class.
|
|
11
|
+
|
|
12
|
+
This rule reports when a class method declares a return type of that class name instead of `this`.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
class Animal {
|
|
16
|
+
eat(): Animal {
|
|
17
|
+
// ~~~~~~
|
|
18
|
+
// Either removing this type annotation or replacing
|
|
19
|
+
// it with `this` would remove the type error below.
|
|
20
|
+
console.log("I'm moving!");
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class Cat extends Animal {
|
|
26
|
+
meow(): Cat {
|
|
27
|
+
console.log('Meow~');
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const cat = new Cat();
|
|
33
|
+
cat.eat().meow();
|
|
34
|
+
// ~~~~
|
|
35
|
+
// Error: Property 'meow' does not exist on type 'Animal'.
|
|
36
|
+
// because `eat` returns `Animal` and not all animals meow.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
<!--tabs-->
|
|
42
|
+
|
|
43
|
+
### ❌ Incorrect
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
class Foo {
|
|
47
|
+
f1(): Foo {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
f2 = (): Foo => {
|
|
51
|
+
return this;
|
|
52
|
+
};
|
|
53
|
+
f3(): Foo | undefined {
|
|
54
|
+
return Math.random() > 0.5 ? this : undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### ✅ Correct
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
class Foo {
|
|
63
|
+
f1(): this {
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
f2() {
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
f3 = (): this => {
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
72
|
+
f4 = () => {
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
class Base {}
|
|
78
|
+
class Derived extends Base {
|
|
79
|
+
f(): Base {
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## When Not To Use It
|
|
86
|
+
|
|
87
|
+
If you don't use method chaining or explicit return values, you can safely turn this rule off.
|
package/node_modules/@typescript-eslint/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-string-starts-ends-with** for documentation.
|
|
8
|
+
|
|
9
|
+
There are multiple ways to verify if a string starts or ends with a specific string, such as `foo.indexOf('bar') === 0`.
|
|
10
|
+
As of ES2015, the most common way in JavaScript is to use `String#startsWith` and `String#endsWith`.
|
|
11
|
+
Keeping to those methods consistently helps with code readability.
|
|
12
|
+
|
|
13
|
+
This rule reports when a string method can be replaced safely with `String#startsWith` or `String#endsWith`.
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
<!--tabs-->
|
|
18
|
+
|
|
19
|
+
### ❌ Incorrect
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
declare const foo: string;
|
|
23
|
+
|
|
24
|
+
// starts with
|
|
25
|
+
foo[0] === 'b';
|
|
26
|
+
foo.charAt(0) === 'b';
|
|
27
|
+
foo.indexOf('bar') === 0;
|
|
28
|
+
foo.slice(0, 3) === 'bar';
|
|
29
|
+
foo.substring(0, 3) === 'bar';
|
|
30
|
+
foo.match(/^bar/) != null;
|
|
31
|
+
/^bar/.test(foo);
|
|
32
|
+
|
|
33
|
+
// ends with
|
|
34
|
+
foo[foo.length - 1] === 'b';
|
|
35
|
+
foo.charAt(foo.length - 1) === 'b';
|
|
36
|
+
foo.lastIndexOf('bar') === foo.length - 3;
|
|
37
|
+
foo.slice(-3) === 'bar';
|
|
38
|
+
foo.substring(foo.length - 3) === 'bar';
|
|
39
|
+
foo.match(/bar$/) != null;
|
|
40
|
+
/bar$/.test(foo);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### ✅ Correct
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
declare const foo: string;
|
|
47
|
+
|
|
48
|
+
// starts with
|
|
49
|
+
foo.startsWith('bar');
|
|
50
|
+
|
|
51
|
+
// ends with
|
|
52
|
+
foo.endsWith('bar');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## When Not To Use It
|
|
56
|
+
|
|
57
|
+
If you don't mind that style, you can turn this rule off safely.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Enforce using `@ts-expect-error` over `@ts-ignore`.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-ts-expect-error** for documentation.
|
|
8
|
+
|
|
9
|
+
TypeScript allows you to suppress all errors on a line by placing a comment starting with `@ts-ignore` or `@ts-expect-error` immediately before the erroring line.
|
|
10
|
+
The two directives work the same, except `@ts-expect-error` causes a type error if placed before a line that's not erroring in the first place.
|
|
11
|
+
|
|
12
|
+
This means its easy for `@ts-ignore`s to be forgotten about, and remain in code even after the error they were suppressing is fixed.
|
|
13
|
+
This is dangerous, as if a new error arises on that line it'll be suppressed by the forgotten about `@ts-ignore`, and so be missed.
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
This rule reports any usage of `@ts-ignore`, including a fixer to replace with `@ts-expect-error`.
|
|
18
|
+
|
|
19
|
+
<!--tabs-->
|
|
20
|
+
|
|
21
|
+
### ❌ Incorrect
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const str: string = 1;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Explaining comment
|
|
29
|
+
*
|
|
30
|
+
* @ts-ignore */
|
|
31
|
+
const multiLine: number = 'value';
|
|
32
|
+
|
|
33
|
+
/** @ts-ignore */
|
|
34
|
+
const block: string = 1;
|
|
35
|
+
|
|
36
|
+
const isOptionEnabled = (key: string): boolean => {
|
|
37
|
+
// @ts-ignore: if key isn't in globalOptions it'll be undefined which is false
|
|
38
|
+
return !!globalOptions[key];
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### ✅ Correct
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
const str: string = 1;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Explaining comment
|
|
50
|
+
*
|
|
51
|
+
* @ts-expect-error */
|
|
52
|
+
const multiLine: number = 'value';
|
|
53
|
+
|
|
54
|
+
/** @ts-expect-error */
|
|
55
|
+
const block: string = 1;
|
|
56
|
+
|
|
57
|
+
const isOptionEnabled = (key: string): boolean => {
|
|
58
|
+
// @ts-expect-error: if key isn't in globalOptions it'll be undefined which is false
|
|
59
|
+
return !!globalOptions[key];
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## When Not To Use It
|
|
64
|
+
|
|
65
|
+
If you are compiling against multiple versions of TypeScript and using `@ts-ignore` to ignore version-specific type errors, this rule might get in your way.
|
|
66
|
+
|
|
67
|
+
## Further Reading
|
|
68
|
+
|
|
69
|
+
- [Original Implementing PR](https://github.com/microsoft/TypeScript/pull/36014)
|