diff --git a/sdk/storage/storage-blob/package.json b/sdk/storage/storage-blob/package.json index 603da3d22a8e..1c57b3d4c492 100644 --- a/sdk/storage/storage-blob/package.json +++ b/sdk/storage/storage-blob/package.json @@ -52,7 +52,7 @@ "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000 \"dist-esm/storage-blob/test/*.spec.js\" \"dist-esm/storage-blob/test/node/*.spec.js\"", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix", - "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o storage-blob-lintReport.html || exit 0", + "lint": "eslint package.json api-extractor.json src test --ext .ts", "pack": "npm pack 2>&1", "prebuild": "npm run clean", "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", diff --git a/sdk/storage/storage-blob/src/BatchResponseParser.ts b/sdk/storage/storage-blob/src/BatchResponseParser.ts index d9cfdae81a17..3a9211e0bb61 100644 --- a/sdk/storage/storage-blob/src/BatchResponseParser.ts +++ b/sdk/storage/storage-blob/src/BatchResponseParser.ts @@ -54,7 +54,7 @@ export class BatchResponseParser { public async parseBatchResponse(): Promise { // When logic reach here, suppose batch request has already succeeded with 202, so we can further parse // sub request's response. - if (this.batchResponse._response.status != HTTPURLConnection.HTTP_ACCEPTED) { + if (this.batchResponse._response.status !== HTTPURLConnection.HTTP_ACCEPTED) { throw new Error( `Invalid state: batch request failed with status: '${this.batchResponse._response.status}'.` ); @@ -72,7 +72,7 @@ export class BatchResponseParser { // Note: subResponseCount == 1 is special case where sub request is invalid. // We try to prevent such cases through early validation, e.g. validate sub request count >= 1. // While in unexpected sub request invalid case, we allow sub response to be parsed and return to user. - if (subResponseCount != this.subRequests.size && subResponseCount != 1) { + if (subResponseCount !== this.subRequests.size && subResponseCount !== 1) { throw new Error("Invalid state: sub responses' count is not equal to sub requests' count."); } @@ -152,7 +152,7 @@ export class BatchResponseParser { // to be 1-1 mapping from the [0, subRequests.size) to the Content-IDs returned. If not, we simply don't return that // unexpected subResponse in the parsed reponse and we can always look it up in the raw response for debugging purpose. if ( - contentId != NOT_FOUND && + contentId !== NOT_FOUND && Number.isInteger(contentId) && contentId >= 0 && contentId < this.subRequests.size && diff --git a/sdk/storage/storage-blob/src/BatchUtils.browser.ts b/sdk/storage/storage-blob/src/BatchUtils.browser.ts index 1a360737d5e1..2971924e12a8 100644 --- a/sdk/storage/storage-blob/src/BatchUtils.browser.ts +++ b/sdk/storage/storage-blob/src/BatchUtils.browser.ts @@ -8,7 +8,7 @@ export async function getBodyAsText( batchResponse: ServiceSubmitBatchResponseModel ): Promise { const blob = (await batchResponse.blobBody) as Blob; - return await blobToString(blob); + return blobToString(blob); } export function utf8ByteLength(str: string): number { diff --git a/sdk/storage/storage-blob/src/BlobBatch.ts b/sdk/storage/storage-blob/src/BlobBatch.ts index 93b064f33298..d3506ebcd37f 100644 --- a/sdk/storage/storage-blob/src/BlobBatch.ts +++ b/sdk/storage/storage-blob/src/BlobBatch.ts @@ -416,7 +416,7 @@ class InnerBatchRequest { // Fast fail if url for sub request is invalid const path = getURLPath(subRequest.url); - if (!path || path == "") { + if (!path || path === "") { throw new RangeError(`Invalid url for sub request: '${subRequest.url}'`); } } @@ -481,6 +481,8 @@ class BatchRequestAssemblePolicyFactory implements RequestPolicyFactory { } class BatchHeaderFilterPolicy extends BaseRequestPolicy { + // The base class has a protected constructor. Adding a public one to enable constructing of this class. + /* eslint-disable-next-line @typescript-eslint/no-useless-constructor*/ constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) { super(nextPolicy, options); } @@ -503,8 +505,6 @@ class BatchHeaderFilterPolicy extends BaseRequestPolicy { } class BatchHeaderFilterPolicyFactory implements RequestPolicyFactory { - constructor() {} - public create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): BatchHeaderFilterPolicy { return new BatchHeaderFilterPolicy(nextPolicy, options); } diff --git a/sdk/storage/storage-blob/src/BlobBatchClient.ts b/sdk/storage/storage-blob/src/BlobBatchClient.ts index c6e8e9e1490c..67a677087aaa 100644 --- a/sdk/storage/storage-blob/src/BlobBatchClient.ts +++ b/sdk/storage/storage-blob/src/BlobBatchClient.ts @@ -73,8 +73,11 @@ export class BlobBatchClient { constructor( url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); + /** * Creates an instance of BlobBatchClient. * @@ -92,6 +95,8 @@ export class BlobBatchClient { | AnonymousCredential | TokenCredential | PipelineLike, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { let pipeline: PipelineLike; @@ -137,6 +142,8 @@ export class BlobBatchClient { public async deleteBlobs( urls: string[], credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobDeleteOptions ): Promise; @@ -152,6 +159,8 @@ export class BlobBatchClient { */ public async deleteBlobs( blobClients: BlobClient[], + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobDeleteOptions ): Promise; @@ -163,6 +172,8 @@ export class BlobBatchClient { | TokenCredential | BlobDeleteOptions | undefined, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobDeleteOptions ): Promise { const batch = new BlobBatch(); @@ -196,6 +207,8 @@ export class BlobBatchClient { urls: string[], credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, tier: AccessTier, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobSetTierOptions ): Promise; @@ -217,6 +230,8 @@ export class BlobBatchClient { public async setBlobsAccessTier( blobClients: BlobClient[], tier: AccessTier, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobSetTierOptions ): Promise; @@ -228,6 +243,8 @@ export class BlobBatchClient { | TokenCredential | AccessTier, tierOrOptions?: AccessTier | BlobSetTierOptions, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: BlobSetTierOptions ): Promise { const batch = new BlobBatch(); @@ -289,7 +306,7 @@ export class BlobBatchClient { batchRequest: BlobBatch, options: BlobBatchSubmitBatchOptionalParams = {} ): Promise { - if (!batchRequest || batchRequest.getSubRequests().size == 0) { + if (!batchRequest || batchRequest.getSubRequests().size === 0) { throw new RangeError("Batch request should contain one or more sub requests."); } diff --git a/sdk/storage/storage-blob/src/BlobServiceClient.ts b/sdk/storage/storage-blob/src/BlobServiceClient.ts index 6e568a276399..46aaff782ff2 100644 --- a/sdk/storage/storage-blob/src/BlobServiceClient.ts +++ b/sdk/storage/storage-blob/src/BlobServiceClient.ts @@ -404,7 +404,12 @@ export class BlobServiceClient extends StorageClient { * `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString` * @param options - Optional. Options to configure the HTTP pipeline. */ - public static fromConnectionString(connectionString: string, options?: StoragePipelineOptions) { + public static fromConnectionString( + connectionString: string, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ + options?: StoragePipelineOptions + ): BlobServiceClient { options = options || {}; const extractedCreds = extractConnectionStringParts(connectionString); if (extractedCreds.kind === "AccountConnString") { @@ -466,6 +471,8 @@ export class BlobServiceClient extends StorageClient { constructor( url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -485,6 +492,8 @@ export class BlobServiceClient extends StorageClient { | AnonymousCredential | TokenCredential | PipelineLike, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { let pipeline: PipelineLike; @@ -630,6 +639,7 @@ export class BlobServiceClient extends StorageClient { * @param destinationContainerName - The new name of the container. * @param options - Options to configure Container Rename operation. */ + /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ // @ts-ignore Need to hide this interface for now. Make it public and turn on the live tests for it when the service is ready. private async renameContainer( sourceContainerName: string, diff --git a/sdk/storage/storage-blob/src/Clients.ts b/sdk/storage/storage-blob/src/Clients.ts index 363c50caab56..78fd5527e221 100644 --- a/sdk/storage/storage-blob/src/Clients.ts +++ b/sdk/storage/storage-blob/src/Clients.ts @@ -877,6 +877,8 @@ export class BlobClient extends StorageClient { connectionString: string, containerName: string, blobName: string, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -894,6 +896,8 @@ export class BlobClient extends StorageClient { constructor( url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -923,6 +927,8 @@ export class BlobClient extends StorageClient { | TokenCredential | PipelineLike, blobNameOrOptions?: string | StoragePipelineOptions, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { options = options || {}; @@ -1186,7 +1192,7 @@ export class BlobClient extends StorageClient { return new BlobDownloadResponse( wrappedRes, async (start: number): Promise => { - const updatedOptions: BlobDownloadOptionalParams = { + const updatedDownloadOptions: BlobDownloadOptionalParams = { leaseAccessConditions: options.conditions, modifiedAccessConditions: { ifMatch: options.conditions!.ifMatch || res.etag, @@ -1215,7 +1221,7 @@ export class BlobClient extends StorageClient { return ( await this.blobContext.download({ abortSignal: options.abortSignal, - ...updatedOptions + ...updatedDownloadOptions }) ).readableStreamBody!; }, @@ -1890,7 +1896,7 @@ export class BlobClient extends StorageClient { param2?: number, param3?: BlobDownloadToBufferOptions | number, param4: BlobDownloadToBufferOptions = {} - ) { + ): Promise { let buffer: Buffer | undefined; let offset = 0; let count = 0; @@ -2525,6 +2531,8 @@ export class AppendBlobClient extends BlobClient { connectionString: string, containerName: string, blobName: string, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -2547,6 +2555,8 @@ export class AppendBlobClient extends BlobClient { constructor( url: string, credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -2576,6 +2586,8 @@ export class AppendBlobClient extends BlobClient { | TokenCredential | PipelineLike, blobNameOrOptions?: string | StoragePipelineOptions, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { // In TypeScript we cannot simply pass all parameters to super() like below so have to duplicate the code instead. @@ -3523,6 +3535,8 @@ export class BlockBlobClient extends BlobClient { connectionString: string, containerName: string, blobName: string, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -3545,6 +3559,8 @@ export class BlockBlobClient extends BlobClient { constructor( url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -3574,6 +3590,8 @@ export class BlockBlobClient extends BlobClient { | TokenCredential | PipelineLike, blobNameOrOptions?: string | StoragePipelineOptions, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { // In TypeScript we cannot simply pass all parameters to super() like below so have to duplicate the code instead. @@ -4771,6 +4789,8 @@ export class PageBlobClient extends BlobClient { connectionString: string, containerName: string, blobName: string, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -4788,6 +4808,8 @@ export class PageBlobClient extends BlobClient { constructor( url: string, credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -4814,6 +4836,8 @@ export class PageBlobClient extends BlobClient { | TokenCredential | PipelineLike, blobNameOrOptions?: string | StoragePipelineOptions, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { // In TypeScript we cannot simply pass all parameters to super() like below so have to duplicate the code instead. diff --git a/sdk/storage/storage-blob/src/ContainerClient.ts b/sdk/storage/storage-blob/src/ContainerClient.ts index 7bc4a70f9918..7d7cc82102c2 100644 --- a/sdk/storage/storage-blob/src/ContainerClient.ts +++ b/sdk/storage/storage-blob/src/ContainerClient.ts @@ -591,6 +591,8 @@ export class ContainerClient extends StorageClient { * @param containerName - Container name. * @param options - Optional. Options to configure the HTTP pipeline. */ + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ constructor(connectionString: string, containerName: string, options?: StoragePipelineOptions); /** * Creates an instance of ContainerClient. @@ -608,6 +610,8 @@ export class ContainerClient extends StorageClient { constructor( url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ); /** @@ -632,6 +636,8 @@ export class ContainerClient extends StorageClient { | AnonymousCredential | TokenCredential | PipelineLike, + // Legacy, no fix for eslint error without breaking. Disable it for this interface. + /* eslint-disable-next-line @azure/azure-sdk/ts-naming-options*/ options?: StoragePipelineOptions ) { let pipeline: PipelineLike; diff --git a/sdk/storage/storage-blob/src/Pipeline.ts b/sdk/storage/storage-blob/src/Pipeline.ts index 11526138b812..6b13e41282ad 100644 --- a/sdk/storage/storage-blob/src/Pipeline.ts +++ b/sdk/storage/storage-blob/src/Pipeline.ts @@ -96,7 +96,7 @@ export interface PipelineLike { /** * A helper to decide if a given argument satisfies the Pipeline contract - * @param pipeline An argument that may be a Pipeline + * @param pipeline - An argument that may be a Pipeline * @returns true when the argument satisfies the Pipeline contract */ export function isPipelineLike(pipeline: unknown): pipeline is PipelineLike { diff --git a/sdk/storage/storage-blob/src/Range.ts b/sdk/storage/storage-blob/src/Range.ts index 3d133f871466..3d4efbffd292 100644 --- a/sdk/storage/storage-blob/src/Range.ts +++ b/sdk/storage/storage-blob/src/Range.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// tslint:disable:max-line-length /** * Range for Blob Service Operations. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/specifying-the-range-header-for-blob-service-operations diff --git a/sdk/storage/storage-blob/src/credentials/Credential.ts b/sdk/storage/storage-blob/src/credentials/Credential.ts index ec1bee135c2c..bd795dcd129d 100644 --- a/sdk/storage/storage-blob/src/credentials/Credential.ts +++ b/sdk/storage/storage-blob/src/credentials/Credential.ts @@ -15,12 +15,7 @@ export abstract class Credential implements RequestPolicyFactory { * @param _nextPolicy - * @param _options - */ - public create( - // tslint:disable-next-line:variable-name - _nextPolicy: RequestPolicy, - // tslint:disable-next-line:variable-name - _options: RequestPolicyOptions - ): RequestPolicy { + public create(_nextPolicy: RequestPolicy, _options: RequestPolicyOptions): RequestPolicy { throw new Error("Method should be implemented in children classes."); } } diff --git a/sdk/storage/storage-blob/src/models.ts b/sdk/storage/storage-blob/src/models.ts index ad4f0049d849..7947556be83f 100644 --- a/sdk/storage/storage-blob/src/models.ts +++ b/sdk/storage/storage-blob/src/models.ts @@ -174,14 +174,14 @@ export enum PremiumPageBlobTier { export function toAccessTier( tier: BlockBlobTier | PremiumPageBlobTier | string | undefined ): AccessTier | undefined { - if (tier == undefined) { + if (tier === undefined) { return undefined; } return tier as AccessTier; // No more check if string is a valid AccessTier, and left this to underlay logic to decide(service). } -export function ensureCpkIfSpecified(cpk: CpkInfo | undefined, isHttps: boolean) { +export function ensureCpkIfSpecified(cpk: CpkInfo | undefined, isHttps: boolean): void { if (cpk && !isHttps) { throw new RangeError("Customer-provided encryption key must be used over HTTPS."); } diff --git a/sdk/storage/storage-blob/src/policies/AnonymousCredentialPolicy.ts b/sdk/storage/storage-blob/src/policies/AnonymousCredentialPolicy.ts index 08e4118ad4c0..fbe370ad037d 100644 --- a/sdk/storage/storage-blob/src/policies/AnonymousCredentialPolicy.ts +++ b/sdk/storage/storage-blob/src/policies/AnonymousCredentialPolicy.ts @@ -15,6 +15,8 @@ export class AnonymousCredentialPolicy extends CredentialPolicy { * @param nextPolicy - * @param options - */ + // The base class has a protected constructor. Adding a public one to enable constructing of this class. + /* eslint-disable-next-line @typescript-eslint/no-useless-constructor*/ constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) { super(nextPolicy, options); } diff --git a/sdk/storage/storage-blob/src/policies/StorageBrowserPolicy.ts b/sdk/storage/storage-blob/src/policies/StorageBrowserPolicy.ts index 35748194822e..814b65e6a05b 100644 --- a/sdk/storage/storage-blob/src/policies/StorageBrowserPolicy.ts +++ b/sdk/storage/storage-blob/src/policies/StorageBrowserPolicy.ts @@ -30,6 +30,8 @@ export class StorageBrowserPolicy extends BaseRequestPolicy { * @param nextPolicy - * @param options - */ + // The base class has a protected constructor. Adding a public one to enable constructing of this class. + /* eslint-disable-next-line @typescript-eslint/no-useless-constructor*/ constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) { super(nextPolicy, options); } diff --git a/sdk/storage/storage-blob/src/policies/StorageRetryPolicy.ts b/sdk/storage/storage-blob/src/policies/StorageRetryPolicy.ts index a37c34629ddc..3d6135609044 100644 --- a/sdk/storage/storage-blob/src/policies/StorageRetryPolicy.ts +++ b/sdk/storage/storage-blob/src/policies/StorageRetryPolicy.ts @@ -180,7 +180,7 @@ export class StorageRetryPolicy extends BaseRequestPolicy { } await this.delay(isPrimaryRetry, attempt, request.abortSignal); - return await this.attemptSendRequest(request, secondaryHas404, ++attempt); + return this.attemptSendRequest(request, secondaryHas404, ++attempt); } /** diff --git a/sdk/storage/storage-blob/src/policies/StorageSharedKeyCredentialPolicy.ts b/sdk/storage/storage-blob/src/policies/StorageSharedKeyCredentialPolicy.ts index d17572d6715d..7ea3fde1720b 100644 --- a/sdk/storage/storage-blob/src/policies/StorageSharedKeyCredentialPolicy.ts +++ b/sdk/storage/storage-blob/src/policies/StorageSharedKeyCredentialPolicy.ts @@ -155,7 +155,7 @@ export class StorageSharedKeyCredentialPolicy extends CredentialPolicy { if (queries) { const queryKeys: string[] = []; for (const key in queries) { - if (queries.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(queries, key)) { const lowercaseKey = key.toLowerCase(); lowercaseQueries[lowercaseKey] = queries[key]; queryKeys.push(lowercaseKey); diff --git a/sdk/storage/storage-blob/src/sas/ContainerSASPermissions.ts b/sdk/storage/storage-blob/src/sas/ContainerSASPermissions.ts index c56ffd5b8da0..33519a11483e 100644 --- a/sdk/storage/storage-blob/src/sas/ContainerSASPermissions.ts +++ b/sdk/storage/storage-blob/src/sas/ContainerSASPermissions.ts @@ -15,7 +15,7 @@ export class ContainerSASPermissions { * * @param permissions - */ - public static parse(permissions: string) { + public static parse(permissions: string): ContainerSASPermissions { const containerSASPermissions = new ContainerSASPermissions(); for (const char of permissions) { diff --git a/sdk/storage/storage-blob/src/sas/SASQueryParameters.ts b/sdk/storage/storage-blob/src/sas/SASQueryParameters.ts index 7441f45f4a64..ee0d1159e066 100644 --- a/sdk/storage/storage-blob/src/sas/SASQueryParameters.ts +++ b/sdk/storage/storage-blob/src/sas/SASQueryParameters.ts @@ -109,7 +109,7 @@ export interface SASQueryParametersOptions { /** * Represents the components that make up an Azure Storage SAS' query parameters. This type is not constructed directly * by the user; it is only generated by the {@link AccountSASSignatureValues} and {@link BlobSASSignatureValues} - * types. Once generated, it can be encoded into a {@code String} and appended to a URL directly (though caution should + * types. Once generated, it can be encoded into a {@link String} and appended to a URL directly (though caution should * be taken here in case there are existing query parameters, which might affect the appropriate means of appending * these query parameters). * diff --git a/sdk/storage/storage-blob/src/utils/BlobQuickQueryStream.ts b/sdk/storage/storage-blob/src/utils/BlobQuickQueryStream.ts index 364144aec489..85f6c8dc6764 100644 --- a/sdk/storage/storage-blob/src/utils/BlobQuickQueryStream.ts +++ b/sdk/storage/storage-blob/src/utils/BlobQuickQueryStream.ts @@ -35,7 +35,7 @@ export interface BlobQuickQueryStreamOptions { export class BlobQuickQueryStream extends Readable { private source: NodeJS.ReadableStream; private avroReader: AvroReader; - private avroIter: AsyncIterableIterator; + private avroIter: AsyncIterableIterator; private avroPaused: boolean = true; private onProgress?: (progress: TransferProgressEvent) => void; private onError?: (error: BlobQueryError) => void; @@ -55,7 +55,7 @@ export class BlobQuickQueryStream extends Readable { this.avroIter = this.avroReader.parseObjects({ abortSignal: options.abortSignal }); } - public _read() { + public _read(): void { if (this.avroPaused) { this.readInternal().catch((err) => { this.emit("error", err); @@ -79,21 +79,25 @@ export class BlobQuickQueryStream extends Readable { switch (schema) { case "com.microsoft.azure.storage.queryBlobContents.resultData": - const data = (obj as any).data; - if (data instanceof Uint8Array === false) { - throw Error("Invalid data in avro result record."); - } - if (!this.push(Buffer.from(data))) { - this.avroPaused = true; + { + const data = (obj as any).data; + if (data instanceof Uint8Array === false) { + throw Error("Invalid data in avro result record."); + } + if (!this.push(Buffer.from(data))) { + this.avroPaused = true; + } } break; case "com.microsoft.azure.storage.queryBlobContents.progress": - const bytesScanned = (obj as any).bytesScanned; - if (typeof bytesScanned !== "number") { - throw Error("Invalid bytesScanned in avro progress record."); - } - if (this.onProgress) { - this.onProgress({ loadedBytes: bytesScanned }); + { + const bytesScanned = (obj as any).bytesScanned; + if (typeof bytesScanned !== "number") { + throw Error("Invalid bytesScanned in avro progress record."); + } + if (this.onProgress) { + this.onProgress({ loadedBytes: bytesScanned }); + } } break; case "com.microsoft.azure.storage.queryBlobContents.end": diff --git a/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts b/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts index cba8672705f6..199749b4a123 100644 --- a/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts +++ b/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts @@ -81,7 +81,7 @@ export class RetriableReadableStream extends Readable { this.setSourceEventHandlers(); } - public _read() { + public _read(): void { this.source.resume(); } @@ -142,6 +142,7 @@ export class RetriableReadableStream extends Readable { .then((newSource) => { this.source = newSource; this.setSourceEventHandlers(); + return; }) .catch((error) => { this.destroy(error); @@ -149,7 +150,6 @@ export class RetriableReadableStream extends Readable { } else { this.destroy( new Error( - // tslint:disable-next-line:max-line-length `Data corruption failure: received less data than required and reached maxRetires limitation. Received data offset: ${this .offset - 1}, data needed offset: ${this.end}, retries: ${ this.retries diff --git a/sdk/storage/storage-blob/src/utils/utils.browser.ts b/sdk/storage/storage-blob/src/utils/utils.browser.ts index a125ae18e017..63336bea678a 100644 --- a/sdk/storage/storage-blob/src/utils/utils.browser.ts +++ b/sdk/storage/storage-blob/src/utils/utils.browser.ts @@ -33,12 +33,22 @@ export async function blobToString(blob: Blob): Promise { }); } -export function streamToBuffer() {} +export function streamToBuffer(): void { + /* empty */ +} -export function streamToBuffer2() {} +export function streamToBuffer2(): void { + /* empty */ +} -export function readStreamToLocalFile() {} +export function readStreamToLocalFile(): void { + /* empty */ +} -export const fsStat = function stat() {}; +export const fsStat = function stat(): void { + /* empty */ +}; -export const fsCreateReadStream = function createReadStream() {}; +export const fsCreateReadStream = function createReadStream(): void { + /* empty */ +}; diff --git a/sdk/storage/storage-blob/src/utils/utils.common.ts b/sdk/storage/storage-blob/src/utils/utils.common.ts index 8c07ef23b15f..762c0c8a35a9 100644 --- a/sdk/storage/storage-blob/src/utils/utils.common.ts +++ b/sdk/storage/storage-blob/src/utils/utils.common.ts @@ -118,7 +118,7 @@ export function getValueInConnString( | "DefaultEndpointsProtocol" | "EndpointSuffix" | "SharedAccessSignature" -) { +): string { const elements = connectionString.split(";"); for (const element of elements) { if (element.trim().startsWith(argument)) { @@ -315,7 +315,7 @@ export function getURLPathAndQuery(url: string): string | undefined { let queryString = urlParsed.getQuery() || ""; queryString = queryString.trim(); - if (queryString != "") { + if (queryString !== "") { queryString = queryString.startsWith("?") ? queryString : `?${queryString}`; // Ensure query string start with '?' } @@ -442,8 +442,13 @@ export function generateBlockID(blockIDPrefix: string, blockIndex: number): stri * @param aborter - * @param abortError - */ -export async function delay(timeInMs: number, aborter?: AbortSignalLike, abortError?: Error) { +export async function delay( + timeInMs: number, + aborter?: AbortSignalLike, + abortError?: Error +): Promise { return new Promise((resolve, reject) => { + /* eslint-disable-next-line prefer-const */ let timeout: any; const abortHandler = () => { @@ -461,6 +466,7 @@ export async function delay(timeInMs: number, aborter?: AbortSignalLike, abortEr }; timeout = setTimeout(resolveHandler, timeInMs); + if (aborter !== undefined) { aborter.addEventListener("abort", abortHandler); } @@ -479,8 +485,7 @@ export function padStart( targetLength: number, padString: string = " " ): string { - // TS doesn't know this code needs to run downlevel sometimes. - // @ts-expect-error + // @ts-expect-error: TS doesn't know this code needs to run downlevel sometimes if (String.prototype.padStart) { return currentString.padStart(targetLength, padString); } @@ -558,12 +563,12 @@ export function getAccountNameFromUrl(url: string): string { } export function isIpEndpointStyle(parsedUrl: URLBuilder): boolean { - if (parsedUrl.getHost() == undefined) { + if (parsedUrl.getHost() === undefined) { return false; } const host = - parsedUrl.getHost()! + (parsedUrl.getPort() == undefined ? "" : ":" + parsedUrl.getPort()); + parsedUrl.getHost()! + (parsedUrl.getPort() === undefined ? "" : ":" + parsedUrl.getPort()); // Case 1: Ipv6, use a broad regex to find out candidates whose host contains two ':'. // Case 2: localhost(:port), use broad regex to match port part. @@ -586,7 +591,7 @@ export function toBlobTagsString(tags?: Tags): string | undefined { const tagPairs = []; for (const key in tags) { - if (tags.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(tags, key)) { const value = tags[key]; tagPairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`); } @@ -610,7 +615,7 @@ export function toBlobTags(tags?: Tags): BlobTags | undefined { }; for (const key in tags) { - if (tags.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(tags, key)) { const value = tags[key]; res.blobTagSet.push({ key, diff --git a/sdk/storage/storage-blob/test/aborter.spec.ts b/sdk/storage/storage-blob/test/aborter.spec.ts index 72452dd99259..2f8332314841 100644 --- a/sdk/storage/storage-blob/test/aborter.spec.ts +++ b/sdk/storage/storage-blob/test/aborter.spec.ts @@ -8,16 +8,16 @@ import { ContainerClient } from "../src"; import { getBSU, recorderEnvSetup } from "./utils"; import { record, Recorder } from "@azure/test-utils-recorder"; import * as dotenv from "dotenv"; +import { Context } from "mocha"; dotenv.config(); -// tslint:disable:no-empty describe("Aborter", () => { let containerName: string; let containerClient: ContainerClient; let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); diff --git a/sdk/storage/storage-blob/test/appendblobclient.spec.ts b/sdk/storage/storage-blob/test/appendblobclient.spec.ts index 30e1821000fe..d704fa3b498a 100644 --- a/sdk/storage/storage-blob/test/appendblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/appendblobclient.spec.ts @@ -4,6 +4,7 @@ import { record, Recorder } from "@azure/test-utils-recorder"; import * as assert from "assert"; import * as dotenv from "dotenv"; +import { Context } from "mocha"; import { AppendBlobClient, ContainerClient } from "../src"; import { @@ -23,7 +24,7 @@ describe("AppendBlobClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -94,7 +95,9 @@ describe("AppendBlobClient", () => { const content = "Hello World!"; await appendBlobClient.appendBlock(content, content.length, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); const downloadResponse = await appendBlobClient.download(0); @@ -115,7 +118,6 @@ describe("AppendBlobClient", () => { it("throws error if constructor containerName parameter is empty", async () => { try { - // tslint:disable-next-line: no-unused-expression new AppendBlobClient(getSASConnectionStringFromEnvironment(), "", "blobName"); assert.fail("Expecting an thrown error but didn't get one."); } catch (error) { diff --git a/sdk/storage/storage-blob/test/blobbatch.spec.ts b/sdk/storage/storage-blob/test/blobbatch.spec.ts index 5641d2615344..1e224e706b88 100644 --- a/sdk/storage/storage-blob/test/blobbatch.spec.ts +++ b/sdk/storage/storage-blob/test/blobbatch.spec.ts @@ -21,6 +21,7 @@ import { BlobBatchClient, StorageSharedKeyCredential } from "../src"; +import { Context } from "mocha"; dotenv.config(); @@ -37,7 +38,7 @@ describe("BlobBatch", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getGenericBSU(""); @@ -60,7 +61,7 @@ describe("BlobBatch", () => { blockBlobClients[blockBlobCount - 1] = tmpBlockBlobClient; }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); @@ -92,7 +93,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } @@ -129,7 +130,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } @@ -304,13 +305,13 @@ describe("BlobBatch", () => { // First succeeded. assert.equal(resp.subResponses[0].errorCode, undefined); assert.equal(resp.subResponses[0].status, 202); - assert.ok(resp.subResponses[0].statusMessage != ""); + assert.ok(resp.subResponses[0].statusMessage !== ""); assert.equal(resp.subResponses[0]._request.url, blockBlobClients[0].url); // Second failed. - assert.ok(resp.subResponses[1].errorCode != undefined); - assert.ok(resp.subResponses[1].status == 412); - assert.ok(resp.subResponses[1].statusMessage != ""); + assert.ok(resp.subResponses[1].errorCode !== undefined); + assert.ok(resp.subResponses[1].status === 412); + assert.ok(resp.subResponses[1].statusMessage !== ""); assert.equal(resp.subResponses[1]._request.url, blockBlobClients[1].url); }); @@ -339,7 +340,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); @@ -369,7 +370,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); @@ -392,7 +393,7 @@ describe("BlobBatch", () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 30; const leaseResp = await blockBlobClients[1].getBlobLeaseClient(guid).acquireLease(duration); - assert.ok(leaseResp.leaseId! != ""); + assert.ok(leaseResp.leaseId! !== ""); // Assemble batch set tier request. const batchSetTierRequest = new BlobBatch(); @@ -410,7 +411,7 @@ describe("BlobBatch", () => { for (let i = 0; i < 2; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); @@ -456,7 +457,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobClients.length; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClientsWithVersion[i].url); @@ -501,7 +502,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobClients.length; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClientsWithSnapshot[i].url); @@ -511,23 +512,11 @@ describe("BlobBatch", () => { } }); - it("submitBatch should work with multiple types of credentials for subrequests", async function() { + it("submitBatch should work with multiple types of credentials for subrequests", async function(this: Context) { recorder.skip( undefined, "UUID is randomly generated within the SDK and used in the HTTP request and cannot be preserved." ); - // Try to get serviceURL object with TokenCredential - // when ACCOUNT_TOKEN environment variable is set - let tokenCredential; - try { - tokenCredential = getTokenCredential(); - } catch {} - - // Requires bearer token for this case which cannot be generated in the runtime - // Make sure this case passed in sanity test - if (tokenCredential === undefined) { - this.skip(); - } // Upload blobs. await blockBlobClients[0].upload(content, content.length); @@ -538,16 +527,26 @@ describe("BlobBatch", () => { await batchSetTierRequest.setBlobAccessTier(blockBlobClients[0].url, credential, "Cool"); // When it's using token credential be sure it's not with SAS (browser testing case) let blockBlobClient1WithoutSAS = blockBlobClients[1].url; - if (blockBlobClient1WithoutSAS.indexOf("?") != -1) { + if (blockBlobClient1WithoutSAS.indexOf("?") !== -1) { // remove query part for this testing for ease blockBlobClient1WithoutSAS = blockBlobClients[1].url.substring( 0, blockBlobClients[1].url.indexOf("?") ); } + + // Try to get serviceURL object with TokenCredential + // when ACCOUNT_TOKEN environment variable is set + let tokenCredential; + try { + tokenCredential = getTokenCredential(); + } catch { + this.skip(); + } + await batchSetTierRequest.setBlobAccessTier( blockBlobClient1WithoutSAS, - getTokenCredential(), + tokenCredential, "Cool" ); @@ -560,7 +559,7 @@ describe("BlobBatch", () => { for (let i = 0; i < 2; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 200); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); // Check blob tier set properly. @@ -589,7 +588,7 @@ describe("BlobBatch", () => { } catch (err) { if ( err instanceof RangeError && - err.message == "Cannot exceed 256 sub requests in a single batch" + err.message === "Cannot exceed 256 sub requests in a single batch" ) { exceptionCaught = true; } @@ -605,7 +604,10 @@ describe("BlobBatch", () => { try { await batchSetTierRequest.setBlobAccessTier("invalidurl", credential, "Cool"); } catch (err) { - if (err instanceof RangeError && err.message.indexOf("Invalid url for sub request: ") != -1) { + if ( + err instanceof RangeError && + err.message.indexOf("Invalid url for sub request: ") !== -1 + ) { exceptionCaught = true; } } @@ -621,7 +623,7 @@ describe("BlobBatch", () => { } catch (err) { if ( err instanceof RangeError && - err.message == "Batch request should contain one or more sub requests." + err.message === "Batch request should contain one or more sub requests." ) { exceptionCaught = true; } @@ -671,7 +673,7 @@ describe("BlobBatch", () => { } catch (err) { if ( err instanceof RangeError && - err.message == + err.message === "BlobBatch only supports one operation type per batch and it already is being used for delete operations." ) { exceptionCaught = true; @@ -705,7 +707,7 @@ describe("BlobBatch", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } @@ -733,7 +735,7 @@ describe("BlobBatch Token auth", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); // Try to get serviceURL object with TokenCredential when ACCOUNT_TOKEN environment variable is set @@ -760,7 +762,7 @@ describe("BlobBatch Token auth", () => { blockBlobClients[blockBlobCount - 1] = tmpBlockBlobClient; }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); @@ -792,7 +794,7 @@ describe("BlobBatch Token auth", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } @@ -823,7 +825,7 @@ describe("BlobBatch Token auth", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } diff --git a/sdk/storage/storage-blob/test/blobclient.spec.ts b/sdk/storage/storage-blob/test/blobclient.spec.ts index f755f3b18cdc..7c858aa5bfc5 100644 --- a/sdk/storage/storage-blob/test/blobclient.spec.ts +++ b/sdk/storage/storage-blob/test/blobclient.spec.ts @@ -27,6 +27,7 @@ import { import { Test_CPK_INFO } from "./utils/constants"; import { base64encode } from "../src/utils/utils.common"; import { context, setSpan } from "@azure/core-tracing"; +import { Context } from "mocha"; dotenv.config(); describe("BlobClient", () => { @@ -40,7 +41,7 @@ describe("BlobClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -52,7 +53,7 @@ describe("BlobClient", () => { await blockBlobClient.upload(content, content.length); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); @@ -849,7 +850,7 @@ describe("BlobClient", () => { await checkRehydratePriority("Standard"); }); - it("lastAccessed returned", async function() { + it("lastAccessed returned", async function(this: Context) { if (isLiveMode()) { // Skipped for now as it's not working in live tests pipeline. this.skip(); @@ -1340,13 +1341,13 @@ describe("BlobClient - Object Replication", () => { } ]; - before(async function() { + before(async function(this: Context) { if (isLiveMode()) { this.skip(); } }); - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); srcBlobServiceClient = getGenericBSU(""); destBlobServiceClient = getGenericBSU("ORS_DEST_"); @@ -1411,7 +1412,7 @@ describe("BlobClient - Object Replication", () => { assert.equal(destRes.objectReplicationSourceProperties, undefined); }); - it("download to file", async function() { + it("download to file", async function(this: Context) { if (!isNode) { this.skip(); } @@ -1446,7 +1447,7 @@ describe("BlobClient - ImmutabilityPolicy", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); @@ -1461,7 +1462,7 @@ describe("BlobClient - ImmutabilityPolicy", () => { blobClient = containerClient.getBlobClient(blobName); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { const listResult = ( await containerClient @@ -1471,8 +1472,9 @@ describe("BlobClient - ImmutabilityPolicy", () => { ).value; for (let i = 0; i < listResult.segment.blobItems!.length; ++i) { - let deleteBlobClient: BlobClient; - deleteBlobClient = containerClient.getBlobClient(listResult.segment.blobItems[i].name); + const deleteBlobClient = containerClient.getBlobClient( + listResult.segment.blobItems[i].name + ); await deleteBlobClient.setLegalHold(false); diff --git a/sdk/storage/storage-blob/test/blobclientpollers.spec.ts b/sdk/storage/storage-blob/test/blobclientpollers.spec.ts index 1eb34ecf440e..c177bf40ce42 100644 --- a/sdk/storage/storage-blob/test/blobclientpollers.spec.ts +++ b/sdk/storage/storage-blob/test/blobclientpollers.spec.ts @@ -16,6 +16,7 @@ import { PollOperationState } from "../src"; import { URLBuilder, URLQuery } from "@azure/core-http"; +import { Context } from "mocha"; dotenv.config(); describe("BlobClient beginCopyFromURL Poller", () => { @@ -30,7 +31,7 @@ describe("BlobClient beginCopyFromURL Poller", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -45,7 +46,7 @@ describe("BlobClient beginCopyFromURL Poller", () => { await destinationContainerClient.create(); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await destinationContainerClient.delete(); @@ -137,7 +138,7 @@ describe("BlobClient beginCopyFromURL Poller", () => { ); }); - it("supports cancellation of the copy", async function() { + it("supports cancellation of the copy", async function(this: Context) { if (!(isRecordMode() || isPlaybackMode())) { // Depends on the service not returning 'success' as soon as // the copy is initiated. Since this can't be guaranteed in the live tests, @@ -161,7 +162,7 @@ describe("BlobClient beginCopyFromURL Poller", () => { } }); - it("supports updating on progress events", async function() { + it("supports updating on progress events", async function(this: Context) { if (!(isRecordMode() || isPlaybackMode())) { // Depends on the service not returning 'success' as soon as // the copy is initiated. Since this can't be guaranteed in the live tests, diff --git a/sdk/storage/storage-blob/test/blobserviceclient.spec.ts b/sdk/storage/storage-blob/test/blobserviceclient.spec.ts index 1e55b7aa8344..22e44772609f 100644 --- a/sdk/storage/storage-blob/test/blobserviceclient.spec.ts +++ b/sdk/storage/storage-blob/test/blobserviceclient.spec.ts @@ -16,12 +16,13 @@ import { } from "./utils"; import { record, delay, Recorder, isLiveMode } from "@azure/test-utils-recorder"; import { Tags } from "../src/models"; +import { Context } from "mocha"; dotenv.config(); describe("BlobServiceClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); }); @@ -397,6 +398,7 @@ describe("BlobServiceClient", () => { .then((result) => { assert.ok(result.geoReplication!.lastSyncOn); done(); + return; }) .catch(done); }); @@ -446,10 +448,11 @@ describe("BlobServiceClient", () => { assert.ok(result.requestId!.length > 0); }); - it("getUserDelegationKey should work", async function() { + it("getUserDelegationKey should work", async function(this: Context) { // Try to get serviceURL object with TokenCredential // when ACCOUNT_TOKEN environment variable is set let serviceURLWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { serviceURLWithToken = getTokenBSU(); } catch {} @@ -576,7 +579,7 @@ describe("BlobServiceClient", () => { assert.equal(staticWebsite?.defaultIndexDocumentPath, defaultIndexDocumentPath); }); - it("restore container", async function() { + it("restore container", async function(this: Context) { let blobServiceClient: BlobServiceClient; try { blobServiceClient = getGenericBSU("SOFT_DELETE_"); @@ -613,7 +616,7 @@ describe("BlobServiceClient", () => { assert.ok(listed); }); - it("rename container", async function() { + it("rename container", async function(this: Context) { if (isLiveMode()) { // Turn on this case when the Container Rename feature is ready in the service side. this.skip(); @@ -637,7 +640,7 @@ describe("BlobServiceClient", () => { await newContainerClient.delete(); }); - it("rename container should work with source lease", async function() { + it("rename container should work with source lease", async function(this: Context) { if (isLiveMode()) { // Turn on this case when the Container Rename feature is ready in the service side. this.skip(); diff --git a/sdk/storage/storage-blob/test/blobversioning.spec.ts b/sdk/storage/storage-blob/test/blobversioning.spec.ts index f77ad60ead67..f7897d5c2a08 100644 --- a/sdk/storage/storage-blob/test/blobversioning.spec.ts +++ b/sdk/storage/storage-blob/test/blobversioning.spec.ts @@ -16,6 +16,7 @@ import { BlobBatch } from "../src"; import { setURLParameter } from "../src/utils/utils.common"; +import { Context } from "mocha"; dotenv.config({ path: "../.env" }); describe("Blob versioning", () => { @@ -31,7 +32,7 @@ describe("Blob versioning", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -92,7 +93,7 @@ describe("Blob versioning", () => { } }); - it("download a version to file", async function() { + it("download a version to file", async function(this: Context) { if (!isNode) { // downloadToFile only available in Node.js this.skip(); @@ -184,7 +185,7 @@ describe("Blob versioning", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal( resp.subResponses[i]._request.url, diff --git a/sdk/storage/storage-blob/test/blockblobclient.spec.ts b/sdk/storage/storage-blob/test/blockblobclient.spec.ts index 4b238a8758d8..272bf433d23f 100644 --- a/sdk/storage/storage-blob/test/blockblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/blockblobclient.spec.ts @@ -15,6 +15,8 @@ import { import { ContainerClient, BlobClient, BlockBlobClient } from "../src"; import { Test_CPK_INFO } from "./utils/constants"; import { BlockBlobTier } from "../src"; +import { Context } from "mocha"; +import { isNode } from "@azure/core-http"; dotenv.config(); describe("BlockBlobClient", () => { @@ -26,7 +28,7 @@ describe("BlockBlobClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -37,7 +39,7 @@ describe("BlockBlobClient", () => { blockBlobClient = blobClient.getBlockBlobClient(); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); @@ -54,7 +56,9 @@ describe("BlockBlobClient", () => { it("upload with progress report", async () => { const body: string = recorder.getUniqueName("randomstring"); await blockBlobClient.upload(body, body.length, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); const result = await blobClient.download(0); assert.deepStrictEqual(await bodyToString(result, body.length), body); @@ -106,10 +110,14 @@ describe("BlockBlobClient", () => { it("stageBlock with progress report", async () => { const body = "HelloWorld"; await blockBlobClient.stageBlock(base64encode("1"), body, body.length, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); await blockBlobClient.stageBlock(base64encode("2"), body, body.length, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); await blockBlobClient.commitBlockList([base64encode("1"), base64encode("2")]); const listResponse = await blockBlobClient.getBlockList("committed"); @@ -124,12 +132,11 @@ describe("BlockBlobClient", () => { const body = "HelloWorld"; await blockBlobClient.upload(body, body.length); - // When testing is in Node.js environment with shared key, setAccessPolicy will work - // But in browsers testing with SAS tokens, below will throw an exception, ignore it - try { + // When in browsers testing with SAS tokens, setAccessPolicy won't work. + // so only test setAccessPolicy in Node.js environment. + if (isNode) { await containerClient.setAccessPolicy("container"); - // tslint:disable-next-line:no-empty - } catch (err) {} + } const newBlockBlobClient = containerClient.getBlockBlobClient( recorder.getUniqueName("newblockblob") @@ -146,12 +153,11 @@ describe("BlockBlobClient", () => { const body = "HelloWorld"; await blockBlobClient.upload(body, body.length); - // When testing is in Node.js environment with shared key, setAccessPolicy will work - // But in browsers testing with SAS tokens, below will throw an exception, ignore it - try { + // When in browsers testing with SAS tokens, setAccessPolicy won't work. + // so only test setAccessPolicy in Node.js environment. + if (isNode) { await containerClient.setAccessPolicy("container"); - // tslint:disable-next-line:no-empty - } catch (err) {} + } const newBlockBlobClient = containerClient.getBlockBlobClient( recorder.getUniqueName("newblockblob") @@ -262,7 +268,6 @@ describe("BlockBlobClient", () => { it("throws error if constructor containerName parameter is empty", async () => { try { - // tslint:disable-next-line: no-unused-expression new BlockBlobClient(getSASConnectionStringFromEnvironment(), "", "blobName"); assert.fail("Expecting an thrown error but didn't get one."); } catch (error) { @@ -323,12 +328,11 @@ describe("BlockBlobClient", () => { const body = "HelloWorld"; await blockBlobClient.upload(body, body.length); - // When testing is in Node.js environment with shared key, setAccessPolicy will work - // But in browsers testing with SAS tokens, below will throw an exception, ignore it - try { + // When in browsers testing with SAS tokens, setAccessPolicy won't work. + // so only test setAccessPolicy in Node.js environment. + if (isNode) { await containerClient.setAccessPolicy("container"); - // tslint:disable-next-line:no-empty - } catch (err) {} + } const newBlockBlobURL = containerClient.getBlockBlobClient( recorder.getUniqueName("newblockblob") diff --git a/sdk/storage/storage-blob/test/browser/highlevel.browser.spec.ts b/sdk/storage/storage-blob/test/browser/highlevel.browser.spec.ts index 1ae6dc255a3b..a78cb8781aa1 100644 --- a/sdk/storage/storage-blob/test/browser/highlevel.browser.spec.ts +++ b/sdk/storage/storage-blob/test/browser/highlevel.browser.spec.ts @@ -15,8 +15,8 @@ import { } from "../utils/index.browser"; import { record, Recorder } from "@azure/test-utils-recorder"; import { ContainerClient, BlobClient, BlockBlobClient, BlobServiceClient } from "../../src"; +import { Context } from "mocha"; -// tslint:disable:no-empty describe("Highlevel", () => { let containerName: string; let containerClient: ContainerClient; @@ -31,7 +31,7 @@ describe("Highlevel", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -42,21 +42,23 @@ describe("Highlevel", () => { blockBlobClient = blobClient.getBlockBlobClient(); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); } }); - before(async function() { + before(async function(this: Context) { recorder = record(this, recorderEnvSetup); tempFile1 = getBrowserFile(recorder.getUniqueName("browserfile"), tempFile1Length); tempFile2 = getBrowserFile(recorder.getUniqueName("browserfile2"), tempFile2Length); await recorder.stop(); }); - after(async () => {}); + after(async () => { + /* empty */ + }); it("uploadBrowserDataToBlockBlob should abort when blob >= BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES", async () => { recorder.skip("browser", "Temp file - recorder doesn't support saving the file"); @@ -93,6 +95,7 @@ describe("Highlevel", () => { let eventTriggered = false; const aborter = new AbortController(); + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await blockBlobClient.uploadBrowserData(tempFile1, { abortSignal: aborter.signal, @@ -113,6 +116,7 @@ describe("Highlevel", () => { let eventTriggered = false; const aborter = new AbortController(); + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await blockBlobClient.uploadBrowserData(tempFile2, { abortSignal: aborter.signal, diff --git a/sdk/storage/storage-blob/test/containerclient.spec.ts b/sdk/storage/storage-blob/test/containerclient.spec.ts index 11d245540c1b..131b2fc314dd 100644 --- a/sdk/storage/storage-blob/test/containerclient.spec.ts +++ b/sdk/storage/storage-blob/test/containerclient.spec.ts @@ -21,6 +21,7 @@ import { } from "../src"; import { Test_CPK_INFO } from "./utils/constants"; import { context, setSpan } from "@azure/core-tracing"; +import { Context } from "mocha"; dotenv.config(); describe("ContainerClient", () => { @@ -30,7 +31,7 @@ describe("ContainerClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -879,7 +880,7 @@ describe("ContainerClient - Verify Name Properties", () => { const containerName = "containerName"; const accountName = "myAccount"; - function verifyNameProperties(url: string) { + function verifyNameProperties(url: string): void { const newClient = new ContainerClient(url); assert.equal( newClient.containerName, diff --git a/sdk/storage/storage-blob/test/encrytion.spec.ts b/sdk/storage/storage-blob/test/encrytion.spec.ts index 2dd86316a711..211c570131a9 100644 --- a/sdk/storage/storage-blob/test/encrytion.spec.ts +++ b/sdk/storage/storage-blob/test/encrytion.spec.ts @@ -8,6 +8,7 @@ import { record, isPlaybackMode, Recorder } from "@azure/test-utils-recorder"; import { BlobServiceClient, BlobClient, BlockBlobClient, ContainerClient } from "../src"; import { Test_CPK_INFO } from "./utils/constants"; import { isNode } from "@azure/core-http"; +import { Context } from "mocha"; dotenv.config(); describe("Encryption Scope", function() { @@ -26,7 +27,7 @@ describe("Encryption Scope", function() { let encryptionScopeName2: string | undefined; let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); if (isNode) { diff --git a/sdk/storage/storage-blob/test/leaseclient.spec.ts b/sdk/storage/storage-blob/test/leaseclient.spec.ts index f75d94e66781..ddc27b91c27a 100644 --- a/sdk/storage/storage-blob/test/leaseclient.spec.ts +++ b/sdk/storage/storage-blob/test/leaseclient.spec.ts @@ -7,6 +7,7 @@ import * as dotenv from "dotenv"; import { getBSU, recorderEnvSetup } from "./utils"; import { record, delay, Recorder } from "@azure/test-utils-recorder"; import { ContainerClient, BlobClient, BlockBlobClient, BlobServiceClient } from "../src"; +import { Context } from "mocha"; dotenv.config(); describe("LeaseClient from Container", () => { @@ -16,7 +17,7 @@ describe("LeaseClient from Container", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -150,7 +151,7 @@ describe("LeaseClient from Blob", () => { const content = "Hello World"; let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); diff --git a/sdk/storage/storage-blob/test/node/appendblobclient.spec.ts b/sdk/storage/storage-blob/test/node/appendblobclient.spec.ts index 6f5dc8b130a4..6cc1d6b8b760 100644 --- a/sdk/storage/storage-blob/test/node/appendblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/appendblobclient.spec.ts @@ -25,6 +25,7 @@ import { TokenCredential } from "@azure/core-http"; import { assertClientUsesTokenCredential } from "../utils/assert"; import { isPlaybackMode, record, Recorder } from "@azure/test-utils-recorder"; import { Test_CPK_INFO } from "../utils/constants"; +import { Context } from "mocha"; dotenv.config(); describe("AppendBlobClient Node.js only", () => { @@ -36,7 +37,7 @@ describe("AppendBlobClient Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -153,7 +154,7 @@ describe("AppendBlobClient Node.js only", () => { assert.equal(downloadResponse.contentLength!, content.length * 2); }); - it("appendBlockFromURL - source SAS and destination bearer token", async function() { + it("appendBlockFromURL - source SAS and destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -197,7 +198,7 @@ describe("AppendBlobClient Node.js only", () => { assert.equal(downloadResponse.contentLength!, content.length); }); - it("appendBlockFromURL - source bear token and destination account key", async function() { + it("appendBlockFromURL - source bear token and destination account key", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -226,7 +227,7 @@ describe("AppendBlobClient Node.js only", () => { assert.equal(downloadResponse.contentLength!, content.length); }); - it("appendBlockFromURL - destination bearer token", async function() { + it("appendBlockFromURL - destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); diff --git a/sdk/storage/storage-blob/test/node/blobclient.spec.ts b/sdk/storage/storage-blob/test/node/blobclient.spec.ts index 9642f6b58577..916c22fddc0d 100644 --- a/sdk/storage/storage-blob/test/node/blobclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/blobclient.spec.ts @@ -33,6 +33,7 @@ import { import { assertClientUsesTokenCredential } from "../utils/assert"; import { readStreamToLocalFileWithLogs } from "../utils/testutils.node"; import { streamToBuffer3 } from "../../src/utils/utils.node"; +import { Context } from "mocha"; dotenv.config(); @@ -48,7 +49,7 @@ describe("BlobClient Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -191,13 +192,9 @@ describe("BlobClient Node.js only", () => { // As a snapshot doesn't have leaseStatus and leaseState properties but origin blob has, // let assign them to undefined both for other properties' easy comparison - // tslint:disable-next-line:max-line-length result3.segment.blobItems![0].properties.leaseState = result3.segment.blobItems![1].properties.leaseState = undefined; - // tslint:disable-next-line:max-line-length result3.segment.blobItems![0].properties.leaseStatus = result3.segment.blobItems![1].properties.leaseStatus = undefined; - // tslint:disable-next-line:max-line-length result3.segment.blobItems![0].properties.accessTier = result3.segment.blobItems![1].properties.accessTier = undefined; - // tslint:disable-next-line:max-line-length result3.segment.blobItems![0].properties.accessTierInferred = result3.segment.blobItems![1].properties.accessTierInferred = undefined; assert.deepStrictEqual( @@ -207,7 +204,7 @@ describe("BlobClient Node.js only", () => { assert.ok(result3.segment.blobItems![0].snapshot || result3.segment.blobItems![1].snapshot); }); - it("syncCopyFromURL - source SAS and destination bearer token", async function() { + it("syncCopyFromURL - source SAS and destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -246,7 +243,7 @@ describe("BlobClient Node.js only", () => { assert.deepStrictEqual(properties2.copyId, result.copyId); }); - it("syncCopyFromURL - destination bearer token", async function() { + it("syncCopyFromURL - destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -267,7 +264,7 @@ describe("BlobClient Node.js only", () => { assert.deepStrictEqual(properties2.copyId, result.copyId); }); - it("syncCopyFromURL - source bearer token and destination account key", async function() { + it("syncCopyFromURL - source bearer token and destination account key", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -642,7 +639,9 @@ describe("BlobClient Node.js only", () => { .then((response) => { return bodyToString(response); }) - .then((_data) => {}) + .then((_data) => { + return; + }) .catch(reject); }); }); @@ -774,8 +773,8 @@ describe("BlobClient Node.js only", () => { }); }); - it("query should work with Parquet input configuration", async function() { - //Enable the case when STG78 - version 2020-10-02 features is enabled in production. + it("query should work with Parquet input configuration", async function(this: Context) { + // Enable the case when STG78 - version 2020-10-02 features is enabled in production. this.skip(); const parquetFilePath = join("test", "resources", "parquet.parquet"); await blockBlobClient.uploadFile(parquetFilePath); @@ -800,7 +799,7 @@ describe("BlobClient Node.js Only - ImmutabilityPolicy", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); try { @@ -813,7 +812,7 @@ describe("BlobClient Node.js Only - ImmutabilityPolicy", () => { blobClient = containerClient.getBlobClient(blobName); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { const listResult = ( await containerClient @@ -825,8 +824,9 @@ describe("BlobClient Node.js Only - ImmutabilityPolicy", () => { ).value; for (let i = 0; i < listResult.segment.blobItems!.length; ++i) { - let deleteBlobClient: BlobClient; - deleteBlobClient = containerClient.getBlobClient(listResult.segment.blobItems[i].name); + const deleteBlobClient = containerClient.getBlobClient( + listResult.segment.blobItems[i].name + ); await deleteBlobClient.setLegalHold(false); await deleteBlobClient.deleteImmutabilityPolicy(); await deleteBlobClient.delete(); diff --git a/sdk/storage/storage-blob/test/node/blobserviceclient.spec.ts b/sdk/storage/storage-blob/test/node/blobserviceclient.spec.ts index 84c23a457f56..d033b1ef51d4 100644 --- a/sdk/storage/storage-blob/test/node/blobserviceclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/blobserviceclient.spec.ts @@ -7,12 +7,13 @@ import * as dotenv from "dotenv"; import { BlobServiceClient, newPipeline, StorageSharedKeyCredential } from "../../src"; import { getBSU, getConnectionStringFromEnvironment, recorderEnvSetup } from "../utils"; import { record, Recorder } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; dotenv.config(); describe("BlobServiceClient Node.js only", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); }); diff --git a/sdk/storage/storage-blob/test/node/blockblobclient.spec.ts b/sdk/storage/storage-blob/test/node/blockblobclient.spec.ts index 3042755b106d..7af669aedfa4 100644 --- a/sdk/storage/storage-blob/test/node/blockblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/blockblobclient.spec.ts @@ -30,6 +30,7 @@ import { isPlaybackMode, record, Recorder } from "@azure/test-utils-recorder"; import { streamToBuffer3 } from "../../src/utils/utils.node"; import * as crypto from "crypto"; import { BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES } from "../../src/utils/constants"; +import { Context } from "mocha"; describe("BlockBlobClient Node.js only", () => { let containerName: string; @@ -40,7 +41,7 @@ describe("BlockBlobClient Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -51,7 +52,7 @@ describe("BlockBlobClient Node.js only", () => { blockBlobClient = blobClient.getBlockBlobClient(); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); @@ -205,7 +206,7 @@ describe("syncUploadFromURL", () => { largeContent = genearteRandomUint8Array(BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES); }); - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); const blobServiceClient = getBSU(); const containerName = recorder.getUniqueName("container"); @@ -236,14 +237,14 @@ describe("syncUploadFromURL", () => { sourceBlobURLWithSAS = sourceBlob.url + "?" + sas; }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); } }); - it("stageBlockFromURL - source SAS and destination bearer token", async function() { + it("stageBlockFromURL - source SAS and destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -275,7 +276,7 @@ describe("syncUploadFromURL", () => { assert.equal(listResponse.committedBlocks![1].size, content.length); }); - it("stageBlockFromURL - source bear token and destination account key", async function() { + it("stageBlockFromURL - source bear token and destination account key", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -325,7 +326,7 @@ describe("syncUploadFromURL", () => { assert.equal(listResponse.committedBlocks![1].size, body.length); }); - it("stageBlockFromURL - destination bearer token", async function() { + it("stageBlockFromURL - destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -378,7 +379,7 @@ describe("syncUploadFromURL", () => { assert.equal(listResponse.committedBlocks![1].size, body.length); }); - it("syncUploadFromURL - source SAS and destination bearer token", async function() { + it("syncUploadFromURL - source SAS and destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -396,7 +397,7 @@ describe("syncUploadFromURL", () => { assert.ok(downloadBuffer.compare(Buffer.from(content)) === 0); }); - it("syncUploadFromURL - source bear token and destination account key", async function() { + it("syncUploadFromURL - source bear token and destination account key", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -424,7 +425,7 @@ describe("syncUploadFromURL", () => { assert.equal(downloadRes.contentLength!, body.length); }); - it("syncUploadFromURL - destination bearer token", async function() { + it("syncUploadFromURL - destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); diff --git a/sdk/storage/storage-blob/test/node/containerclient.spec.ts b/sdk/storage/storage-blob/test/node/containerclient.spec.ts index c792dc742c9c..bf53678c2da1 100644 --- a/sdk/storage/storage-blob/test/node/containerclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/containerclient.spec.ts @@ -15,6 +15,7 @@ import { import { TokenCredential } from "@azure/core-http"; import { assertClientUsesTokenCredential } from "../utils/assert"; import { record, Recorder } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; describe("ContainerClient Node.js only", () => { let containerName: string; @@ -22,7 +23,7 @@ describe("ContainerClient Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); diff --git a/sdk/storage/storage-blob/test/node/emulator-tests.spec.ts b/sdk/storage/storage-blob/test/node/emulator-tests.spec.ts index bd9997f473ff..dab8c70fe18d 100644 --- a/sdk/storage/storage-blob/test/node/emulator-tests.spec.ts +++ b/sdk/storage/storage-blob/test/node/emulator-tests.spec.ts @@ -12,6 +12,7 @@ import { } from "../../src"; import { getBSU, getConnectionStringFromEnvironment, bodyToString, getUniqueName } from "../utils"; import { env } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; dotenv.config(); // Expected environment variable to run this test-suite @@ -25,7 +26,7 @@ describe("Emulator Tests", () => { let blockBlobClient: BlockBlobClient; const content = "Hello World"; - beforeEach(async function() { + beforeEach(async function(this: Context) { if (!env.STORAGE_CONNECTION_STRING.startsWith("UseDevelopmentStorage=true")) { this.skip(); } @@ -39,7 +40,7 @@ describe("Emulator Tests", () => { await blockBlobClient.upload(content, content.length); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); } diff --git a/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts b/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts index c59183523c3c..9e6586d6e229 100644 --- a/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts +++ b/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts @@ -23,8 +23,8 @@ import { BLOCK_BLOB_MAX_STAGE_BLOCK_BYTES } from "../../src/utils/constants"; import { Test_CPK_INFO } from "../utils/constants"; import { streamToBuffer2 } from "../../src/utils/utils.node"; import { delay } from "../../src/utils/utils.common"; +import { Context } from "mocha"; -// tslint:disable:no-empty describe("Highlevel", () => { let containerName: string; let containerClient: ContainerClient; @@ -41,7 +41,7 @@ describe("Highlevel", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU({ keepAliveOptions: { @@ -56,14 +56,14 @@ describe("Highlevel", () => { blockBlobClient = blobClient.getBlockBlobClient(); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { await containerClient.delete(); await recorder.stop(); } }); - before(async function() { + before(async function(this: Context) { recorder = record(this, recorderEnvSetup); if (!fs.existsSync(tempFolderPath)) { fs.mkdirSync(tempFolderPath); @@ -84,7 +84,7 @@ describe("Highlevel", () => { await recorder.stop(); }); - after(async function() { + after(async function(this: Context) { recorder = record(this, recorderEnvSetup); fs.unlinkSync(tempFileLarge); fs.unlinkSync(tempFileSmall); @@ -218,6 +218,7 @@ describe("Highlevel", () => { let eventTriggered = false; const aborter = new AbortController(); + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await blockBlobClient.uploadFile(tempFileLarge, { abortSignal: aborter.signal, @@ -241,6 +242,7 @@ describe("Highlevel", () => { let eventTriggered = false; const aborter = new AbortController(); + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await blockBlobClient.uploadFile(tempFileSmall, { abortSignal: aborter.signal, @@ -498,6 +500,7 @@ describe("Highlevel", () => { let eventTriggered = false; const buf = Buffer.alloc(tempFileSmallLength); const aborter = new AbortController(); + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await blockBlobClient.downloadToBuffer(buf, 0, undefined, { abortSignal: aborter.signal, @@ -544,6 +547,7 @@ describe("Highlevel", () => { concurrency: 20 }); + /* eslint-disable prefer-const */ let retirableReadableStreamOptions: RetriableReadableStreamOptions; const downloadResponse = await blockBlobClient.download(0, undefined, { conditions: { @@ -558,6 +562,7 @@ describe("Highlevel", () => { }); retirableReadableStreamOptions = (downloadResponse.readableStreamBody! as any).options; + /* eslint-enable prefer-const */ const downloadedFile = path.join(tempFolderPath, recorder.getUniqueName("downloadfile.")); await readStreamToLocalFileWithLogs(downloadResponse.readableStreamBody!, downloadedFile); @@ -576,6 +581,7 @@ describe("Highlevel", () => { concurrency: 20 }); + /* eslint-disable prefer-const */ let retirableReadableStreamOptions: RetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobClient.download(0, undefined, { @@ -591,6 +597,7 @@ describe("Highlevel", () => { }); retirableReadableStreamOptions = (downloadResponse.readableStreamBody! as any).options; + /* eslint-enable prefer-const */ const downloadedFile = path.join(tempFolderPath, recorder.getUniqueName("downloadfile.")); await readStreamToLocalFileWithLogs(downloadResponse.readableStreamBody!, downloadedFile); @@ -611,6 +618,7 @@ describe("Highlevel", () => { const partialSize = 500 * 1024; + /* eslint-disable prefer-const */ let retirableReadableStreamOptions: RetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobClient.download(0, partialSize, { @@ -626,6 +634,7 @@ describe("Highlevel", () => { }); retirableReadableStreamOptions = (downloadResponse.readableStreamBody! as any).options; + /* eslint-enable prefer-const */ const downloadedFile = path.join(tempFolderPath, recorder.getUniqueName("downloadfile.")); await readStreamToLocalFileWithLogs(downloadResponse.readableStreamBody!, downloadedFile); diff --git a/sdk/storage/storage-blob/test/node/pageblobclient.spec.ts b/sdk/storage/storage-blob/test/node/pageblobclient.spec.ts index a4249b755532..894d87130a5f 100644 --- a/sdk/storage/storage-blob/test/node/pageblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/node/pageblobclient.spec.ts @@ -25,6 +25,7 @@ import { TokenCredential } from "@azure/core-http"; import { assertClientUsesTokenCredential } from "../utils/assert"; import { record, delay, Recorder, isPlaybackMode } from "@azure/test-utils-recorder"; import { Test_CPK_INFO } from "../utils/constants"; +import { Context } from "mocha"; describe("PageBlobClient Node.js only", () => { let containerName: string; @@ -36,7 +37,7 @@ describe("PageBlobClient Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -72,7 +73,7 @@ describe("PageBlobClient Node.js only", () => { let copySource = pageBlobClient.withSnapshot(snapshotResult.snapshot!).url; let copyResponse = await destPageBlobClient.startCopyIncremental(copySource); - async function waitForCopy(retries = 0) { + async function waitForCopy(retries = 0): Promise { if (retries >= 30) { throw new Error("Check copy status exceed max retries counts"); } @@ -169,7 +170,7 @@ describe("PageBlobClient Node.js only", () => { assert.equal(await bodyToString(page2, 512), "b".repeat(512)); }); - it("uploadPagesFromURL - source SAS and destination bearer token", async function() { + it("uploadPagesFromURL - source SAS and destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -215,7 +216,7 @@ describe("PageBlobClient Node.js only", () => { assert.equal(await bodyToString(page2, 512), "b".repeat(512)); }); - it("uploadPagesFromURL - source bear token and destination account key", async function() { + it("uploadPagesFromURL - source bear token and destination account key", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -255,7 +256,7 @@ describe("PageBlobClient Node.js only", () => { assert.equal(await bodyToString(page2, 512), "b".repeat(512)); }); - it("uploadPagesFromURL - destination bearer token", async function() { + it("uploadPagesFromURL - destination bearer token", async function(this: Context) { if (!isPlaybackMode()) { // Enable this when STG78 - version 2020-10-02 is enabled on production. this.skip(); @@ -491,6 +492,7 @@ describe("PageBlobClient Node.js only", () => { const copyResponse = await destPageBlobClient.startCopyIncremental(copySource); if (copyResponse.copyStatus === "pending") { // May fail as the copy succeeded during between? If so, ignore error in the abort as we don't care. + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { await destPageBlobClient.abortCopyFromURL(copyResponse.copyId!); } catch (err) {} diff --git a/sdk/storage/storage-blob/test/node/sas.spec.ts b/sdk/storage/storage-blob/test/node/sas.spec.ts index 5c4cb22bcdaa..172cc88cb557 100644 --- a/sdk/storage/storage-blob/test/node/sas.spec.ts +++ b/sdk/storage/storage-blob/test/node/sas.spec.ts @@ -32,12 +32,13 @@ import { } from "../utils"; import { delay, record, Recorder } from "@azure/test-utils-recorder"; import { SERVICE_VERSION } from "../../src/utils/constants"; +import { Context } from "mocha"; describe("Shared Access Signature (SAS) generation Node.js only", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); }); @@ -216,12 +217,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { newPipeline(new AnonymousCredential()) ); - ( + const result = ( await containerClientWithSAS .listBlobsFlat() .byPage() .next() ).value; + assert.ok(result.serviceEndpoint.length > 0); + assert.deepStrictEqual(result.continuationToken, ""); await containerClient.delete(); }); @@ -677,10 +680,11 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { await containerClient.delete(); }); - it("GenerateUserDelegationSAS should work for container with all configurations", async function() { + it("GenerateUserDelegationSAS should work for container with all configurations", async function(this: Context) { // Try to get BlobServiceClient object with DefaultCredential // when AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET environment variables are set let blobServiceClientWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { blobServiceClientWithToken = getTokenBSUWithDefaultCredential(); } catch {} @@ -726,19 +730,22 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { newPipeline(new AnonymousCredential()) ); - ( + const result = ( await containerClientWithSAS .listBlobsFlat() .byPage() .next() ).value; + assert.ok(result.serviceEndpoint.length > 0); + assert.deepStrictEqual(result.continuationToken, ""); await containerClient.delete(); }); - it("GenerateUserDelegationSAS should work for container with minimum parameters", async function() { + it("GenerateUserDelegationSAS should work for container with minimum parameters", async function(this: Context) { // Try to get BlobServiceClient object with DefaultCredential // when AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET environment variables are set let blobServiceClientWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { blobServiceClientWithToken = getTokenBSUWithDefaultCredential(); } catch {} @@ -780,19 +787,22 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { newPipeline(new AnonymousCredential()) ); - ( + const result = ( await containerClientWithSAS .listBlobsFlat() .byPage() .next() ).value; + assert.ok(result.serviceEndpoint.length > 0); + assert.deepStrictEqual(result.continuationToken, ""); await containerClient.delete(); }); - it("GenerateUserDelegationSAS should work for blob", async function() { + it("GenerateUserDelegationSAS should work for blob", async function(this: Context) { // Try to get blobServiceClient object with DefaultCredential // when AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET environment variables are set let blobServiceClientWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { blobServiceClientWithToken = getTokenBSUWithDefaultCredential(); } catch {} @@ -858,10 +868,11 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { await containerClient.delete(); }); - it("GenerateUserDelegationSAS should work for blob snapshot", async function() { + it("GenerateUserDelegationSAS should work for blob snapshot", async function(this: Context) { // Try to get blobServiceClient object with DefaultCredential // when AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET environment variables are set let blobServiceClientWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { blobServiceClientWithToken = getTokenBSUWithDefaultCredential(); } catch {} @@ -1016,10 +1027,11 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { await containerClient.delete(); }); - it("GenerateUserDelegationSAS should work for blob version delete", async function() { + it("GenerateUserDelegationSAS should work for blob version delete", async function(this: Context) { // Try to get blobServiceClient object with DefaultCredential // when AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET environment variables are set let blobServiceClientWithToken: BlobServiceClient | undefined; + /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ try { blobServiceClientWithToken = getTokenBSUWithDefaultCredential(); } catch {} @@ -1351,12 +1363,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { }); const containerClientWithSAS = new ContainerClient(sasURL); - ( + const result = ( await containerClientWithSAS .listBlobsFlat() .byPage() .next() ).value; + assert.ok(result.serviceEndpoint.length > 0); + assert.deepStrictEqual(result.continuationToken, ""); try { await containerClientWithSAS.generateSasUrl({}); @@ -1608,7 +1622,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { for (let i = 0; i < blockBlobCount; i++) { assert.equal(resp.subResponses[i].errorCode, undefined); assert.equal(resp.subResponses[i].status, 202); - assert.ok(resp.subResponses[i].statusMessage != ""); + assert.ok(resp.subResponses[i].statusMessage !== ""); assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id")); assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url); } @@ -1636,7 +1650,7 @@ describe("Generation for user delegation SAS Node.js only", () => { let containerClient: ContainerClient; let blobClient: BlobClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); try { blobServiceClient = getTokenBSUWithDefaultCredential(); @@ -1736,7 +1750,7 @@ describe("Shared Access Signature (SAS) generation Node.js Only - ImmutabilityPo let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); try { @@ -1749,7 +1763,7 @@ describe("Shared Access Signature (SAS) generation Node.js Only - ImmutabilityPo blobClient = containerClient.getBlobClient(blobName); }); - afterEach(async function() { + afterEach(async function(this: Context) { if (!this.currentTest?.isPending()) { const listResult = ( await containerClient @@ -1761,8 +1775,9 @@ describe("Shared Access Signature (SAS) generation Node.js Only - ImmutabilityPo ).value; for (let i = 0; i < listResult.segment.blobItems!.length; ++i) { - let deleteBlobClient: BlobClient; - deleteBlobClient = containerClient.getBlobClient(listResult.segment.blobItems[i].name); + const deleteBlobClient = containerClient.getBlobClient( + listResult.segment.blobItems[i].name + ); await deleteBlobClient.setLegalHold(false); await deleteBlobClient.deleteImmutabilityPolicy(); await deleteBlobClient.delete(); diff --git a/sdk/storage/storage-blob/test/node/utils.spec.ts b/sdk/storage/storage-blob/test/node/utils.spec.ts index 229d4a955950..84a015c6eab4 100644 --- a/sdk/storage/storage-blob/test/node/utils.spec.ts +++ b/sdk/storage/storage-blob/test/node/utils.spec.ts @@ -26,7 +26,7 @@ describe("Utility Helpers Node.js only", () => { const accountKey = "myAccountKey"; const blobEndpoint = `${protocol}://${accountName}.blob.${endpointSuffix}`; - function verifyConnectionString(connectionString: string) { + function verifyConnectionString(connectionString: string): void { const connectionStringParts = extractConnectionStringParts(connectionString); assert.equal( "AccountConnString", @@ -361,9 +361,9 @@ describe("Utility Helpers Node.js only", () => { // the last call to read() returns the last bytes, and there is never a call which returns null. // I'm not sure why this behavior is different, but streamToBuffer2() should support both. let readStream: Readable; - if (test.streamType == "test") { + if (test.streamType === "test") { readStream = new TestReadableStream(inputBuffer, test.bytesPerRead!); - } else if (test.streamType == "passthrough") { + } else if (test.streamType === "passthrough") { const passthrough = new PassThrough(); passthrough.end(inputBuffer); readStream = passthrough; diff --git a/sdk/storage/storage-blob/test/pageblobclient.spec.ts b/sdk/storage/storage-blob/test/pageblobclient.spec.ts index b41d5ecfe598..921fda7a16ba 100644 --- a/sdk/storage/storage-blob/test/pageblobclient.spec.ts +++ b/sdk/storage/storage-blob/test/pageblobclient.spec.ts @@ -18,6 +18,7 @@ import { BlobServiceClient } from "../src"; import { record, Recorder } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; dotenv.config(); describe("PageBlobClient", () => { @@ -30,7 +31,7 @@ describe("PageBlobClient", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); @@ -131,10 +132,14 @@ describe("PageBlobClient", () => { assert.equal(await bodyToString(result, 1024), "\u0000".repeat(1024)); await pageBlobClient.uploadPages("a".repeat(512), 0, 512, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); await pageBlobClient.uploadPages("b".repeat(512), 512, 512, { - onProgress: () => {} + onProgress: () => { + /* empty */ + } }); const page1 = await pageBlobClient.download(0, 512); @@ -195,7 +200,7 @@ describe("PageBlobClient", () => { assert.equal(rangesDiff.clearRange![0].count, 511); }); - it("getPageRangesDiffForManagedDisks", async function(): Promise { + it("getPageRangesDiffForManagedDisks", async function(this: Context): Promise { let mdBlobServiceClient: BlobServiceClient; try { mdBlobServiceClient = getGenericBSU("MD_", ""); @@ -291,7 +296,6 @@ describe("PageBlobClient", () => { it("throws error if constructor containerName parameter is empty", async () => { try { - // tslint:disable-next-line: no-unused-expression new PageBlobClient(getSASConnectionStringFromEnvironment(), "", "blobName"); assert.fail("Expecting an thrown error but didn't get one."); } catch (error) { @@ -305,7 +309,6 @@ describe("PageBlobClient", () => { it("throws error if constructor blobName parameter is empty", async () => { try { - // tslint:disable-next-line: no-unused-expression new PageBlobClient(getSASConnectionStringFromEnvironment(), "containerName", ""); assert.fail("Expecting an thrown error but didn't get one."); } catch (error) { diff --git a/sdk/storage/storage-blob/test/retrypolicy.spec.ts b/sdk/storage/storage-blob/test/retrypolicy.spec.ts index fd2206763169..9a2011b864bc 100644 --- a/sdk/storage/storage-blob/test/retrypolicy.spec.ts +++ b/sdk/storage/storage-blob/test/retrypolicy.spec.ts @@ -11,6 +11,7 @@ import { newPipeline, Pipeline } from "../src"; import { getBSU, recorderEnvSetup } from "./utils"; import { InjectorPolicyFactory } from "./utils/InjectorPolicyFactory"; import { record, Recorder } from "@azure/test-utils-recorder"; +import { Context } from "mocha"; dotenv.config(); @@ -21,7 +22,7 @@ describe("RetryPolicy", () => { let recorder: Recorder; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("container"); diff --git a/sdk/storage/storage-blob/test/specialnaming.spec.ts b/sdk/storage/storage-blob/test/specialnaming.spec.ts index 69a280bef92b..2e7ac6f5a903 100644 --- a/sdk/storage/storage-blob/test/specialnaming.spec.ts +++ b/sdk/storage/storage-blob/test/specialnaming.spec.ts @@ -8,6 +8,7 @@ import { appendToURLPath } from "../src/utils/utils.common"; import { record, Recorder } from "@azure/test-utils-recorder"; import * as dotenv from "dotenv"; import { ContainerClient } from "../src"; +import { Context } from "mocha"; dotenv.config(); describe("Special Naming Tests", () => { @@ -17,7 +18,7 @@ describe("Special Naming Tests", () => { let recorder: Recorder; let blobServiceClient: BlobServiceClient; - beforeEach(async function() { + beforeEach(async function(this: Context) { recorder = record(this, recorderEnvSetup); blobServiceClient = getBSU(); containerName = recorder.getUniqueName("1container-with-dash"); diff --git a/sdk/storage/storage-blob/test/utils/assert.ts b/sdk/storage/storage-blob/test/utils/assert.ts index 88cd43d602d2..562c49e69f64 100644 --- a/sdk/storage/storage-blob/test/utils/assert.ts +++ b/sdk/storage/storage-blob/test/utils/assert.ts @@ -4,7 +4,7 @@ import * as assert from "assert"; import { StorageClient } from "../../src/StorageClient"; -export function assertClientUsesTokenCredential(client: StorageClient) { +export function assertClientUsesTokenCredential(client: StorageClient): void { const factories = (client as any).pipeline.factories; const authPolicy = factories[factories.length - 1].create(); assert.strictEqual(authPolicy.constructor.name, "BearerTokenAuthenticationPolicy"); diff --git a/sdk/storage/storage-blob/test/utils/index.browser.ts b/sdk/storage/storage-blob/test/utils/index.browser.ts index a3fad621ca58..ad11e251b1a8 100644 --- a/sdk/storage/storage-blob/test/utils/index.browser.ts +++ b/sdk/storage/storage-blob/test/utils/index.browser.ts @@ -10,7 +10,8 @@ import { TokenCredential } from "@azure/core-http"; export * from "./testutils.common"; export function getGenericCredential(accountType: string): AnonymousCredential { - accountType = accountType; // bypass compiling error + const anewAccountType = accountType; // bypass compiling error + accountType = anewAccountType; return new AnonymousCredential(); } export function getGenericBSU( @@ -20,9 +21,8 @@ export function getGenericBSU( const accountNameEnvVar = `${accountType}ACCOUNT_NAME`; const accountSASEnvVar = `${accountType}ACCOUNT_SAS`; - let accountName: string | undefined; + const accountName = (self as any).__env__[accountNameEnvVar]; let accountSAS: string | undefined; - accountName = (self as any).__env__[accountNameEnvVar]; accountSAS = (self as any).__env__[accountSASEnvVar]; if (!accountName || !accountSAS || accountName === "" || accountSAS === "") { @@ -46,9 +46,8 @@ export function getGenericBSU( export function getTokenCredential(): TokenCredential { const accountTokenEnvVar = `ACCOUNT_TOKEN`; - let accountToken: string | undefined; - accountToken = (self as any).__env__[accountTokenEnvVar]; + const accountToken = (self as any).__env__[accountTokenEnvVar]; if (!accountToken || accountToken === "") { throw new Error(`${accountTokenEnvVar} environment variables not specified.`); @@ -60,9 +59,7 @@ export function getTokenCredential(): TokenCredential { export function getTokenBSU(): BlobServiceClient { const accountNameEnvVar = `ACCOUNT_NAME`; - let accountName: string | undefined; - - accountName = (self as any).__env__[accountNameEnvVar]; + const accountName = (self as any).__env__[accountNameEnvVar]; if (!accountName || accountName === "") { throw new Error(`${accountNameEnvVar} environment variables not specified.`); @@ -79,9 +76,8 @@ export function getTokenBSU(): BlobServiceClient { export function getImmutableContainerName(): string { const immutableContainerEnvVar = `IMMUTABLE_CONTAINER_NAME`; - let immutableContainerName: string | undefined; - immutableContainerName = (self as any).__env__[immutableContainerEnvVar]; + const immutableContainerName = (self as any).__env__[immutableContainerEnvVar]; if (!immutableContainerName || immutableContainerName === "") { throw new Error(`${immutableContainerEnvVar} environment variables not specified.`); @@ -110,7 +106,6 @@ export async function bodyToString( readableStreamBody?: NodeJS.ReadableStream; blobBody?: Promise; }, - // tslint:disable-next-line:variable-name _length?: number ): Promise { const blob = await response.blobBody!; diff --git a/sdk/storage/storage-blob/test/utils/index.ts b/sdk/storage/storage-blob/test/utils/index.ts index 30cda35b95e2..4e68082f955b 100644 --- a/sdk/storage/storage-blob/test/utils/index.ts +++ b/sdk/storage/storage-blob/test/utils/index.ts @@ -31,11 +31,8 @@ export function getGenericCredential(accountType: string): StorageSharedKeyCrede const accountNameEnvVar = `${accountType}ACCOUNT_NAME`; const accountKeyEnvVar = `${accountType}ACCOUNT_KEY`; - let accountName: string | undefined; - let accountKey: string | undefined; - - accountName = process.env[accountNameEnvVar]; - accountKey = process.env[accountKeyEnvVar]; + const accountName = process.env[accountNameEnvVar]; + const accountKey = process.env[accountKeyEnvVar]; if (!accountName || !accountKey || accountName === "" || accountKey === "") { throw new Error( @@ -71,9 +68,8 @@ export function getGenericBSU( export function getTokenCredential(): TokenCredential { const accountTokenEnvVar = `ACCOUNT_TOKEN`; - let accountToken: string | undefined; - accountToken = process.env[accountTokenEnvVar]; + const accountToken = process.env[accountTokenEnvVar]; if (!accountToken || accountToken === "") { throw new Error(`${accountTokenEnvVar} environment variables not specified.`); @@ -85,9 +81,7 @@ export function getTokenCredential(): TokenCredential { export function getTokenBSU(): BlobServiceClient { const accountNameEnvVar = `ACCOUNT_NAME`; - let accountName: string | undefined; - - accountName = process.env[accountNameEnvVar]; + const accountName = process.env[accountNameEnvVar]; if (!accountName || accountName === "") { throw new Error(`${accountNameEnvVar} environment variables not specified.`); @@ -167,8 +161,7 @@ export async function bodyToString( ): Promise { return new Promise((resolve, reject) => { response.readableStreamBody!.on("readable", () => { - let chunk; - chunk = response.readableStreamBody!.read(length); + const chunk = response.readableStreamBody!.read(length); if (chunk) { resolve(chunk.toString()); } @@ -226,16 +219,18 @@ export async function createRandomLocalFile( } ws.on("open", () => { - // tslint:disable-next-line:no-empty - while (offsetInMB++ < blockNumber && ws.write(randomValueHex(offsetInMB))) {} + while (offsetInMB++ < blockNumber && ws.write(randomValueHex(offsetInMB))) { + /* empty */ + } if (offsetInMB >= blockNumber) { ws.end(); } }); ws.on("drain", () => { - // tslint:disable-next-line:no-empty - while (offsetInMB++ < blockNumber && ws.write(randomValueHex(offsetInMB))) {} + while (offsetInMB++ < blockNumber && ws.write(randomValueHex(offsetInMB))) { + /* empty */ + } if (offsetInMB >= blockNumber) { ws.end(); }