Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Abort Controller] Update linting and fix linting errors #11269

Merged
merged 14 commits into from
Sep 21, 2020
5 changes: 3 additions & 2 deletions sdk/core/abort-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 -c ../../../.eslintrc.json \"src/**/*.ts\" \"test/**/*.ts\" --fix --fix-type [problem,suggestion]",
"lint": "eslint -c ../../../.eslintrc.json package.json api-extractor.json src test --ext .ts",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"pretest": "npm run build:test",
Expand Down Expand Up @@ -67,6 +67,7 @@
"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",
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/abort-controller/src/AbortController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal";

/**
Expand Down Expand Up @@ -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;
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
}
for (const parentSignal of parentSignals) {
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/abort-controller/src/AbortSignal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./shims-public.d.ts" />
type AbortEventListener = (this: AbortSignalLike, ev?: any) => any;

Expand Down
3 changes: 3 additions & 0 deletions sdk/core/abort-controller/src/aborter.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/abort-controller/src/shims-public.d.ts
Original file line number Diff line number Diff line change
@@ -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 {}
15 changes: 9 additions & 6 deletions sdk/core/abort-controller/test/aborter.spec.ts
Original file line number Diff line number Diff line change
@@ -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";

describe("AbortController", () => {
function doAsyncOperation(aborter: AbortSignal, runningTimeinMs: number = 100): Promise<number> {
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.
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down