From 08cf57261e667566081da8306a7c790559b02ea5 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sun, 9 Aug 2020 16:37:23 -0700 Subject: [PATCH 01/14] Installed eslint, removed tslint and related files and added rules --- .eslintignore | 8 + .eslintrc.json | 17 + CONTRIBUTING.md | 5 +- README.md | 3 +- package-lock.json | 792 +++++++++++++++++- package.json | 9 +- spec/DummyHandlerOptions.ts | 2 +- spec/core/urlParsing.ts | 2 +- spec/middleware/MiddlewareUtil.ts | 14 +- spec/middleware/RetryHandlerOptions.ts | 4 +- src/Client.ts | 4 +- src/GraphError.ts | 2 +- src/GraphErrorHandler.ts | 2 +- src/GraphRequest.ts | 12 +- src/GraphResponseHandler.ts | 2 +- src/ImplicitMSALAuthenticationProvider.ts | 2 +- src/Range.ts | 2 +- src/content/BatchRequestContent.ts | 4 +- src/middleware/AuthenticationHandler.ts | 4 +- src/middleware/ChaosHandler.ts | 17 +- src/middleware/MiddlewareUtil.ts | 2 +- src/middleware/RedirectHandler.ts | 10 +- src/middleware/RetryHandler.ts | 6 +- src/middleware/TelemetryHandler.ts | 2 +- src/middleware/options/ChaosHandlerOptions.ts | 2 +- .../options/RedirectHandlerOptions.ts | 4 +- src/middleware/options/RetryHandlerOptions.ts | 8 +- src/tasks/OneDriveLargeFileUploadTask.ts | 4 +- tslint.json | 21 - 29 files changed, 844 insertions(+), 122 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json delete mode 100644 tslint.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..f0be5e755 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,8 @@ +*.js +*.js.map +*.d.ts + +node_modules +lib +samples +spec/development \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..14854563a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,17 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"], + "rules": { + "max-len": "off", + "sort-imports": ["warn", { "allowSeparatedGroups": true }], + "sort-keys": "warn", + "no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. + "no-constant-condition": "off", + "no-empty-interface": "off", + "prefer-rest-params": "off", + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/ban-types": "off" + } +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a2f6c5bb..9dd15dce2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,10 +114,9 @@ npm install To edit files, open them in an editor of your choice and modify them. To create a new file, use the editor of your choice and save the new file in the appropriate location in your local copy of the repository. While working, save your work frequently. -*Note: Make sure to add unit tests to validate you changes.* +_Note: Make sure to add unit tests to validate you changes._ -Once you have done with your changes, You have to build and test your changes -To build the library run, +Once you have done with your changes, You have to build and test your changes To build the library run, ```cmd npm run build diff --git a/README.md b/README.md index 94c25c7a5..bb840f42c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,6 @@ Refer devDependencies in [package.json](./package.json) for the compatible msal ``` ```typescript - // Configuration options for MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL.js-1.0.0-api-release#configuration-options const msalConfig = { auth: { @@ -97,7 +96,7 @@ npm install msal@ import { UserAgentApplication } from "msal"; import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider"; -import { MSALAuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions'; +import { MSALAuthenticationProviderOptions } from "@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions"; // An Optional options for initializing the MSAL @see https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics#configuration-options const msalConfig = { diff --git a/package-lock.json b/package-lock.json index 08478c7a0..67bc45f44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -785,12 +785,30 @@ "any-observable": "^0.3.0" } }, + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", + "dev": true + }, + "@types/eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", + "dev": true + }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, + "@types/json-schema": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz", + "integrity": "sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==", + "dev": true + }, "@types/mocha": { "version": "5.2.6", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.6.tgz", @@ -818,12 +836,137 @@ "@types/node": "*" } }, + "@typescript-eslint/eslint-plugin": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.8.0.tgz", + "integrity": "sha512-lFb4VCDleFSR+eo4Ew+HvrJ37ZH1Y9ZyE+qyP7EiwBpcCVxwmUc5PAqhShCQ8N8U5vqYydm74nss+a0wrrCErw==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "3.8.0", + "debug": "^4.1.1", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^3.0.0", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.8.0.tgz", + "integrity": "sha512-o8T1blo1lAJE0QDsW7nSyvZHbiDzQDjINJKyB44Z3sSL39qBy5L10ScI/XwDtaiunoyKGLiY9bzRk4YjsUZl8w==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/types": "3.8.0", + "@typescript-eslint/typescript-estree": "3.8.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/parser": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.8.0.tgz", + "integrity": "sha512-u5vjOBaCsnMVQOvkKCXAmmOhyyMmFFf5dbkM3TIbg3MZ2pyv5peE4gj81UAbTHwTOXEwf7eCQTUMKrDl/+qGnA==", + "dev": true, + "requires": { + "@types/eslint-visitor-keys": "^1.0.0", + "@typescript-eslint/experimental-utils": "3.8.0", + "@typescript-eslint/types": "3.8.0", + "@typescript-eslint/typescript-estree": "3.8.0", + "eslint-visitor-keys": "^1.1.0" + } + }, + "@typescript-eslint/types": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-3.8.0.tgz", + "integrity": "sha512-8kROmEQkv6ss9kdQ44vCN1dTrgu4Qxrd2kXr10kz2NP5T8/7JnEfYNxCpPkArbLIhhkGLZV3aVMplH1RXQRF7Q==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.8.0.tgz", + "integrity": "sha512-MTv9nPDhlKfclwnplRNDL44mP2SY96YmPGxmMbMy6x12I+pERcxpIUht7DXZaj4mOKKtet53wYYXU0ABaiXrLw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "3.8.0", + "@typescript-eslint/visitor-keys": "3.8.0", + "debug": "^4.1.1", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": 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" + } + }, + "lodash": { + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", + "dev": true + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, + "@typescript-eslint/visitor-keys": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.8.0.tgz", + "integrity": "sha512-gfqQWyVPpT9NpLREXNR820AYwgz+Kr1GuF3nf1wxpHD6hdxI62tq03ToomFnDxY0m3pUB39IF7sil7D5TQexLA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, "acorn": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", "dev": true }, + "acorn-jsx": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.2.0.tgz", + "integrity": "sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==", + "dev": true + }, + "ajv": { + "version": "6.12.3", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", + "integrity": "sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, "ansi-colors": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", @@ -1047,6 +1190,12 @@ "integrity": "sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=", "dev": true }, + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, "async-done": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/async-done/-/async-done-1.3.1.tgz", @@ -1736,6 +1885,12 @@ "type-detect": "^4.0.0" } }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, "default-compare": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/default-compare/-/default-compare-1.0.0.tgz", @@ -1835,6 +1990,15 @@ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "duplexify": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz", @@ -1893,6 +2057,23 @@ "once": "^1.4.0" } }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + }, + "dependencies": { + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true + } + } + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1977,12 +2158,324 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "eslint": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.6.0.tgz", + "integrity": "sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "eslint-scope": "^5.1.0", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^1.3.0", + "espree": "^7.2.0", + "esquery": "^1.2.0", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.1.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.0", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "import-fresh": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", + "integrity": "sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "lodash": { + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", + "dev": true + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + } + } + }, + "eslint-config-prettier": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz", + "integrity": "sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + }, + "dependencies": { + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + } + } + }, + "eslint-plugin-prettier": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz", + "integrity": "sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, + "eslint-scope": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz", + "integrity": "sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + }, + "espree": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.2.0.tgz", + "integrity": "sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g==", + "dev": true, + "requires": { + "acorn": "^7.3.1", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.3.0" + }, + "dependencies": { + "acorn": { + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz", + "integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==", + "dev": true + } + } + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, + "esquery": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz", + "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==", + "dev": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "^4.1.0" + } + }, + "estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true + }, "estree-walker": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.0.tgz", @@ -2173,6 +2666,30 @@ "time-stamp": "^1.0.0" } }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, "figures": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", @@ -2183,6 +2700,15 @@ "object-assign": "^4.1.0" } }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, "fill-range": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", @@ -2269,6 +2795,23 @@ } } }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + } + }, + "flatted": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", + "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "dev": true + }, "flush-write-stream": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.1.1.tgz", @@ -2879,6 +3422,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "g-status": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/g-status/-/g-status-2.0.2.tgz", @@ -3341,6 +3890,12 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, "import-fresh": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", @@ -3351,6 +3906,12 @@ "resolve-from": "^3.0.0" } }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "indent-string": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-3.2.0.tgz", @@ -3791,6 +4352,12 @@ "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "dev": true }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", @@ -3855,6 +4422,16 @@ "flush-write-stream": "^1.0.2" } }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, "liftoff": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-3.1.0.tgz", @@ -4403,6 +4980,12 @@ "to-regex": "^3.0.1" } }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, "next-tick": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", @@ -4642,6 +5225,20 @@ "mimic-fn": "^1.0.0" } }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, "ordered-read-streams": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ordered-read-streams/-/ordered-read-streams-1.0.1.tgz", @@ -4710,6 +5307,23 @@ "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + }, + "dependencies": { + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + } + } + }, "parse-filepath": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-filepath/-/parse-filepath-1.0.2.tgz", @@ -4870,12 +5484,27 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=", "dev": true }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, "prettier": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.1.tgz", "integrity": "sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", @@ -4894,6 +5523,12 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "property-expr": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-1.5.1.tgz", @@ -4933,6 +5568,12 @@ } } }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + }, "read-pkg": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.1.1.tgz", @@ -5067,6 +5708,12 @@ "integrity": "sha512-9ASu7tuCKzdFa2YKfJmnmlilFrIJ8HFfE6MCs4aDLUw4gTBAaNwTTx/gw8Qo97fsV+UTVQXTmz9sHByeC8sKZg==", "dev": true }, + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, "regexpu-core": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.4.tgz", @@ -5858,6 +6505,69 @@ "integrity": "sha512-xYavZtFC1vKgJu0AOSYdrLeikNCsNwmUeZaV1XF9cMqEhBVVxLq6rEbYzOGrF1MV2MNPkhsJqqiXuQ4a76CEUg==", "dev": true }, + "table": { + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", + "dev": true, + "requires": { + "ajv": "^6.10.2", + "lodash": "^4.17.14", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "lodash": { + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", + "dev": true + }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + } + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, "terser": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/terser/-/terser-4.0.2.tgz", @@ -5877,6 +6587,12 @@ } } }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -5987,48 +6703,22 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" }, - "tslint": { - "version": "5.16.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.16.0.tgz", - "integrity": "sha512-UxG2yNxJ5pgGwmMzPMYh/CCnCnh0HfPgtlVRDs1ykZklufFBL1ZoTlWFRz2NQjcoEiDoRp+JyT0lhBbbH/obyA==", + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", "dev": true, "requires": { - "@babel/code-frame": "^7.0.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^3.2.0", - "glob": "^7.1.1", - "js-yaml": "^3.13.0", - "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": { - "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 - } + "tslib": "^1.8.1" } }, - "tslint-config-prettier": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz", - "integrity": "sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==", - "dev": true - }, - "tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "requires": { - "tslib": "^1.8.1" + "prelude-ls": "^1.2.1" } }, "type-detect": { @@ -6227,6 +6917,15 @@ "integrity": "sha512-kXpym8nmDmlCBr7nKdIx8P2jNBa+pBpIUFRnKJ4dr8htyYGJFokkr2ZvERRtUN+9SY+JqXouNgUPtv6JQva/2Q==", "dev": true }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, "urix": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", @@ -6245,6 +6944,12 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, + "v8-compile-cache": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz", + "integrity": "sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ==", + "dev": true + }, "v8flags": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.1.3.tgz", @@ -6354,6 +7059,12 @@ "string-width": "^1.0.2 || 2" } }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, "wrap-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-3.0.1.tgz", @@ -6403,6 +7114,15 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", diff --git a/package.json b/package.json index 033467a57..205d32f1e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,12 @@ "@babel/preset-env": "^7.4.4", "@types/mocha": "^5.2.6", "@types/node": "^12.0.10", + "@typescript-eslint/eslint-plugin": "^3.8.0", + "@typescript-eslint/parser": "^3.8.0", "chai": "^4.2.0", + "eslint": "^7.6.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.4", "gulp": "^4.0.2", "husky": "^2.2.0", "isomorphic-fetch": "^2.2.1", @@ -34,8 +39,6 @@ "rollup-plugin-commonjs": "^10.0.1", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-terser": "^5.0.0", - "tslint": "^5.16.0", - "tslint-config-prettier": "^1.18.0", "typescript": "^3.4.5", "uglify-es": "^3.3.9" }, @@ -52,7 +55,7 @@ "test:tasks": "tsc --p spec/tsconfig.json && mocha spec/tasks", "test:development": "tsc --p spec/tsconfig.json && mocha spec/development/workload", "test:workload": "tsc --p spec/tsconfig.json && mocha spec/development/workload", - "lint": "tslint --project ./tsconfig-cjs.json -c tslint.json", + "lint": "eslint ./ --quiet", "format:css": "prettier --write \"**/*.css\"", "format:html": "prettier --write \"**/*.html\"", "format:js": "prettier --write \"**/*.js\"", diff --git a/spec/DummyHandlerOptions.ts b/spec/DummyHandlerOptions.ts index 72bab57db..cdf27eb61 100644 --- a/spec/DummyHandlerOptions.ts +++ b/spec/DummyHandlerOptions.ts @@ -31,7 +31,7 @@ export class DummyHandlerOptions implements MiddlewareOptions { * @param {string} dummyString - The dummy string * @returns An instance of DummyHandlerOptions */ - public constructor(dummyString: string = "dummy") { + public constructor(dummyString = "dummy") { this.dummyString = dummyString; } } diff --git a/spec/core/urlParsing.ts b/spec/core/urlParsing.ts index e73dea023..6a1d12611 100644 --- a/spec/core/urlParsing.ts +++ b/spec/core/urlParsing.ts @@ -45,7 +45,7 @@ describe("urlParsing.ts", () => { /* tslint:disable: no-string-literal */ describe("parsePath", () => { for (const path in testCases) { - if (testCases.hasOwnProperty(path)) { + if (Object.prototype.hasOwnProperty.call(testCases, path)) { it("should correctly parse " + path, () => { const request = client.api(path); assert.equal(request["buildFullUrl"](), testCases[path]); diff --git a/spec/middleware/MiddlewareUtil.ts b/spec/middleware/MiddlewareUtil.ts index 9669c59f7..3e0080a91 100644 --- a/spec/middleware/MiddlewareUtil.ts +++ b/spec/middleware/MiddlewareUtil.ts @@ -13,8 +13,8 @@ import { appendRequestHeader, generateUUID, getRequestHeader, setRequestHeader } describe("MiddlewareUtil.ts", async () => { describe("getRequestHeader", () => { - const key: string = "Content-Type"; - const value: string = "application/json"; + const key = "Content-Type"; + const value = "application/json"; const url = "dummy_url"; it("Should get header from request object", () => { const request: Request = new Request(url, { @@ -63,8 +63,8 @@ describe("MiddlewareUtil.ts", async () => { }); describe("setRequestHeader", () => { - const key: string = "Content-Type"; - const value: string = "application/json"; + const key = "Content-Type"; + const value = "application/json"; const url = "dummy_url"; it("Should set header in request object", () => { const request: Request = new Request(url, { @@ -165,9 +165,9 @@ describe("MiddlewareUtil.ts", async () => { }); describe("appendRequestHeader", () => { - const key: string = "Content-Type"; - const value: string = "application/json"; - const firstValue: string = "text/html"; + const key = "Content-Type"; + const value = "application/json"; + const firstValue = "text/html"; const url = "dummy_url"; it("Should set header in request object if the header is not present", () => { const request: Request = new Request(url, { diff --git a/spec/middleware/RetryHandlerOptions.ts b/spec/middleware/RetryHandlerOptions.ts index 4b9cdb99e..fa3f4fa69 100644 --- a/spec/middleware/RetryHandlerOptions.ts +++ b/spec/middleware/RetryHandlerOptions.ts @@ -79,8 +79,8 @@ describe("RetryHandlerOptions.ts", () => { it("Should accept all the given values", () => { try { - const delay: number = 1; - const maxRetries: number = 3; + const delay = 1; + const maxRetries = 3; const shouldRetry: ShouldRetry = (d, a, req, o, res) => { return false; }; diff --git a/src/Client.ts b/src/Client.ts index 0cd9b04c8..a4bce1d88 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -45,7 +45,7 @@ export class Client { public static init(options: Options): Client { const clientOptions: ClientOptions = {}; for (const i in options) { - if (options.hasOwnProperty(i)) { + if (Object.prototype.hasOwnProperty.call(options, i)) { clientOptions[i] = i === "authProvider" ? new CustomAuthenticationProvider(options[i]) : options[i]; } } @@ -80,7 +80,7 @@ export class Client { throw error; } for (const key in clientOptions) { - if (clientOptions.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(clientOptions, key)) { this.config[key] = clientOptions[key]; } } diff --git a/src/GraphError.ts b/src/GraphError.ts index 08dc7bde2..6fde1a2c0 100644 --- a/src/GraphError.ts +++ b/src/GraphError.ts @@ -61,7 +61,7 @@ export class GraphError { * @param {number} [statusCode = -1] - The status code of the error * @returns An instance of GraphError */ - public constructor(statusCode: number = -1) { + public constructor(statusCode = -1) { this.statusCode = statusCode; this.code = null; this.message = null; diff --git a/src/GraphErrorHandler.ts b/src/GraphErrorHandler.ts index e5506663d..c407a8cb1 100644 --- a/src/GraphErrorHandler.ts +++ b/src/GraphErrorHandler.ts @@ -85,7 +85,7 @@ export class GraphErrorHandler { * @param {GraphRequestCallback} [callback] - The graph request callback function * @returns A promise that resolves to GraphError instance */ - public static async getError(error: any = null, statusCode: number = -1, callback?: GraphRequestCallback): Promise { + public static async getError(error: any = null, statusCode = -1, callback?: GraphRequestCallback): Promise { let gError: GraphError; if (error && error.error) { gError = GraphErrorHandler.constructErrorFromResponse(error, statusCode); diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index f7f923fa6..6c24ecf21 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -227,14 +227,14 @@ export class GraphRequest { const query: string[] = []; if (Object.keys(urlComponents.oDataQueryParams).length !== 0) { for (const property in urlComponents.oDataQueryParams) { - if (urlComponents.oDataQueryParams.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(urlComponents.oDataQueryParams, property)) { query.push(property + "=" + urlComponents.oDataQueryParams[property]); } } } if (Object.keys(urlComponents.otherURLQueryParams).length !== 0) { for (const property in urlComponents.otherURLQueryParams) { - if (urlComponents.otherURLQueryParams.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(urlComponents.otherURLQueryParams, property)) { query.push(property + "=" + urlComponents.otherURLQueryParams[property]); } } @@ -270,7 +270,7 @@ export class GraphRequest { } } else if (queryDictionaryOrString.constructor === Object) { for (const key in queryDictionaryOrString) { - if (queryDictionaryOrString.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(queryDictionaryOrString, key)) { this.setURLComponentsQueryParamater(key, queryDictionaryOrString[key]); } } @@ -413,7 +413,7 @@ export class GraphRequest { */ public headers(headers: KeyValuePairObjectStringNumber): GraphRequest { for (const key in headers) { - if (headers.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(headers, key)) { this._headers[key] = headers[key] as string; } } @@ -440,7 +440,7 @@ export class GraphRequest { */ public options(options: { [key: string]: any }): GraphRequest { for (const key in options) { - if (options.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(options, key)) { this._options[key] = options[key]; } } @@ -580,7 +580,7 @@ export class GraphRequest { * @param {boolean} isCount - The count boolean * @returns The same GraphRequest instance that is being called with, after adding the boolean value for the $count query option */ - public count(isCount: boolean = false): GraphRequest { + public count(isCount = false): GraphRequest { this.urlComponents.oDataQueryParams.$count = isCount.toString(); return this; } diff --git a/src/GraphResponseHandler.ts b/src/GraphResponseHandler.ts index 1065ccb8b..223506680 100644 --- a/src/GraphResponseHandler.ts +++ b/src/GraphResponseHandler.ts @@ -101,6 +101,7 @@ export class GraphResponseHandler { return Promise.resolve(); } let responseValue: any; + const contentType = rawResponse.headers.get("Content-type"); try { switch (responseType) { case ResponseType.ARRAYBUFFER: @@ -122,7 +123,6 @@ export class GraphResponseHandler { responseValue = await rawResponse.text(); break; default: - const contentType = rawResponse.headers.get("Content-type"); if (contentType !== null) { const mimeType = contentType.split(";")[0]; if (new RegExp(ContentTypeRegexStr.DOCUMENT).test(mimeType)) { diff --git a/src/ImplicitMSALAuthenticationProvider.ts b/src/ImplicitMSALAuthenticationProvider.ts index 00eb53cb9..39fdc8dfb 100644 --- a/src/ImplicitMSALAuthenticationProvider.ts +++ b/src/ImplicitMSALAuthenticationProvider.ts @@ -9,7 +9,7 @@ * @module ImplicitMSALAuthenticationProvider */ -import { AuthenticationParameters, AuthResponse, InteractionRequiredAuthError, UserAgentApplication } from "msal"; +import { AuthResponse, AuthenticationParameters, InteractionRequiredAuthError, UserAgentApplication } from "msal"; import { AuthenticationProvider } from "./IAuthenticationProvider"; import { AuthenticationProviderOptions } from "./IAuthenticationProviderOptions"; diff --git a/src/Range.ts b/src/Range.ts index f637df4be..bf552c8c9 100644 --- a/src/Range.ts +++ b/src/Range.ts @@ -34,7 +34,7 @@ export class Range { * @param {number} [maxVal = -1] - The maximum value. * @returns An instance of a Range */ - public constructor(minVal: number = -1, maxVal: number = -1) { + public constructor(minVal = -1, maxVal = -1) { this.minValue = minVal; this.maxValue = maxVal; } diff --git a/src/content/BatchRequestContent.ts b/src/content/BatchRequestContent.ts index a767743df..5cb0f53da 100644 --- a/src/content/BatchRequestContent.ts +++ b/src/content/BatchRequestContent.ts @@ -84,7 +84,7 @@ export class BatchRequestContent { * @static * Limit for number of requests {@link - https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching} */ - private static requestLimit: number = 20; + private static requestLimit = 20; /** * @public @@ -227,7 +227,7 @@ export class BatchRequestContent { * @returns The Promise that resolves to a body value of a Request */ private static async getRequestBody(request: IsomorphicRequest): Promise { - let bodyParsed: boolean = false; + let bodyParsed = false; let body; try { const cloneReq = request.clone(); diff --git a/src/middleware/AuthenticationHandler.ts b/src/middleware/AuthenticationHandler.ts index 3275c6092..0eb9e698f 100644 --- a/src/middleware/AuthenticationHandler.ts +++ b/src/middleware/AuthenticationHandler.ts @@ -29,7 +29,7 @@ export class AuthenticationHandler implements Middleware { * @private * A member representing the authorization header name */ - private static AUTHORIZATION_HEADER: string = "Authorization"; + private static AUTHORIZATION_HEADER = "Authorization"; /** * @private @@ -76,7 +76,7 @@ export class AuthenticationHandler implements Middleware { authenticationProvider = this.authenticationProvider; } const token: string = await authenticationProvider.getAccessToken(authenticationProviderOptions); - const bearerKey: string = `Bearer ${token}`; + const bearerKey = `Bearer ${token}`; appendRequestHeader(context.request, context.options, AuthenticationHandler.AUTHORIZATION_HEADER, bearerKey); TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED); return await this.nextMiddleware.execute(context); diff --git a/src/middleware/ChaosHandler.ts b/src/middleware/ChaosHandler.ts index c79252cd0..57f643374 100644 --- a/src/middleware/ChaosHandler.ts +++ b/src/middleware/ChaosHandler.ts @@ -123,16 +123,13 @@ export class ChaosHandler implements Middleware { */ private createResponse(chaosHandlerOptions: ChaosHandlerOptions, context: Context) { try { - let responseBody: any; - let responseHeader: Headers; - let requestID: string; - let requestDate: Date; + const requestID: string = generateUUID(); + const requestDate: Date = new Date(); + const responseBody: any = this.createResponseBody(chaosHandlerOptions.statusCode, chaosHandlerOptions.statusMessage, requestID, requestDate.toString()); + const responseHeader: Headers = this.createResponseHeaders(chaosHandlerOptions.statusCode, requestID, requestDate.toString()); + const requestURL = context.request as string; - requestID = generateUUID(); - requestDate = new Date(); - responseHeader = this.createResponseHeaders(chaosHandlerOptions.statusCode, requestID, requestDate.toString()); - responseBody = this.createResponseBody(chaosHandlerOptions.statusCode, chaosHandlerOptions.statusMessage, requestID, requestDate.toString()); const init: any = { url: requestURL, status: chaosHandlerOptions.statusCode, statusText: chaosHandlerOptions.statusMessage, headers: responseHeader }; context.response = new Response(responseBody, init); } catch (error) { @@ -182,7 +179,7 @@ export class ChaosHandler implements Middleware { * @returns the string as relative URL */ private getRelativeURL(urlMethod: string): string { - const pattern: RegExp = /https?:\/\/graph\.microsoft\.com\/[^/]+(.+?)(\?|$)/; + const pattern = /https?:\/\/graph\.microsoft\.com\/[^/]+(.+?)(\?|$)/; let relativeURL: string; if (pattern.exec(urlMethod) !== null) { relativeURL = pattern.exec(urlMethod)[1]; @@ -212,7 +209,7 @@ export class ChaosHandler implements Middleware { } else { // checking for regex match if exact match doesn't work this.manualMap.forEach((value: Map, key: string) => { - const regexURL: RegExp = new RegExp(key + "$"); + const regexURL = new RegExp(key + "$"); if (regexURL.test(relativeURL)) { if (this.manualMap.get(key).get(requestMethod) !== undefined) { chaosHandlerOptions.statusCode = this.manualMap.get(key).get(requestMethod); diff --git a/src/middleware/MiddlewareUtil.ts b/src/middleware/MiddlewareUtil.ts index f06e22c2c..b346037ca 100644 --- a/src/middleware/MiddlewareUtil.ts +++ b/src/middleware/MiddlewareUtil.ts @@ -17,7 +17,7 @@ import { FetchOptions } from "../IFetchOptions"; * @returns The UUID string */ export const generateUUID = (): string => { - let uuid: string = ""; + let uuid = ""; for (let j = 0; j < 32; j++) { if (j === 8 || j === 12 || j === 16 || j === 20) { uuid += "-"; diff --git a/src/middleware/RedirectHandler.ts b/src/middleware/RedirectHandler.ts index 4bdcc9e39..11c808ac7 100644 --- a/src/middleware/RedirectHandler.ts +++ b/src/middleware/RedirectHandler.ts @@ -43,21 +43,21 @@ export class RedirectHandler implements Middleware { * @static * A member holding SeeOther status code */ - private static STATUS_CODE_SEE_OTHER: number = 303; + private static STATUS_CODE_SEE_OTHER = 303; /** * @private * @static * A member holding the name of the location header */ - private static LOCATION_HEADER: string = "Location"; + private static LOCATION_HEADER = "Location"; /** * @private * @static * A member representing the authorization header name */ - private static AUTHORIZATION_HEADER: string = "Authorization"; + private static AUTHORIZATION_HEADER = "Authorization"; /** * @private @@ -138,7 +138,7 @@ export class RedirectHandler implements Middleware { * @returns A boolean representing whether the authorization header in the request should be dropped for consequent redirected requests */ private shouldDropAuthorizationHeader(requestUrl: string, redirectUrl: string): boolean { - const schemeHostRegex: RegExp = /^[A-Za-z].+?:\/\/.+?(?=\/|$)/; + const schemeHostRegex = /^[A-Za-z].+?:\/\/.+?(?=\/|$)/; const requestMatches: string[] = schemeHostRegex.exec(requestUrl); let requestAuthority: string; let redirectAuthority: string; @@ -224,7 +224,7 @@ export class RedirectHandler implements Middleware { */ public async execute(context: Context): Promise { try { - const redirectCount: number = 0; + const redirectCount = 0; const options = this.getOptions(context); context.options.redirect = RedirectHandler.MANUAL_REDIRECT; TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.REDIRECT_HANDLER_ENABLED); diff --git a/src/middleware/RetryHandler.ts b/src/middleware/RetryHandler.ts index 56b5c22c3..27d57079b 100644 --- a/src/middleware/RetryHandler.ts +++ b/src/middleware/RetryHandler.ts @@ -41,14 +41,14 @@ export class RetryHandler implements Middleware { * @static * A member holding the name of retry attempt header */ - private static RETRY_ATTEMPT_HEADER: string = "Retry-Attempt"; + private static RETRY_ATTEMPT_HEADER = "Retry-Attempt"; /** * @private * @static * A member holding the name of retry after header */ - private static RETRY_AFTER_HEADER: string = "Retry-After"; + private static RETRY_AFTER_HEADER = "Retry-After"; /** * @private @@ -198,7 +198,7 @@ export class RetryHandler implements Middleware { */ public async execute(context: Context): Promise { try { - const retryAttempts: number = 0; + const retryAttempts = 0; const options: RetryHandlerOptions = this.getOptions(context); TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.RETRY_HANDLER_ENABLED); return await this.executeWithRetry(context, retryAttempts, options); diff --git a/src/middleware/TelemetryHandler.ts b/src/middleware/TelemetryHandler.ts index e72d2c187..28b5ce511 100644 --- a/src/middleware/TelemetryHandler.ts +++ b/src/middleware/TelemetryHandler.ts @@ -71,7 +71,7 @@ export class TelemetryHandler implements Middleware { clientRequestId = generateUUID(); setRequestHeader(context.request, context.options, TelemetryHandler.CLIENT_REQUEST_ID_HEADER, clientRequestId); } - let sdkVersionValue: string = `${TelemetryHandler.PRODUCT_NAME}/${PACKAGE_VERSION}`; + let sdkVersionValue = `${TelemetryHandler.PRODUCT_NAME}/${PACKAGE_VERSION}`; let options: TelemetryHandlerOptions; if (context.middlewareControl instanceof MiddlewareControl) { options = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions; diff --git a/src/middleware/options/ChaosHandlerOptions.ts b/src/middleware/options/ChaosHandlerOptions.ts index c74fe76cb..b586ab456 100644 --- a/src/middleware/options/ChaosHandlerOptions.ts +++ b/src/middleware/options/ChaosHandlerOptions.ts @@ -57,7 +57,7 @@ export class ChaosHandlerOptions implements MiddlewareOptions { * @param {string} - The Message to be returned in the response * @returns An instance of ChaosHandlerOptions */ - public constructor(chaosStrategy: ChaosStrategy = ChaosStrategy.RANDOM, statusCode?: number, statusMessage: string = "Some error Happened", chaosPercentage?: number) { + public constructor(chaosStrategy: ChaosStrategy = ChaosStrategy.RANDOM, statusCode?: number, statusMessage = "Some error Happened", chaosPercentage?: number) { this.chaosStrategy = chaosStrategy; this.statusCode = statusCode; this.statusMessage = statusMessage; diff --git a/src/middleware/options/RedirectHandlerOptions.ts b/src/middleware/options/RedirectHandlerOptions.ts index 49f12ae8c..a1becf562 100644 --- a/src/middleware/options/RedirectHandlerOptions.ts +++ b/src/middleware/options/RedirectHandlerOptions.ts @@ -28,14 +28,14 @@ export class RedirectHandlerOptions implements MiddlewareOptions { * @static * A member holding default max redirects value */ - private static DEFAULT_MAX_REDIRECTS: number = 5; + private static DEFAULT_MAX_REDIRECTS = 5; /** * @private * @static * A member holding maximum max redirects value */ - private static MAX_MAX_REDIRECTS: number = 20; + private static MAX_MAX_REDIRECTS = 20; /** * @public diff --git a/src/middleware/options/RetryHandlerOptions.ts b/src/middleware/options/RetryHandlerOptions.ts index cda2fa682..c2458c0d9 100644 --- a/src/middleware/options/RetryHandlerOptions.ts +++ b/src/middleware/options/RetryHandlerOptions.ts @@ -31,28 +31,28 @@ export class RetryHandlerOptions implements MiddlewareOptions { * @static * A member holding default delay value in seconds */ - private static DEFAULT_DELAY: number = 3; + private static DEFAULT_DELAY = 3; /** * @private * @static * A member holding default maxRetries value */ - private static DEFAULT_MAX_RETRIES: number = 3; + private static DEFAULT_MAX_RETRIES = 3; /** * @private * @static * A member holding maximum delay value in seconds */ - private static MAX_DELAY: number = 180; + private static MAX_DELAY = 180; /** * @private * @static * A member holding maximum maxRetries value */ - private static MAX_MAX_RETRIES: number = 10; + private static MAX_MAX_RETRIES = 10; /** * @public diff --git a/src/tasks/OneDriveLargeFileUploadTask.ts b/src/tasks/OneDriveLargeFileUploadTask.ts index 2716f4a22..ecf076109 100644 --- a/src/tasks/OneDriveLargeFileUploadTask.ts +++ b/src/tasks/OneDriveLargeFileUploadTask.ts @@ -37,7 +37,7 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask { * @static * Default path for the file being uploaded */ - private static DEFAULT_UPLOAD_PATH: string = "/"; + private static DEFAULT_UPLOAD_PATH = "/"; /** * @private @@ -93,8 +93,8 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask { const session = await OneDriveLargeFileUploadTask.createUploadSession(client, requestUrl, options.fileName); const rangeSize = getValidRangeSize(options.rangeSize); const fileObj: FileObject = { - name, content, + name, size, }; return new OneDriveLargeFileUploadTask(client, fileObj, session, { diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 8c2e1b5c0..000000000 --- a/tslint.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": ["tslint:latest", "tslint-config-prettier"], - "rules": { - "interface-name": [true, "never-prefix"], - "max-line-length": false, - "no-implicit-dependencies": [true, "dev"], - "object-literal-sort-keys": false, - "ordered-imports": [ - true, - { - "grouped-imports": true - } - ], - "member-ordering": [ - true, - { - "order": ["private-static-field", "protected-static-field", "public-static-field", "private-instance-field", "protected-instance-field", "public-instance-field", "private-static-method", "protected-static-method", "public-static-method", "private-constructor", "protected-constructor", "public-constructor", "private-instance-method", "protected-instance-method", "public-instance-method"] - } - ] - } -} From f0bfec098899b9c6ac332a8ce37a65cebb3b7e47 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sun, 9 Aug 2020 16:44:14 -0700 Subject: [PATCH 02/14] Temporary disabling no-mixed-spaces-and-tabs rule --- .eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 14854563a..2b456ebd1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,6 +12,7 @@ "no-empty-interface": "off", "prefer-rest-params": "off", "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/ban-types": "off" + "@typescript-eslint/ban-types": "off", + "no-mixed-spaces-and-tabs": "off" } } From eed4f73d74e270eec37fa9712920d1a14aba8db8 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sun, 16 Aug 2020 20:08:09 -0700 Subject: [PATCH 03/14] Adding prettier rule in eslint.rc --- .eslintrc.json | 19 ++++++++++++++----- package.json | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2b456ebd1..3c2289cac 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,18 +1,27 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], - "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"], + "plugins": ["@typescript-eslint", "prettier"], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { "max-len": "off", - "sort-imports": ["warn", { "allowSeparatedGroups": true }], - "sort-keys": "warn", + "sort-imports": [ + "off", + { + "allowSeparatedGroups": true + } + ], + "sort-keys": "off", "no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. "no-constant-condition": "off", "no-empty-interface": "off", "prefer-rest-params": "off", "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/ban-types": "off", - "no-mixed-spaces-and-tabs": "off" + "no-mixed-spaces-and-tabs": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "prettier/prettier": "error" } } diff --git a/package.json b/package.json index 205d32f1e..7f99bfe07 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "test:tasks": "tsc --p spec/tsconfig.json && mocha spec/tasks", "test:development": "tsc --p spec/tsconfig.json && mocha spec/development/workload", "test:workload": "tsc --p spec/tsconfig.json && mocha spec/development/workload", - "lint": "eslint ./ --quiet", + "lint": "eslint . --ext .ts", "format:css": "prettier --write \"**/*.css\"", "format:html": "prettier --write \"**/*.html\"", "format:js": "prettier --write \"**/*.js\"", From 16a3ff049ae357406089c9771632524ed46dbdc4 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Tue, 25 Aug 2020 12:46:18 -0700 Subject: [PATCH 04/14] Removing the inline tslint rules --- spec/content/BatchRequestContent.ts | 2 -- spec/core/Client.ts | 2 -- spec/core/GraphErrorHandler.ts | 2 -- spec/core/GraphResponseHandler.ts | 3 +-- spec/core/HTTPClient.ts | 3 --- spec/core/HTTPClientFactory.ts | 2 -- spec/core/urlGeneration.ts | 2 -- spec/core/urlParsing.ts | 2 -- spec/middleware/AuthenticationHandler.ts | 2 -- spec/middleware/ChaosHandler.ts | 1 - spec/middleware/MiddlewareControl.ts | 3 +-- spec/middleware/RedirectHandler.ts | 2 -- spec/middleware/RedirectHandlerOptions.ts | 2 -- spec/middleware/RetryHandler.ts | 3 +-- spec/middleware/RetryHandlerOptions.ts | 2 -- spec/middleware/TelemetryHandler.ts | 2 -- spec/middleware/TelemetryHandlerOptions.ts | 2 -- spec/tasks/LargeFileUploadTask.ts | 2 -- spec/tasks/OneDriveLargeFileUploadTask.ts | 2 -- spec/tasks/PageIterator.ts | 2 -- src/GraphErrorHandler.ts | 2 +- src/GraphRequest.ts | 4 +--- src/HTTPClientFactory.ts | 2 +- src/content/BatchRequestContent.ts | 4 ++-- src/middleware/MiddlewareControl.ts | 4 ---- src/middleware/RetryHandler.ts | 2 -- src/middleware/options/IMiddlewareOptions.ts | 1 - src/middleware/options/TelemetryHandlerOptions.ts | 2 -- 28 files changed, 8 insertions(+), 56 deletions(-) diff --git a/spec/content/BatchRequestContent.ts b/spec/content/BatchRequestContent.ts index 44427a00a..aa7a76d82 100644 --- a/spec/content/BatchRequestContent.ts +++ b/spec/content/BatchRequestContent.ts @@ -419,7 +419,6 @@ describe("BatchRequestContent.ts", () => { }); describe("validateDependencies", () => { - /* tslint:disable: no-string-literal */ it("Should throw error for empty request object", (done) => { try { BatchRequestContent["validateDependencies"](new Map() as Map); @@ -645,6 +644,5 @@ describe("BatchRequestContent.ts", () => { const batchReq = new BatchRequestContent([req1, req2, req3]); assert.equal(false, BatchRequestContent["validateDependencies"](batchReq.requests)); }); - /* tslint:enable: no-string-literal */ }); }); diff --git a/spec/core/Client.ts b/spec/core/Client.ts index 64165e8e7..f4b0ff0bc 100644 --- a/spec/core/Client.ts +++ b/spec/core/Client.ts @@ -16,7 +16,6 @@ import { DummyAuthenticationProvider } from "../DummyAuthenticationProvider"; import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler"; describe("Client.ts", () => { - /* tslint:disable: no-string-literal */ describe("initWithMiddleware", () => { const dummyAuthProvider = new DummyAuthenticationProvider(); const dummyHTTPHandler = new DummyHTTPMessageHandler(); @@ -75,5 +74,4 @@ describe("Client.ts", () => { assert.isDefined(client["httpClient"]); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/core/GraphErrorHandler.ts b/spec/core/GraphErrorHandler.ts index f16ae3ebf..177426848 100644 --- a/spec/core/GraphErrorHandler.ts +++ b/spec/core/GraphErrorHandler.ts @@ -10,7 +10,6 @@ import { assert } from "chai"; import { GraphErrorHandler } from "../../src/GraphErrorHandler"; describe("GraphErrorHandler.ts", () => { - /* tslint:disable: no-string-literal */ describe("constructError", () => { it("Should return custom error without code", () => { const message = "test"; @@ -67,7 +66,6 @@ describe("GraphErrorHandler.ts", () => { assert.equal(gError.date.toUTCString(), date.toUTCString()); }); }); - /* tslint:enable: no-string-literal */ describe("getError", async () => { it("Should construct error from response", async () => { diff --git a/spec/core/GraphResponseHandler.ts b/spec/core/GraphResponseHandler.ts index e5c1a1052..a350af6d6 100644 --- a/spec/core/GraphResponseHandler.ts +++ b/spec/core/GraphResponseHandler.ts @@ -65,7 +65,7 @@ describe("GraphResponseHandler.ts", () => { "Content-Type": "dummy/unknown", }, }; - /* tslint:disable: no-string-literal */ + describe("parseDocumentResponse", () => { it("Should return the html string", async () => { const response = new Response(htmlString, status200); @@ -143,7 +143,6 @@ describe("GraphResponseHandler.ts", () => { assert.equal(responseValue, htmlString); }); }); - /* tslint:enable: no-string-literal */ describe("getResponse", () => { it("Should return a raw response", async () => { diff --git a/spec/core/HTTPClient.ts b/spec/core/HTTPClient.ts index 8c00d9aee..5f6e5fcfb 100644 --- a/spec/core/HTTPClient.ts +++ b/spec/core/HTTPClient.ts @@ -15,15 +15,12 @@ import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler"; describe("HTTPClient.ts", () => { const httpMessageHandler: DummyHTTPMessageHandler = new DummyHTTPMessageHandler(); const httpClient: HTTPClient = new HTTPClient(httpMessageHandler); - /* tslint:disable: no-string-literal */ describe("constructor", () => { it("Should create an instance and populate middleware member", () => { assert.isDefined(httpClient["middleware"]); assert.equal(httpClient["middleware"], httpMessageHandler); }); }); - /* tslint:enable: no-string-literal */ - describe("sendRequest", async () => { it("Should throw error for invalid request options incase if the url and options are passed", async () => { try { diff --git a/spec/core/HTTPClientFactory.ts b/spec/core/HTTPClientFactory.ts index 5c07cddf9..2c8b6e67e 100644 --- a/spec/core/HTTPClientFactory.ts +++ b/spec/core/HTTPClientFactory.ts @@ -13,7 +13,6 @@ import { DummyAuthenticationProvider } from "../DummyAuthenticationProvider"; import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler"; describe("HTTPClientFactory.ts", () => { - /* tslint:disable: no-string-literal */ describe("createWithAuthenticationProvider", () => { const dummyAuthProvider = new DummyAuthenticationProvider(); const dummyHTTPHandler = new DummyHTTPMessageHandler(); @@ -29,5 +28,4 @@ describe("HTTPClientFactory.ts", () => { assert.isDefined(client["middleware"]); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/core/urlGeneration.ts b/spec/core/urlGeneration.ts index 74ca64ce6..6ce052fce 100644 --- a/spec/core/urlGeneration.ts +++ b/spec/core/urlGeneration.ts @@ -153,7 +153,6 @@ cases.push({ }); describe("urlGeneration.ts", () => { - /* tslint:disable: no-string-literal */ describe("buildFullUrl", () => { for (const testCase of cases) { it("should correctly build " + testCase.url, () => { @@ -161,5 +160,4 @@ describe("urlGeneration.ts", () => { }); } }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/core/urlParsing.ts b/spec/core/urlParsing.ts index 6a1d12611..669f0242f 100644 --- a/spec/core/urlParsing.ts +++ b/spec/core/urlParsing.ts @@ -42,7 +42,6 @@ const testCases = { }; describe("urlParsing.ts", () => { - /* tslint:disable: no-string-literal */ describe("parsePath", () => { for (const path in testCases) { if (Object.prototype.hasOwnProperty.call(testCases, path)) { @@ -54,4 +53,3 @@ describe("urlParsing.ts", () => { } }); }); -/* tslint:enable: no-string-literal */ diff --git a/spec/middleware/AuthenticationHandler.ts b/spec/middleware/AuthenticationHandler.ts index 8b445f6cc..28bf769cf 100644 --- a/spec/middleware/AuthenticationHandler.ts +++ b/spec/middleware/AuthenticationHandler.ts @@ -14,12 +14,10 @@ const dummyAuthProvider = new DummyAuthenticationProvider(); const authHandler = new AuthenticationHandler(dummyAuthProvider); describe("AuthenticationHandler.ts", async () => { - /* tslint:disable: no-string-literal */ describe("Constructor", () => { it("Should return an AuthenticationHandler for given AuthenticationProvider", () => { assert.isTrue(authHandler instanceof AuthenticationHandler); assert.equal(authHandler["authenticationProvider"], dummyAuthProvider); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/middleware/ChaosHandler.ts b/spec/middleware/ChaosHandler.ts index 8e6f605aa..4d340b572 100644 --- a/spec/middleware/ChaosHandler.ts +++ b/spec/middleware/ChaosHandler.ts @@ -12,7 +12,6 @@ const chaosHandlerOptions = new ChaosHandlerOptions(); const chaosHandler = new ChaosHandler(); describe("ChaosHandler.ts", () => { - /* tslint:disable: no-string-literal */ describe("constructor", () => { it("Should create an instance with given options", () => { const handler = new ChaosHandler(chaosHandlerOptions); diff --git a/spec/middleware/MiddlewareControl.ts b/spec/middleware/MiddlewareControl.ts index ff9cb64bd..6103c8898 100644 --- a/spec/middleware/MiddlewareControl.ts +++ b/spec/middleware/MiddlewareControl.ts @@ -17,7 +17,7 @@ import { DummyHandlerOptions } from "../DummyHandlerOptions"; describe("MiddlewareControl.ts", () => { const dummyHandlerOption = new DummyHandlerOptions(); - /* tslint:disable: no-string-literal */ + describe("constructor", () => { it("Should populate its middleware options map", () => { const middlewareControl = new MiddlewareControl([dummyHandlerOption]); @@ -31,7 +31,6 @@ describe("MiddlewareControl.ts", () => { assert.equal(middlewareControl["middlewareOptions"].size, 0); }); }); - /* tslint:enable: no-string-literal */ describe("getMiddlewareOption", () => { it("Should return the middleware option for a given class name", () => { diff --git a/spec/middleware/RedirectHandler.ts b/spec/middleware/RedirectHandler.ts index 4099e16fa..0b6f33481 100644 --- a/spec/middleware/RedirectHandler.ts +++ b/spec/middleware/RedirectHandler.ts @@ -16,7 +16,6 @@ import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler"; const redirectHandlerOptions = new RedirectHandlerOptions(); const redirectHandler = new RedirectHandler(); describe("RedirectHandler.ts", () => { - /* tslint:disable: no-string-literal */ describe("constructor", () => { it("Should create an instance with given options", () => { const handler = new RedirectHandler(redirectHandlerOptions); @@ -340,5 +339,4 @@ describe("RedirectHandler.ts", () => { assert.equal(context.options.redirect, RedirectHandler["MANUAL_REDIRECT"]); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/middleware/RedirectHandlerOptions.ts b/spec/middleware/RedirectHandlerOptions.ts index 05cad5b1e..7d7afe015 100644 --- a/spec/middleware/RedirectHandlerOptions.ts +++ b/spec/middleware/RedirectHandlerOptions.ts @@ -41,12 +41,10 @@ describe("RedirectHandlerOptions.ts", () => { } }); - /* tslint:disable: no-string-literal */ it("Should initialize instance with default options", () => { const options = new RedirectHandlerOptions(); assert.equal(options.maxRedirects, RedirectHandlerOptions["DEFAULT_MAX_REDIRECTS"]); assert.equal(options.shouldRedirect, RedirectHandlerOptions["DEFAULT_SHOULD_RETRY"]); }); - /* tslint:enable: no-string-literal */ }); }); diff --git a/spec/middleware/RetryHandler.ts b/spec/middleware/RetryHandler.ts index bd3396ad3..decb7a747 100644 --- a/spec/middleware/RetryHandler.ts +++ b/spec/middleware/RetryHandler.ts @@ -45,7 +45,7 @@ describe("RetryHandler.ts", function() { status: 200, statusText: "OK", }); - /* tslint:disable: no-string-literal */ + describe("constructor", () => { it("Should set the option member with retryHanderOptions", () => { const handler = new RetryHandler(retryHandlerOptions); @@ -235,5 +235,4 @@ describe("RetryHandler.ts", function() { assert.equal(cxt.response.status, 429); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/middleware/RetryHandlerOptions.ts b/spec/middleware/RetryHandlerOptions.ts index fa3f4fa69..b8addf15d 100644 --- a/spec/middleware/RetryHandlerOptions.ts +++ b/spec/middleware/RetryHandlerOptions.ts @@ -10,7 +10,6 @@ import { assert } from "chai"; import { RetryHandlerOptions, ShouldRetry } from "../../src/middleware/options/RetryHandlerOptions"; describe("RetryHandlerOptions.ts", () => { - /* tslint:disable: no-string-literal */ describe("Constructor", () => { it("Should use default values if not given", () => { try { @@ -100,5 +99,4 @@ describe("RetryHandlerOptions.ts", () => { assert.equal(options.getMaxDelay(), RetryHandlerOptions["MAX_DELAY"]); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/middleware/TelemetryHandler.ts b/spec/middleware/TelemetryHandler.ts index 81f5c7809..831d16722 100644 --- a/spec/middleware/TelemetryHandler.ts +++ b/spec/middleware/TelemetryHandler.ts @@ -15,7 +15,6 @@ import { PACKAGE_VERSION } from "../../src/Version"; import { DummyHTTPMessageHandler } from "../DummyHTTPMessageHandler"; describe("TelemetryHandler.ts", () => { - /* tslint:disable: no-string-literal */ describe("execute", function() { this.timeout(20 * 1000); const telemetryHandler = new TelemetryHandler(); @@ -101,5 +100,4 @@ describe("TelemetryHandler.ts", () => { } }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/middleware/TelemetryHandlerOptions.ts b/spec/middleware/TelemetryHandlerOptions.ts index 8cdb01516..733f28a56 100644 --- a/spec/middleware/TelemetryHandlerOptions.ts +++ b/spec/middleware/TelemetryHandlerOptions.ts @@ -12,7 +12,6 @@ import { MiddlewareControl } from "../../src/middleware/MiddlewareControl"; import { FeatureUsageFlag, TelemetryHandlerOptions } from "../../src/middleware/options/TelemetryHandlerOptions"; describe("TelemetryHandlerOptions.ts", () => { - /* tslint:disable: no-string-literal no-bitwise */ describe("constructor", () => { it("Should initialize the feature usage flag with NONE flag", () => { const telemetryOptions = new TelemetryHandlerOptions(); @@ -71,5 +70,4 @@ describe("TelemetryHandlerOptions.ts", () => { assert.equal(usageFlag, "6"); }); }); - /* tslint:enable: no-string-literal no-bitwise*/ }); diff --git a/spec/tasks/LargeFileUploadTask.ts b/spec/tasks/LargeFileUploadTask.ts index e442fd0a1..a7332cedc 100644 --- a/spec/tasks/LargeFileUploadTask.ts +++ b/spec/tasks/LargeFileUploadTask.ts @@ -11,7 +11,6 @@ import { LargeFileUploadTask } from "../../src/tasks/LargeFileUploadTask"; import { getClient } from "../test-helper"; describe("LargeFileUploadTask.ts", () => { - /* tslint:disable: no-string-literal */ describe("Parsing Range", () => { const name = "sample_image.jpg"; const arrayBuffer = new ArrayBuffer(80000); @@ -177,5 +176,4 @@ describe("LargeFileUploadTask.ts", () => { }); }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/spec/tasks/OneDriveLargeFileUploadTask.ts b/spec/tasks/OneDriveLargeFileUploadTask.ts index 10ec90f54..2d2290c2f 100644 --- a/spec/tasks/OneDriveLargeFileUploadTask.ts +++ b/spec/tasks/OneDriveLargeFileUploadTask.ts @@ -16,7 +16,6 @@ describe("OneDriveLargeFileUploadTask.ts", () => { const specialFileName = "test file.png"; const encodedFileName = "test%20file.png"; - /* tslint:disable: no-string-literal */ it("Should trim the extra spaces in the filename", () => { assert.equal(`/me/drive/root:/${fileName}:/createUploadSession`, OneDriveLargeFileUploadTask["constructCreateSessionUrl"](spaceFileName)); }); @@ -44,6 +43,5 @@ describe("OneDriveLargeFileUploadTask.ts", () => { it("Should trim the extra spaces in the path", () => { assert.equal(`/me/drive/root:/Documents/${fileName}:/createUploadSession`, OneDriveLargeFileUploadTask["constructCreateSessionUrl"](fileName, " /Documents/ ")); }); - /* tslint:enable: no-string-literal */ }); }); diff --git a/spec/tasks/PageIterator.ts b/spec/tasks/PageIterator.ts index db454c66e..beaebb81f 100644 --- a/spec/tasks/PageIterator.ts +++ b/spec/tasks/PageIterator.ts @@ -104,7 +104,6 @@ describe("PageIterator.ts", () => { }); }); - /* tslint:disable: no-string-literal */ describe("iterationHelper", () => { it("Should return true for empty collection with next link", () => { const pageIterator = new PageIterator(client, getEmptyPageCollectionWithNext(), truthyCallback); @@ -154,5 +153,4 @@ describe("PageIterator.ts", () => { } }); }); - /* tslint:enable: no-string-literal */ }); diff --git a/src/GraphErrorHandler.ts b/src/GraphErrorHandler.ts index c407a8cb1..3c000da71 100644 --- a/src/GraphErrorHandler.ts +++ b/src/GraphErrorHandler.ts @@ -70,7 +70,7 @@ export class GraphErrorHandler { try { gError.body = JSON.stringify(error); } catch (error) { - // tslint:disable-line: no-empty + // TODO- Handle empty catches } return gError; } diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index fc9d71195..189732be0 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -74,7 +74,6 @@ export class GraphRequest { */ private urlComponents: URLComponents; - /* tslint:disable: variable-name */ /** * @private * A member to hold custom header options for a request @@ -100,7 +99,6 @@ export class GraphRequest { * A member to hold custom response type for a request */ private _responseType: ResponseType; - /* tslint:enable: variable-name */ /** * @public @@ -210,7 +208,7 @@ export class GraphRequest { const url = urlJoin([this.urlComponents.host, this.urlComponents.version, this.urlComponents.path]) + this.createQueryString(); if (this.config.debugLogging) { - console.log(url); // tslint:disable-line: no-console + console.log(url); } return url; } diff --git a/src/HTTPClientFactory.ts b/src/HTTPClientFactory.ts index 673b90dbe..cabda2924 100644 --- a/src/HTTPClientFactory.ts +++ b/src/HTTPClientFactory.ts @@ -26,7 +26,7 @@ import { TelemetryHandler } from "./middleware/TelemetryHandler"; * @returns A boolean representing the environment is node or not */ const isNodeEnvironment = (): boolean => { - return new Function("try {return this === global;}catch(e){return false;}")(); // tslint:disable-line: function-constructor + return new Function("try {return this === global;}catch(e){return false;}")(); }; /** diff --git a/src/content/BatchRequestContent.ts b/src/content/BatchRequestContent.ts index 5cb0f53da..8e94b3b2e 100644 --- a/src/content/BatchRequestContent.ts +++ b/src/content/BatchRequestContent.ts @@ -234,7 +234,7 @@ export class BatchRequestContent { body = await cloneReq.json(); bodyParsed = true; } catch (e) { - // tslint:disable-line: no-empty + //TODO- Handle empty catches } if (!bodyParsed) { try { @@ -269,7 +269,7 @@ export class BatchRequestContent { } bodyParsed = true; } catch (e) { - // tslint:disable-line: no-empty + // TODO-Handle empty catches } } return body; diff --git a/src/middleware/MiddlewareControl.ts b/src/middleware/MiddlewareControl.ts index 857d9dc3e..93ab7ad9c 100644 --- a/src/middleware/MiddlewareControl.ts +++ b/src/middleware/MiddlewareControl.ts @@ -20,7 +20,6 @@ export class MiddlewareControl { * @private * A member holding map of MiddlewareOptions */ - // tslint:disable-next-line:ban-types private middlewareOptions: Map; /** @@ -31,7 +30,6 @@ export class MiddlewareControl { * @returns The instance of MiddlewareControl */ public constructor(middlewareOptions: MiddlewareOptions[] = []) { - // tslint:disable-next-line:ban-types this.middlewareOptions = new Map(); for (const option of middlewareOptions) { const fn = option.constructor; @@ -49,7 +47,6 @@ export class MiddlewareControl { * // call this function like this: * getMiddlewareOptions(MiddlewareControl) */ - // tslint:disable-next-line:ban-types public getMiddlewareOptions(fn: Function): MiddlewareOptions { return this.middlewareOptions.get(fn); } @@ -61,7 +58,6 @@ export class MiddlewareControl { * @param {MiddlewareOptions} option - The strongly typed middleware option * @returns nothing */ - // tslint:disable-next-line:ban-types public setMiddlewareOptions(fn: Function, option: MiddlewareOptions): void { this.middlewareOptions.set(fn, option); } diff --git a/src/middleware/RetryHandler.ts b/src/middleware/RetryHandler.ts index 27d57079b..fadb122ec 100644 --- a/src/middleware/RetryHandler.ts +++ b/src/middleware/RetryHandler.ts @@ -116,13 +116,11 @@ export class RetryHandler implements Middleware { const retryAfter = response.headers !== undefined ? response.headers.get(RetryHandler.RETRY_AFTER_HEADER) : null; let newDelay: number; if (retryAfter !== null) { - // tslint:disable: prefer-conditional-expression if (Number.isNaN(Number(retryAfter))) { newDelay = Math.round((new Date(retryAfter).getTime() - Date.now()) / 1000); } else { newDelay = Number(retryAfter); } - // tslint:enable: prefer-conditional-expression } else { // Adding randomness to avoid retrying at a same newDelay = retryAttempts >= 2 ? this.getExponentialBackOffTime(retryAttempts) + delay + getRandomness() : delay + getRandomness(); diff --git a/src/middleware/options/IMiddlewareOptions.ts b/src/middleware/options/IMiddlewareOptions.ts index 652560810..69de93cc1 100644 --- a/src/middleware/options/IMiddlewareOptions.ts +++ b/src/middleware/options/IMiddlewareOptions.ts @@ -10,5 +10,4 @@ * Signature representing the middleware options */ -/* tslint:disable: no-empty-interface */ export interface MiddlewareOptions {} diff --git a/src/middleware/options/TelemetryHandlerOptions.ts b/src/middleware/options/TelemetryHandlerOptions.ts index 96e5f2412..9d366eae7 100644 --- a/src/middleware/options/TelemetryHandlerOptions.ts +++ b/src/middleware/options/TelemetryHandlerOptions.ts @@ -70,9 +70,7 @@ export class TelemetryHandlerOptions implements MiddlewareOptions { * @returns nothing */ private setFeatureUsage(flag: FeatureUsageFlag): void { - /* tslint:disable: no-bitwise */ this.featureUsage = this.featureUsage | flag; - /* tslint:enable: no-bitwise */ } /** From 7a01c600fa7983ec5a10534e315b3204455277f1 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Tue, 25 Aug 2020 12:52:10 -0700 Subject: [PATCH 05/14] Added period --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9dd15dce2..caa84b078 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -116,7 +116,7 @@ To edit files, open them in an editor of your choice and modify them. To create _Note: Make sure to add unit tests to validate you changes._ -Once you have done with your changes, You have to build and test your changes To build the library run, +Once you have done with your changes, You have to build and test your changes. To build the library run, ```cmd npm run build From 7a631d1486a3ca88efcee31e49c90261ef89c8b3 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sat, 19 Sep 2020 01:49:03 -0700 Subject: [PATCH 06/14] More rules --- .eslintrc.json | 197 ++++++++++++++++-- spec/content/BatchRequestContent.ts | 4 + spec/core/Client.ts | 3 +- spec/core/GraphResponseHandler.ts | 14 +- spec/middleware/RedirectHandler.ts | 7 - spec/middleware/RedirectHandlerOptions.ts | 4 +- spec/middleware/RetryHandler.ts | 2 +- spec/middleware/RetryHandlerOptions.ts | 9 +- spec/tasks/LargeFileUploadTask.ts | 2 +- spec/tasks/PageIterator.ts | 2 + src/GraphRequest.ts | 4 +- .../options/RedirectHandlerOptions.ts | 4 +- src/middleware/options/RetryHandlerOptions.ts | 4 +- .../options/TelemetryHandlerOptions.ts | 9 +- 14 files changed, 223 insertions(+), 42 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3c2289cac..dc5a5c810 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,24 +4,195 @@ "plugins": ["@typescript-eslint", "prettier"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { - "max-len": "off", - "sort-imports": [ - "off", - { - "allowSeparatedGroups": true - } - ], - "sort-keys": "off", "no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. - "no-constant-condition": "off", - "no-empty-interface": "off", "prefer-rest-params": "off", + "no-constant-condition": "off", + // @typescript-eslint rules "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/ban-types": "off", - "no-mixed-spaces-and-tabs": "off", - "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "error", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/explicit-module-boundary-types": "off", - "prettier/prettier": "error" + "prettier/prettier": "error", + "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "typeLike", + "format": ["PascalCase"], + "filter": { + "regex": "^(__String|[A-Za-z]+_[A-Za-z]+)$", + "match": false + } + }, + { + "selector": "interface", + "format": ["PascalCase"], + "custom": { + "regex": "^I[A-Z]", + "match": false + }, + "filter": { + "regex": "^I(Arguments|TextWriter|O([A-Z][a-z]+[A-Za-z]*)?)$", + "match": false + } + }, + { + "selector": "variable", + "format": ["camelCase", "PascalCase", "UPPER_CASE"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^(_{1,2}filename|_{1,2}dirname|_+|[A-Za-z]+_[A-Za-z]+)$", + "match": false + } + }, + { + "selector": "function", + "format": ["camelCase", "PascalCase"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^[A-Za-z]+_[A-Za-z]+$", + "match": false + } + }, + { + "selector": "parameter", + "format": ["camelCase"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^(_+|[A-Za-z]+_[A-Z][a-z]+)$", + "match": false + } + }, + { + "selector": "method", + "format": ["camelCase", "PascalCase"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^[A-Za-z]+_[A-Za-z]+$", + "match": false + } + }, + { + "selector": "memberLike", + "format": ["camelCase"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^[A-Za-z]+_[A-Za-z]+$", + "match": false + } + }, + { + "selector": "enumMember", + "format": ["camelCase", "PascalCase"], + "leadingUnderscore": "allow", + "filter": { + "regex": "^[A-Za-z]+_[A-Za-z]+$", + "match": false + } + }, + { + "selector": "property", + "format": null + } + ], + "@typescript-eslint/semi": "error", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/prefer-for-of": "error", + "@typescript-eslint/prefer-function-type": "error", + "@typescript-eslint/prefer-namespace-keyword": "error", + "@typescript-eslint/quotes": [ + "error", + "double", + { + "avoidEscape": true, + "allowTemplateLiterals": true + } + ], + "@typescript-eslint/space-within-parens": ["off", "never"], + "@typescript-eslint/triple-slash-reference": "error", + "@typescript-eslint/type-annotation-spacing": "error", + "@typescript-eslint/unified-signatures": "error", + "@typescript-eslint/adjacent-overload-signatures": "error", + "@typescript-eslint/array-type": "error", + "@typescript-eslint/consistent-type-definitions": ["error", "interface"], + "@typescript-eslint/no-inferrable-types": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-this-alias": "error", + "no-unused-expressions": "off", + "@typescript-eslint/no-unused-expressions": [ + "error", + { + "allowTernary": true + } + ], + "@typescript-eslint/space-before-function-paren": [ + "error", + { + "asyncArrow": "always", + "anonymous": "never", + "named": "never" + } + ], + "@typescript-eslint/consistent-type-assertions": "error", + "@typescript-eslint/explicit-member-accessibility": [ + "off", + { + "accessibility": "explicit" + } + ], + "@typescript-eslint/indent": "off", + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/member-delimiter-style": [ + "off", + { + "multiline": { + "delimiter": "none", + "requireLast": true + }, + "singleline": { + "delimiter": "semi", + "requireLast": false + } + } + ], + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/no-empty-function": "error", + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-parameter-properties": "off", + // eslint + // eslint + "brace-style": "off", + "constructor-super": "error", + "curly": ["error", "multi-line"], + "dot-notation": "off", + "eqeqeq": "error", + "new-parens": "error", + "no-caller": "error", + "no-duplicate-case": "error", + "no-duplicate-imports": "error", + "no-empty": "error", + "no-eval": "error", + "no-extra-bind": "error", + "no-fallthrough": "error", + "no-new-func": "off", + "no-new-wrappers": "error", + "no-return-await": "error", + "no-sparse-arrays": "error", + "no-template-curly-in-string": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef-init": "error", + "no-unsafe-finally": "error", + "no-unused-labels": "error", + "no-var": "error", + "object-shorthand": "error", + "prefer-const": "error", + "prefer-object-spread": "error", + "quote-props": "off", + "space-in-parens": "error", + "unicode-bom": ["error", "never"], + "use-isnan": "error" } } diff --git a/spec/content/BatchRequestContent.ts b/spec/content/BatchRequestContent.ts index aa7a76d82..2891240eb 100644 --- a/spec/content/BatchRequestContent.ts +++ b/spec/content/BatchRequestContent.ts @@ -71,6 +71,7 @@ describe("BatchRequestContent.ts", () => { const createFolderDuplicate1 = getCreateFolderRequestCopy(); createFolderDuplicate1.id = ""; try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const batchReq = new BatchRequestContent([createFolderDuplicate1]); throw new Error("Something wrong with the empty id check"); } catch (error) { @@ -87,6 +88,7 @@ describe("BatchRequestContent.ts", () => { requests.push(req); } try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const batchReq = new BatchRequestContent(requests); throw new Error("Something wrong with the limiting requests"); } catch (error) { @@ -296,6 +298,7 @@ describe("BatchRequestContent.ts", () => { it("Should return error for empty requests", async () => { const batchReq = new BatchRequestContent(); try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const content = await batchReq.getContent(); throw new Error("Something wrong with the empty requests validation"); } catch (error) { @@ -354,6 +357,7 @@ describe("BatchRequestContent.ts", () => { }, ]); try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const content = await batchReq.getContent(); throw new Error("Something wrong with the header checking"); } catch (error) { diff --git a/spec/core/Client.ts b/spec/core/Client.ts index f4b0ff0bc..3b1832ee4 100644 --- a/spec/core/Client.ts +++ b/spec/core/Client.ts @@ -26,6 +26,7 @@ describe("Client.ts", () => { authProvider: dummyAuthProvider, middleware: dummyHTTPHandler, }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const client: Client = Client.initWithMiddleware(options); throw new Error("Something wrong with the ambiguity check"); } catch (error) { @@ -39,7 +40,7 @@ describe("Client.ts", () => { }; const client: Client = Client.initWithMiddleware(options); assert.isTrue(client instanceof Client); - assert.isDefined(client["httpClient"]); + assert.isDefined(["httpClient"]); }); it("Should return client instance for a custom middleware chain", () => { diff --git a/spec/core/GraphResponseHandler.ts b/spec/core/GraphResponseHandler.ts index a350af6d6..d133a497a 100644 --- a/spec/core/GraphResponseHandler.ts +++ b/spec/core/GraphResponseHandler.ts @@ -51,13 +51,7 @@ describe("GraphResponseHandler.ts", () => { "Content-Type": "application/json", }, }; - const status200Image = { - status: 200, - stautsText: "OK", - headers: { - "Content-Type": "image/jpeg", - }, - }; + const status200Unknown = { status: 200, statusText: "OK", @@ -82,6 +76,12 @@ describe("GraphResponseHandler.ts", () => { assert.isUndefined(responseValue); }); + it("Should return internal server error (500 response)", async () => { + const response = new Response(undefined, status500); + const responseValue = await GraphResponseHandler["convertResponse"](response); + assert.isUndefined(responseValue); + }); + it("Should return empty text value for empty response", async () => { const response = new Response(undefined, status202); const responseValue = await GraphResponseHandler["convertResponse"](response); diff --git a/spec/middleware/RedirectHandler.ts b/spec/middleware/RedirectHandler.ts index 0b6f33481..118640494 100644 --- a/spec/middleware/RedirectHandler.ts +++ b/spec/middleware/RedirectHandler.ts @@ -226,13 +226,6 @@ describe("RedirectHandler.ts", () => { it("Should drop body and change method to get for SEE_OTHER status code", async () => { const options = new RedirectHandlerOptions(); - const cxt: Context = { - request: "/me", - options: { - method: "POST", - body: "dummy body", - }, - }; dummyHTTPHandler.setResponses([ new Response("", { status: 303, diff --git a/spec/middleware/RedirectHandlerOptions.ts b/spec/middleware/RedirectHandlerOptions.ts index 7d7afe015..a7ff38cbf 100644 --- a/spec/middleware/RedirectHandlerOptions.ts +++ b/spec/middleware/RedirectHandlerOptions.ts @@ -26,6 +26,7 @@ describe("RedirectHandlerOptions.ts", () => { it("Should throw error for setting max redirects more than allowed", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RedirectHandlerOptions(100); throw new Error("Something wrong with the max redirects value redirection"); } catch (error) { @@ -34,6 +35,7 @@ describe("RedirectHandlerOptions.ts", () => { }); it("Should throw error for setting max redirects to negative", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RedirectHandlerOptions(-10); throw new Error("Something wrong with the max redirects value redirection"); } catch (error) { @@ -44,7 +46,7 @@ describe("RedirectHandlerOptions.ts", () => { it("Should initialize instance with default options", () => { const options = new RedirectHandlerOptions(); assert.equal(options.maxRedirects, RedirectHandlerOptions["DEFAULT_MAX_REDIRECTS"]); - assert.equal(options.shouldRedirect, RedirectHandlerOptions["DEFAULT_SHOULD_RETRY"]); + assert.equal(options.shouldRedirect, RedirectHandlerOptions["defaultShouldRetry"]); }); }); }); diff --git a/spec/middleware/RetryHandler.ts b/spec/middleware/RetryHandler.ts index decb7a747..7ba3c06d0 100644 --- a/spec/middleware/RetryHandler.ts +++ b/spec/middleware/RetryHandler.ts @@ -224,7 +224,7 @@ describe("RetryHandler.ts", function() { it("Should successfully retry and return ok response", async () => { const opts = new RetryHandlerOptions(1); dummyHTTPHandler.setResponses([new Response(null, { status: 429 }), new Response(null, { status: 429 }), new Response("ok", { status: 200 })]); - await handler["executeWithRetry"](cxt, 0, options); + await handler["executeWithRetry"](cxt, 0, opts); assert.equal(cxt.response.status, 200); }); diff --git a/spec/middleware/RetryHandlerOptions.ts b/spec/middleware/RetryHandlerOptions.ts index b8addf15d..bea98525c 100644 --- a/spec/middleware/RetryHandlerOptions.ts +++ b/spec/middleware/RetryHandlerOptions.ts @@ -16,7 +16,7 @@ describe("RetryHandlerOptions.ts", () => { const options = new RetryHandlerOptions(); assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]); assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]); - assert.equal(options["shouldRetry"], RetryHandlerOptions["DEFAULT_SHOULD_RETRY"]); + assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]); } catch (error) { throw error; } @@ -24,6 +24,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for both delay and maxRetries are higher than the limit", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(1000, 1000); throw new Error("Something wrong with the delay and maxRetries max limit validation"); } catch (error) { @@ -33,6 +34,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for delay is higher than the limit", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(1000, 2); throw new Error("Something wrong with the delay max limit validation"); } catch (error) { @@ -42,6 +44,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for maxRetries is higher than the limit", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(1, 2000); throw new Error("Something wrong with the maxRetries max limit validation"); } catch (error) { @@ -51,6 +54,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for both delay and maxRetries are negative", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(-1, -100); throw new Error("Something wrong with the delay and maxRetries max limit validation"); } catch (error) { @@ -60,6 +64,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for delay is negative", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(-5, 2); throw new Error("Something wrong with the delay max limit validation"); } catch (error) { @@ -69,6 +74,7 @@ describe("RetryHandlerOptions.ts", () => { it("Should throw error for maxRetries is negative", () => { try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const options = new RetryHandlerOptions(1, -10); throw new Error("Something wrong with the maxRetries max limit validation"); } catch (error) { @@ -80,6 +86,7 @@ describe("RetryHandlerOptions.ts", () => { try { const delay = 1; const maxRetries = 3; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const shouldRetry: ShouldRetry = (d, a, req, o, res) => { return false; }; diff --git a/spec/tasks/LargeFileUploadTask.ts b/spec/tasks/LargeFileUploadTask.ts index a7332cedc..3ce15094b 100644 --- a/spec/tasks/LargeFileUploadTask.ts +++ b/spec/tasks/LargeFileUploadTask.ts @@ -166,7 +166,7 @@ describe("LargeFileUploadTask.ts", () => { uploadTask["updateTaskStatus"](statusResponse); uploadTask .upload() - .then((res) => { + .then(() => { throw new Error("Upload is working for upload completed task"); }) .catch((err) => { diff --git a/spec/tasks/PageIterator.ts b/spec/tasks/PageIterator.ts index beaebb81f..6aec0d924 100644 --- a/spec/tasks/PageIterator.ts +++ b/spec/tasks/PageIterator.ts @@ -43,11 +43,13 @@ const getEmptyPageCollectionWithNext = () => { }; }; +// eslint-disable-next-line @typescript-eslint/no-unused-vars const truthyCallback: PageIteratorCallback = (data) => { return true; }; let halfWayCallbackCounter = 5; +// eslint-disable-next-line @typescript-eslint/no-unused-vars const halfWayCallback: PageIteratorCallback = (data) => { halfWayCallbackCounter--; if (halfWayCallbackCounter === 0) { diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index 189732be0..c996d27dc 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -272,7 +272,7 @@ export class GraphRequest { } } } else { - /*Push values which are not of key-value structure. + /*Push values which are not of key-value structure. Example-> Handle an invalid input->.query(123) and let the Graph API respond with the error in the URL*/ this.urlComponents.otherURLQueryOptions.push(queryDictionaryOrString); } @@ -294,7 +294,7 @@ export class GraphRequest { const paramValue = queryParameter.substring(indexOfFirstEquals + 1, queryParameter.length); this.setURLComponentsQueryParamater(paramKey, paramValue); } else { - /* Push values which are not of key-value structure. + /* Push values which are not of key-value structure. Example-> Handle an invalid input->.query(test), .query($select($select=name)) and let the Graph API respond with the error in the URL*/ this.urlComponents.otherURLQueryOptions.push(queryParameter); } diff --git a/src/middleware/options/RedirectHandlerOptions.ts b/src/middleware/options/RedirectHandlerOptions.ts index a1becf562..7488dc878 100644 --- a/src/middleware/options/RedirectHandlerOptions.ts +++ b/src/middleware/options/RedirectHandlerOptions.ts @@ -53,7 +53,7 @@ export class RedirectHandlerOptions implements MiddlewareOptions { * @private * A member holding default shouldRedirect callback */ - private static DEFAULT_SHOULD_RETRY: ShouldRedirect = () => true; + private static defaultShouldRetry: ShouldRedirect = () => true; /** * @public @@ -63,7 +63,7 @@ export class RedirectHandlerOptions implements MiddlewareOptions { * @param {ShouldRedirect} [shouldRedirect = RedirectHandlerOptions.DEFAULT_SHOULD_RETRY] - The should redirect callback * @returns An instance of RedirectHandlerOptions */ - public constructor(maxRedirects: number = RedirectHandlerOptions.DEFAULT_MAX_REDIRECTS, shouldRedirect: ShouldRedirect = RedirectHandlerOptions.DEFAULT_SHOULD_RETRY) { + public constructor(maxRedirects: number = RedirectHandlerOptions.DEFAULT_MAX_REDIRECTS, shouldRedirect: ShouldRedirect = RedirectHandlerOptions.defaultShouldRetry) { if (maxRedirects > RedirectHandlerOptions.MAX_MAX_REDIRECTS) { const error = new Error(`MaxRedirects should not be more than ${RedirectHandlerOptions.MAX_MAX_REDIRECTS}`); error.name = "MaxLimitExceeded"; diff --git a/src/middleware/options/RetryHandlerOptions.ts b/src/middleware/options/RetryHandlerOptions.ts index c2458c0d9..8e9ff1503 100644 --- a/src/middleware/options/RetryHandlerOptions.ts +++ b/src/middleware/options/RetryHandlerOptions.ts @@ -76,7 +76,7 @@ export class RetryHandlerOptions implements MiddlewareOptions { * @private * A member holding default shouldRetry callback */ - private static DEFAULT_SHOULD_RETRY: ShouldRetry = () => true; + private static defaultShouldRetry: ShouldRetry = () => true; /** * @public @@ -87,7 +87,7 @@ export class RetryHandlerOptions implements MiddlewareOptions { * @param {ShouldRetry} [shouldRetry = RetryHandlerOptions.DEFAULT_SHOULD_RETRY] - The shouldRetry callback function * @returns An instance of RetryHandlerOptions */ - public constructor(delay: number = RetryHandlerOptions.DEFAULT_DELAY, maxRetries: number = RetryHandlerOptions.DEFAULT_MAX_RETRIES, shouldRetry: ShouldRetry = RetryHandlerOptions.DEFAULT_SHOULD_RETRY) { + public constructor(delay: number = RetryHandlerOptions.DEFAULT_DELAY, maxRetries: number = RetryHandlerOptions.DEFAULT_MAX_RETRIES, shouldRetry: ShouldRetry = RetryHandlerOptions.defaultShouldRetry) { if (delay > RetryHandlerOptions.MAX_DELAY && maxRetries > RetryHandlerOptions.MAX_MAX_RETRIES) { const error = new Error(`Delay and MaxRetries should not be more than ${RetryHandlerOptions.MAX_DELAY} and ${RetryHandlerOptions.MAX_MAX_RETRIES}`); error.name = "MaxLimitExceeded"; diff --git a/src/middleware/options/TelemetryHandlerOptions.ts b/src/middleware/options/TelemetryHandlerOptions.ts index 9d366eae7..2033bc556 100644 --- a/src/middleware/options/TelemetryHandlerOptions.ts +++ b/src/middleware/options/TelemetryHandlerOptions.ts @@ -21,11 +21,12 @@ import { MiddlewareOptions } from "./IMiddlewareOptions"; * @property {number} RETRY_HANDLER_ENABLED - The hexadecimal flag value for retry handler enabled * @property {number} AUTHENTICATION_HANDLER_ENABLED - The hexadecimal flag value for the authentication handler enabled */ + export enum FeatureUsageFlag { - NONE = 0x0, - REDIRECT_HANDLER_ENABLED = 0x1, - RETRY_HANDLER_ENABLED = 0x2, - AUTHENTICATION_HANDLER_ENABLED = 0x4, + NONE = 0x0, // eslint-disable-line @typescript-eslint/naming-convention + REDIRECT_HANDLER_ENABLED = 0x1, // eslint-disable-line @typescript-eslint/naming-convention + RETRY_HANDLER_ENABLED = 0x2, // eslint-disable-line @typescript-eslint/naming-convention + AUTHENTICATION_HANDLER_ENABLED = 0x4, // eslint-disable-line @typescript-eslint/naming-convention } /** From 2b5b59ea0aad50e274c33cbc1bd0b3ed90965ddd Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Thu, 31 Dec 2020 02:02:46 -0800 Subject: [PATCH 07/14] Removing rethrown errors --- .eslintrc.json | 10 +- spec/content/BatchRequestContent.ts | 18 +-- spec/core/HTTPClient.ts | 40 +++--- spec/middleware/RetryHandler.ts | 6 +- spec/middleware/RetryHandlerOptions.ts | 36 ++--- spec/tasks/PageIterator.ts | 60 +++------ src/Client.ts | 12 +- src/GraphRequest.ts | 74 +++-------- src/GraphResponseHandler.ts | 124 ++++++++---------- src/ImplicitMSALAuthenticationProvider.ts | 24 ++-- .../ImplicitMSALAuthenticationProvider.ts | 16 +-- src/middleware/AuthenticationHandler.ts | 38 +++--- src/middleware/ChaosHandler.ts | 108 +++++++-------- src/middleware/HTTPMessageHandler.ts | 8 +- src/middleware/RedirectHandler.ts | 48 +++---- src/middleware/RetryHandler.ts | 34 ++--- src/middleware/TelemetryHandler.ts | 50 ++++--- src/middleware/options/IMiddlewareOptions.ts | 1 + src/tasks/LargeFileUploadTask.ts | 96 +++++--------- src/tasks/OneDriveLargeFileUploadTask.ts | 48 +++---- src/tasks/PageIterator.ts | 64 ++++----- 21 files changed, 348 insertions(+), 567 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index dc5a5c810..bd2f026d4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,11 +4,11 @@ "plugins": ["@typescript-eslint", "prettier"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { - "no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. + "no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. "prefer-rest-params": "off", "no-constant-condition": "off", // @typescript-eslint rules - "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/ban-types": "off", "@typescript-eslint/no-unused-vars": "error", "@typescript-eslint/no-explicit-any": "off", @@ -161,9 +161,9 @@ "@typescript-eslint/no-empty-function": "error", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-parameter-properties": "off", + // eslint - // eslint - "brace-style": "off", + "brace-style": "error", "constructor-super": "error", "curly": ["error", "multi-line"], "dot-notation": "off", @@ -178,7 +178,7 @@ "no-fallthrough": "error", "no-new-func": "off", "no-new-wrappers": "error", - "no-return-await": "error", + "no-return-await": "off", "no-sparse-arrays": "error", "no-template-curly-in-string": "error", "no-throw-literal": "error", diff --git a/spec/content/BatchRequestContent.ts b/spec/content/BatchRequestContent.ts index 2891240eb..0f53c7a77 100644 --- a/spec/content/BatchRequestContent.ts +++ b/spec/content/BatchRequestContent.ts @@ -309,13 +309,9 @@ describe("BatchRequestContent.ts", () => { it("Should return json content", async () => { const req = getCreateFolderRequestCopy(); const batchReq = new BatchRequestContent([req]); - try { - const content = await batchReq.getContent(); - assert.isDefined(content.requests[0].body); - assert.equal(typeof content.requests[0].body, "object"); - } catch (error) { - throw error; - } + const content = await batchReq.getContent(); + assert.isDefined(content.requests[0].body); + assert.equal(typeof content.requests[0].body, "object"); }); it("Should return image's base64 string", async () => { @@ -335,12 +331,8 @@ describe("BatchRequestContent.ts", () => { }), }; const batchReq = new BatchRequestContent([uploadOneDriveFile]); - try { - const content = await batchReq.getContent(); - assert.isDefined(content.requests[0].body); - } catch (error) { - throw error; - } + const content = await batchReq.getContent(); + assert.isDefined(content.requests[0].body); }); }); diff --git a/spec/core/HTTPClient.ts b/spec/core/HTTPClient.ts index 9c9e3c40c..ba9daa056 100644 --- a/spec/core/HTTPClient.ts +++ b/spec/core/HTTPClient.ts @@ -63,33 +63,25 @@ describe("HTTPClient.ts", () => { }); it("Should execute for context object with Request instance", async () => { - try { - const request: Request = new Request("dummy_url", { - method: "GET", - }); - const context: Context = { - request, - }; - await httpClient.sendRequest(context); - } catch (error) { - throw error; - } + const request: Request = new Request("dummy_url", { + method: "GET", + }); + const context: Context = { + request, + }; + await httpClient.sendRequest(context); }); it("Should execute for context object with request uri and options", async () => { - try { - const url = "dummy_url"; - const options: FetchOptions = { - method: "GET", - }; - const context: Context = { - request: url, - options, - }; - await httpClient.sendRequest(context); - } catch (error) { - throw error; - } + const url = "dummy_url"; + const options: FetchOptions = { + method: "GET", + }; + const context: Context = { + request: url, + options, + }; + await httpClient.sendRequest(context); }); }); }); diff --git a/spec/middleware/RetryHandler.ts b/spec/middleware/RetryHandler.ts index 7ba3c06d0..a0531faea 100644 --- a/spec/middleware/RetryHandler.ts +++ b/spec/middleware/RetryHandler.ts @@ -148,11 +148,7 @@ describe("RetryHandler.ts", function() { describe("sleep", async () => { it("Should run the sleep method for 1 second", async () => { - try { - await retryHandler["sleep"](1); - } catch (error) { - throw error; - } + await retryHandler["sleep"](1); }); }); diff --git a/spec/middleware/RetryHandlerOptions.ts b/spec/middleware/RetryHandlerOptions.ts index bea98525c..c980f0e7f 100644 --- a/spec/middleware/RetryHandlerOptions.ts +++ b/spec/middleware/RetryHandlerOptions.ts @@ -12,14 +12,10 @@ import { RetryHandlerOptions, ShouldRetry } from "../../src/middleware/options/R describe("RetryHandlerOptions.ts", () => { describe("Constructor", () => { it("Should use default values if not given", () => { - try { - const options = new RetryHandlerOptions(); - assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]); - assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]); - assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]); - } catch (error) { - throw error; - } + const options = new RetryHandlerOptions(); + assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]); + assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]); + assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]); }); it("Should throw error for both delay and maxRetries are higher than the limit", () => { @@ -83,20 +79,16 @@ describe("RetryHandlerOptions.ts", () => { }); it("Should accept all the given values", () => { - try { - const delay = 1; - const maxRetries = 3; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const shouldRetry: ShouldRetry = (d, a, req, o, res) => { - return false; - }; - const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry); - assert.equal(options.delay, delay); - assert.equal(options.maxRetries, maxRetries); - assert.equal(options.shouldRetry, shouldRetry); - } catch (error) { - throw error; - } + const delay = 1; + const maxRetries = 3; + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const shouldRetry: ShouldRetry = (d, a, req, o, res) => { + return false; + }; + const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry); + assert.equal(options.delay, delay); + assert.equal(options.maxRetries, maxRetries); + assert.equal(options.shouldRetry, shouldRetry); }); }); diff --git a/spec/tasks/PageIterator.ts b/spec/tasks/PageIterator.ts index 6aec0d924..82f257ed3 100644 --- a/spec/tasks/PageIterator.ts +++ b/spec/tasks/PageIterator.ts @@ -75,46 +75,30 @@ describe("PageIterator.ts", () => { describe("iterate", () => { it("Should iterate over a complete collection without nextLink", async () => { const pageIterator = new PageIterator(client, getPageCollection(), truthyCallback); - try { - await pageIterator.iterate(); - assert.isTrue(pageIterator.isComplete()); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.isTrue(pageIterator.isComplete()); }); it("Should not iterate over an empty collection", async () => { const pageIterator = new PageIterator(client, getEmptyPageCollection(), truthyCallback); halfWayCallbackCounter = 1; - try { - await pageIterator.iterate(); - assert.equal(halfWayCallbackCounter, 1); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.equal(halfWayCallbackCounter, 1); }); it("Should break in the middle way", async () => { const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback); halfWayCallbackCounter = 5; - try { - await pageIterator.iterate(); - assert.isFalse(pageIterator.isComplete()); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.isFalse(pageIterator.isComplete()); }); }); describe("iterationHelper", () => { it("Should return true for empty collection with next link", () => { const pageIterator = new PageIterator(client, getEmptyPageCollectionWithNext(), truthyCallback); - try { - const advance = pageIterator["iterationHelper"](); - assert.isTrue(advance); - } catch (error) { - throw error; - } + const advance = pageIterator["iterationHelper"](); + assert.isTrue(advance); }); }); @@ -122,14 +106,10 @@ describe("PageIterator.ts", () => { it("Should start from the place where it left the iteration", async () => { const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback); halfWayCallbackCounter = 5; - try { - await pageIterator.iterate(); - assert.isFalse(pageIterator.isComplete()); - await pageIterator.resume(); - assert.isTrue(pageIterator.isComplete()); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.isFalse(pageIterator.isComplete()); + await pageIterator.resume(); + assert.isTrue(pageIterator.isComplete()); }); }); @@ -137,22 +117,14 @@ describe("PageIterator.ts", () => { it("Should return false for incomplete iteration", async () => { const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback); halfWayCallbackCounter = 5; - try { - await pageIterator.iterate(); - assert.isFalse(pageIterator.isComplete()); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.isFalse(pageIterator.isComplete()); }); it("Should return true for complete iteration", async () => { const pageIterator = new PageIterator(client, getPageCollection(), truthyCallback); - try { - await pageIterator.iterate(); - assert.isTrue(pageIterator.isComplete()); - } catch (error) { - throw error; - } + await pageIterator.iterate(); + assert.isTrue(pageIterator.isComplete()); }); }); }); diff --git a/src/Client.ts b/src/Client.ts index 1112cbc91..ac8a76831 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -60,11 +60,7 @@ export class Client { * @returns The Client instance */ public static initWithMiddleware(clientOptions: ClientOptions): Client { - try { - return new Client(clientOptions); - } catch (error) { - throw error; - } + return new Client(clientOptions); } /** @@ -74,11 +70,7 @@ export class Client { * @param {ClientOptions} clientOptions - The options to instantiate the client object */ private constructor(clientOptions: ClientOptions) { - try { - validatePolyFilling(); - } catch (error) { - throw error; - } + validatePolyFilling(); for (const key in clientOptions) { if (Object.prototype.hasOwnProperty.call(clientOptions, key)) { this.config[key] = clientOptions[key]; diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index 0470ad9a8..2d9ab42c2 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -629,12 +629,8 @@ export class GraphRequest { const options: FetchOptions = { method: RequestMethod.GET, }; - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } /** @@ -659,12 +655,8 @@ export class GraphRequest { this.setHeaderContentType(); options.headers = this._headers; } - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } /** @@ -676,11 +668,7 @@ export class GraphRequest { * @returns A promise that resolves to the post response */ public async create(content: any, callback?: GraphRequestCallback): Promise { - try { - return await this.post(content, callback); - } catch (error) { - throw error; - } + return await this.post(content, callback); } /** @@ -698,12 +686,8 @@ export class GraphRequest { method: RequestMethod.PUT, body: serializeContent(content), }; - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } /** @@ -721,12 +705,8 @@ export class GraphRequest { method: RequestMethod.PATCH, body: serializeContent(content), }; - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } /** @@ -738,11 +718,7 @@ export class GraphRequest { * @returns A promise that resolves to the patch response */ public async update(content: any, callback?: GraphRequestCallback): Promise { - try { - return await this.patch(content, callback); - } catch (error) { - throw error; - } + return await this.patch(content, callback); } /** @@ -757,12 +733,8 @@ export class GraphRequest { const options: FetchOptions = { method: RequestMethod.DELETE, }; - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } /** @@ -773,11 +745,7 @@ export class GraphRequest { * @returns A promise that resolves to the delete response */ public async del(callback?: GraphRequestCallback): Promise { - try { - return await this.delete(callback); - } catch (error) { - throw error; - } + return await this.delete(callback); } /** @@ -793,12 +761,8 @@ export class GraphRequest { method: RequestMethod.GET, }; this.responseType(ResponseType.STREAM); - try { - const stream = await this.send(url, options, callback); - return stream; - } catch (error) { - throw error; - } + const stream = await this.send(url, options, callback); + return stream; } /** @@ -818,11 +782,7 @@ export class GraphRequest { }, body: stream, }; - try { - const response = await this.send(url, options, callback); - return response; - } catch (error) { - throw error; - } + const response = await this.send(url, options, callback); + return response; } } diff --git a/src/GraphResponseHandler.ts b/src/GraphResponseHandler.ts index 223506680..982e9694e 100644 --- a/src/GraphResponseHandler.ts +++ b/src/GraphResponseHandler.ts @@ -65,24 +65,20 @@ export class GraphResponseHandler { * @returns A promise that resolves to a document content */ private static parseDocumentResponse(rawResponse: Response, type: DocumentType): Promise { - try { - if (typeof DOMParser !== "undefined") { - return new Promise((resolve, reject) => { - rawResponse.text().then((xmlString) => { - try { - const parser = new DOMParser(); - const xmlDoc = parser.parseFromString(xmlString, type); - resolve(xmlDoc); - } catch (error) { - reject(error); - } - }); + if (typeof DOMParser !== "undefined") { + return new Promise((resolve, reject) => { + rawResponse.text().then((xmlString) => { + try { + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(xmlString, type); + resolve(xmlDoc); + } catch (error) { + reject(error); + } }); - } else { - return Promise.resolve(rawResponse.body); - } - } catch (error) { - throw error; + }); + } else { + return Promise.resolve(rawResponse.body); } } @@ -102,58 +98,54 @@ export class GraphResponseHandler { } let responseValue: any; const contentType = rawResponse.headers.get("Content-type"); - try { - switch (responseType) { - case ResponseType.ARRAYBUFFER: - responseValue = await rawResponse.arrayBuffer(); - break; - case ResponseType.BLOB: - responseValue = await rawResponse.blob(); - break; - case ResponseType.DOCUMENT: - responseValue = await GraphResponseHandler.parseDocumentResponse(rawResponse, DocumentType.TEXT_XML); - break; - case ResponseType.JSON: - responseValue = await rawResponse.json(); - break; - case ResponseType.STREAM: - responseValue = await Promise.resolve(rawResponse.body); - break; - case ResponseType.TEXT: - responseValue = await rawResponse.text(); - break; - default: - if (contentType !== null) { - const mimeType = contentType.split(";")[0]; - if (new RegExp(ContentTypeRegexStr.DOCUMENT).test(mimeType)) { - responseValue = await GraphResponseHandler.parseDocumentResponse(rawResponse, mimeType as DocumentType); - } else if (new RegExp(ContentTypeRegexStr.IMAGE).test(mimeType)) { - responseValue = rawResponse.blob(); - } else if (mimeType === ContentType.TEXT_PLAIN) { - responseValue = await rawResponse.text(); - } else if (mimeType === ContentType.APPLICATION_JSON) { - responseValue = await rawResponse.json(); - } else { - responseValue = Promise.resolve(rawResponse.body); - } + switch (responseType) { + case ResponseType.ARRAYBUFFER: + responseValue = await rawResponse.arrayBuffer(); + break; + case ResponseType.BLOB: + responseValue = await rawResponse.blob(); + break; + case ResponseType.DOCUMENT: + responseValue = await GraphResponseHandler.parseDocumentResponse(rawResponse, DocumentType.TEXT_XML); + break; + case ResponseType.JSON: + responseValue = await rawResponse.json(); + break; + case ResponseType.STREAM: + responseValue = await Promise.resolve(rawResponse.body); + break; + case ResponseType.TEXT: + responseValue = await rawResponse.text(); + break; + default: + if (contentType !== null) { + const mimeType = contentType.split(";")[0]; + if (new RegExp(ContentTypeRegexStr.DOCUMENT).test(mimeType)) { + responseValue = await GraphResponseHandler.parseDocumentResponse(rawResponse, mimeType as DocumentType); + } else if (new RegExp(ContentTypeRegexStr.IMAGE).test(mimeType)) { + responseValue = rawResponse.blob(); + } else if (mimeType === ContentType.TEXT_PLAIN) { + responseValue = await rawResponse.text(); + } else if (mimeType === ContentType.APPLICATION_JSON) { + responseValue = await rawResponse.json(); } else { - /** - * RFC specification {@link https://tools.ietf.org/html/rfc7231#section-3.1.1.5} says: - * A sender that generates a message containing a payload body SHOULD - * generate a Content-Type header field in that message unless the - * intended media type of the enclosed representation is unknown to the - * sender. If a Content-Type header field is not present, the recipient - * MAY either assume a media type of "application/octet-stream" - * ([RFC2046], Section 4.5.1) or examine the data to determine its type. - * - * So assuming it as a stream type so returning the body. - */ responseValue = Promise.resolve(rawResponse.body); } - break; - } - } catch (error) { - throw error; + } else { + /** + * RFC specification {@link https://tools.ietf.org/html/rfc7231#section-3.1.1.5} says: + * A sender that generates a message containing a payload body SHOULD + * generate a Content-Type header field in that message unless the + * intended media type of the enclosed representation is unknown to the + * sender. If a Content-Type header field is not present, the recipient + * MAY either assume a media type of "application/octet-stream" + * ([RFC2046], Section 4.5.1) or examine the data to determine its type. + * + * So assuming it as a stream type so returning the body. + */ + responseValue = Promise.resolve(rawResponse.body); + } + break; } return responseValue; } diff --git a/src/ImplicitMSALAuthenticationProvider.ts b/src/ImplicitMSALAuthenticationProvider.ts index 39fdc8dfb..725d3ed42 100644 --- a/src/ImplicitMSALAuthenticationProvider.ts +++ b/src/ImplicitMSALAuthenticationProvider.ts @@ -77,27 +77,19 @@ export class ImplicitMSALAuthenticationProvider implements AuthenticationProvide return authResponse.accessToken; } catch (error) { if (error instanceof InteractionRequiredAuthError) { - try { - const authResponse: AuthResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); - return authResponse.accessToken; - } catch (error) { - throw error; - } + const authResponse: AuthResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); + return authResponse.accessToken; } else { throw error; } } } else { - try { - const tokenRequest: AuthenticationParameters = { - scopes, - }; - await this.msalApplication.loginPopup(tokenRequest); - const authResponse: AuthResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } catch (error) { - throw error; - } + const tokenRequest: AuthenticationParameters = { + scopes, + }; + await this.msalApplication.loginPopup(tokenRequest); + const authResponse: AuthResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); + return authResponse.accessToken; } } } diff --git a/src/browser/ImplicitMSALAuthenticationProvider.ts b/src/browser/ImplicitMSALAuthenticationProvider.ts index 6fb08a695..f4549fc50 100644 --- a/src/browser/ImplicitMSALAuthenticationProvider.ts +++ b/src/browser/ImplicitMSALAuthenticationProvider.ts @@ -93,16 +93,12 @@ export class ImplicitMSALAuthenticationProvider implements AuthenticationProvide } } } else { - try { - const tokenRequest = { - scopes, - }; - await this.msalApplication.loginPopup(tokenRequest); - const authResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); - return authResponse.accessToken; - } catch (error) { - throw error; - } + const tokenRequest = { + scopes, + }; + await this.msalApplication.loginPopup(tokenRequest); + const authResponse = await this.msalApplication.acquireTokenSilent(tokenRequest); + return authResponse.accessToken; } } } diff --git a/src/middleware/AuthenticationHandler.ts b/src/middleware/AuthenticationHandler.ts index 0eb9e698f..6ef197a53 100644 --- a/src/middleware/AuthenticationHandler.ts +++ b/src/middleware/AuthenticationHandler.ts @@ -61,28 +61,24 @@ export class AuthenticationHandler implements Middleware { * @returns A Promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - let options: AuthenticationHandlerOptions; - if (context.middlewareControl instanceof MiddlewareControl) { - options = context.middlewareControl.getMiddlewareOptions(AuthenticationHandlerOptions) as AuthenticationHandlerOptions; - } - let authenticationProvider: AuthenticationProvider; - let authenticationProviderOptions: AuthenticationProviderOptions; - if (typeof options !== "undefined") { - authenticationProvider = options.authenticationProvider; - authenticationProviderOptions = options.authenticationProviderOptions; - } - if (typeof authenticationProvider === "undefined") { - authenticationProvider = this.authenticationProvider; - } - const token: string = await authenticationProvider.getAccessToken(authenticationProviderOptions); - const bearerKey = `Bearer ${token}`; - appendRequestHeader(context.request, context.options, AuthenticationHandler.AUTHORIZATION_HEADER, bearerKey); - TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED); - return await this.nextMiddleware.execute(context); - } catch (error) { - throw error; + let options: AuthenticationHandlerOptions; + if (context.middlewareControl instanceof MiddlewareControl) { + options = context.middlewareControl.getMiddlewareOptions(AuthenticationHandlerOptions) as AuthenticationHandlerOptions; } + let authenticationProvider: AuthenticationProvider; + let authenticationProviderOptions: AuthenticationProviderOptions; + if (typeof options !== "undefined") { + authenticationProvider = options.authenticationProvider; + authenticationProviderOptions = options.authenticationProviderOptions; + } + if (typeof authenticationProvider === "undefined") { + authenticationProvider = this.authenticationProvider; + } + const token: string = await authenticationProvider.getAccessToken(authenticationProviderOptions); + const bearerKey = `Bearer ${token}`; + appendRequestHeader(context.request, context.options, AuthenticationHandler.AUTHORIZATION_HEADER, bearerKey); + TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED); + return await this.nextMiddleware.execute(context); } /** diff --git a/src/middleware/ChaosHandler.ts b/src/middleware/ChaosHandler.ts index c87021f0d..62b56dde3 100644 --- a/src/middleware/ChaosHandler.ts +++ b/src/middleware/ChaosHandler.ts @@ -126,17 +126,13 @@ export class ChaosHandler implements Middleware { * @param {Context} context - Contains the context of the request */ private createResponse(chaosHandlerOptions: ChaosHandlerOptions, context: Context) { - try { - const requestURL = context.request as string; - const requestID = generateUUID(); - const requestDate = new Date(); - const responseHeader = this.createResponseHeaders(chaosHandlerOptions.statusCode, requestID, requestDate.toString()); - const responseBody = this.createResponseBody(chaosHandlerOptions.statusCode, chaosHandlerOptions.statusMessage, requestID, requestDate.toString(), chaosHandlerOptions.responseBody); - const init: any = { url: requestURL, status: chaosHandlerOptions.statusCode, statusText: chaosHandlerOptions.statusMessage, headers: responseHeader }; - context.response = new Response(responseBody, init); - } catch (error) { - throw error; - } + const requestURL = context.request as string; + const requestID = generateUUID(); + const requestDate = new Date(); + const responseHeader = this.createResponseHeaders(chaosHandlerOptions.statusCode, requestID, requestDate.toString()); + const responseBody = this.createResponseBody(chaosHandlerOptions.statusCode, chaosHandlerOptions.statusMessage, requestID, requestDate.toString(), chaosHandlerOptions.responseBody); + const init: any = { url: requestURL, status: chaosHandlerOptions.statusCode, statusText: chaosHandlerOptions.statusMessage, headers: responseHeader }; + context.response = new Response(responseBody, init); } /** @@ -147,15 +143,11 @@ export class ChaosHandler implements Middleware { * @returns nothing */ private async sendRequest(chaosHandlerOptions: ChaosHandlerOptions, context: Context): Promise { - try { - this.setStatusCode(chaosHandlerOptions, context.request as string, context.options.method as RequestMethod); - if (!chaosHandlerOptions.statusCode) { - await this.nextMiddleware.execute(context); - } else { - this.createResponse(chaosHandlerOptions, context); - } - } catch (error) { - throw error; + this.setStatusCode(chaosHandlerOptions, context.request as string, context.options.method as RequestMethod); + if (!chaosHandlerOptions.statusCode) { + await this.nextMiddleware.execute(context); + } else { + this.createResponse(chaosHandlerOptions, context); } } @@ -166,12 +158,8 @@ export class ChaosHandler implements Middleware { * @returns a random status code from a given set of status codes */ private getRandomStatusCode(requestMethod: RequestMethod): number { - try { - const statusCodeArray: number[] = methodStatusCode[requestMethod] as number[]; - return statusCodeArray[Math.floor(Math.random() * statusCodeArray.length)]; - } catch (error) { - throw error; - } + const statusCodeArray: number[] = methodStatusCode[requestMethod] as number[]; + return statusCodeArray[Math.floor(Math.random() * statusCodeArray.length)]; } /** @@ -197,41 +185,37 @@ export class ChaosHandler implements Middleware { * @param {string} requestMethod - the API method for the request */ private setStatusCode(chaosHandlerOptions: ChaosHandlerOptions, requestURL: string, requestMethod: RequestMethod) { - try { - if (chaosHandlerOptions.chaosStrategy === ChaosStrategy.MANUAL) { - if (chaosHandlerOptions.statusCode === undefined) { - // manual mode with no status code, can be a global level or request level without statusCode - const relativeURL: string = this.getRelativeURL(requestURL); - if (this.manualMap.get(relativeURL) !== undefined) { - // checking Manual Map for exact match - if (this.manualMap.get(relativeURL).get(requestMethod) !== undefined) { - chaosHandlerOptions.statusCode = this.manualMap.get(relativeURL).get(requestMethod); - } - // else statusCode would be undefined - } else { - // checking for regex match if exact match doesn't work - this.manualMap.forEach((value: Map, key: string) => { - const regexURL = new RegExp(key + "$"); - if (regexURL.test(relativeURL)) { - if (this.manualMap.get(key).get(requestMethod) !== undefined) { - chaosHandlerOptions.statusCode = this.manualMap.get(key).get(requestMethod); - } - // else statusCode would be undefined - } - }); + if (chaosHandlerOptions.chaosStrategy === ChaosStrategy.MANUAL) { + if (chaosHandlerOptions.statusCode === undefined) { + // manual mode with no status code, can be a global level or request level without statusCode + const relativeURL: string = this.getRelativeURL(requestURL); + if (this.manualMap.get(relativeURL) !== undefined) { + // checking Manual Map for exact match + if (this.manualMap.get(relativeURL).get(requestMethod) !== undefined) { + chaosHandlerOptions.statusCode = this.manualMap.get(relativeURL).get(requestMethod); } - - // Case of redirection or request url not in map ---> statusCode would be undefined - } - } else { - // Handling the case of Random here - if (Math.floor(Math.random() * 100) < chaosHandlerOptions.chaosPercentage) { - chaosHandlerOptions.statusCode = this.getRandomStatusCode(requestMethod); + // else statusCode would be undefined + } else { + // checking for regex match if exact match doesn't work + this.manualMap.forEach((value: Map, key: string) => { + const regexURL = new RegExp(key + "$"); + if (regexURL.test(relativeURL)) { + if (this.manualMap.get(key).get(requestMethod) !== undefined) { + chaosHandlerOptions.statusCode = this.manualMap.get(key).get(requestMethod); + } + // else statusCode would be undefined + } + }); } - // else statusCode would be undefined + + // Case of redirection or request url not in map ---> statusCode would be undefined } - } catch (error) { - throw error; + } else { + // Handling the case of Random here + if (Math.floor(Math.random() * 100) < chaosHandlerOptions.chaosPercentage) { + chaosHandlerOptions.statusCode = this.getRandomStatusCode(requestMethod); + } + // else statusCode would be undefined } } @@ -261,12 +245,8 @@ export class ChaosHandler implements Middleware { * @returns A Promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - const chaosHandlerOptions: ChaosHandlerOptions = this.getOptions(context); - return await this.sendRequest(chaosHandlerOptions, context); - } catch (error) { - throw error; - } + const chaosHandlerOptions: ChaosHandlerOptions = this.getOptions(context); + return await this.sendRequest(chaosHandlerOptions, context); } /** diff --git a/src/middleware/HTTPMessageHandler.ts b/src/middleware/HTTPMessageHandler.ts index c69d5ead9..69f5870e8 100644 --- a/src/middleware/HTTPMessageHandler.ts +++ b/src/middleware/HTTPMessageHandler.ts @@ -27,11 +27,7 @@ export class HTTPMessageHandler implements Middleware { * @returns A promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - context.response = await fetch(context.request, context.options); - return; - } catch (error) { - throw error; - } + context.response = await fetch(context.request, context.options); + return; } } diff --git a/src/middleware/RedirectHandler.ts b/src/middleware/RedirectHandler.ts index ad4d698df..f6e20fe3d 100644 --- a/src/middleware/RedirectHandler.ts +++ b/src/middleware/RedirectHandler.ts @@ -191,27 +191,23 @@ export class RedirectHandler implements Middleware { * @returns A promise that resolves to nothing */ private async executeWithRedirect(context: Context, redirectCount: number, options: RedirectHandlerOptions): Promise { - try { - await this.nextMiddleware.execute(context); - const response = context.response; - if (redirectCount < options.maxRedirects && this.isRedirect(response) && this.hasLocationHeader(response) && options.shouldRedirect(response)) { - ++redirectCount; - if (response.status === RedirectHandler.STATUS_CODE_SEE_OTHER) { - context.options.method = RequestMethod.GET; - delete context.options.body; - } else { - const redirectUrl: string = this.getLocationHeader(response); - if (!this.isRelativeURL(redirectUrl) && this.shouldDropAuthorizationHeader(response.url, redirectUrl)) { - delete context.options.headers[RedirectHandler.AUTHORIZATION_HEADER]; - } - await this.updateRequestUrl(redirectUrl, context); - } - await this.executeWithRedirect(context, redirectCount, options); + await this.nextMiddleware.execute(context); + const response = context.response; + if (redirectCount < options.maxRedirects && this.isRedirect(response) && this.hasLocationHeader(response) && options.shouldRedirect(response)) { + ++redirectCount; + if (response.status === RedirectHandler.STATUS_CODE_SEE_OTHER) { + context.options.method = RequestMethod.GET; + delete context.options.body; } else { - return; + const redirectUrl: string = this.getLocationHeader(response); + if (!this.isRelativeURL(redirectUrl) && this.shouldDropAuthorizationHeader(response.url, redirectUrl)) { + delete context.options.headers[RedirectHandler.AUTHORIZATION_HEADER]; + } + await this.updateRequestUrl(redirectUrl, context); } - } catch (error) { - throw error; + await this.executeWithRedirect(context, redirectCount, options); + } else { + return; } } @@ -223,15 +219,11 @@ export class RedirectHandler implements Middleware { * @returns A Promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - const redirectCount = 0; - const options = this.getOptions(context); - context.options.redirect = RedirectHandler.MANUAL_REDIRECT; - TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.REDIRECT_HANDLER_ENABLED); - return await this.executeWithRedirect(context, redirectCount, options); - } catch (error) { - throw error; - } + const redirectCount = 0; + const options = this.getOptions(context); + context.options.redirect = RedirectHandler.MANUAL_REDIRECT; + TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.REDIRECT_HANDLER_ENABLED); + return await this.executeWithRedirect(context, redirectCount, options); } /** diff --git a/src/middleware/RetryHandler.ts b/src/middleware/RetryHandler.ts index fadb122ec..fcaf82070 100644 --- a/src/middleware/RetryHandler.ts +++ b/src/middleware/RetryHandler.ts @@ -171,19 +171,15 @@ export class RetryHandler implements Middleware { * @returns A Promise that resolves to nothing */ private async executeWithRetry(context: Context, retryAttempts: number, options: RetryHandlerOptions): Promise { - try { - await this.nextMiddleware.execute(context); - if (retryAttempts < options.maxRetries && this.isRetry(context.response) && this.isBuffered(context.request, context.options) && options.shouldRetry(options.delay, retryAttempts, context.request, context.options, context.response)) { - ++retryAttempts; - setRequestHeader(context.request, context.options, RetryHandler.RETRY_ATTEMPT_HEADER, retryAttempts.toString()); - const delay = this.getDelay(context.response, retryAttempts, options.delay); - await this.sleep(delay); - return await this.executeWithRetry(context, retryAttempts, options); - } else { - return; - } - } catch (error) { - throw error; + await this.nextMiddleware.execute(context); + if (retryAttempts < options.maxRetries && this.isRetry(context.response) && this.isBuffered(context.request, context.options) && options.shouldRetry(options.delay, retryAttempts, context.request, context.options, context.response)) { + ++retryAttempts; + setRequestHeader(context.request, context.options, RetryHandler.RETRY_ATTEMPT_HEADER, retryAttempts.toString()); + const delay = this.getDelay(context.response, retryAttempts, options.delay); + await this.sleep(delay); + return await this.executeWithRetry(context, retryAttempts, options); + } else { + return; } } @@ -195,14 +191,10 @@ export class RetryHandler implements Middleware { * @returns A Promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - const retryAttempts = 0; - const options: RetryHandlerOptions = this.getOptions(context); - TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.RETRY_HANDLER_ENABLED); - return await this.executeWithRetry(context, retryAttempts, options); - } catch (error) { - throw error; - } + const retryAttempts = 0; + const options: RetryHandlerOptions = this.getOptions(context); + TelemetryHandlerOptions.updateFeatureUsageFlag(context, FeatureUsageFlag.RETRY_HANDLER_ENABLED); + return await this.executeWithRetry(context, retryAttempts, options); } /** diff --git a/src/middleware/TelemetryHandler.ts b/src/middleware/TelemetryHandler.ts index 8fa20d779..a8f0dbfe8 100644 --- a/src/middleware/TelemetryHandler.ts +++ b/src/middleware/TelemetryHandler.ts @@ -65,35 +65,31 @@ export class TelemetryHandler implements Middleware { * @returns A Promise that resolves to nothing */ public async execute(context: Context): Promise { - try { - const url = typeof context.request === "string" ? context.request : context.request.url; - if (isGraphURL(url)) { - // Add telemetry only if the request url is a Graph URL. - // Errors are reported as in issue #265 if headers are present when redirecting to a non Graph URL - let clientRequestId: string = getRequestHeader(context.request, context.options, TelemetryHandler.CLIENT_REQUEST_ID_HEADER); - if (!clientRequestId) { - clientRequestId = generateUUID(); - setRequestHeader(context.request, context.options, TelemetryHandler.CLIENT_REQUEST_ID_HEADER, clientRequestId); - } - let sdkVersionValue = `${TelemetryHandler.PRODUCT_NAME}/${PACKAGE_VERSION}`; - let options: TelemetryHandlerOptions; - if (context.middlewareControl instanceof MiddlewareControl) { - options = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions; - } - if (options) { - const featureUsage: string = options.getFeatureUsage(); - sdkVersionValue += ` (${TelemetryHandler.FEATURE_USAGE_STRING}=${featureUsage})`; - } - appendRequestHeader(context.request, context.options, TelemetryHandler.SDK_VERSION_HEADER, sdkVersionValue); - } else { - // Remove telemetry headers if present during redirection. - delete context.options.headers[TelemetryHandler.CLIENT_REQUEST_ID_HEADER]; - delete context.options.headers[TelemetryHandler.SDK_VERSION_HEADER]; + const url = typeof context.request === "string" ? context.request : context.request.url; + if (isGraphURL(url)) { + // Add telemetry only if the request url is a Graph URL. + // Errors are reported as in issue #265 if headers are present when redirecting to a non Graph URL + let clientRequestId: string = getRequestHeader(context.request, context.options, TelemetryHandler.CLIENT_REQUEST_ID_HEADER); + if (!clientRequestId) { + clientRequestId = generateUUID(); + setRequestHeader(context.request, context.options, TelemetryHandler.CLIENT_REQUEST_ID_HEADER, clientRequestId); } - return await this.nextMiddleware.execute(context); - } catch (error) { - throw error; + let sdkVersionValue = `${TelemetryHandler.PRODUCT_NAME}/${PACKAGE_VERSION}`; + let options: TelemetryHandlerOptions; + if (context.middlewareControl instanceof MiddlewareControl) { + options = context.middlewareControl.getMiddlewareOptions(TelemetryHandlerOptions) as TelemetryHandlerOptions; + } + if (options) { + const featureUsage: string = options.getFeatureUsage(); + sdkVersionValue += ` (${TelemetryHandler.FEATURE_USAGE_STRING}=${featureUsage})`; + } + appendRequestHeader(context.request, context.options, TelemetryHandler.SDK_VERSION_HEADER, sdkVersionValue); + } else { + // Remove telemetry headers if present during redirection. + delete context.options.headers[TelemetryHandler.CLIENT_REQUEST_ID_HEADER]; + delete context.options.headers[TelemetryHandler.SDK_VERSION_HEADER]; } + return await this.nextMiddleware.execute(context); } /** diff --git a/src/middleware/options/IMiddlewareOptions.ts b/src/middleware/options/IMiddlewareOptions.ts index 69de93cc1..ebbf30827 100644 --- a/src/middleware/options/IMiddlewareOptions.ts +++ b/src/middleware/options/IMiddlewareOptions.ts @@ -10,4 +10,5 @@ * Signature representing the middleware options */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface MiddlewareOptions {} diff --git a/src/tasks/LargeFileUploadTask.ts b/src/tasks/LargeFileUploadTask.ts index a55a13c33..412de5986 100644 --- a/src/tasks/LargeFileUploadTask.ts +++ b/src/tasks/LargeFileUploadTask.ts @@ -117,19 +117,15 @@ export class LargeFileUploadTask { * @returns The promise that resolves to LargeFileUploadSession */ public static async createUploadSession(client: Client, requestUrl: string, payload: any, headers: KeyValuePairObjectStringNumber = {}): Promise { - try { - const session = await client - .api(requestUrl) - .headers(headers) - .post(payload); - const largeFileUploadSession: LargeFileUploadSession = { - url: session.uploadUrl, - expiry: new Date(session.expirationDateTime), - }; - return largeFileUploadSession; - } catch (err) { - throw err; - } + const session = await client + .api(requestUrl) + .headers(headers) + .post(payload); + const largeFileUploadSession: LargeFileUploadSession = { + url: session.uploadUrl, + expiry: new Date(session.expirationDateTime), + }; + return largeFileUploadSession; } /** @@ -219,25 +215,21 @@ export class LargeFileUploadTask { * @returns The promise resolves to uploaded response */ public async upload(): Promise { - try { - while (true) { - const nextRange = this.getNextRange(); - if (nextRange.maxValue === -1) { - const err = new Error("Task with which you are trying to upload is already completed, Please check for your uploaded file"); - err.name = "Invalid Session"; - throw err; - } - const fileSlice = this.sliceFile(nextRange); - const response = await this.uploadSlice(fileSlice, nextRange, this.file.size); - // Upon completion of upload process incase of onedrive, driveItem is returned, which contains id - if (response.id !== undefined) { - return response; - } else { - this.updateTaskStatus(response); - } + while (true) { + const nextRange = this.getNextRange(); + if (nextRange.maxValue === -1) { + const err = new Error("Task with which you are trying to upload is already completed, Please check for your uploaded file"); + err.name = "Invalid Session"; + throw err; + } + const fileSlice = this.sliceFile(nextRange); + const response = await this.uploadSlice(fileSlice, nextRange, this.file.size); + // Upon completion of upload process incase of onedrive, driveItem is returned, which contains id + if (response.id !== undefined) { + return response; + } else { + this.updateTaskStatus(response); } - } catch (err) { - throw err; } } @@ -250,17 +242,13 @@ export class LargeFileUploadTask { * @param {number} totalSize - The total size of a complete file */ public async uploadSlice(fileSlice: ArrayBuffer | Blob | File, range: Range, totalSize: number): Promise { - try { - return await this.client - .api(this.uploadSession.url) - .headers({ - "Content-Length": `${range.maxValue - range.minValue + 1}`, - "Content-Range": `bytes ${range.minValue}-${range.maxValue}/${totalSize}`, - }) - .put(fileSlice); - } catch (err) { - throw err; - } + return await this.client + .api(this.uploadSession.url) + .headers({ + "Content-Length": `${range.maxValue - range.minValue + 1}`, + "Content-Range": `bytes ${range.minValue}-${range.maxValue}/${totalSize}`, + }) + .put(fileSlice); } /** @@ -270,11 +258,7 @@ export class LargeFileUploadTask { * @returns The promise resolves to cancelled response */ public async cancel(): Promise { - try { - return await this.client.api(this.uploadSession.url).delete(); - } catch (err) { - throw err; - } + return await this.client.api(this.uploadSession.url).delete(); } /** @@ -284,13 +268,9 @@ export class LargeFileUploadTask { * @returns The promise resolves to the status enquiry response */ public async getStatus(): Promise { - try { - const response = await this.client.api(this.uploadSession.url).get(); - this.updateTaskStatus(response); - return response; - } catch (err) { - throw err; - } + const response = await this.client.api(this.uploadSession.url).get(); + this.updateTaskStatus(response); + return response; } /** @@ -300,11 +280,7 @@ export class LargeFileUploadTask { * @returns The promise resolves to the uploaded response */ public async resume(): Promise { - try { - await this.getStatus(); - return await this.upload(); - } catch (err) { - throw err; - } + await this.getStatus(); + return await this.upload(); } } diff --git a/src/tasks/OneDriveLargeFileUploadTask.ts b/src/tasks/OneDriveLargeFileUploadTask.ts index 2be5a4e2d..857eec79b 100644 --- a/src/tasks/OneDriveLargeFileUploadTask.ts +++ b/src/tasks/OneDriveLargeFileUploadTask.ts @@ -93,21 +93,17 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask { content = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength); } - try { - const requestUrl = OneDriveLargeFileUploadTask.constructCreateSessionUrl(options.fileName, options.path); - const session = await OneDriveLargeFileUploadTask.createUploadSession(client, requestUrl, options.fileName); - const rangeSize = getValidRangeSize(options.rangeSize); - const fileObj: FileObject = { - content, - name, - size, - }; - return new OneDriveLargeFileUploadTask(client, fileObj, session, { - rangeSize, - }); - } catch (err) { - throw err; - } + const requestUrl = OneDriveLargeFileUploadTask.constructCreateSessionUrl(options.fileName, options.path); + const session = await OneDriveLargeFileUploadTask.createUploadSession(client, requestUrl, options.fileName); + const rangeSize = getValidRangeSize(options.rangeSize); + const fileObj: FileObject = { + content, + name, + size, + }; + return new OneDriveLargeFileUploadTask(client, fileObj, session, { + rangeSize, + }); } /** @@ -127,11 +123,7 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask { name: fileName, }, }; - try { - return super.createUploadSession(client, requestUrl, payload); - } catch (err) { - throw err; - } + return super.createUploadSession(client, requestUrl, payload); } /** @@ -155,15 +147,11 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask { * @returns The promise resolves to committed response */ public async commit(requestUrl: string): Promise { - try { - const payload = { - name: this.file.name, - "@microsoft.graph.conflictBehavior": "rename", - "@microsoft.graph.sourceUrl": this.uploadSession.url, - }; - return await this.client.api(requestUrl).put(payload); - } catch (err) { - throw err; - } + const payload = { + name: this.file.name, + "@microsoft.graph.conflictBehavior": "rename", + "@microsoft.graph.sourceUrl": this.uploadSession.url, + }; + return await this.client.api(requestUrl).put(payload); } } diff --git a/src/tasks/PageIterator.ts b/src/tasks/PageIterator.ts index 8f6838a14..7730f1ea2 100644 --- a/src/tasks/PageIterator.ts +++ b/src/tasks/PageIterator.ts @@ -137,27 +137,23 @@ export class PageIterator { * @returns A promise that resolves to a response data with next page collection */ private async fetchAndUpdateNextPageData(): Promise { - try { - let graphRequest = this.client.api(this.nextLink); - if (this.requestOptions) { - if (this.requestOptions.headers) { - graphRequest = graphRequest.headers(this.requestOptions.headers); - } - if (this.requestOptions.middlewareOptions) { - graphRequest = graphRequest.middlewareOptions(this.requestOptions.middlewareOptions); - } - if (this.requestOptions.options) { - graphRequest = graphRequest.options(this.requestOptions.options); - } + let graphRequest = this.client.api(this.nextLink); + if (this.requestOptions) { + if (this.requestOptions.headers) { + graphRequest = graphRequest.headers(this.requestOptions.headers); + } + if (this.requestOptions.middlewareOptions) { + graphRequest = graphRequest.middlewareOptions(this.requestOptions.middlewareOptions); + } + if (this.requestOptions.options) { + graphRequest = graphRequest.options(this.requestOptions.options); } - - const response: PageCollection = await graphRequest.get(); - this.collection = response.value; - this.nextLink = response["@odata.nextLink"]; - this.deltaLink = response["@odata.deltaLink"]; - } catch (error) { - throw error; } + + const response: PageCollection = await graphRequest.get(); + this.collection = response.value; + this.nextLink = response["@odata.nextLink"]; + this.deltaLink = response["@odata.deltaLink"]; } /** @@ -177,21 +173,17 @@ export class PageIterator { * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy. */ public async iterate(): Promise { - try { - let advance = this.iterationHelper(); - while (advance) { - if (this.nextLink !== undefined) { - await this.fetchAndUpdateNextPageData(); - advance = this.iterationHelper(); - } else { - advance = false; - } + let advance = this.iterationHelper(); + while (advance) { + if (this.nextLink !== undefined) { + await this.fetchAndUpdateNextPageData(); + advance = this.iterationHelper(); + } else { + advance = false; } - if (this.nextLink === undefined && this.collection.length === 0) { - this.complete = true; - } - } catch (error) { - throw error; + } + if (this.nextLink === undefined && this.collection.length === 0) { + this.complete = true; } } @@ -203,11 +195,7 @@ export class PageIterator { * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy */ public async resume(): Promise { - try { - return this.iterate(); - } catch (error) { - throw error; - } + return this.iterate(); } /** From 4d2cd23bd900a964057cc73526580f47ea6b33f4 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sat, 2 Jan 2021 00:17:24 -0800 Subject: [PATCH 08/14] Removing rethrown errors --- .eslintrc.json | 14 ++++++++-- src/GraphResponseHandler.ts | 28 ++++++++----------- src/HTTPClient.ts | 16 ++++------- .../ImplicitMSALAuthenticationProvider.ts | 8 ++---- src/tasks/LargeFileUploadTask.ts | 1 + 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index bd2f026d4..905cd005c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,7 @@ "rules": { "no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. "prefer-rest-params": "off", - "no-constant-condition": "off", + "no-constant-condition": "error", // @typescript-eslint rules "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/ban-types": "off", @@ -161,8 +161,18 @@ "@typescript-eslint/no-empty-function": "error", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-parameter-properties": "off", - + "@typescript-eslint/no-array-constructor": "error", // eslint + // "sort-imports": [ + // "error", + // { + // "ignoreCase": false, + // "ignoreDeclarationSort": false, + // "ignoreMemberSort": false, + // "memberSyntaxSortOrder": ["none", "all", "multiple", "single"], + // "allowSeparatedGroups": false + // } + // ], "brace-style": "error", "constructor-super": "error", "curly": ["error", "multi-line"], diff --git a/src/GraphResponseHandler.ts b/src/GraphResponseHandler.ts index 982e9694e..11309e6b1 100644 --- a/src/GraphResponseHandler.ts +++ b/src/GraphResponseHandler.ts @@ -161,25 +161,21 @@ export class GraphResponseHandler { * @returns The parsed response */ public static async getResponse(rawResponse: Response, responseType?: ResponseType, callback?: GraphRequestCallback): Promise { - try { - if (responseType === ResponseType.RAW) { - return Promise.resolve(rawResponse); - } else { - const response = await GraphResponseHandler.convertResponse(rawResponse, responseType); - if (rawResponse.ok) { - // Status Code 2XX - if (typeof callback === "function") { - callback(null, response); - } else { - return response; - } + if (responseType === ResponseType.RAW) { + return Promise.resolve(rawResponse); + } else { + const response = await GraphResponseHandler.convertResponse(rawResponse, responseType); + if (rawResponse.ok) { + // Status Code 2XX + if (typeof callback === "function") { + callback(null, response); } else { - // NOT OK Response - throw response; + return response; } + } else { + // NOT OK Response + throw response; } - } catch (error) { - throw error; } } } diff --git a/src/HTTPClient.ts b/src/HTTPClient.ts index c4e866d95..71fa606ef 100644 --- a/src/HTTPClient.ts +++ b/src/HTTPClient.ts @@ -79,17 +79,13 @@ export class HTTPClient { * @returns A promise that resolves to the Context */ public async sendRequest(context: Context): Promise { - try { - if (typeof context.request === "string" && context.options === undefined) { - const error = new Error(); - error.name = "InvalidRequestOptions"; - error.message = "Unable to execute the middleware, Please provide valid options for a request"; - throw error; - } - await this.middleware.execute(context); - return context; - } catch (error) { + if (typeof context.request === "string" && context.options === undefined) { + const error = new Error(); + error.name = "InvalidRequestOptions"; + error.message = "Unable to execute the middleware, Please provide valid options for a request"; throw error; } + await this.middleware.execute(context); + return context; } } diff --git a/src/browser/ImplicitMSALAuthenticationProvider.ts b/src/browser/ImplicitMSALAuthenticationProvider.ts index f4549fc50..ffdf7bdc9 100644 --- a/src/browser/ImplicitMSALAuthenticationProvider.ts +++ b/src/browser/ImplicitMSALAuthenticationProvider.ts @@ -82,12 +82,8 @@ export class ImplicitMSALAuthenticationProvider implements AuthenticationProvide return authResponse.accessToken; } catch (error) { if (error.name === "InteractionRequiredAuthError") { - try { - const authResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); - return authResponse.accessToken; - } catch (error) { - throw error; - } + const authResponse = await this.msalApplication.acquireTokenPopup(tokenRequest); + return authResponse.accessToken; } else { throw error; } diff --git a/src/tasks/LargeFileUploadTask.ts b/src/tasks/LargeFileUploadTask.ts index 412de5986..185390f9d 100644 --- a/src/tasks/LargeFileUploadTask.ts +++ b/src/tasks/LargeFileUploadTask.ts @@ -215,6 +215,7 @@ export class LargeFileUploadTask { * @returns The promise resolves to uploaded response */ public async upload(): Promise { + // eslint-disable-next-line no-constant-condition while (true) { const nextRange = this.getNextRange(); if (nextRange.maxValue === -1) { From 5a8ed6acc7efdc9947d6d7869c4ce071cd408529 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Sun, 3 Jan 2021 20:45:43 -0800 Subject: [PATCH 09/14] Adding eslint-sort-import plugin --- .eslintrc.json | 13 ++----------- package-lock.json | 6 ++++++ package.json | 2 ++ spec/content/BatchRequestContent.ts | 3 ++- spec/core/Client.ts | 3 ++- spec/middleware/MiddlewareControl.ts | 3 ++- spec/middleware/RetryHandler.ts | 3 ++- spec/test-helper.ts | 1 - src/ImplicitMSALAuthenticationProvider.ts | 2 +- src/middleware/AuthenticationHandler.ts | 1 - src/middleware/ChaosHandler.ts | 1 - src/middleware/HTTPMessageHandler.ts | 1 - src/middleware/MiddlewareFactory.ts | 1 - src/middleware/RedirectHandler.ts | 1 - src/middleware/RetryHandler.ts | 1 - src/middleware/TelemetryHandler.ts | 1 - .../options/AuthenticationHandlerOptions.ts | 1 - src/middleware/options/RetryHandlerOptions.ts | 1 - src/middleware/options/TelemetryHandlerOptions.ts | 1 - src/tasks/OneDriveLargeFileUploadTask.ts | 1 - 20 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 905cd005c..8f4b6a658 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "prettier"], + "plugins": ["@typescript-eslint", "prettier", "simple-import-sort"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { "no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. @@ -163,16 +163,7 @@ "@typescript-eslint/no-parameter-properties": "off", "@typescript-eslint/no-array-constructor": "error", // eslint - // "sort-imports": [ - // "error", - // { - // "ignoreCase": false, - // "ignoreDeclarationSort": false, - // "ignoreMemberSort": false, - // "memberSyntaxSortOrder": ["none", "all", "multiple", "single"], - // "allowSeparatedGroups": false - // } - // ], + "simple-import-sort/imports": "error", "brace-style": "error", "constructor-super": "error", "curly": ["error", "multi-line"], diff --git a/package-lock.json b/package-lock.json index 3517f3584..84f608595 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2394,6 +2394,12 @@ "prettier-linter-helpers": "^1.0.0" } }, + "eslint-plugin-simple-import-sort": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz", + "integrity": "sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==", + "dev": true + }, "eslint-scope": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz", diff --git a/package.json b/package.json index b1e0a3461..244884d01 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "eslint": "^7.6.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-prettier": "^3.1.4", + "eslint-plugin-simple-import-sort": "^7.0.0", "gulp": "^4.0.2", "husky": "^2.2.0", "isomorphic-fetch": "^2.2.1", @@ -56,6 +57,7 @@ "test:development": "tsc --p spec/tsconfig.json && mocha spec/development/workload", "test:workload": "tsc --p spec/tsconfig.json && mocha spec/development/workload", "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", "format:css": "prettier --write \"**/*.css\"", "format:html": "prettier --write \"**/*.html\"", "format:js": "prettier --write \"**/*.js\"", diff --git a/spec/content/BatchRequestContent.ts b/spec/content/BatchRequestContent.ts index 0f53c7a77..a02261bc6 100644 --- a/spec/content/BatchRequestContent.ts +++ b/spec/content/BatchRequestContent.ts @@ -5,9 +5,10 @@ * ------------------------------------------------------------------------------------------- */ +import "isomorphic-fetch"; + import { assert } from "chai"; import * as fs from "fs"; -import "isomorphic-fetch"; import { BatchRequestContent, BatchRequestStep } from "../../src/content/BatchRequestContent"; import { randomString } from "../test-helper"; diff --git a/spec/core/Client.ts b/spec/core/Client.ts index 0a56cb0bc..570f470cf 100644 --- a/spec/core/Client.ts +++ b/spec/core/Client.ts @@ -5,9 +5,10 @@ * ------------------------------------------------------------------------------------------- */ -import { assert } from "chai"; import "isomorphic-fetch"; +import { assert } from "chai"; + import { CustomAuthenticationProvider, TelemetryHandler } from "../../src"; import { Client } from "../../src/Client"; import { GraphClientError } from "../../src/GraphClientError"; diff --git a/spec/middleware/MiddlewareControl.ts b/spec/middleware/MiddlewareControl.ts index 6103c8898..3620ce7a9 100644 --- a/spec/middleware/MiddlewareControl.ts +++ b/spec/middleware/MiddlewareControl.ts @@ -9,9 +9,10 @@ * @module MiddlewareControl */ -import { assert } from "chai"; import "isomorphic-fetch"; +import { assert } from "chai"; + import { MiddlewareControl } from "../../src/middleware/MiddlewareControl"; import { DummyHandlerOptions } from "../DummyHandlerOptions"; diff --git a/spec/middleware/RetryHandler.ts b/spec/middleware/RetryHandler.ts index a0531faea..5fcffc323 100644 --- a/spec/middleware/RetryHandler.ts +++ b/spec/middleware/RetryHandler.ts @@ -5,9 +5,10 @@ * ------------------------------------------------------------------------------------------- */ -import { assert } from "chai"; import "isomorphic-fetch"; +import { assert } from "chai"; + import { Context } from "../../src/IContext"; import { FetchOptions } from "../../src/IFetchOptions"; import { MiddlewareControl } from "../../src/middleware/MiddlewareControl"; diff --git a/spec/test-helper.ts b/spec/test-helper.ts index 83082ed7b..b2e51151f 100644 --- a/spec/test-helper.ts +++ b/spec/test-helper.ts @@ -8,7 +8,6 @@ import "isomorphic-fetch"; import { Client } from "../src/index"; - import { DummyAuthenticationProvider } from "./DummyAuthenticationProvider"; export function getClient(): Client { diff --git a/src/ImplicitMSALAuthenticationProvider.ts b/src/ImplicitMSALAuthenticationProvider.ts index 725d3ed42..9695749c9 100644 --- a/src/ImplicitMSALAuthenticationProvider.ts +++ b/src/ImplicitMSALAuthenticationProvider.ts @@ -9,7 +9,7 @@ * @module ImplicitMSALAuthenticationProvider */ -import { AuthResponse, AuthenticationParameters, InteractionRequiredAuthError, UserAgentApplication } from "msal"; +import { AuthenticationParameters, AuthResponse, InteractionRequiredAuthError, UserAgentApplication } from "msal"; import { AuthenticationProvider } from "./IAuthenticationProvider"; import { AuthenticationProviderOptions } from "./IAuthenticationProviderOptions"; diff --git a/src/middleware/AuthenticationHandler.ts b/src/middleware/AuthenticationHandler.ts index 6ef197a53..121c5e0b1 100644 --- a/src/middleware/AuthenticationHandler.ts +++ b/src/middleware/AuthenticationHandler.ts @@ -12,7 +12,6 @@ import { AuthenticationProvider } from "../IAuthenticationProvider"; import { AuthenticationProviderOptions } from "../IAuthenticationProviderOptions"; import { Context } from "../IContext"; - import { Middleware } from "./IMiddleware"; import { MiddlewareControl } from "./MiddlewareControl"; import { appendRequestHeader } from "./MiddlewareUtil"; diff --git a/src/middleware/ChaosHandler.ts b/src/middleware/ChaosHandler.ts index 62b56dde3..c1a2e299e 100644 --- a/src/middleware/ChaosHandler.ts +++ b/src/middleware/ChaosHandler.ts @@ -11,7 +11,6 @@ import { Context } from "../IContext"; import { RequestMethod } from "../RequestMethod"; - import { Middleware } from "./IMiddleware"; import { MiddlewareControl } from "./MiddlewareControl"; import { generateUUID } from "./MiddlewareUtil"; diff --git a/src/middleware/HTTPMessageHandler.ts b/src/middleware/HTTPMessageHandler.ts index 69f5870e8..f3882bb74 100644 --- a/src/middleware/HTTPMessageHandler.ts +++ b/src/middleware/HTTPMessageHandler.ts @@ -10,7 +10,6 @@ */ import { Context } from "../IContext"; - import { Middleware } from "./IMiddleware"; /** diff --git a/src/middleware/MiddlewareFactory.ts b/src/middleware/MiddlewareFactory.ts index 619e55d63..98bb6f083 100644 --- a/src/middleware/MiddlewareFactory.ts +++ b/src/middleware/MiddlewareFactory.ts @@ -10,7 +10,6 @@ */ import { AuthenticationProvider } from "../IAuthenticationProvider"; - import { AuthenticationHandler } from "./AuthenticationHandler"; import { HTTPMessageHandler } from "./HTTPMessageHandler"; import { Middleware } from "./IMiddleware"; diff --git a/src/middleware/RedirectHandler.ts b/src/middleware/RedirectHandler.ts index f6e20fe3d..911e408f2 100644 --- a/src/middleware/RedirectHandler.ts +++ b/src/middleware/RedirectHandler.ts @@ -11,7 +11,6 @@ import { Context } from "../IContext"; import { RequestMethod } from "../RequestMethod"; - import { Middleware } from "./IMiddleware"; import { MiddlewareControl } from "./MiddlewareControl"; import { cloneRequestWithNewUrl } from "./MiddlewareUtil"; diff --git a/src/middleware/RetryHandler.ts b/src/middleware/RetryHandler.ts index fcaf82070..36836fecb 100644 --- a/src/middleware/RetryHandler.ts +++ b/src/middleware/RetryHandler.ts @@ -12,7 +12,6 @@ import { Context } from "../IContext"; import { FetchOptions } from "../IFetchOptions"; import { RequestMethod } from "../RequestMethod"; - import { Middleware } from "./IMiddleware"; import { MiddlewareControl } from "./MiddlewareControl"; import { getRequestHeader, setRequestHeader } from "./MiddlewareUtil"; diff --git a/src/middleware/TelemetryHandler.ts b/src/middleware/TelemetryHandler.ts index a8f0dbfe8..3b609a4a0 100644 --- a/src/middleware/TelemetryHandler.ts +++ b/src/middleware/TelemetryHandler.ts @@ -11,7 +11,6 @@ import { isGraphURL } from "../GraphRequestUtil"; import { Context } from "../IContext"; import { PACKAGE_VERSION } from "../Version"; - import { Middleware } from "./IMiddleware"; import { MiddlewareControl } from "./MiddlewareControl"; import { appendRequestHeader, generateUUID, getRequestHeader, setRequestHeader } from "./MiddlewareUtil"; diff --git a/src/middleware/options/AuthenticationHandlerOptions.ts b/src/middleware/options/AuthenticationHandlerOptions.ts index 8eff20b84..547b326ba 100644 --- a/src/middleware/options/AuthenticationHandlerOptions.ts +++ b/src/middleware/options/AuthenticationHandlerOptions.ts @@ -11,7 +11,6 @@ import { AuthenticationProvider } from "../../IAuthenticationProvider"; import { AuthenticationProviderOptions } from "../../IAuthenticationProviderOptions"; - import { MiddlewareOptions } from "./IMiddlewareOptions"; /** diff --git a/src/middleware/options/RetryHandlerOptions.ts b/src/middleware/options/RetryHandlerOptions.ts index 8e9ff1503..8191d165c 100644 --- a/src/middleware/options/RetryHandlerOptions.ts +++ b/src/middleware/options/RetryHandlerOptions.ts @@ -10,7 +10,6 @@ */ import { FetchOptions } from "../../IFetchOptions"; - import { MiddlewareOptions } from "./IMiddlewareOptions"; /** diff --git a/src/middleware/options/TelemetryHandlerOptions.ts b/src/middleware/options/TelemetryHandlerOptions.ts index 2033bc556..aa251eb15 100644 --- a/src/middleware/options/TelemetryHandlerOptions.ts +++ b/src/middleware/options/TelemetryHandlerOptions.ts @@ -11,7 +11,6 @@ import { Context } from "../../IContext"; import { MiddlewareControl } from "../MiddlewareControl"; - import { MiddlewareOptions } from "./IMiddlewareOptions"; /** diff --git a/src/tasks/OneDriveLargeFileUploadTask.ts b/src/tasks/OneDriveLargeFileUploadTask.ts index 857eec79b..e671489e1 100644 --- a/src/tasks/OneDriveLargeFileUploadTask.ts +++ b/src/tasks/OneDriveLargeFileUploadTask.ts @@ -10,7 +10,6 @@ */ import { Client } from "../index"; - import { FileObject, LargeFileUploadSession, LargeFileUploadTask, LargeFileUploadTaskOptions } from "./LargeFileUploadTask"; import { getValidRangeSize } from "./OneDriveLargeFileUploadTaskUtil"; From 8d5d75648d8c3ed2a637a323c1bd8c1ae1426191 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Fri, 29 Jan 2021 01:09:05 -0800 Subject: [PATCH 10/14] Removing try-catch blocks --- .eslintrc.json | 9 +- package.json | 4 +- src/middleware/ChaosHandler.ts | 23 ++--- test/common/core/GraphResponseHandler.ts | 1 + test/common/tasks/LargeFileUploadTask.ts | 1 + test/development/workload/OneNote.ts | 84 +++++++--------- test/development/workload/excel.ts | 50 ++++------ test/development/workload/groups.ts | 32 +++--- test/development/workload/insights.ts | 52 ++++------ test/development/workload/open-extensions.ts | 26 ++--- test/development/workload/users.ts | 98 +++++++------------ .../TokenCredentialAuthenticationProvider.ts | 1 + test/node/content/BatchRequestContent.ts | 8 +- 13 files changed, 143 insertions(+), 246 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8f4b6a658..693b8dc34 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -127,14 +127,7 @@ "allowTernary": true } ], - "@typescript-eslint/space-before-function-paren": [ - "error", - { - "asyncArrow": "always", - "anonymous": "never", - "named": "never" - } - ], + "@typescript-eslint/space-before-function-paren": "off", "@typescript-eslint/consistent-type-assertions": "error", "@typescript-eslint/explicit-member-accessibility": [ "off", diff --git a/package.json b/package.json index 49ac5fd90..261e6b143 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "types": "./lib/src/index.d.ts", "dependencies": { "@babel/runtime": "^7.4.4", - "sinon": "^9.2.4", "tslib": "^1.9.3" }, "devDependencies": { @@ -63,6 +62,9 @@ "rollup-plugin-commonjs": "^10.0.1", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-terser": "^5.0.0", + "sinon": "^9.2.4", + "source-map-support": "^0.5.19", + "ts-node": "^9.0.0", "typescript": "^3.4.5", "uglify-es": "^3.3.9" }, diff --git a/src/middleware/ChaosHandler.ts b/src/middleware/ChaosHandler.ts index 96b02b639..23deb783f 100644 --- a/src/middleware/ChaosHandler.ts +++ b/src/middleware/ChaosHandler.ts @@ -123,22 +123,13 @@ export class ChaosHandler implements Middleware { * @param {Context} context - Contains the context of the request */ private createResponse(chaosHandlerOptions: ChaosHandlerOptions, context: Context) { - try { - let responseBody: any; - let responseHeader: Headers; - let requestID: string; - let requestDate: Date; - const requestURL = context.request as string; - - requestID = generateUUID(); - requestDate = new Date(); - responseHeader = this.createResponseHeaders(chaosHandlerOptions, requestID, requestDate.toString()); - responseBody = this.createResponseBody(chaosHandlerOptions, requestID, requestDate.toString()); - const init: any = { url: requestURL, status: chaosHandlerOptions.statusCode, statusText: chaosHandlerOptions.statusMessage, headers: responseHeader }; - context.response = new Response(responseBody, init); - } catch (error) { - throw error; - } + const requestURL = context.request as string; + const requestID = generateUUID(); + const requestDate = new Date(); + const responseHeader = this.createResponseHeaders(chaosHandlerOptions, requestID, requestDate.toString()); + const responseBody = this.createResponseBody(chaosHandlerOptions, requestID, requestDate.toString()); + const init: any = { url: requestURL, status: chaosHandlerOptions.statusCode, statusText: chaosHandlerOptions.statusMessage, headers: responseHeader }; + context.response = new Response(responseBody, init); } /** diff --git a/test/common/core/GraphResponseHandler.ts b/test/common/core/GraphResponseHandler.ts index eac75cf60..3820aa6b7 100644 --- a/test/common/core/GraphResponseHandler.ts +++ b/test/common/core/GraphResponseHandler.ts @@ -98,6 +98,7 @@ describe("GraphResponseHandler.ts", () => { it("Should return raw response incase of unknown content-type", async () => { const data = "test data"; const response = new Response(data, status200Unknown); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const responseValue = await GraphResponseHandler["convertResponse"](response); // TODO - Handle unknown responses // assert.equal(responseValue, data); diff --git a/test/common/tasks/LargeFileUploadTask.ts b/test/common/tasks/LargeFileUploadTask.ts index 1dd0b1604..62fceefbe 100644 --- a/test/common/tasks/LargeFileUploadTask.ts +++ b/test/common/tasks/LargeFileUploadTask.ts @@ -166,6 +166,7 @@ describe("LargeFileUploadTask.ts", () => { uploadTask["updateTaskStatus"](statusResponse); uploadTask .upload() + // eslint-disable-next-line @typescript-eslint/no-unused-vars .then((res) => { throw new Error("Test Failed - Upload is working for upload completed task"); }) diff --git a/test/development/workload/OneNote.ts b/test/development/workload/OneNote.ts index c7774ed44..297a2ef0d 100644 --- a/test/development/workload/OneNote.ts +++ b/test/development/workload/OneNote.ts @@ -28,46 +28,34 @@ describe("OneNote", function() { const PageContent = "Sample page content - " + randomString(); it("Create a OneNote notebook", async () => { - try { - const json = await client.api("/me/onenote/notebooks").post(notebook); - const createdNotebook = json as Notebook; - assert.isDefined(createdNotebook.id); - assert.equal(notebook.displayName, createdNotebook.displayName); - assert.isUndefined(createdNotebook["random fake property that should be null"]); - // if this passes, use this notebook in the following tests - notebook = createdNotebook; - } catch (error) { - throw error; - } + const json = await client.api("/me/onenote/notebooks").post(notebook); + const createdNotebook = json as Notebook; + assert.isDefined(createdNotebook.id); + assert.equal(notebook.displayName, createdNotebook.displayName); + assert.isUndefined(createdNotebook["random fake property that should be null"]); + // if this passes, use this notebook in the following tests + notebook = createdNotebook; }); it("Create a OneNote section in a Notebook", async () => { - try { - const json = await client.api(`/me/onenote/notebooks/${notebook.id}/sections`).post(section); - const createdSection = json as OnenoteSection; - assert.isDefined(createdSection.id); - assert.equal(section.displayName, createdSection.displayName); - assert.isUndefined(createdSection["random fake property that should be null"]); - // if this passes, use this notebook in the following tests - section = createdSection; - } catch (error) { - throw error; - } + const json = await client.api(`/me/onenote/notebooks/${notebook.id}/sections`).post(section); + const createdSection = json as OnenoteSection; + assert.isDefined(createdSection.id); + assert.equal(section.displayName, createdSection.displayName); + assert.isUndefined(createdSection["random fake property that should be null"]); + // if this passes, use this notebook in the following tests + section = createdSection; }); it("Create a OneNote page in a section with basic text content", async () => { - try { - const json = await client - .api(`/me/onenote/sections/${section.id}/pages`) - .header("Content-Type", "text/html") - .post(PageContent); - createdPage = json as OnenotePage; - assert.isDefined(createdPage.id); - assert.isDefined(createdPage.contentUrl); - assert.isUndefined(createdPage["random fake property that should be null"]); - } catch (error) { - throw error; - } + const json = await client + .api(`/me/onenote/sections/${section.id}/pages`) + .header("Content-Type", "text/html") + .post(PageContent); + createdPage = json as OnenotePage; + assert.isDefined(createdPage.id); + assert.isDefined(createdPage.contentUrl); + assert.isUndefined(createdPage["random fake property that should be null"]); }); it("Create a OneNote page with html page content", async () => { const formData = new FormData(); @@ -88,24 +76,20 @@ describe("OneNote", function() { .header("content-type", "application/xhtml+xml") .post(body); const createdPageFromHTML = json as OnenotePage; - assert.isDefined(createdPage.id); - assert.isDefined(createdPage.contentUrl); - assert.isUndefined(createdPage["random fake property that should be null"]); + assert.isDefined(createdPageFromHTML.id); + assert.isDefined(createdPageFromHTML.contentUrl); + assert.isUndefined(createdPageFromHTML["random fake property that should be null"]); }); it("create a OneNote page with html page content and file attachment", async () => { - try { - const formData = new FormData(); - formData.append("Presentation", fs.createReadStream("./test/sample_files/onenotepage_fileattachment.html")); - formData.append("fileBlock1", fs.createReadStream("./sample.png")); - const json = await client.api(`/me/onenote/sections/${section.id}/pages`).post(formData); - const createdPageFromHTML = json as OnenotePage; - assert.isDefined(createdPage.id); - assert.isDefined(createdPage.contentUrl); - assert.equal("A page with rendered file attachment", createdPageFromHTML.title); - assert.isUndefined(createdPage["random fake property that should be null"]); - } catch (error) { - throw error; - } + const formData = new FormData(); + formData.append("Presentation", fs.createReadStream("./test/sample_files/onenotepage_fileattachment.html")); + formData.append("fileBlock1", fs.createReadStream("./sample.png")); + const json = await client.api(`/me/onenote/sections/${section.id}/pages`).post(formData); + const createdPageFromHTML = json as OnenotePage; + assert.isDefined(createdPage.id); + assert.isDefined(createdPage.contentUrl); + assert.equal("A page with rendered file attachment", createdPageFromHTML.title); + assert.isUndefined(createdPage["random fake property that should be null"]); }); }); diff --git a/test/development/workload/excel.ts b/test/development/workload/excel.ts index a469b41b0..f6a155573 100644 --- a/test/development/workload/excel.ts +++ b/test/development/workload/excel.ts @@ -23,27 +23,19 @@ describe("Excel", function() { }, 1000); }); it("Uploads an Excel file to OneDrive", async () => { - try { - const file = fs.readFileSync("./test/sample_files/empty-spreadsheet.xlsx"); - const res = await client.api(`/me/drive/root/children/${ExcelFilename}/content`).put(file); - assert.isDefined(res.id); - } catch (error) { - throw error; - } + const file = fs.readFileSync("./test/sample_files/empty-spreadsheet.xlsx"); + const res = await client.api(`/me/drive/root/children/${ExcelFilename}/content`).put(file); + assert.isDefined(res.id); }); it("Lists the worksheets in an excel file", async () => { - try { - const res = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets`).get(); - const worksheets = res.value as WorkbookWorksheet[]; - const sheet1 = worksheets[0]; - assert.isNumber(sheet1.position); - assert.isString(sheet1.visibility); - assert.isString(sheet1.id); - assert.isUndefined(sheet1["random fake property that should be null"]); - } catch (error) { - throw error; - } + const res = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets`).get(); + const worksheets = res.value as WorkbookWorksheet[]; + const sheet1 = worksheets[0]; + assert.isNumber(sheet1.position); + assert.isString(sheet1.visibility); + assert.isString(sheet1.id); + assert.isUndefined(sheet1["random fake property that should be null"]); }); it("Updates workbook worksheet range", async () => { @@ -53,23 +45,15 @@ describe("Excel", function() { ["cell b1", "cell b2"], ], }; - try { - const response = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range(address='A1:B2')`).patch(sampleData); - assert.isDefined(response["@odata.id"]); - assert.isDefined(response.values); - } catch (error) { - throw error; - } + const response = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range(address='A1:B2')`).patch(sampleData); + assert.isDefined(response["@odata.id"]); + assert.isDefined(response.values); }); it("GETs the used range of the worksheet", async () => { - try { - const res: WorkbookRange = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range/usedrange`).get(); - assert.isNumber(res.cellCount); - assert.isString(res.address); - assert.isUndefined(res["random fake property that should be null"]); - } catch (error) { - throw error; - } + const res: WorkbookRange = await client.api(`/me/drive/root:/${ExcelFilename}:/workbook/worksheets/Sheet1/range/usedrange`).get(); + assert.isNumber(res.cellCount); + assert.isString(res.address); + assert.isUndefined(res["random fake property that should be null"]); }); }); diff --git a/test/development/workload/groups.ts b/test/development/workload/groups.ts index 24c0fdb72..7ec45fdcd 100644 --- a/test/development/workload/groups.ts +++ b/test/development/workload/groups.ts @@ -15,16 +15,12 @@ const client = getClient(); describe("Groups", function() { this.timeout(10 * 1000); it("Fetch a list of groups and access properties on a collection item", async () => { - try { - const res = await client.api("/groups").get(); - const group = res.value[0] as Group; - assert.isDefined(group.displayName); - assert.isDefined(group.mail); - assert.isDefined(group.id); - assert.isUndefined(group["random fake property that should be null"]); - } catch (error) { - throw error; - } + const res = await client.api("/groups").get(); + const group = res.value[0] as Group; + assert.isDefined(group.displayName); + assert.isDefined(group.mail); + assert.isDefined(group.id); + assert.isUndefined(group["random fake property that should be null"]); }); it("Create a group and validate properties were set", async () => { @@ -36,15 +32,11 @@ describe("Groups", function() { mailNickname: randomString(), securityEnabled: true, }; - try { - const res = await client.api("/groups").post(group); - const createdGroup = res as Group; - assert.equal(createdGroup.displayName, group.displayName); - assert.equal(createdGroup.description, group.description); - assert.equal(createdGroup.mailEnabled, group.mailEnabled); - assert.isString(createdGroup.id); - } catch (error) { - throw error; - } + const res = await client.api("/groups").post(group); + const createdGroup = res as Group; + assert.equal(createdGroup.displayName, group.displayName); + assert.equal(createdGroup.description, group.description); + assert.equal(createdGroup.mailEnabled, group.mailEnabled); + assert.isString(createdGroup.id); }); }); diff --git a/test/development/workload/insights.ts b/test/development/workload/insights.ts index 6cc765b71..6c08d9d4d 100644 --- a/test/development/workload/insights.ts +++ b/test/development/workload/insights.ts @@ -15,48 +15,32 @@ const client = getClient(); describe("Social and Insights", function() { this.timeout(10 * 1000); it("Fetch a list of people", async () => { - try { - const res = await client.api("/me/people").get(); - const person = res.value[0] as Person; - assert.isDefined(person.displayName); - assert.isDefined(person.surname); - assert.isDefined(person.id); - assert.isUndefined(person["random fake property that should be null"]); - } catch (error) { - throw error; - } + const res = await client.api("/me/people").get(); + const person = res.value[0] as Person; + assert.isDefined(person.displayName); + assert.isDefined(person.surname); + assert.isDefined(person.id); + assert.isUndefined(person["random fake property that should be null"]); }); it("Searches the people list", async () => { - try { - await client - .api("/me/people") - .query("$search=j") - .get(); - } catch (error) { - throw error; - } + await client + .api("/me/people") + .query("$search=j") + .get(); }); it("Searches the people list with a topic", async () => { - try { - await client - .api("/me/people") - .query(`$search="topic: planning"`) - .get(); - } catch (error) { - throw error; - } + await client + .api("/me/people") + .query(`$search="topic: planning"`) + .get(); }); it("Finds items trending around me", async () => { - try { - await client - .api("/me/insights/trending") - .version("beta") - .get(); - } catch (error) { - throw error; - } + await client + .api("/me/insights/trending") + .version("beta") + .get(); }); }); diff --git a/test/development/workload/open-extensions.ts b/test/development/workload/open-extensions.ts index 72da48b2f..ee25cad59 100644 --- a/test/development/workload/open-extensions.ts +++ b/test/development/workload/open-extensions.ts @@ -25,25 +25,17 @@ describe("Open Extensions", function() { this.timeout(10 * 1000); it("Use open extensions to add a field to users", async () => { - try { - const response = await client.api("/me/extensions").post(extension); - const createdExtension = response as ColorOpenExtension; - assert.isDefined(createdExtension.id); - assert.equal(createdExtension.color, extension.color); - assert.equal(createdExtension.extensionName, extension.extensionName); - assert.isUndefined(createdExtension["random fake property that should be null"]); - // save this createdExtension for later tests (id) - extension = createdExtension; - } catch (error) { - throw error; - } + const response = await client.api("/me/extensions").post(extension); + const createdExtension = response as ColorOpenExtension; + assert.isDefined(createdExtension.id); + assert.equal(createdExtension.color, extension.color); + assert.equal(createdExtension.extensionName, extension.extensionName); + assert.isUndefined(createdExtension["random fake property that should be null"]); + // save this createdExtension for later tests (id) + extension = createdExtension; }); it("Deletes the created open extension", async () => { - try { - await client.api(`/me/extensions/${extension.id}`).delete(); - } catch (error) { - throw error; - } + await client.api(`/me/extensions/${extension.id}`).delete(); }); }); diff --git a/test/development/workload/users.ts b/test/development/workload/users.ts index 40dd2a0cd..1f870a809 100644 --- a/test/development/workload/users.ts +++ b/test/development/workload/users.ts @@ -18,85 +18,61 @@ describe("Users", function() { this.timeout(10 * 1000); it("Fetch the authenticated user and access entity properties", async () => { - try { - const res = await client.api("/me").get(); - const user = res as User; - assert.isDefined(user.displayName); - assert.isDefined(user.mail); - assert.isDefined(user.id); + const res = await client.api("/me").get(); + const user = res as User; + assert.isDefined(user.displayName); + assert.isDefined(user.mail); + assert.isDefined(user.id); - assert.isDefined(user.surname); - assert.isDefined(user.userPrincipalName); + assert.isDefined(user.surname); + assert.isDefined(user.userPrincipalName); - assert.isArray(user.businessPhones); - assert.isUndefined(user["random fake property that should be null"]); - } catch (error) { - throw error; - } + assert.isArray(user.businessPhones); + assert.isUndefined(user["random fake property that should be null"]); }); it("Fetch the authenticated user and access entity properties", async () => { - try { - const res = await client.api("/me").get(); - const user = res as User; - assert.isDefined(user.displayName); - assert.isDefined(user.mail); - assert.isDefined(user.id); + const res = await client.api("/me").get(); + const user = res as User; + assert.isDefined(user.displayName); + assert.isDefined(user.mail); + assert.isDefined(user.id); - assert.isDefined(user.surname); - assert.isDefined(user.userPrincipalName); + assert.isDefined(user.surname); + assert.isDefined(user.userPrincipalName); - assert.isArray(user.businessPhones); - assert.isUndefined(user["random fake property that should be null"]); - } catch (error) { - throw error; - } + assert.isArray(user.businessPhones); + assert.isUndefined(user["random fake property that should be null"]); }); it("Modify and verify officeLocation property", async () => { - try { - const officeLocation = randomString(); - await client.api("/me").patch({ officeLocation }); - const res = await client.api("/me").get(); - const user = res as User; - assert.equal(user.officeLocation, officeLocation); - } catch (error) { - throw error; - } + const officeLocation = randomString(); + await client.api("/me").patch({ officeLocation }); + const res = await client.api("/me").get(); + const user = res as User; + assert.equal(user.officeLocation, officeLocation); }); it("Modify and verify givenName property", async () => { - try { - const givenName = randomString(); - await client.api("/me").patch({ givenName }); - const res = await client.api("/me").get(); - const user = res as User; - assert.equal(user.givenName, givenName); - } catch (error) { - throw error; - } + const givenName = randomString(); + await client.api("/me").patch({ givenName }); + const res = await client.api("/me").get(); + const user = res as User; + assert.equal(user.givenName, givenName); }); it("Fetch a list of users and access properties on a collection item", async () => { - try { - const collection = await client.api("/users").get(); - const users: User[] = collection.value; - assert.isDefined(users[0].displayName); - assert.isDefined(users[0].id); - assert.isDefined(users[0].mail); - } catch (error) { - throw error; - } + const collection = await client.api("/users").get(); + const users: User[] = collection.value; + assert.isDefined(users[0].displayName); + assert.isDefined(users[0].id); + assert.isDefined(users[0].mail); }); it("Filters on users list", async () => { - try { - await client - .api("/users") - .filter("Department eq 'Finance'") - .get(); - } catch (error) { - throw error; - } + await client + .api("/users") + .filter("Department eq 'Finance'") + .get(); }); }); diff --git a/test/node/authentication/TokenCredentialAuthenticationProvider.ts b/test/node/authentication/TokenCredentialAuthenticationProvider.ts index dc137f721..2d52b4780 100644 --- a/test/node/authentication/TokenCredentialAuthenticationProvider.ts +++ b/test/node/authentication/TokenCredentialAuthenticationProvider.ts @@ -51,6 +51,7 @@ describe("TokenCredentialAuthenticationProvider.ts", () => { const moq = sinon.mock(client); moq.expects("getToken").resolves(accessToken); const tokenCredentialAuthenticationProvider = new TokenCredentialAuthenticationProvider(client, authProviderOptions); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const access = await tokenCredentialAuthenticationProvider.getAccessToken(); } catch (err) { expectedError = err; diff --git a/test/node/content/BatchRequestContent.ts b/test/node/content/BatchRequestContent.ts index c91da79ff..51a1f6d6f 100644 --- a/test/node/content/BatchRequestContent.ts +++ b/test/node/content/BatchRequestContent.ts @@ -31,12 +31,8 @@ describe("BatchRequestContent.ts", () => { }), }; const batchReq = new BatchRequestContent([uploadOneDriveFile]); - try { - const content = await batchReq.getContent(); - assert.isDefined(content.requests[0].body); - } catch (error) { - throw error; - } + const content = await batchReq.getContent(); + assert.isDefined(content.requests[0].body); }); }); }); From 9cbc5a5abebc37ad1fa9fd86849f348f2ebe74ad Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Tue, 2 Feb 2021 02:01:37 -0800 Subject: [PATCH 11/14] update packages --- .eslintrc.json | 2 +- package-lock.json | 111 +++++++++++++++++++++++++++++++++------------- package.json | 10 ++--- 3 files changed, 86 insertions(+), 37 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 693b8dc34..06819e5b2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -155,7 +155,7 @@ "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-parameter-properties": "off", "@typescript-eslint/no-array-constructor": "error", - // eslint + // eslint rules "simple-import-sort/imports": "error", "brace-style": "error", "constructor-super": "error", diff --git a/package-lock.json b/package-lock.json index 61bd8dfcb..593587b11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1377,6 +1377,7 @@ "version": "1.8.2", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz", "integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==", + "dev": true, "requires": { "type-detect": "4.0.8" } @@ -1385,6 +1386,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz", "integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==", + "dev": true, "requires": { "@sinonjs/commons": "^1.7.0" } @@ -1393,6 +1395,7 @@ "version": "5.3.1", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.1.tgz", "integrity": "sha512-1Hc0b1TtyfBu8ixF/tpfSHTVWKwCBLY4QJbkgnE7HcwyvT2xArDxb4K7dMgqRm3szI+LJbzmW/s4xxEhv6hwDg==", + "dev": true, "requires": { "@sinonjs/commons": "^1.6.0", "lodash.get": "^4.4.2", @@ -1402,7 +1405,8 @@ "@sinonjs/text-encoding": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", - "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==" + "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", + "dev": true }, "@types/chai": { "version": "4.2.14", @@ -1791,6 +1795,12 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -3084,6 +3094,12 @@ "sha.js": "^2.4.8" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -3758,9 +3774,9 @@ "dev": true }, "eslint": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.18.0.tgz", - "integrity": "sha512-fbgTiE8BfUJZuBeq2Yi7J3RB3WGUQ9PNuNbmgi6jt9Iv8qrkxfy19Ds3OpL1Pm7zg3BtTVhvcUZbIRQ0wmSjAQ==", + "version": "7.19.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.19.0.tgz", + "integrity": "sha512-CGlMgJY56JZ9ZSYhJuhow61lMPPjUzWmChFya71Z/jilVos7mR/jPgaEfVGgMBY5DshbKdG8Ezb8FDCHcoMEMg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -3971,21 +3987,10 @@ } }, "eslint-config-prettier": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz", - "integrity": "sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==", - "dev": true, - "requires": { - "get-stdin": "^6.0.0" - }, - "dependencies": { - "get-stdin": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", - "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", - "dev": true - } - } + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-7.2.0.tgz", + "integrity": "sha512-rV4Qu0C3nfJKPOAhFujFxB7RMP+URFyQqqOZW9DMRD7ZDTFyjaIlETU3xzHELt++4ugC0+Jm084HQYkkJe+Ivg==", + "dev": true }, "eslint-plugin-prettier": { "version": "3.3.1", @@ -6111,7 +6116,8 @@ "just-extend": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.1.1.tgz", - "integrity": "sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==" + "integrity": "sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==", + "dev": true }, "jwa": { "version": "1.4.1", @@ -6931,7 +6937,8 @@ "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true }, "lodash.includes": { "version": "4.3.0", @@ -7092,6 +7099,12 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "make-iterator": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/make-iterator/-/make-iterator-1.0.1.tgz", @@ -7632,6 +7645,7 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz", "integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==", + "dev": true, "requires": { "@sinonjs/commons": "^1.7.0", "@sinonjs/fake-timers": "^6.0.0", @@ -8441,6 +8455,7 @@ "version": "1.8.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dev": true, "requires": { "isarray": "0.0.1" }, @@ -8448,7 +8463,8 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true } } }, @@ -9356,6 +9372,7 @@ "version": "9.2.4", "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", "integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==", + "dev": true, "requires": { "@sinonjs/commons": "^1.8.1", "@sinonjs/fake-timers": "^6.0.1", @@ -9368,17 +9385,20 @@ "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "requires": { "has-flag": "^4.0.0" } @@ -10088,9 +10108,9 @@ }, "dependencies": { "ajv": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.0.3.tgz", - "integrity": "sha512-R50QRlXSxqXcQP5SvKUrw8VZeypvo12i2IX0EeR5PiZ7bEKeHWgzgo264LDadUsCU42lTJVhFikTqJwNeH34gQ==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.0.4.tgz", + "integrity": "sha512-xzzzaqgEQfmuhbhAoqjJ8T/1okb6gAzXn/eQRNpAN1AEUoHJTNF9xCDRTtf/s3SKldtZfa+RJeTs+BQq+eZ/sw==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", @@ -10408,6 +10428,28 @@ "universalify": "^0.1.2" } }, + "ts-node": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", + "integrity": "sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + } + } + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -10453,7 +10495,8 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true }, "type-fest": { "version": "0.6.0", @@ -10661,9 +10704,9 @@ "dev": true }, "uri-js": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", - "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "requires": { "punycode": "^2.1.0" @@ -11151,6 +11194,12 @@ "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=", "dev": true }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + }, "yup": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/yup/-/yup-0.27.0.tgz", diff --git a/package.json b/package.json index 261e6b143..ebf33aa4b 100644 --- a/package.json +++ b/package.json @@ -33,14 +33,14 @@ "@types/chai": "^4.2.14", "@types/mocha": "^5.2.7", "@types/node": "^12.0.10", + "@types/sinon": "^9.0.9", "@typescript-eslint/eslint-plugin": "^3.8.0", "@typescript-eslint/parser": "^3.8.0", "chai": "^4.2.0", - "eslint": "^7.6.0", - "eslint-config-prettier": "^6.11.0", - "eslint-plugin-prettier": "^3.1.4", + "eslint": "^7.19.0", + "eslint-config-prettier": "^7.2.0", + "eslint-plugin-prettier": "^3.3.1", "eslint-plugin-simple-import-sort": "^7.0.0", - "@types/sinon": "^9.0.9", "esm": "^3.2.25", "form-data": "^2.3.3", "gulp": "^4.0.2", @@ -56,7 +56,7 @@ "mocha": "^6.2.3", "msal": "^1.0.0", "nyc": "^15.1.0", - "prettier": "^1.17.0", + "prettier": "^1.19.1", "rollup": "^1.10.1", "rollup-plugin-babel": "^4.3.2", "rollup-plugin-commonjs": "^10.0.1", From ca19972cb40588d086dea045de7af2a2c6eb9a33 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Thu, 4 Feb 2021 02:31:44 -0800 Subject: [PATCH 12/14] Lint samples, eslint remove comments --- .eslintignore | 1 - .eslintrc.json | 8 +++---- .../AuthenticationCodeFlow/src/index.ts | 24 +++++++++---------- .../ClientCredentialFlow/typescript/index.ts | 6 ++--- src/GraphRequest.ts | 18 +++++--------- src/middleware/HTTPMessageHandler.ts | 1 - 6 files changed, 23 insertions(+), 35 deletions(-) diff --git a/.eslintignore b/.eslintignore index f0be5e755..8942aa232 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,5 +4,4 @@ node_modules lib -samples spec/development \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 06819e5b2..42b52b1a5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,10 +4,6 @@ "plugins": ["@typescript-eslint", "prettier", "simple-import-sort"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"], "rules": { - "no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule. - "prefer-rest-params": "off", - "no-constant-condition": "error", - // @typescript-eslint rules "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/ban-types": "off", "@typescript-eslint/no-unused-vars": "error", @@ -155,7 +151,9 @@ "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-parameter-properties": "off", "@typescript-eslint/no-array-constructor": "error", - // eslint rules + "no-useless-catch": "error", + "prefer-rest-params": "off", + "no-constant-condition": "error", "simple-import-sort/imports": "error", "brace-style": "error", "constructor-super": "error", diff --git a/samples/tokenCredentialSamples/AuthenticationCodeFlow/src/index.ts b/samples/tokenCredentialSamples/AuthenticationCodeFlow/src/index.ts index 0e9146d2f..99b8e6f3e 100644 --- a/samples/tokenCredentialSamples/AuthenticationCodeFlow/src/index.ts +++ b/samples/tokenCredentialSamples/AuthenticationCodeFlow/src/index.ts @@ -8,16 +8,17 @@ /** * This sample is referenced from - https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/manual/authorizationCodeSample.ts */ +import "isomorphic-fetch"; + import { AuthorizationCodeCredential } from "@azure/identity"; +import { Client } from "@microsoft/microsoft-graph-client"; +import { TokenCredentialAuthenticationProvider } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; import express from "express"; import { Server } from "http"; -import "isomorphic-fetch"; import open from "open"; import qs from "qs"; -import { TokenCredentialAuthenticationProvider } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; -import { Client } from "@microsoft/microsoft-graph-client"; -import { port, tenantId, clientSecret, clientId, scopes, authorityHost, redirectUri } from "./secrets"; +import { authorityHost, clientId, clientSecret, port, redirectUri, scopes, tenantId } from "./secrets"; if (tenantId === undefined || clientId === undefined) { console.error("AZURE_TENANT_ID and AZURE_CLIENT_ID environment variables must be set"); @@ -40,8 +41,7 @@ async function getCredential(): Promise { // authentication redirect to be sent to the local redirect URI. const authCodePromise = new Promise((resolve, reject) => { const app = express(); - let server: Server | undefined = undefined; - + const server: Server = app.listen(port, () => console.log(`Authorization code redirect server listening on port ${port}`)); app.get("/authresponse", (req, res) => { // Close the temporary server once we've received the redirect. res.sendStatus(200); @@ -57,14 +57,12 @@ async function getCredential(): Promise { reject(new Error(`Authentication Error "${req.query["error"]}":\n\n${req.query["error_description"]}`)); } }); - - server = app.listen(port, () => console.log(`Authorization code redirect server listening on port ${port}`)); }); // Direct the user to the authentication URI either by opening a // browser (desktop and mobile apps) or redirecting their browser // using a Location header (web apps and APIs). - const authorizeUrl = getAuthorizeUrl(tenantId!, clientId!, scopes); + const authorizeUrl = getAuthorizeUrl(tenantId, clientId, scopes); console.log("Opening user's browser to URL:", authorizeUrl); await open(authorizeUrl); @@ -77,8 +75,8 @@ async function getCredential(): Promise { // refreshing the access token from this point forward. if (clientSecret) { return new AuthorizationCodeCredential( - tenantId!, - clientId!, + tenantId, + clientId, clientSecret, authorizationCode, redirectUri, @@ -92,8 +90,8 @@ async function getCredential(): Promise { // NOTE: If there is no client secret, we can construct an auth code credential // using this method. return new AuthorizationCodeCredential( - tenantId!, - clientId!, + tenantId, + clientId, authorizationCode, redirectUri, // NOTE: It is not necessary to explicitly pass the authorityHost when using diff --git a/samples/tokenCredentialSamples/ClientCredentialFlow/typescript/index.ts b/samples/tokenCredentialSamples/ClientCredentialFlow/typescript/index.ts index 32f9042c0..7107a1a48 100644 --- a/samples/tokenCredentialSamples/ClientCredentialFlow/typescript/index.ts +++ b/samples/tokenCredentialSamples/ClientCredentialFlow/typescript/index.ts @@ -1,9 +1,9 @@ -import { ClientSecretCredential } from "@azure/identity"; - import "isomorphic-fetch"; -import { TokenCredentialAuthenticationProvider } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; +import { ClientSecretCredential } from "@azure/identity"; import { Client } from "@microsoft/microsoft-graph-client"; +import { TokenCredentialAuthenticationProvider } from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials"; + import { clientId, clientSecret, scopes, tenantId } from "./secrets"; async function runExample() { diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index a3bdb3d55..743af0a28 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -655,8 +655,7 @@ export class GraphRequest { this.setHeaderContentType(); options.headers = this._headers; } - const response = await this.send(url, options, callback); - return response; + return await this.send(url, options, callback); } /** @@ -686,8 +685,7 @@ export class GraphRequest { method: RequestMethod.PUT, body: serializeContent(content), }; - const response = await this.send(url, options, callback); - return response; + return await this.send(url, options, callback); } /** @@ -705,8 +703,7 @@ export class GraphRequest { method: RequestMethod.PATCH, body: serializeContent(content), }; - const response = await this.send(url, options, callback); - return response; + return await this.send(url, options, callback); } /** @@ -733,8 +730,7 @@ export class GraphRequest { const options: FetchOptions = { method: RequestMethod.DELETE, }; - const response = await this.send(url, options, callback); - return response; + return await this.send(url, options, callback); } /** @@ -761,8 +757,7 @@ export class GraphRequest { method: RequestMethod.GET, }; this.responseType(ResponseType.STREAM); - const stream = await this.send(url, options, callback); - return stream; + return await this.send(url, options, callback); } /** @@ -782,7 +777,6 @@ export class GraphRequest { }, body: stream, }; - const response = await this.send(url, options, callback); - return response; + return await this.send(url, options, callback); } } diff --git a/src/middleware/HTTPMessageHandler.ts b/src/middleware/HTTPMessageHandler.ts index f3882bb74..cc6f50416 100644 --- a/src/middleware/HTTPMessageHandler.ts +++ b/src/middleware/HTTPMessageHandler.ts @@ -27,6 +27,5 @@ export class HTTPMessageHandler implements Middleware { */ public async execute(context: Context): Promise { context.response = await fetch(context.request, context.options); - return; } } From be8e8532b7efd3665ac666d3016c2a6422cb69f5 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Fri, 5 Feb 2021 14:25:11 -0800 Subject: [PATCH 13/14] Correcting test assertion, using multiline disabling --- src/middleware/options/TelemetryHandlerOptions.ts | 9 +++++---- test/common/core/Client.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/middleware/options/TelemetryHandlerOptions.ts b/src/middleware/options/TelemetryHandlerOptions.ts index aa251eb15..30f5bde41 100644 --- a/src/middleware/options/TelemetryHandlerOptions.ts +++ b/src/middleware/options/TelemetryHandlerOptions.ts @@ -22,10 +22,11 @@ import { MiddlewareOptions } from "./IMiddlewareOptions"; */ export enum FeatureUsageFlag { - NONE = 0x0, // eslint-disable-line @typescript-eslint/naming-convention - REDIRECT_HANDLER_ENABLED = 0x1, // eslint-disable-line @typescript-eslint/naming-convention - RETRY_HANDLER_ENABLED = 0x2, // eslint-disable-line @typescript-eslint/naming-convention - AUTHENTICATION_HANDLER_ENABLED = 0x4, // eslint-disable-line @typescript-eslint/naming-convention + /* eslint-disable @typescript-eslint/naming-convention */ + NONE = 0x0, + REDIRECT_HANDLER_ENABLED = 0x1, + RETRY_HANDLER_ENABLED = 0x2, + AUTHENTICATION_HANDLER_ENABLED = 0x4, } /** diff --git a/test/common/core/Client.ts b/test/common/core/Client.ts index a1ee6fb95..4fa615bc6 100644 --- a/test/common/core/Client.ts +++ b/test/common/core/Client.ts @@ -47,7 +47,7 @@ describe("Client.ts", () => { }; const client: Client = Client.initWithMiddleware(options); assert.isTrue(client instanceof Client); - assert.isDefined(["httpClient"]); + assert.isDefined(client["httpClient"]); }); it("Should return client instance for a custom middleware chain", () => { From 7ff9039510e982e441585d884ebb56390a418f9e Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Fri, 5 Feb 2021 15:30:07 -0800 Subject: [PATCH 14/14] Reenable eslint after code-block --- src/middleware/options/TelemetryHandlerOptions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/middleware/options/TelemetryHandlerOptions.ts b/src/middleware/options/TelemetryHandlerOptions.ts index 30f5bde41..f268218fc 100644 --- a/src/middleware/options/TelemetryHandlerOptions.ts +++ b/src/middleware/options/TelemetryHandlerOptions.ts @@ -27,6 +27,7 @@ export enum FeatureUsageFlag { REDIRECT_HANDLER_ENABLED = 0x1, RETRY_HANDLER_ENABLED = 0x2, AUTHENTICATION_HANDLER_ENABLED = 0x4, + /* eslint-enable @typescript-eslint/naming-convention */ } /**