From 3495fe325edc3ff2138495511b9472c64ead6d2e Mon Sep 17 00:00:00 2001 From: Deyaaeldeen Almahallawi Date: Mon, 21 Sep 2020 16:29:28 -0400 Subject: [PATCH] [Abort Controller] Update linting and fix linting errors (#11269) * update linting and fix linting errors * update linting scripts * formatting * fix linting errors * fixes * fix * run api-extractor * include the shim files in shipped files * use the unrolledup type declarations * do not lint package.json * still lint package.json * remove the call to api-extractor from the npm build script * simplify eslint commands * only ship src types --- sdk/core/abort-controller/.eslintrc.json | 7 +++++++ sdk/core/abort-controller/api-extractor.json | 4 ++-- sdk/core/abort-controller/package.json | 21 +++++++++++-------- .../review/abort-controller.api.md | 2 +- .../abort-controller/rollup.base.config.js | 2 +- .../{src => }/shims-public.d.ts | 3 +++ .../abort-controller/src/AbortController.ts | 4 ++++ sdk/core/abort-controller/src/AbortSignal.ts | 6 +++++- .../src/{aborter.ts => index.ts} | 3 +++ .../abort-controller/test/aborter.spec.ts | 17 ++++++++------- 10 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 sdk/core/abort-controller/.eslintrc.json rename sdk/core/abort-controller/{src => }/shims-public.d.ts (52%) rename sdk/core/abort-controller/src/{aborter.ts => index.ts} (87%) diff --git a/sdk/core/abort-controller/.eslintrc.json b/sdk/core/abort-controller/.eslintrc.json new file mode 100644 index 000000000000..e71d23ff6f57 --- /dev/null +++ b/sdk/core/abort-controller/.eslintrc.json @@ -0,0 +1,7 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "rules": { + "@azure/azure-sdk/ts-package-json-types": "off" + } +} diff --git a/sdk/core/abort-controller/api-extractor.json b/sdk/core/abort-controller/api-extractor.json index 263e349ba659..8265070b9a1f 100644 --- a/sdk/core/abort-controller/api-extractor.json +++ b/sdk/core/abort-controller/api-extractor.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "types/src/aborter.d.ts", + "mainEntryPointFilePath": "types/src/index.d.ts", "docModel": { "enabled": true }, @@ -11,7 +11,7 @@ "dtsRollup": { "enabled": true, "untrimmedFilePath": "", - "publicTrimmedFilePath": "./types/aborter.d.ts" + "publicTrimmedFilePath": "./types/abort-controller.d.ts" }, "messages": { "tsdocMessageReporting": { diff --git a/sdk/core/abort-controller/package.json b/sdk/core/abort-controller/package.json index dfe3893ef8b4..d5958c96cf0b 100644 --- a/sdk/core/abort-controller/package.json +++ b/sdk/core/abort-controller/package.json @@ -4,7 +4,7 @@ "version": "1.0.1", "description": "Microsoft Azure SDK for JavaScript - Aborter", "main": "./dist/index.js", - "module": "./dist-esm/src/aborter.js", + "module": "dist-esm/src/index.js", "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:es6": "tsc -p tsconfig.json", @@ -19,8 +19,8 @@ "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" -c ../../.eslintrc.old.json --fix --fix-type [problem,suggestion]", - "lint": "eslint -c ../../.eslintrc.old.json src test --ext .ts -f html -o abort-controller-lintReport.html || exit 0", + "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json api-extractor.json src test --ext .ts", "pack": "npm pack 2>&1", "prebuild": "npm run clean", "pretest": "npm run build:test", @@ -31,21 +31,22 @@ "unit-test:node": "cross-env TS_NODE_FILES=true TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" mocha --require ts-node/register --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace --no-timeouts test/*.spec.ts", "unit-test": "npm run unit-test:node && npm run unit-test:browser" }, - "types": "./types/src/aborter.d.ts", + "types": "./types/src/index.d.ts", "engine": { "node": ">=8.0.0" }, "files": [ "dist/", "dist-esm/src/", + "shims-public.d.ts", "types/src", "README.md", "LICENSE" ], - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-sdk-for-js.git" + "engines": { + "node": ">=8.0.0" }, + "repository": "github:Azure/azure-sdk-for-js", "keywords": [ "azure", "aborter", @@ -54,19 +55,21 @@ "node.js", "typescript", "javascript", - "browser" + "browser", + "cloud" ], "author": "Microsoft Corporation", "license": "MIT", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/abort-controller", + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/abort-controller/README.md", "sideEffects": false, "dependencies": { "tslib": "^2.0.0" }, "devDependencies": { + "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "7.7.11", "@rollup/plugin-commonjs": "11.0.2", "@rollup/plugin-multi-entry": "^3.0.0", diff --git a/sdk/core/abort-controller/review/abort-controller.api.md b/sdk/core/abort-controller/review/abort-controller.api.md index 2b646496a2dd..4eaac226487a 100644 --- a/sdk/core/abort-controller/review/abort-controller.api.md +++ b/sdk/core/abort-controller/review/abort-controller.api.md @@ -38,4 +38,4 @@ export interface AbortSignalLike { // (No @packageDocumentation comment for this package) -``` +``` \ No newline at end of file diff --git a/sdk/core/abort-controller/rollup.base.config.js b/sdk/core/abort-controller/rollup.base.config.js index b86b97b12ecd..ee3203a27837 100644 --- a/sdk/core/abort-controller/rollup.base.config.js +++ b/sdk/core/abort-controller/rollup.base.config.js @@ -10,7 +10,7 @@ import sourcemaps from "rollup-plugin-sourcemaps"; const pkg = require("./package.json"); const depNames = Object.keys(pkg.dependencies); -const input = "./dist-esm/src/aborter.js"; +const input = "./dist-esm/src/index.js"; const production = process.env.NODE_ENV === "production"; export function nodeConfig(test = false) { diff --git a/sdk/core/abort-controller/src/shims-public.d.ts b/sdk/core/abort-controller/shims-public.d.ts similarity index 52% rename from sdk/core/abort-controller/src/shims-public.d.ts rename to sdk/core/abort-controller/shims-public.d.ts index 7ef8e860aa31..002bec375f33 100644 --- a/sdk/core/abort-controller/src/shims-public.d.ts +++ b/sdk/core/abort-controller/shims-public.d.ts @@ -1,2 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + // forward declaration of Event in case DOM libs are not present. interface Event {} diff --git a/sdk/core/abort-controller/src/AbortController.ts b/sdk/core/abort-controller/src/AbortController.ts index d660a28c9d89..edd5f2123ffc 100644 --- a/sdk/core/abort-controller/src/AbortController.ts +++ b/sdk/core/abort-controller/src/AbortController.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal"; /** @@ -76,6 +79,7 @@ export class AbortController { } // coerce parentSignals into an array if (!Array.isArray(parentSignals)) { + // eslint-disable-next-line prefer-rest-params parentSignals = arguments; } for (const parentSignal of parentSignals) { diff --git a/sdk/core/abort-controller/src/AbortSignal.ts b/sdk/core/abort-controller/src/AbortSignal.ts index 04e8e7500869..4c15c3e60bc3 100644 --- a/sdk/core/abort-controller/src/AbortSignal.ts +++ b/sdk/core/abort-controller/src/AbortSignal.ts @@ -1,4 +1,8 @@ -/// +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// type AbortEventListener = (this: AbortSignalLike, ev?: any) => any; const listenersMap = new WeakMap(); diff --git a/sdk/core/abort-controller/src/aborter.ts b/sdk/core/abort-controller/src/index.ts similarity index 87% rename from sdk/core/abort-controller/src/aborter.ts rename to sdk/core/abort-controller/src/index.ts index 20ebe21376c4..be655bbc6387 100644 --- a/sdk/core/abort-controller/src/aborter.ts +++ b/sdk/core/abort-controller/src/index.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + // Changes to Aborter // * Rename Aborter to AbortSignal // * Remove withValue and getValue - async context should be solved differently/wholistically, not tied to cancellation diff --git a/sdk/core/abort-controller/test/aborter.spec.ts b/sdk/core/abort-controller/test/aborter.spec.ts index b42fcfbf379a..a60f914adb65 100644 --- a/sdk/core/abort-controller/test/aborter.spec.ts +++ b/sdk/core/abort-controller/test/aborter.spec.ts @@ -1,22 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import * as assert from "assert"; -import { AbortController, AbortSignal, AbortError } from "../src/aborter"; +import { AbortController, AbortSignal, AbortError } from "../src"; describe("AbortController", () => { function doAsyncOperation(aborter: AbortSignal, runningTimeinMs: number = 100): Promise { const s = Date.now(); - return new Promise((res, rej) => { + return new Promise((resolve, reject) => { // check status every 10 ms. const handle = setInterval(() => { // check if we're aborted. if (aborter.aborted) { clearInterval(handle); - return rej(new AbortError()); + return reject(new AbortError()); } // if we're completed, resolve. if (Date.now() - s > runningTimeinMs) { clearInterval(handle); - return res(); + return resolve(); } // else, continue trying. @@ -34,7 +37,7 @@ describe("AbortController", () => { const response = doAsyncOperation(aborter); controller.abort(); try { - let rs = await response; + const rs = await response; console.log("got result", rs); assert.fail(); } catch (err) { @@ -48,7 +51,7 @@ describe("AbortController", () => { const response = doAsyncOperation(aborter, 500); setTimeout(() => controller.abort(), 50); try { - let r = await response; + const r = await response; console.log("got, r", r); assert.fail(); } catch (err) { @@ -83,7 +86,7 @@ describe("AbortController", () => { it("should invoke abort listener callbacks when aborting", async () => { const controller = new AbortController(); const aborter = controller.signal; - let s: string[] = []; + const s: string[] = []; try { aborter.addEventListener("abort", () => { s.push("aborted");