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

Use @this to satisfy ESLint's no-invalid-this #14406

Merged
9 commits merged into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ describe("AnomalyDetectorClient", () => {
let recorder: Recorder;
const apiKey = new AzureKeyCredential(testEnv.ANOMALY_DETECTOR_API_KEY);

beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this*/ function() {
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
({ recorder, client } = createRecordedAnomalyDetectorClient(this, apiKey));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("[AAD] Attestation Client", function() {
let recorder: Recorder;

beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this*/ function() {
recorder = createRecorder(this);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("PolicyGetSetTests ", function() {
let recorder: Recorder;

beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this*/ function() {
recorder = createRecorder(this);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { verifyAttestationToken } from "../utils/helpers";
describe("PolicyManagementTests ", function() {
let recorder: Recorder;

beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this*/ function() {
recorder = createRecorder(this);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { Buffer } from "../utils/Buffer";
describe("TokenCertTests", function() {
let recorder: Recorder;

beforeEach(function() {
// eslint-disable-next-line no-invalid-this
beforeEach(/** @this*/ function() {
recorder = createRecorder(this);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ describe.skip("ContainerRegistryClient functional tests", function() {
// NOTE: use of "function" and not ES6 arrow-style functions with the
// beforeEach hook is IMPORTANT due to the use of `this` in the function
// body.
beforeEach(function(this: Context) {
beforeEach(/** @this*/ function(this: Context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the @this annotation needed in cases where we specify the type of this and use the function syntax - such as this example (and the note above)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think the rule overlooks the names of the arguments.

// The recorder has some convenience methods, and we need to store a
// reference to it so that we can `stop()` the recorder later in the
// `afterEach` hook.
// eslint-disable-next-line no-invalid-this
recorder = record(this, {
// == Recorder Environment Setup == Add the replaceable variables from
// above
Expand Down
4 changes: 4 additions & 0 deletions sdk/containerregistry/container-registry/tsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["../../../tsdoc.json"]
}
3 changes: 1 addition & 2 deletions sdk/core/core-http/test/defaultHttpClientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ describe("defaultHttpClient", function() {
}
});

it("should give a graceful error for nonexistent hosts", async function() {
it("should give a graceful error for nonexistent hosts", /** @this*/ async function() {
// Increase timeout to give the request time to fail
// eslint-disable-next-line no-invalid-this
this.timeout(10000);
const requestUrl = "http://fake.domain";
const request = new WebResource(requestUrl, "GET");
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/core-lro/test/utils/testOperation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-invalid-this */

import { HttpOperationResponse, RequestOptionsBase } from "@azure/core-http";
import { AbortSignalLike } from "@azure/abort-controller";
Expand All @@ -22,6 +21,7 @@ export interface TestOperationState extends PollOperationState<string> {

export interface TestOperation extends PollOperation<TestOperationState, string> {}

/** @this*/
async function update(
this: TestOperation,
options: {
Expand Down Expand Up @@ -70,6 +70,7 @@ async function update(
return makeOperation(newState);
}

/** @this*/
async function cancel(
this: TestOperation,
options: { abortSignal?: AbortSignal } = {}
Expand Down Expand Up @@ -100,6 +101,7 @@ async function cancel(
});
}

/** @this*/
function toString(this: TestOperation): string {
return JSON.stringify({
state: this.state
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/logger/src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/* eslint-disable no-invalid-this */

import { log } from "./log";

/**
Expand Down Expand Up @@ -157,6 +155,7 @@ function createDebugger(namespace: string): Debugger {
return newDebugger;
}

/** @this*/
function destroy(this: Debugger): boolean {
const index = debuggers.indexOf(this);
if (index >= 0) {
Expand All @@ -166,6 +165,7 @@ function destroy(this: Debugger): boolean {
return false;
}

/** @this*/
function extend(this: Debugger, namespace: string): Debugger {
const newDebugger = createDebugger(`${this.namespace}:${namespace}`);
newDebugger.log = this.log;
Expand Down
1 change: 0 additions & 1 deletion sdk/cosmosdb/cosmos/test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": ["../.eslintrc.json"],
"rules": {
"no-console": "off",
"no-invalid-this": "off",
"space-before-function-paren": "off"
}
}
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/test/internal/session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getCollection2TokenMap(
return (sessionContainer as any).collectionResourceIdToSessionTokens;
}

describe("Session Token", function() {
describe("Session Token", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);

const containerId = "sessionTestColl";
Expand Down Expand Up @@ -304,7 +304,7 @@ describe("Session Token", function() {
spy.restore();
});

it("validate 'lsn not caught up' error for higher lsn and clearing session token", async function() {
it("validate 'lsn not caught up' error for higher lsn and clearing session token", /** @this*/ async function() {
this.retries(2);
const database = await getTestDatabase("session test", client);

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/internal/unit/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { getAuthorizationTokenUsingResourceTokens } from "../../../src/auth";
import assert from "assert";

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);

it("should find exact match", async function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
removeAllDatabases
} from "../common/TestHelpers";

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import AbortController from "node-abort-controller";
import { UsernamePasswordCredential } from "@azure/identity";

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);

describe("Validate client request timeout", function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import assert from "assert";
import { removeAllDatabases, getTestContainer } from "../common/TestHelpers";

describe("Conflicts", function() {
describe("Conflicts", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { SpatialType } from "../../../src";
import { GeospatialType } from "../../../src";

describe("Containers", function() {
describe("Containers", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DatabaseRequest } from "../../../src";

const client = new CosmosClient({ endpoint, key: masterKey });

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { endpoint, masterKey } from "../common/_testConfig";

const client = new CosmosClient({ endpoint, key: masterKey });

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
beforeEach(/** @this*/ async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
});

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface TestItem {
replace?: string;
}

describe("Item CRUD", function() {
describe("Item CRUD", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/test/public/functional/offer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const validateOfferResponseBody = function(offer: any): void {
assert(offer._self.indexOf(offer.id) !== -1, "Offer id not contained in offer self link.");
};

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);

beforeEach(async function() {
beforeEach(/** @this*/ async function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
await removeAllDatabases();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
replaceOrUpsertPermission
} from "../common/TestHelpers";

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/test/public/functional/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (!Symbol || !Symbol.asyncIterator) {
(Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator");
}

describe("Queries", function() {
describe("Queries", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
before(async function() {
await removeAllDatabases();
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("Queries", function() {
});
});

describe("QueryIterator", function() {
describe("QueryIterator", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);
let resources: { container: Container; doc1: any; doc2: any; doc3: any };

Expand Down Expand Up @@ -143,7 +143,7 @@ describe("Queries", function() {
}
});

describe("SUM query iterator", function() {
describe("SUM query iterator", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);

it("returns undefined sum with null value in aggregator", async function() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/spatial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from "assert";
import { Database, DataType, IndexKind } from "../../../src";
import { createOrUpsertItem, getTestDatabase, removeAllDatabases } from "../common/TestHelpers";

describe("Spatial Indexes", function() {
describe("Spatial Indexes", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/test/public/functional/sproc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
// Used for sproc
declare let getContext: any;

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
});
describe("Validate sproc CRUD", function() {
let container: Container;
beforeEach(async function() {
beforeEach(/** @this*/ async function() {
container = await getTestContainer(this.test.fullTitle());
});

Expand Down Expand Up @@ -92,7 +92,7 @@ describe("NodeJS CRUD Tests", function() {

describe("Validate stored procedure functionality", function() {
let container: Container;
beforeEach(async function() {
beforeEach(/** @this*/ async function() {
container = await getTestContainer(this.test.fullTitle());
});

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/trigger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const notFoundErrorCode = 404;
// Mock for trigger function bodies
declare let getContext: any;

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
let container: Container;

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/ttl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function sleep(time: number): Promise<unknown> {
});
}

describe("Container TTL", function() {
describe("Container TTL", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 600000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/udf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from "assert";
import { UserDefinedFunctionDefinition, Container } from "../../../src";
import { removeAllDatabases, getTestContainer } from "../common/TestHelpers";

describe("User Defined Function", function() {
describe("User Defined Function", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
let container: Container;

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/test/public/functional/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from "assert";
import { UserDefinition } from "../../../src";
import { createOrUpsertUser, getTestDatabase, removeAllDatabases } from "../common/TestHelpers";

describe("NodeJS CRUD Tests", function() {
describe("NodeJS CRUD Tests", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function() {
await removeAllDatabases();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FeedOptions } from "../../../src";
import { TestData } from "../common/TestData";
import { bulkInsertItems, getTestContainer, removeAllDatabases } from "../common/TestHelpers";

describe("Aggregate Query", function() {
describe("Aggregate Query", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
const partitionKey = "key";
const uniquePartitionKey = "uniquePartitionKey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Database } from "../../../src";
import { endpoint } from "../common/_testConfig";
import { getTestContainer, removeAllDatabases } from "../common/TestHelpers";

describe("Authorization", function() {
describe("Authorization", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);

// TODO: should have types for all these things
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestOptions } from "../../../src";
import { Container, ContainerDefinition } from "../../../src";
import { getTestContainer, removeAllDatabases } from "../common/TestHelpers";

describe("Change Feed Iterator", function() {
describe("Change Feed Iterator", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);

// delete all databases and create sample database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function compare(key: string) {
};
}

describe("Cross Partition", function() {
describe("Cross Partition", /** @this*/ function() {
this.timeout(process.env.MOCHA_TIMEOUT || "30000");

describe("Validate Query", function() {
Expand Down

Large diffs are not rendered by default.

Loading