Skip to content

Commit

Permalink
Fix ESLint errors in storage-blob package. (Azure#16881)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaZhu authored and ckairen committed Aug 24, 2021
1 parent 1b9105a commit 6147102
Show file tree
Hide file tree
Showing 50 changed files with 374 additions and 252 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/storage-blob/src/BatchResponseParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class BatchResponseParser {
public async parseBatchResponse(): Promise<ParsedBatchResponse> {
// 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}'.`
);
Expand All @@ -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.");
}

Expand Down Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/src/BatchUtils.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function getBodyAsText(
batchResponse: ServiceSubmitBatchResponseModel
): Promise<string> {
const blob = (await batchResponse.blobBody) as Blob;
return await blobToString(blob);
return blobToString(blob);
}

export function utf8ByteLength(str: string): number {
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/storage-blob/src/BlobBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`);
}
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
19 changes: 18 additions & 1 deletion sdk/storage/storage-blob/src/BlobBatchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down Expand Up @@ -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<BlobBatchDeleteBlobsResponse>;

Expand All @@ -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<BlobBatchDeleteBlobsResponse>;

Expand All @@ -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<BlobBatchDeleteBlobsResponse> {
const batch = new BlobBatch();
Expand Down Expand Up @@ -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<BlobBatchSetBlobsAccessTierResponse>;

Expand All @@ -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<BlobBatchSetBlobsAccessTierResponse>;

Expand All @@ -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<BlobBatchSetBlobsAccessTierResponse> {
const batch = new BlobBatch();
Expand Down Expand Up @@ -289,7 +306,7 @@ export class BlobBatchClient {
batchRequest: BlobBatch,
options: BlobBatchSubmitBatchOptionalParams = {}
): Promise<BlobBatchSubmitBatchResponse> {
if (!batchRequest || batchRequest.getSubRequests().size == 0) {
if (!batchRequest || batchRequest.getSubRequests().size === 0) {
throw new RangeError("Batch request should contain one or more sub requests.");
}

Expand Down
12 changes: 11 additions & 1 deletion sdk/storage/storage-blob/src/BlobServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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
);
/**
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 27 additions & 3 deletions sdk/storage/storage-blob/src/Clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
/**
Expand All @@ -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
);
/**
Expand Down Expand Up @@ -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 || {};
Expand Down Expand Up @@ -1186,7 +1192,7 @@ export class BlobClient extends StorageClient {
return new BlobDownloadResponse(
wrappedRes,
async (start: number): Promise<NodeJS.ReadableStream> => {
const updatedOptions: BlobDownloadOptionalParams = {
const updatedDownloadOptions: BlobDownloadOptionalParams = {
leaseAccessConditions: options.conditions,
modifiedAccessConditions: {
ifMatch: options.conditions!.ifMatch || res.etag,
Expand Down Expand Up @@ -1215,7 +1221,7 @@ export class BlobClient extends StorageClient {
return (
await this.blobContext.download({
abortSignal: options.abortSignal,
...updatedOptions
...updatedDownloadOptions
})
).readableStreamBody!;
},
Expand Down Expand Up @@ -1890,7 +1896,7 @@ export class BlobClient extends StorageClient {
param2?: number,
param3?: BlobDownloadToBufferOptions | number,
param4: BlobDownloadToBufferOptions = {}
) {
): Promise<Buffer | undefined> {
let buffer: Buffer | undefined;
let offset = 0;
let count = 0;
Expand Down Expand Up @@ -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
);
/**
Expand All @@ -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
);
/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
);
/**
Expand All @@ -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
);
/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
);
/**
Expand All @@ -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
);
/**
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions sdk/storage/storage-blob/src/ContainerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
);
/**
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/src/Pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion sdk/storage/storage-blob/src/Range.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions sdk/storage/storage-blob/src/credentials/Credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down
Loading

0 comments on commit 6147102

Please sign in to comment.