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
7 changes: 7 additions & 0 deletions sdk/core/abort-controller/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions sdk/core/abort-controller/api-extractor.json
Original file line number Diff line number Diff line change
@@ -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
},
Expand All @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/aborter.d.ts"
"publicTrimmedFilePath": "./types/abort-controller.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand Down
21 changes: 12 additions & 9 deletions sdk/core/abort-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/abort-controller/review/abort-controller.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export interface AbortSignalLike {

// (No @packageDocumentation comment for this package)

```
```
2 changes: 1 addition & 1 deletion sdk/core/abort-controller/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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 {}
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
6 changes: 5 additions & 1 deletion sdk/core/abort-controller/src/AbortSignal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/// <reference path="./shims-public.d.ts" />
// 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;

const listenersMap = new WeakMap<AbortSignal, AbortEventListener[]>();
Expand Down
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
17 changes: 10 additions & 7 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";
import { AbortController, AbortSignal, AbortError } from "../src";

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