From 247aeb7668c4787596aeaea22f727549bcdf068d Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 26 Mar 2020 13:04:10 -0700 Subject: [PATCH] chore: use gts v2 (#757) * chore: use gts v2 * chore: ahhhhh thaaaats why * chore: do not run on node8 * fix: new gts rules --- .eslintignore | 1 + .eslintrc.json | 3 + .eslintrc.yml | 15 --- .github/workflows/ci.yaml | 2 +- .prettierrc | 8 -- .prettierrc.js | 17 +++ package.json | 3 +- samples/.eslintrc.yml | 3 - src/bundlingCalls/bundleExecutor.ts | 1 + src/bundlingCalls/bundlingUtils.ts | 3 +- src/bundlingCalls/task.ts | 17 ++- src/call.ts | 3 +- src/fallback.ts | 19 ++- src/fallbackError.ts | 1 + src/gax.ts | 9 +- src/grpc.ts | 10 +- src/longRunningCalls/longRunningApiCaller.ts | 2 - src/longRunningCalls/longRunningDescriptor.ts | 4 +- src/longRunningCalls/longrunning.ts | 6 +- src/operationsClient.ts | 10 +- src/paginationCalls/pageDescriptor.ts | 12 +- src/paginationCalls/pagedApiCaller.ts | 1 + src/paginationCalls/resourceCollector.ts | 8 +- src/pathTemplate.ts | 1 + src/pathTemplateParser.js | 113 ++++++++++-------- src/streamingCalls/streaming.ts | 2 + src/warnings.ts | 1 - test/browser-test/test.endtoend.ts | 4 +- test/browser-test/test.grpc-fallback.ts | 26 ++-- test/browser-test/test.unit.ts | 3 +- test/fixtures/echoProtoJson.ts | 3 +- .../.eslintrc.yml | 14 --- .../google-gax-packaging-test-app/.prettierrc | 8 -- .../src/index.js | 21 ---- .../src/v1beta1/echo_client.js | 13 +- .../test/.eslintrc.yml | 3 - .../test/gapic-v1beta1.js | 21 ++-- test/system-test/showcase-server.ts | 1 - test/system-test/test.clientlibs.ts | 2 + test/system-test/test.endtoend.ts | 7 +- test/unit/apiCallable.ts | 28 ++--- test/unit/bundling.ts | 31 ++--- test/unit/compileProtos.ts | 2 +- test/unit/gax.ts | 3 + test/unit/grpc-fallback.ts | 22 ++-- test/unit/grpc.ts | 18 +-- test/unit/longrunning.ts | 20 ++-- test/unit/pagedIteration.ts | 10 +- test/unit/pathTemplate.ts | 1 + test/unit/pathTemplateParser.ts | 3 + test/unit/routingHeader.ts | 1 + test/unit/streaming.ts | 16 +-- test/unit/warning.ts | 1 + tools/compileProtos.ts | 1 + tsconfig.json | 3 +- tslint.json | 7 -- webpack.config.js | 69 ++++++----- 57 files changed, 295 insertions(+), 342 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 .eslintrc.yml delete mode 100644 .prettierrc create mode 100644 .prettierrc.js delete mode 100644 samples/.eslintrc.yml delete mode 100644 test/fixtures/google-gax-packaging-test-app/.eslintrc.yml delete mode 100644 test/fixtures/google-gax-packaging-test-app/.prettierrc delete mode 100644 test/fixtures/google-gax-packaging-test-app/test/.eslintrc.yml delete mode 100644 tslint.json diff --git a/.eslintignore b/.eslintignore index 09b31fe73..ff7c3f406 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ **/node_modules +**/.coverage src/**/doc/* build/ docs/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..782153495 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 73eeec276..000000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 92394b1e4..7138a79a9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [8, 10, 12, 13] + node: [10, 12, 13] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index df6eac074..000000000 --- a/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..08cba3775 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/package.json b/package.json index 9ab73c477..1ed8dcf9b 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "devDependencies": { "@compodoc/compodoc": "^1.1.7", "@types/chai": "^4.1.3", + "@types/download": "^6.2.4", "@types/lodash.at": "^4.6.4", "@types/lodash.has": "^4.5.4", "@types/mocha": "^7.0.0", @@ -57,7 +58,7 @@ "file-loader": "^6.0.0", "fs-extra": "^9.0.0", "google-proto-files": "^1.0.0", - "gts": "^1.0.0", + "gts": "next", "is-docker": "^2.0.0", "json-loader": "^0.5.7", "karma": "^4.1.0", diff --git a/samples/.eslintrc.yml b/samples/.eslintrc.yml deleted file mode 100644 index 282535f55..000000000 --- a/samples/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - no-console: off diff --git a/src/bundlingCalls/bundleExecutor.ts b/src/bundlingCalls/bundleExecutor.ts index 10dbfd3dc..1a66a0ad3 100644 --- a/src/bundlingCalls/bundleExecutor.ts +++ b/src/bundlingCalls/bundleExecutor.ts @@ -147,6 +147,7 @@ export class BundleExecutor { const bundledField = request[this._descriptor.bundledField] as Array<{}>; const elementCount = bundledField.length; let requestBytes = 0; + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; bundledField.forEach(obj => { requestBytes += this._descriptor.byteLengthFunction(obj); diff --git a/src/bundlingCalls/bundlingUtils.ts b/src/bundlingCalls/bundlingUtils.ts index a98a7d3fb..0b6f6dc65 100644 --- a/src/bundlingCalls/bundlingUtils.ts +++ b/src/bundlingCalls/bundlingUtils.ts @@ -20,7 +20,6 @@ import at = require('lodash.at'); import {RequestType} from '../apitypes'; -import {Dictionary} from 'lodash'; /** * Compute the identifier of the `obj`. The objects of the same ID @@ -40,7 +39,7 @@ export function computeBundleId( const ids: unknown[] = []; let hasIds = false; for (let i = 0; i < discriminatorFields.length; ++i) { - const id = at(obj as Dictionary, discriminatorFields[i])[0]; + const id = at(obj, discriminatorFields[i])[0]; if (id === undefined) { ids.push(null); } else { diff --git a/src/bundlingCalls/task.ts b/src/bundlingCalls/task.ts index 4d1dded70..f4a72c583 100644 --- a/src/bundlingCalls/task.ts +++ b/src/bundlingCalls/task.ts @@ -25,10 +25,8 @@ export interface SubResponseInfo { end?: number; } -export interface TaskElement {} - export interface TaskData { - elements: TaskElement[]; + elements: {}[]; bytes: number; callback: TaskCallback; cancelled?: boolean; @@ -54,11 +52,11 @@ export interface TaskCallback extends APICallback { * @private */ export function deepCopyForResponse( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any obj: any, subresponseInfo: SubResponseInfo | null ) { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let result: any; if (obj === null) { return null; @@ -106,7 +104,7 @@ export function deepCopyForResponse( export class Task { _apiCall: SimpleCallbackFunction; - _request: {[index: string]: TaskElement[]}; + _request: {[index: string]: {}[]}; _bundledField: string; _subresponseField?: string | null; _data: TaskData[]; @@ -167,13 +165,14 @@ export class Task { return []; } const request = this._request; - const elements: TaskElement[] = []; + const elements: {}[] = []; const ids: string[] = []; for (let i = 0; i < this._data.length; ++i) { - elements.push.apply(elements, this._data[i].elements); + elements.push(...this._data[i].elements); ids.push(this._data[i].callback.id!); } request[this._bundledField] = elements; + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; this.callCanceller = this._apiCall( request, @@ -221,7 +220,7 @@ export class Task { * @param {number} bytes - the byte size required to encode elements in the API. * @param {APICallback} callback - the callback of the method call. */ - extend(elements: TaskElement[], bytes: number, callback: TaskCallback) { + extend(elements: {}[], bytes: number, callback: TaskCallback) { this._data.push({ elements, bytes, diff --git a/src/call.ts b/src/call.ts index ac541a817..8912a2397 100644 --- a/src/call.ts +++ b/src/call.ts @@ -78,7 +78,7 @@ export class OngoingCall { if (this.completed) { return; } - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const canceller = func(argument, (...args: any[]) => { this.completed = true; setImmediate(this.callback!, ...args); @@ -99,7 +99,6 @@ export class OngoingCallPromise extends OngoingCall { * @constructor * @private */ - // tslint:disable-next-line variable-name constructor() { let resolveCallback: ( result: [ResponseType, NextPageRequestType, RawResponseType] diff --git a/src/fallback.ts b/src/fallback.ts index f75c83dce..8ebe33e0e 100644 --- a/src/fallback.ts +++ b/src/fallback.ts @@ -141,11 +141,9 @@ export class GrpcClient { // Since gRPC expects each header to be an array, // we are doing the same for fallback here. for (const key in headers) { - if (headers.hasOwnProperty(key)) { - metadata[key] = Array.isArray(headers[key]) - ? (headers[key] as string[]) - : ([headers[key]] as string[]); - } + metadata[key] = Array.isArray(headers[key]) + ? (headers[key] as string[]) + : ([headers[key]] as string[]); } // gRPC-fallback request must have 'grpc-web/' in 'x-goog-api-client' @@ -167,10 +165,7 @@ export class GrpcClient { return metadata; } for (const key in moreHeaders) { - if ( - key.toLowerCase() !== CLIENT_VERSION_HEADER && - moreHeaders.hasOwnProperty(key) - ) { + if (key.toLowerCase() !== CLIENT_VERSION_HEADER) { const value = moreHeaders[key]; if (Array.isArray(value)) { if (metadata[key] === undefined) { @@ -264,9 +259,10 @@ export class GrpcClient { const [method, requestData, serviceCallback] = serviceStub[ methodName ].apply(serviceStub, [req, callback]); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let cancelController: AbortController, cancelSignal: any; if (isBrowser && typeof AbortController !== 'undefined') { + // eslint-disable-next-line no-undef cancelController = new AbortController(); } else { cancelController = new NodeAbortController(); @@ -320,7 +316,8 @@ export class GrpcClient { const url = `${grpcFallbackProtocol}://${servicePath}:${servicePort}/$rpc/${protoServiceName}/${rpcName}`; const fetch = isBrowser() - ? window.fetch + ? // eslint-disable-next-line no-undef + window.fetch : ((nodeFetch as unknown) as NodeFetchType); fetch(url, { headers, diff --git a/src/fallbackError.ts b/src/fallbackError.ts index 68a791cc6..346e07136 100644 --- a/src/fallbackError.ts +++ b/src/fallbackError.ts @@ -39,6 +39,7 @@ export class FallbackErrorDecoder { statusType: protobuf.Type; constructor() { + // eslint-disable-next-line @typescript-eslint/no-var-requires const errorProtoJson = require('../../protos/status.json'); this.root = protobuf.Root.fromJSON(errorProtoJson); this.anyType = this.root.lookupType('google.protobuf.Any'); diff --git a/src/gax.ts b/src/gax.ts index f8261a222..2c566bc51 100644 --- a/src/gax.ts +++ b/src/gax.ts @@ -119,7 +119,7 @@ export interface CallOptions { pageSize?: number; maxResults?: number; maxRetries?: number; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any otherArgs?: {[index: string]: any}; bundleOptions?: BundleOptions | null; isBundling?: boolean; @@ -133,7 +133,7 @@ export class CallSettings { pageToken?: string; pageSize?: number; maxResults?: number; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any otherArgs: {[index: string]: any}; bundleOptions?: BundleOptions | null; isBundling: boolean; @@ -219,11 +219,9 @@ export class CallSettings { if ('otherArgs' in options) { otherArgs = {}; - // tslint:disable-next-line forin for (const key in this.otherArgs) { otherArgs[key] = this.otherArgs[key]; } - // tslint:disable-next-line forin for (const optionsKey in options.otherArgs!) { otherArgs[optionsKey] = options.otherArgs![optionsKey]; } @@ -609,7 +607,7 @@ export function constructSettings( otherArgs?: {} ) { otherArgs = otherArgs || {}; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const defaults: any = {}; const serviceConfig = (clientConfig.interfaces || {})[serviceName]; @@ -620,7 +618,6 @@ export function constructSettings( const overrides = (configOverrides.interfaces || {})[serviceName] || {}; const methods = serviceConfig.methods; const overridingMethods = overrides.methods || {}; - // tslint:disable-next-line forin for (const methodName in methods) { const methodConfig = methods[methodName]; const jsName = methodName[0].toLowerCase() + methodName.slice(1); diff --git a/src/grpc.ts b/src/grpc.ts index 3381e1b32..6bd3a7d69 100644 --- a/src/grpc.ts +++ b/src/grpc.ts @@ -50,6 +50,7 @@ export interface MetadataValue { } export interface Metadata { + // eslint-disable-next-line @typescript-eslint/no-misused-new new (): Metadata; set: (key: {}, value?: {} | null) => void; clone: () => Metadata; @@ -64,7 +65,7 @@ export interface ClientStubOptions { servicePath?: string; port?: number; // TODO: use sslCreds?: grpc.ChannelCredentials; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any sslCreds?: any; [index: string]: string | number | undefined | {}; } @@ -192,7 +193,6 @@ export class GrpcClient { metadataBuilder(headers: OutgoingHttpHeaders) { const Metadata = this.grpc.Metadata; const baseMetadata = new Metadata(); - // tslint:disable-next-line forin for (const key in headers) { const value = headers[key]; if (Array.isArray(value)) { @@ -210,10 +210,7 @@ export class GrpcClient { let metadata = baseMetadata; if (moreHeaders) { for (const key in moreHeaders) { - if ( - key.toLowerCase() !== 'x-goog-api-client' && - moreHeaders!.hasOwnProperty(key) - ) { + if (key.toLowerCase() !== 'x-goog-api-client') { if (!copied) { copied = true; metadata = metadata.clone(); @@ -269,7 +266,6 @@ export class GrpcClient { * to set up gRPC connection. * @return {Promise} A promise which resolves to a gRPC stub instance. */ - // tslint:disable-next-line variable-name async createStub(CreateStub: typeof ClientStub, options: ClientStubOptions) { const serviceAddress = options.servicePath + ':' + options.port; const creds = await this._getCredentials(options); diff --git a/src/longRunningCalls/longRunningApiCaller.ts b/src/longRunningCalls/longRunningApiCaller.ts index 931a3a973..7f4501dcc 100644 --- a/src/longRunningCalls/longRunningApiCaller.ts +++ b/src/longRunningCalls/longRunningApiCaller.ts @@ -20,8 +20,6 @@ import {OngoingCall, OngoingCallPromise} from '../call'; import { BackoffSettings, CallOptions, - CallSettings, - createBackoffSettings, createDefaultBackoffSettings, } from '../gax'; import {GoogleError} from '../googleError'; diff --git a/src/longRunningCalls/longRunningDescriptor.ts b/src/longRunningCalls/longRunningDescriptor.ts index da940197c..673e167c5 100644 --- a/src/longRunningCalls/longRunningDescriptor.ts +++ b/src/longRunningCalls/longRunningDescriptor.ts @@ -16,8 +16,6 @@ import * as protobuf from 'protobufjs'; import {Descriptor} from '../descriptor'; -import {CallSettings} from '../gax'; -import {Metadata} from '../grpc'; import {OperationsClient} from '../operationsClient'; import {LongrunningApiCaller} from './longRunningApiCaller'; @@ -46,7 +44,7 @@ export class LongRunningDescriptor implements Descriptor { this.metadataDecoder = metadataDecoder; } - getApiCaller(settings: CallSettings) { + getApiCaller() { return new LongrunningApiCaller(this); } } diff --git a/src/longRunningCalls/longrunning.ts b/src/longRunningCalls/longrunning.ts index 275c2c19e..e634824ab 100644 --- a/src/longRunningCalls/longrunning.ts +++ b/src/longRunningCalls/longrunning.ts @@ -157,12 +157,12 @@ export class Operation extends EventEmitter { getOperation(): Promise<{}>; getOperation(callback: GetOperationCallback): void; getOperation(callback?: GetOperationCallback): Promise<{}> | void { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; const operationsClient = this.longrunningDescriptor.operationsClient; function promisifyResponse() { if (!callback) { - // tslint:disable-next-line variable-name return new Promise((resolve, reject) => { if (self.latestResponse.error) { const error = new GoogleError(self.latestResponse.error.message!); @@ -241,6 +241,7 @@ export class Operation extends EventEmitter { * @private */ startPolling_() { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; let now = new Date(); @@ -256,7 +257,7 @@ export class Operation extends EventEmitter { previousMetadataBytes = this.latestResponse.metadata.value!; } - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function emit(event: string | symbol, ...args: any[]) { self.emit(event, ...args); } @@ -337,7 +338,6 @@ export class Operation extends EventEmitter { * on operation error. */ promise() { - // tslint:disable-next-line variable-name return new Promise((resolve, reject) => { this.on('error', reject).on( 'complete', diff --git a/src/operationsClient.ts b/src/operationsClient.ts index 8f22043a2..98102f0a7 100644 --- a/src/operationsClient.ts +++ b/src/operationsClient.ts @@ -26,7 +26,7 @@ import {ClientStubOptions, GrpcClient} from './grpc'; import {GrpcClient as FallbackGrpcClient} from './fallback'; import {APICallback} from './apitypes'; -const configData = require('./operations_client_config'); +import configData = require('./operations_client_config.json'); export const SERVICE_ADDRESS = 'longrunning.googleapis.com'; const version = require('../../package.json').version; @@ -78,7 +78,7 @@ export class OperationsClient { constructor( gaxGrpc: GrpcClient | FallbackGrpcClient, - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any operationsProtos: any, options: OperationsClientOptions ) { @@ -134,7 +134,8 @@ export class OperationsClient { for (const methodName of operationsStubMethods) { const innerCallPromise = operationsStub.then( stub => (...args: Array<{}>) => { - return stub[methodName].apply(stub, args); + const func = stub[methodName]; + return func.apply(stub, args); }, err => () => { throw err; @@ -439,9 +440,10 @@ export class OperationsClientBuilder { * @param gaxGrpc {GrpcClient} */ constructor(gaxGrpc: GrpcClient | FallbackGrpcClient) { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let operationsProtos: any; // loaded protos have any type if (gaxGrpc.fallback) { + // eslint-disable-next-line @typescript-eslint/no-var-requires const protoJson = require('../../protos/operations.json'); operationsProtos = gaxGrpc.loadProto(protoJson); } else { diff --git a/src/paginationCalls/pageDescriptor.ts b/src/paginationCalls/pageDescriptor.ts index bdff7875b..68c261c74 100644 --- a/src/paginationCalls/pageDescriptor.ts +++ b/src/paginationCalls/pageDescriptor.ts @@ -124,7 +124,7 @@ export class PageDescriptor implements Descriptor { request: RequestType, options: CallSettings ): AsyncIterable<{} | undefined> { - const iterable = this.createIterator(options); + const iterable = this.createIterator(); const funcPromise = typeof apiCall === 'function' ? Promise.resolve(apiCall) : apiCall; funcPromise @@ -137,7 +137,8 @@ export class PageDescriptor implements Descriptor { return iterable; } - createIterator(options: CallSettings): AsyncIterable<{} | undefined> { + createIterator(): AsyncIterable<{} | undefined> { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; const asyncIterable = { [Symbol.asyncIterator]() { @@ -154,7 +155,10 @@ export class PageDescriptor implements Descriptor { const ongoingCall = new call.OngoingCallPromise(); const [request, func] = await paramPromise; if (self.cache.length > 0) { - return Promise.resolve({done: false, value: self.cache.shift()}); + return Promise.resolve({ + done: false, + value: self.cache.shift(), + }); } if (!firstCall && !nextPageRequest) { return Promise.resolve({done: true, value: undefined}); @@ -184,7 +188,7 @@ export class PageDescriptor implements Descriptor { ): Promise { ongoingCall.call(func, request); let nextPageRequest = null; - const [response, nextRequest, rawResponse] = await ongoingCall.promise; + const [response] = await ongoingCall.promise; const pageToken = (response as ResponseType)[this.responsePageTokenField]; if (pageToken) { nextPageRequest = Object.assign({}, request); diff --git a/src/paginationCalls/pagedApiCaller.ts b/src/paginationCalls/pagedApiCaller.ts index 30d765353..0fe1d0143 100644 --- a/src/paginationCalls/pagedApiCaller.ts +++ b/src/paginationCalls/pagedApiCaller.ts @@ -101,6 +101,7 @@ export class PagedApiCaller implements APICaller { * request, metadata, call options, and callback. */ wrap(func: GRPCCall): GRPCCall { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; return function wrappedCall(argument, metadata, options, callback) { return (func as UnaryCall)( diff --git a/src/paginationCalls/resourceCollector.ts b/src/paginationCalls/resourceCollector.ts index 86c0dd0e5..6afb47646 100644 --- a/src/paginationCalls/resourceCollector.ts +++ b/src/paginationCalls/resourceCollector.ts @@ -17,7 +17,6 @@ import { SimpleCallbackFunction, NextPageRequestType, - RawResponseType, RequestType, } from '../apitypes'; @@ -45,8 +44,7 @@ export class ResourceCollector { private callback( err: Error | null, resources: Array<{}>, - nextPageRequest: NextPageRequestType, - rawResponse: RawResponseType + nextPageRequest: NextPageRequestType ) { if (err) { // Something went wrong with this request - failing everything @@ -71,7 +69,7 @@ export class ResourceCollector { // Schedule the next call const callback = ( - ...args: [Error | null, Array<{}>, NextPageRequestType, RawResponseType] + ...args: [Error | null, Array<{}>, NextPageRequestType] ) => this.callback(...args); setImmediate(this.apiCall, nextPageRequest, callback); } @@ -83,7 +81,7 @@ export class ResourceCollector { // Schedule the first call const callback = ( - ...args: [Error | null, Array<{}>, NextPageRequestType, RawResponseType] + ...args: [Error | null, Array<{}>, NextPageRequestType] ) => this.callback(...args); setImmediate(this.apiCall, firstRequest, callback); }); diff --git a/src/pathTemplate.ts b/src/pathTemplate.ts index 1d16e289e..a08d635eb 100644 --- a/src/pathTemplate.ts +++ b/src/pathTemplate.ts @@ -21,6 +21,7 @@ import has = require('lodash.has'); import * as util from 'util'; import * as extras from './parserExtras'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const parser = require('./pathTemplateParser'); export interface ParseResult { diff --git a/src/pathTemplateParser.js b/src/pathTemplateParser.js index c83a703fe..434a5f0a1 100644 --- a/src/pathTemplateParser.js +++ b/src/pathTemplateParser.js @@ -14,6 +14,9 @@ * limitations under the License. */ +// This was an auto-generated file, we disable all linter checks for this file. +/* eslint-disable */ + module.exports = (() => { /* * Generated by PEG.js 0.9.0. @@ -34,9 +37,9 @@ module.exports = (() => { this.expected = expected; this.found = found; this.location = location; - this.name = 'SyntaxError'; + this.name = "SyntaxError"; - if (typeof Error.captureStackTrace === 'function') { + if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } @@ -47,10 +50,10 @@ module.exports = (() => { const options = arguments.length > 1 ? arguments[1] : {}; const parser = this; const peg$FAILED = {}; - const peg$startRuleFunctions = {template: peg$parsetemplate}; + const peg$startRuleFunctions = { template: peg$parsetemplate }; let peg$startRuleFunction = peg$parsetemplate; - const peg$c0 = '/'; - const peg$c1 = {type: 'literal', value: '/', description: '"/"'}; + const peg$c0 = "/"; + const peg$c1 = { type: "literal", value: "/", description: '"/"' }; const peg$c2 = segments => { return segments; }; @@ -60,66 +63,70 @@ module.exports = (() => { const peg$c4 = s => { return s; }; - const peg$c5 = '{'; - const peg$c6 = {type: 'literal', value: '{', description: '"{"'}; - const peg$c7 = '='; - const peg$c8 = {type: 'literal', value: '=', description: '"="'}; - const peg$c9 = '}'; - const peg$c10 = {type: 'literal', value: '}', description: '"}"'}; + const peg$c5 = "{"; + const peg$c6 = { type: "literal", value: "{", description: '"{"' }; + const peg$c7 = "="; + const peg$c8 = { type: "literal", value: "=", description: '"="' }; + const peg$c9 = "}"; + const peg$c10 = { type: "literal", value: "}", description: '"}"' }; const peg$c11 = (l, segments) => { return [ - {kind: extras.BINDING, literal: l}, + { kind: extras.BINDING, literal: l }, segments, - {kind: extras.END_BINDING, literal: ''}, + { kind: extras.END_BINDING, literal: "" } ].reduce((a, b) => a.concat(b), []); }; const peg$c12 = l => { return [ - {kind: extras.BINDING, literal: l}, - {kind: extras.TERMINAL, literal: '*'}, - {kind: extras.END_BINDING, literal: ''}, + { kind: extras.BINDING, literal: l }, + { kind: extras.TERMINAL, literal: "*" }, + { kind: extras.END_BINDING, literal: "" } ]; }; const peg$c13 = (t, segments) => { return t.concat(segments); }; const peg$c14 = t => { - if (t[0].literal === '*' || t[0].literal === '**') { + if (t[0].literal === "*" || t[0].literal === "**") { return [ { - kind: extras.BINDING, + kind: extras.BINDING }, t[0], - {kind: extras.END_BINDING, literal: ''}, + { kind: extras.END_BINDING, literal: "" } ]; } else { return t; } }; - const peg$c15 = '**'; - const peg$c16 = {type: 'literal', value: '**', description: '"**"'}; - const peg$c17 = '*'; - const peg$c18 = {type: 'literal', value: '*', description: '"*"'}; + const peg$c15 = "**"; + const peg$c16 = { type: "literal", value: "**", description: '"**"' }; + const peg$c17 = "*"; + const peg$c18 = { type: "literal", value: "*", description: '"*"' }; const peg$c19 = l => { - return [{kind: extras.TERMINAL, literal: l}]; + return [{ kind: extras.TERMINAL, literal: l }]; }; const peg$c20 = /^[^*=}{\/]/; - const peg$c21 = {type: 'class', value: '[^*=}{/]', description: '[^*=}{/]'}; + const peg$c21 = { + type: "class", + value: "[^*=}{/]", + description: "[^*=}{/]" + }; const peg$c22 = cs => { - return cs.join(''); + return cs.join(""); }; let peg$currPos = 0; let peg$savedPos = 0; - const peg$posDetailsCache = [{line: 1, column: 1, seenCR: false}]; + const peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }]; let peg$maxFailPos = 0; let peg$maxFailExpected = []; const peg$silentFails = 0; let peg$result; - if ('startRule' in options) { + if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error( - 'Can\'t start parsing from rule "' + options.startRule + '".' + "Can't start parsing from rule \"" + options.startRule + '".' ); } @@ -137,7 +144,7 @@ module.exports = (() => { function expected(description) { throw peg$buildException( null, - [{type: 'other', description}], + [{ type: "other", description }], input.substring(peg$savedPos, peg$currPos), peg$computeLocation(peg$savedPos, peg$currPos) ); @@ -169,18 +176,18 @@ module.exports = (() => { details = { line: details.line, column: details.column, - seenCR: details.seenCR, + seenCR: details.seenCR }; while (p < pos) { ch = input.charAt(p); - if (ch === '\n') { + if (ch === "\n") { if (!details.seenCR) { details.line++; } details.column = 1; details.seenCR = false; - } else if (ch === '\r' || ch === '\u2028' || ch === '\u2029') { + } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { details.line++; details.column = 1; details.seenCR = true; @@ -205,13 +212,13 @@ module.exports = (() => { start: { offset: startPos, line: startPosDetails.line, - column: startPosDetails.column, + column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, - column: endPosDetails.column, - }, + column: endPosDetails.column + } }; } @@ -261,24 +268,24 @@ module.exports = (() => { } return s - .replace(/\\/g, '\\\\') + .replace(/\\/g, "\\\\") .replace(/"/g, '\\"') - .replace(/\x08/g, '\\b') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\f/g, '\\f') - .replace(/\r/g, '\\r') + .replace(/\x08/g, "\\b") + .replace(/\t/g, "\\t") + .replace(/\n/g, "\\n") + .replace(/\f/g, "\\f") + .replace(/\r/g, "\\r") .replace(/[\x00-\x07\x0B\x0E\x0F]/g, ch => { - return '\\x0' + hex(ch); + return "\\x0" + hex(ch); }) .replace(/[\x10-\x1F\x80-\xFF]/g, ch => { - return '\\x' + hex(ch); + return "\\x" + hex(ch); }) .replace(/[\u0100-\u0FFF]/g, ch => { - return '\\u0' + hex(ch); + return "\\u0" + hex(ch); }) .replace(/[\u1000-\uFFFF]/g, ch => { - return '\\u' + hex(ch); + return "\\u" + hex(ch); }); } @@ -291,14 +298,14 @@ module.exports = (() => { expectedDesc = expected.length > 1 - ? expectedDescs.slice(0, -1).join(', ') + - ' or ' + + ? expectedDescs.slice(0, -1).join(", ") + + " or " + expectedDescs[expected.length - 1] : expectedDescs[0]; - foundDesc = found ? '"' + stringEscape(found) + '"' : 'end of input'; + foundDesc = found ? '"' + stringEscape(found) + '"' : "end of input"; - return 'Expected ' + expectedDesc + ' but ' + foundDesc + ' found.'; + return "Expected " + expectedDesc + " but " + foundDesc + " found."; } if (expected !== null) { @@ -644,7 +651,7 @@ module.exports = (() => { return s0; } - const extras = require('./parserExtras'); + const extras = require("./parserExtras"); peg$result = peg$startRuleFunction(); @@ -652,7 +659,7 @@ module.exports = (() => { return peg$result; } else { if (peg$result !== peg$FAILED && peg$currPos < input.length) { - peg$fail({type: 'end', description: 'end of input'}); + peg$fail({ type: "end", description: "end of input" }); } throw peg$buildException( @@ -668,6 +675,6 @@ module.exports = (() => { return { SyntaxError: peg$SyntaxError, - parse: peg$parse, + parse: peg$parse }; })(); diff --git a/src/streamingCalls/streaming.ts b/src/streamingCalls/streaming.ts index 0b0e85c81..8cde38f23 100644 --- a/src/streamingCalls/streaming.ts +++ b/src/streamingCalls/streaming.ts @@ -25,7 +25,9 @@ import { SimpleCallbackFunction, } from '../apitypes'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const duplexify: DuplexifyConstructor = require('duplexify'); +// eslint-disable-next-line @typescript-eslint/no-var-requires const retryRequest = require('retry-request'); // Directly copy over Duplexify interfaces diff --git a/src/warnings.ts b/src/warnings.ts index b5ce60cf3..8f96733a2 100644 --- a/src/warnings.ts +++ b/src/warnings.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import * as semver from 'semver'; import {isBrowser} from './isbrowser'; const emittedWarnings = new Set(); diff --git a/test/browser-test/test.endtoend.ts b/test/browser-test/test.endtoend.ts index 9775d5cf4..8c33980ec 100644 --- a/test/browser-test/test.endtoend.ts +++ b/test/browser-test/test.endtoend.ts @@ -15,8 +15,9 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before} from 'mocha'; import {expect} from 'chai'; +// eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore import * as EchoClient from '../fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client'; @@ -39,6 +40,7 @@ describe('Run tests against gRPC server', () => { port: 1337, }; + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore global.isBrowser = true; const client = new EchoClient(opts); diff --git a/test/browser-test/test.grpc-fallback.ts b/test/browser-test/test.grpc-fallback.ts index cd83fd54f..5143da664 100644 --- a/test/browser-test/test.grpc-fallback.ts +++ b/test/browser-test/test.grpc-fallback.ts @@ -14,8 +14,10 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, before, afterEach, after} from 'mocha'; import * as protobuf from 'protobufjs'; import * as fallback from '../../src/fallback'; import * as sinon from 'sinon'; @@ -24,6 +26,7 @@ import {expect} from 'chai'; //@ts-ignore import * as EchoClient from '../fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const statusJsonProto = require('../../protos/status.json'); const authStub = { @@ -82,7 +85,7 @@ describe('createStub', () => { }); it('should create a stub', async () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const echoStub: any = await gaxGrpc.createStub(echoService, stubOptions); assert(echoStub instanceof protobuf.rpc.Service); @@ -100,7 +103,7 @@ describe('createStub', () => { }); it('should support optional parameters', async () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const echoStub: any = await gaxGrpc.createStub( echoService, stubExtraOptions @@ -127,7 +130,7 @@ describe('grpc-fallback', () => { echoService: protobuf.Service, stubOptions: {}; const createdAbortControllers: string[] = []; - // @ts-ignore + // eslint-disable-next-line no-undef const savedAbortController = window.AbortController; const authStub = { @@ -157,7 +160,6 @@ describe('grpc-fallback', () => { port: 443, }; - //tslint:disable-next-line variable-name const AbortController = function() { // @ts-ignore this.abort = function() { @@ -169,6 +171,7 @@ describe('grpc-fallback', () => { }; // @ts-ignore + // eslint-disable-next-line no-undef window.AbortController = AbortController; }); @@ -182,6 +185,7 @@ describe('grpc-fallback', () => { after(() => { // @ts-ignore + // eslint-disable-next-line no-undef window.AbortController = savedAbortController; }); @@ -196,6 +200,7 @@ describe('grpc-fallback', () => { return Promise.resolve(responseType.encode(response).finish()); }, }); + // eslint-disable-next-line no-undef sinon.replace(window, 'fetch', fakeFetch); const [result] = await client.echo(requestObject); assert.strictEqual(requestObject.content, result.content); @@ -203,11 +208,12 @@ describe('grpc-fallback', () => { it('should be able to cancel an API call using AbortController', async () => { const fakeFetch = sinon.fake.resolves({}); + // eslint-disable-next-line no-undef sinon.replace(window, 'fetch', fakeFetch); const echoStub = await gaxGrpc.createStub(echoService, stubOptions); const request = {content: 'content' + new Date().toString()}; - const call = echoStub.echo(request, {}, {}, (err: {}, result: {}) => {}); + const call = echoStub.echo(request, {}, {}, () => {}); call.cancel(); @@ -218,7 +224,7 @@ describe('grpc-fallback', () => { it('should be able to add extra headers to the request', async () => { const client = new EchoClient(opts); const requestObject = {content: 'test-content'}; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const options: any = {}; options.otherArgs = {}; options.otherArgs.headers = {}; @@ -229,8 +235,10 @@ describe('grpc-fallback', () => { }); const responseType = protos.lookupType('EchoResponse'); const response = responseType.create(requestObject); + // eslint-disable-next-line no-undef const savedFetch = window.fetch; // @ts-ignore + // eslint-disable-next-line no-undef window.fetch = (url, options) => { // @ts-ignore assert.strictEqual(options.headers['x-goog-request-params'], 'abc=def'); @@ -243,6 +251,7 @@ describe('grpc-fallback', () => { }; const [result] = await client.echo(requestObject, options); assert.strictEqual(requestObject.content, result.content); + // eslint-disable-next-line no-undef window.fetch = savedFetch; }); @@ -264,10 +273,11 @@ describe('grpc-fallback', () => { return Promise.resolve(statusType.encode(statusMessage).finish()); }, }); + // eslint-disable-next-line no-undef sinon.replace(window, 'fetch', fakeFetch); gaxGrpc.createStub(echoService, stubOptions).then(echoStub => { - echoStub.echo(requestObject, {}, {}, (err: Error, result: {}) => { + echoStub.echo(requestObject, {}, {}, (err: Error) => { assert.strictEqual(err.message, JSON.stringify(expectedError)); done(); }); diff --git a/test/browser-test/test.unit.ts b/test/browser-test/test.unit.ts index 841c3e275..9d8ec35b8 100644 --- a/test/browser-test/test.unit.ts +++ b/test/browser-test/test.unit.ts @@ -20,7 +20,8 @@ import * as assert from 'assert'; import {describe, it} from 'mocha'; import * as through2 from 'through2'; -//@ts-ignore +// eslint-disable-next-line @typescript-eslint/ban-ts-ignore +// @ts-ignore import * as EchoClient from '../fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client'; interface Operation { promise(): Function; diff --git a/test/fixtures/echoProtoJson.ts b/test/fixtures/echoProtoJson.ts index f4c0ff5b8..1e46a51ea 100644 --- a/test/fixtures/echoProtoJson.ts +++ b/test/fixtures/echoProtoJson.ts @@ -18,4 +18,5 @@ // npx pbjs -p protos -t json -o protos.json ../echo.proto // (NOTE: echo.proto was taken from gapic-showcase/schema/v1beta1 // commit hash: 74e71466e0d5badb3167900a553a6afea62b6e3d) -export const echoProtoJson = require('./google-gax-packaging-test-app/protos/protos.json'); +import echoProtoJson = require('./google-gax-packaging-test-app/protos/protos.json'); +export {echoProtoJson}; diff --git a/test/fixtures/google-gax-packaging-test-app/.eslintrc.yml b/test/fixtures/google-gax-packaging-test-app/.eslintrc.yml deleted file mode 100644 index 53f3165e1..000000000 --- a/test/fixtures/google-gax-packaging-test-app/.eslintrc.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-console: off diff --git a/test/fixtures/google-gax-packaging-test-app/.prettierrc b/test/fixtures/google-gax-packaging-test-app/.prettierrc deleted file mode 100644 index df6eac074..000000000 --- a/test/fixtures/google-gax-packaging-test-app/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/test/fixtures/google-gax-packaging-test-app/src/index.js b/test/fixtures/google-gax-packaging-test-app/src/index.js index f43c87b47..3a38c2847 100644 --- a/test/fixtures/google-gax-packaging-test-app/src/index.js +++ b/test/fixtures/google-gax-packaging-test-app/src/index.js @@ -17,7 +17,6 @@ 'use strict'; const assert = require('assert'); -const {describe, it} = require('mocha'); const grpc = require('@grpc/grpc-js'); // Import the clients for each version supported by this package. @@ -83,26 +82,6 @@ async function testShowcase() { await testEcho(fallbackClient); await testPagedExpand(fallbackClient); await testWait(fallbackClient); - - // Fallback clients do not currently support streaming - try { - await testExpand(fallbackClient); - throw new Error( - 'Expand did not throw an error: Streaming calls should fail with fallback clients' - ); - } catch (err) {} - try { - await testCollect(fallbackClient); - throw new Error( - 'Collect did not throw an error: Streaming calls should fail with fallback clients' - ); - } catch (err) {} - try { - await testChat(fallbackClient); - throw new Error( - 'Chat did not throw an error: Streaming calls should fail with fallback clients' - ); - } catch (err) {} } async function testEcho(client) { diff --git a/test/fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client.js b/test/fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client.js index d0734050a..220681b82 100644 --- a/test/fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client.js +++ b/test/fixtures/google-gax-packaging-test-app/src/v1beta1/echo_client.js @@ -17,6 +17,7 @@ 'use strict'; const gapicConfig = require('./echo_client_config.json'); +// eslint-disable-next-line node/no-missing-require const gax = require('google-gax'); const path = require('path'); @@ -585,10 +586,14 @@ class EchoClient { } pagedExpandAsync(request, options) { - options = options || {}; - request = request || {}; - const callSettings = new gax.CallSettings(options); - return this._descriptors.page.pagedExpand.asyncIterate(this._innerCallPromises['pagedExpand'], request, callSettings); + options = options || {}; + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.pagedExpand.asyncIterate( + this._innerCallPromises['pagedExpand'], + request, + callSettings + ); } } diff --git a/test/fixtures/google-gax-packaging-test-app/test/.eslintrc.yml b/test/fixtures/google-gax-packaging-test-app/test/.eslintrc.yml deleted file mode 100644 index cd088a978..000000000 --- a/test/fixtures/google-gax-packaging-test-app/test/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - node/no-unpublished-require: off diff --git a/test/fixtures/google-gax-packaging-test-app/test/gapic-v1beta1.js b/test/fixtures/google-gax-packaging-test-app/test/gapic-v1beta1.js index 8419f6e0c..f2d4b47d8 100644 --- a/test/fixtures/google-gax-packaging-test-app/test/gapic-v1beta1.js +++ b/test/fixtures/google-gax-packaging-test-app/test/gapic-v1beta1.js @@ -187,26 +187,27 @@ describe('EchoClient', () => { const request = {}; const expectedResponse = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - client._descriptors.page.pagedExpand.asyncIterate = (apiCall, request, options) => { + client._descriptors.page.pagedExpand.asyncIterate = () => { let count = 0; const asyncIterable = { [Symbol.asyncIterator]() { return { - async next(){ + async next() { count = count + 1; - if(count === 10) return Promise.resolve({done: true, value: undefined}); + if (count === 10) + return Promise.resolve({done: true, value: undefined}); return Promise.resolve({done: false, value: count}); - } - } - } - } + }, + }; + }, + }; return asyncIterable; - } + }; // test paging method by async iterator const response = []; const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable){ + for await (const resource of iterable) { response.push(resource); } assert.deepStrictEqual(response, expectedResponse); @@ -303,7 +304,7 @@ describe('EchoClient', () => { }); }); - describe('wait', function() { + describe('wait', () => { it('invokes wait without error', done => { const client = new showcaseModule.v1beta1.EchoClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, diff --git a/test/system-test/showcase-server.ts b/test/system-test/showcase-server.ts index 86aa1a533..1c998a317 100644 --- a/test/system-test/showcase-server.ts +++ b/test/system-test/showcase-server.ts @@ -15,7 +15,6 @@ */ import * as execa from 'execa'; -//@ts-ignore import * as download from 'download'; import * as fs from 'fs'; import * as path from 'path'; diff --git a/test/system-test/test.clientlibs.ts b/test/system-test/test.clientlibs.ts index ae3043feb..dab2198a9 100644 --- a/test/system-test/test.clientlibs.ts +++ b/test/system-test/test.clientlibs.ts @@ -19,6 +19,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as rimraf from 'rimraf'; import * as util from 'util'; +import {describe, it, before} from 'mocha'; const mkdir = util.promisify(fs.mkdir); const rmrf = util.promisify(rimraf); @@ -31,6 +32,7 @@ const gaxDir = path.resolve(__dirname, '..', '..', '..'); // We will pack google-gax using `npm pack`, defining some constants to make it // easier to consume that tarball +// eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../../package.json'); const gaxTarball = path.join(gaxDir, `${pkg.name}-${pkg.version}.tgz`); diff --git a/test/system-test/test.endtoend.ts b/test/system-test/test.endtoend.ts index bf91a2462..93807beb0 100644 --- a/test/system-test/test.endtoend.ts +++ b/test/system-test/test.endtoend.ts @@ -20,6 +20,7 @@ import {ncp} from 'ncp'; import * as path from 'path'; import * as rimraf from 'rimraf'; import * as util from 'util'; +import {describe, it, before, after} from 'mocha'; import {ShowcaseServer} from './showcase-server'; @@ -33,6 +34,7 @@ const fixturesDir = path.join(gaxDir, 'test', 'fixtures'); // We will pack google-gax using `npm pack`, defining some constants to make it // easier to consume that tarball +// eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../../package.json'); const gaxTarball = path.join(gaxDir, `${pkg.name}-${pkg.version}.tgz`); @@ -69,7 +71,10 @@ describe('Run end-to-end test', () => { }); it('should be able to run tests against gRPC server', async () => { - await execa('npm', ['start'], {cwd: testAppDestination, stdio: 'inherit'}); + await execa('npm', ['start'], { + cwd: testAppDestination, + stdio: 'inherit', + }); }); after(async () => { diff --git a/test/unit/apiCallable.ts b/test/unit/apiCallable.ts index 867b0f220..93fde177e 100644 --- a/test/unit/apiCallable.ts +++ b/test/unit/apiCallable.ts @@ -16,19 +16,19 @@ import {expect} from 'chai'; import {status} from '@grpc/grpc-js'; +import {describe, it} from 'mocha'; import * as sinon from 'sinon'; import * as gax from '../../src/gax'; -import {Task} from '../../src/bundlingCalls/task'; import {GoogleError} from '../../src/googleError'; import * as utils from './utils'; const fail = utils.fail; const createApiCall = utils.createApiCall; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any const FAKE_STATUS_CODE_1 = (utils as any).FAKE_STATUS_CODE_1; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any const FAKE_STATUS_CODE_2 = (utils as any).FAKE_STATUS_CODE_1 + 1; describe('createApiCall', () => { @@ -46,7 +46,6 @@ describe('createApiCall', () => { const apiCall = createApiCall(func); apiCall(42, undefined, (err, resp) => { expect(resp).to.eq(42); - // tslint:disable-next-line no-unused-expression expect(deadlineArg).to.be.ok; done(); }); @@ -120,12 +119,11 @@ describe('Promise', () => { callback(null, 42); } const apiCall = createApiCall(func); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (apiCall as any)(null) .then((response: number[]) => { expect(response).to.be.an('array'); expect(response[0]).to.eq(42); - // tslint:disable-next-line no-unused-expression expect(deadlineArg).to.be.ok; done(); }) @@ -151,7 +149,7 @@ describe('Promise', () => { }, 0); } const apiCall = createApiCall(func, {cancel: done}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const promise = (apiCall as any)(null); promise .then(() => { @@ -191,7 +189,7 @@ describe('Promise', () => { settings: {retry: retryOptions}, returnCancelFunc: true, }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const promise = (apiCall as any)(null); promise .then(() => { @@ -214,7 +212,6 @@ describe('Promise', () => { const apiCall = createApiCall(func); expect( apiCall({}, undefined, (err, response) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; expect(response).to.eq(42); done(); @@ -248,7 +245,6 @@ describe('retryable', () => { apiCall({}, undefined, (err, resp) => { expect(resp).to.eq(1729); expect(toAttempt).to.eq(0); - // tslint:disable-next-line no-unused-expression expect(deadlineArg).to.be.ok; done(); }); @@ -277,7 +273,6 @@ describe('retryable', () => { expect(resp).to.be.an('array'); expect(resp[0]).to.eq(1729); expect(toAttempt).to.eq(0); - // tslint:disable-next-line no-unused-expression expect(deadlineArg).to.be.ok; done(); }) @@ -286,8 +281,7 @@ describe('retryable', () => { it('cancels in the middle of retries', done => { let callCount = 0; - // tslint:disable-next-line no-any - let promise: any; + // eslint-disable-next-line @typescript-eslint/no-explicit-any function func(argument: {}, metadata: {}, options: {}, callback: Function) { callCount++; if (callCount <= 2) { @@ -302,7 +296,7 @@ describe('retryable', () => { }, 10); } const apiCall = createApiCall(func, settings); - promise = apiCall({}, undefined); + const promise = apiCall({}, undefined); promise .then(() => { done(new Error('should not reach')); @@ -324,7 +318,6 @@ describe('retryable', () => { apiCall({}, undefined, err => { expect(err).to.be.an('error'); expect(err!.code).to.eq(FAKE_STATUS_CODE_1); - // tslint:disable-next-line no-unused-expression expect(err!.note).to.be.undefined; expect(spy.callCount).to.eq(1); done(); @@ -347,7 +340,6 @@ describe('retryable', () => { apiCall({}, undefined, err => { expect(err).to.be.an('error'); expect(err!.code).to.eq(FAKE_STATUS_CODE_1); - // tslint:disable-next-line no-unused-expression expect(err!.note).to.be.ok; expect(spy.callCount).to.eq(toAttempt); done(); @@ -419,7 +411,6 @@ describe('retryable', () => { apiCall({}, undefined, err => { expect(err).to.be.an('error'); expect(err!.code).to.eq(FAKE_STATUS_CODE_2); - // tslint:disable-next-line no-unused-expression expect(err!.note).to.be.ok; expect(spy.callCount).to.eq(1); done(); @@ -432,9 +423,7 @@ describe('retryable', () => { } const apiCall = createApiCall(func, settings); apiCall({}, undefined, (err, resp) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; - // tslint:disable-next-line no-unused-expression expect(resp).to.be.null; done(); }); @@ -453,7 +442,6 @@ describe('retryable', () => { apiCall({}, undefined, err => { expect(err).to.be.an('error'); expect(err!.code).to.eq(FAKE_STATUS_CODE_1); - // tslint:disable-next-line no-unused-expression expect(err!.note).to.be.ok; const now = new Date(); expect(now.getTime() - startTime.getTime()).to.be.at.least( diff --git a/test/unit/bundling.ts b/test/unit/bundling.ts index 150584d90..a587d227e 100644 --- a/test/unit/bundling.ts +++ b/test/unit/bundling.ts @@ -14,9 +14,12 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import {expect} from 'chai'; import {status} from '@grpc/grpc-js'; import * as sinon from 'sinon'; +import {describe, it, beforeEach} from 'mocha'; import {BundleDescriptor} from '../../src/bundlingCalls/bundleDescriptor'; import { @@ -24,11 +27,7 @@ import { BundleOptions, } from '../../src/bundlingCalls/bundleExecutor'; import {computeBundleId} from '../../src/bundlingCalls/bundlingUtils'; -import { - deepCopyForResponse, - Task, - TaskCallback, -} from '../../src/bundlingCalls/task'; +import {deepCopyForResponse, Task} from '../../src/bundlingCalls/task'; import {GoogleError} from '../../src/googleError'; import {createApiCall} from './utils'; @@ -132,7 +131,6 @@ describe('computeBundleId', () => { ]; testCases.forEach(t => { it(t.message, () => { - // tslint:disable-next-line no-unused-expression expect(computeBundleId(t.object, t.fields)).to.be.undefined; }); }); @@ -204,17 +202,17 @@ describe('deepCopyForResponse', () => { }); describe('Task', () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function testTask(apiCall?: any) { return new Task(apiCall, {}, 'field1', null); } let id = 0; function extendElements( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any task: any, elements: string[] | number[], - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback?: any ) { if (!callback) { @@ -313,7 +311,6 @@ describe('Task', () => { const apiCall = sinon.spy(createApiCall(t.expected!)); const task = testTask((apiCall as unknown) as SimpleCallbackFunction); const callback = sinon.spy((err, data) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; expect(data).to.be.an.instanceOf(Object); if (callback.callCount === t.data.length) { @@ -321,7 +318,7 @@ describe('Task', () => { done(); } }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (t as any).data.forEach((d: string[]) => { extendElements(task!, d, callback); }); @@ -342,11 +339,10 @@ describe('Task', () => { const task = testTask((apiCall as unknown) as SimpleCallbackFunction); task!._subresponseField = 'field1'; let callbackCount = 0; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (t as any).data.forEach((d: string[]) => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any extendElements(task!, d, (err: any, data: {field1: []}) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; expect(data.field1.length).to.be.eq(d.length); callbackCount++; @@ -377,14 +373,13 @@ describe('Task', () => { task!._subresponseField = 'field1'; const callback = sinon.spy((e, data) => { expect(e).to.equal(err); - // tslint:disable-next-line no-unused-expression expect(data).to.be.undefined; if (callback.callCount === t.data.length) { expect(apiCall.callCount).to.eq(1); done(); } }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (t as any).data.forEach((d: string[]) => { extendElements(task!, d, callback); }); @@ -538,7 +533,6 @@ describe('Executor', () => { expect(task._data[0].elements).to.eql([3]); expect(task._data[1].elements).to.eql([6]); - // tslint:disable-next-line forin for (const bundleId in executor._timers) { clearTimeout(executor._timers[bundleId]); } @@ -650,7 +644,6 @@ describe('Executor', () => { let counter = 0; // @ts-ignore cancellation logic is broken here executor.schedule(timedAPI, {field1: [1, 2], field2: 'id'}, err => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; counter++; // counter should be 2 because event2 callback should be called @@ -809,7 +802,7 @@ describe('Executor', () => { executor.schedule(spy, {field1: [1, 2], field2: 'id1'}); setTimeout(() => { expect(spy.callCount).to.eq(1); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any expect((executor._runNow as any).callCount).to.eq(1); done(); }, 20); diff --git a/test/unit/compileProtos.ts b/test/unit/compileProtos.ts index 94e66b78b..d5d3cacbb 100644 --- a/test/unit/compileProtos.ts +++ b/test/unit/compileProtos.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import * as fs from 'fs'; import * as rimraf from 'rimraf'; import * as util from 'util'; diff --git a/test/unit/gax.ts b/test/unit/gax.ts index cb8e60a5f..ccd2b555b 100644 --- a/test/unit/gax.ts +++ b/test/unit/gax.ts @@ -20,7 +20,10 @@ * allowing that causes another errors of non-camelcase symbols anyways. * Therefore quote-props is disabled explicitly only in this file. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import {expect} from 'chai'; +import {describe, it} from 'mocha'; import * as gax from '../../src/gax'; const SERVICE_NAME = 'test.interface.v1.api'; diff --git a/test/unit/grpc-fallback.ts b/test/unit/grpc-fallback.ts index 8e0519219..ad89f0f86 100644 --- a/test/unit/grpc-fallback.ts +++ b/test/unit/grpc-fallback.ts @@ -14,8 +14,10 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach, before, after} from 'mocha'; import * as path from 'path'; import * as fs from 'fs'; import * as nodeFetch from 'node-fetch'; @@ -88,7 +90,7 @@ describe('createStub', () => { }); it('should create a stub', async () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const echoStub: any = await gaxGrpc.createStub(echoService, stubOptions); assert(echoStub instanceof protobuf.rpc.Service); @@ -106,7 +108,7 @@ describe('createStub', () => { }); it('should support optional parameters', async () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const echoStub: any = await gaxGrpc.createStub( echoService, stubExtraOptions @@ -150,7 +152,6 @@ describe('grpc-fallback', () => { port: 443, }; - //tslint:disable-next-line variable-name const AbortController = function() { // @ts-ignore this.abort = function() { @@ -272,15 +273,10 @@ describe('grpc-fallback', () => { ); gaxGrpc.createStub(echoService, stubOptions).then(echoStub => { - echoStub.echo( - requestObject, - {}, - {}, - (err: {message: string}, result: {}) => { - assert.strictEqual(err.message, JSON.stringify(expectedError)); - done(); - } - ); + echoStub.echo(requestObject, {}, {}, (err: {message: string}) => { + assert.strictEqual(err.message, JSON.stringify(expectedError)); + done(); + }); }); }); diff --git a/test/unit/grpc.ts b/test/unit/grpc.ts index 7e1086042..8356c6573 100644 --- a/test/unit/grpc.ts +++ b/test/unit/grpc.ts @@ -14,10 +14,13 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import {expect} from 'chai'; import * as path from 'path'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; +import {describe, it, beforeEach} from 'mocha'; import {protobuf} from '../../src/index'; import { @@ -25,7 +28,6 @@ import { GrpcClient, GrpcClientOptions, GrpcModule, - ClientStub, } from '../../src/grpc'; function gaxGrpc(options?: GrpcClientOptions) { @@ -57,7 +59,6 @@ describe('grpc', () => { }; const builder = grpcClient.metadataBuilder(headers); const metadata = builder(); - // tslint:disable-next-line forin for (const key in headers) { expect(metadata.get(key)).to.deep.eq([headers[key]]); } @@ -114,7 +115,6 @@ describe('grpc', () => { }); describe('createStub', () => { - const TEST_PATH = path.resolve(__dirname, '../../test'); class DummyStub { constructor(public address: {}, public creds: {}, public options: {}) {} } @@ -176,12 +176,12 @@ describe('grpc', () => { expect(stub).to.be.an.instanceOf(DummyStub); expect(stub.address).to.eq('foo.example.com:443'); expect(stub.creds).to.deep.eq(dummyChannelCreds); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (expect(stub.options).has as any).key([ 'max_send_message_length', 'initial_reconnect_backoff_ms', ]); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (expect(stub.options).to.not.have as any).key([ 'servicePath', 'port', @@ -225,7 +225,7 @@ describe('grpc', () => { it('should load the test file', () => { // no-any disabled because if the accessed fields are non-existent, this // test will fail anyway. - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const protos = grpcClient.loadProto(TEST_PATH, TEST_FILE) as any; expect(protos.google.example.library.v1.LibraryService).to.be.a( 'Function' @@ -236,7 +236,7 @@ describe('grpc', () => { const fullPath = path.join(TEST_PATH, TEST_FILE); // no-any disabled because if the accessed fields are non-existent, this // test will fail anyway. - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const protos = grpcClient.loadProto(fullPath) as any; expect(protos.google.example.library.v1.LibraryService).to.be.a( 'Function' @@ -248,7 +248,7 @@ describe('grpc', () => { const iamService = path.join('google', 'iam', 'v1', 'iam_policy.proto'); // no-any disabled because if the accessed fields are non-existent, this // test will fail anyway. - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const protos = grpcClient.loadProto(nonExistentDir, iamService) as any; expect(protos.google.iam.v1.IAMPolicy).to.be.a('Function'); }); @@ -265,7 +265,7 @@ describe('grpc', () => { const protos = grpcClient.loadProto(TEST_PATH, [ TEST_FILE, iamService, - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any ]) as any; expect(protos.google.example.library.v1.LibraryService).to.be.a( 'Function' diff --git a/test/unit/longrunning.ts b/test/unit/longrunning.ts index 5aabd901e..326930f73 100644 --- a/test/unit/longrunning.ts +++ b/test/unit/longrunning.ts @@ -17,6 +17,7 @@ import {expect} from 'chai'; import {status} from '@grpc/grpc-js'; import * as sinon from 'sinon'; +import {describe, it} from 'mocha'; import {LongrunningDescriptor} from '../../src'; import * as operationProtos from '../../protos/operations'; @@ -28,7 +29,7 @@ import {OperationsClient} from '../../src/operationsClient'; import * as utils from './utils'; import {AnyDecoder} from '../../src/longRunningCalls/longRunningDescriptor'; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any const FAKE_STATUS_CODE_1 = (utils as any).FAKE_STATUS_CODE_1; const RESPONSE_VAL = 'response'; @@ -95,18 +96,18 @@ interface SpyableOperationsClient extends OperationsClient { } describe('longrunning', () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function mockOperationsClient(opts?: any): SpyableOperationsClient { opts = opts || {}; let remainingCalls = opts.expectedCalls ? opts.expectedCalls : null; const cancelGetOperationSpy = sinon.spy(); const getOperationSpy = sinon.spy(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let resolver: any; const promise = new Promise(resolve => { resolver = resolve; }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (promise as any).cancel = cancelGetOperationSpy; if (remainingCalls && remainingCalls > 1) { @@ -124,7 +125,7 @@ describe('longrunning', () => { getOperation: getOperationSpy, cancelOperation: cancelOperationSpy, cancelGetOperationSpy, - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any; } @@ -163,10 +164,8 @@ describe('longrunning', () => { ); expect(operation).to.have.property('longrunningDescriptor'); expect(operation.name).to.deep.eq(OPERATION_NAME); - // tslint:disable-next-line no-unused-expression expect(operation.done).to.be.false; expect(operation.latestResponse).to.deep.eq(PENDING_OP); - // tslint:disable-next-line no-unused-expression expect(operation.result).to.be.null; expect(operation.metadata).to.deep.eq(METADATA_VAL); expect(rawResponse).to.deep.eq(PENDING_OP); @@ -219,7 +218,6 @@ describe('longrunning', () => { ); expect(operation).to.have.property('longrunningDescriptor'); expect(operation.name).to.deep.eq(OPERATION_NAME); - // tslint:disable-next-line no-unused-expression expect(operation.done).to.be.true; expect(operation.response).to.deep.eq(RESPONSE); expect(operation.result).to.deep.eq(RESPONSE_VAL); @@ -314,7 +312,6 @@ describe('longrunning', () => { expect(client.getOperation.callCount).to.eq(1); done(); }) - // tslint:disable-next-line no-unused-expression ).to.be.undefined; }) .catch(error => { @@ -426,7 +423,6 @@ describe('longrunning', () => { const [operation] = ((await apiCall({})) as unknown) as [ longrunning.Operation ]; - // tslint:disable-next-line no-unused-expression expect(operation).to.be.not.null; const [finalResult] = ((await operation!.promise()) as unknown) as [ string @@ -513,9 +509,8 @@ describe('longrunning', () => { const operation = responses[0] as longrunning.Operation; const p = operation.promise(); operation.cancel().then(() => { - // tslint:disable-next-line no-unused-expression expect(client.cancelOperation.called).to.be.true; - // tslint:disable-next-line no-unused-expression no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any expect((client as any).cancelGetOperationSpy.called).to.be.true; done(); }); @@ -663,6 +658,7 @@ describe('longrunning', () => { finalOperation: PENDING_OP, }); const apiCall = createApiCall(func, client); + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore incomplete options apiCall( {}, diff --git a/test/unit/pagedIteration.ts b/test/unit/pagedIteration.ts index 5dbdc3d00..66c2832e3 100644 --- a/test/unit/pagedIteration.ts +++ b/test/unit/pagedIteration.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import {expect} from 'chai'; import * as pumpify from 'pumpify'; import * as sinon from 'sinon'; @@ -21,6 +23,7 @@ import * as streamEvents from 'stream-events'; import * as through2 from 'through2'; import {PageDescriptor} from '../../src/paginationCalls/pageDescriptor'; import {APICallback, GaxCallPromise} from '../../src/apitypes'; +import {describe, it, beforeEach} from 'mocha'; import * as util from './utils'; import {Stream} from 'stream'; @@ -76,7 +79,6 @@ describe('paged iteration', () => { expected.push(i); } apiCall({}, undefined, (err, results) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; expect(results).to.deep.equal(expected); done(); @@ -204,8 +206,10 @@ describe('paged iteration', () => { async function iterableChecker(iterable: AsyncIterable<{} | undefined>) { let counter = 0; + const resources = []; for await (const resource of iterable) { counter++; + resources.push(resource); if (counter === 10) break; } expect(counter).to.equal(10); @@ -219,7 +223,7 @@ describe('paged iteration', () => { }); describe('stream conversion', () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let spy: any; let apiCall: GaxCallPromise; beforeEach(() => { @@ -341,7 +345,7 @@ describe('paged iteration', () => { it('cooperates with google-cloud-node usage', done => { let stream; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const output = streamEvents((pumpify as any).obj()) as pumpify; output.once('reading', () => { // @ts-ignore incomplete options diff --git a/test/unit/pathTemplate.ts b/test/unit/pathTemplate.ts index 0579ef67c..a72b57823 100644 --- a/test/unit/pathTemplate.ts +++ b/test/unit/pathTemplate.ts @@ -15,6 +15,7 @@ */ import {expect} from 'chai'; +import {describe, it} from 'mocha'; import {PathTemplate} from '../../src/pathTemplate'; describe('PathTemplate', () => { diff --git a/test/unit/pathTemplateParser.ts b/test/unit/pathTemplateParser.ts index 221e1cf2c..2d0609163 100644 --- a/test/unit/pathTemplateParser.ts +++ b/test/unit/pathTemplateParser.ts @@ -15,14 +15,17 @@ */ import {expect} from 'chai'; +import {describe, it} from 'mocha'; describe('The PathTemplate parser', () => { it('should load the pegjs generated module ok', () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires const parser = require('../../src/pathTemplateParser'); expect(parser).to.not.eql(null); }); describe('function `parse`', () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires const parser = require('../../src/pathTemplateParser'); it('should succeed with valid inputs', () => { diff --git a/test/unit/routingHeader.ts b/test/unit/routingHeader.ts index 2a7f3d83f..4150caf77 100644 --- a/test/unit/routingHeader.ts +++ b/test/unit/routingHeader.ts @@ -16,6 +16,7 @@ import {expect} from 'chai'; import {fromParams} from '../../src/routingHeader'; +import {describe, it} from 'mocha'; describe('fromParams', () => { it('constructs the routing header', () => { diff --git a/test/unit/streaming.ts b/test/unit/streaming.ts index 748d59028..8d19657ce 100644 --- a/test/unit/streaming.ts +++ b/test/unit/streaming.ts @@ -14,9 +14,12 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + import {expect} from 'chai'; import * as sinon from 'sinon'; import * as through2 from 'through2'; +import {describe, it} from 'mocha'; import {GaxCallStream, GRPCCall} from '../../src/apitypes'; import {createApiCall} from '../../src/createApiCall'; @@ -65,9 +68,7 @@ describe('streaming', () => { expect(data).to.deep.equal({resources: [3, 4, 5]}); } }); - // tslint:disable-next-line no-unused-expression expect(s.readable).to.be.true; - // tslint:disable-next-line no-unused-expression expect(s.writable).to.be.false; s.on('data', callback); s.on('end', () => { @@ -97,14 +98,11 @@ describe('streaming', () => { streaming.StreamType.CLIENT_STREAMING ); const s = apiCall({}, undefined, (err, response) => { - // tslint:disable-next-line no-unused-expression expect(err).to.be.null; expect(response).to.deep.eq(['foo', 'bar']); done(); }); - // tslint:disable-next-line no-unused-expression expect(s.readable).to.be.false; - // tslint:disable-next-line no-unused-expression expect(s.writable).to.be.true; s.write('foo'); s.write('bar'); @@ -136,9 +134,7 @@ describe('streaming', () => { expect(callback.callCount).to.eq(2); done(); }); - // tslint:disable-next-line no-unused-expression expect(s.readable).to.be.true; - // tslint:disable-next-line no-unused-expression expect(s.writable).to.be.true; s.write(arg); s.write(arg); @@ -188,9 +184,7 @@ describe('streaming', () => { expect(receivedResponse).to.deep.eq(expectedResponse); done(); }); - // tslint:disable-next-line no-unused-expression expect(s.readable).to.be.true; - // tslint:disable-next-line no-unused-expression expect(s.writable).to.be.true; setTimeout(() => { s.end(s); @@ -198,7 +192,7 @@ describe('streaming', () => { }); it('cancels in the middle', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function schedulePush(s: any, c: number) { const intervalId = setInterval(() => { s.push(c); @@ -212,7 +206,7 @@ describe('streaming', () => { function func() { const s = through2.obj(); schedulePush(s, 0); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (s as any).cancel = () => { s.end(); s.emit('error', cancelError); diff --git a/test/unit/warning.ts b/test/unit/warning.ts index 4c964f42b..81ca9fce7 100644 --- a/test/unit/warning.ts +++ b/test/unit/warning.ts @@ -16,6 +16,7 @@ import {assert} from 'chai'; import * as sinon from 'sinon'; +import {describe, it} from 'mocha'; import {warn} from '../../src/warnings'; diff --git a/tools/compileProtos.ts b/tools/compileProtos.ts index f6a804d0c..dbb618b7e 100644 --- a/tools/compileProtos.ts +++ b/tools/compileProtos.ts @@ -291,6 +291,7 @@ function usage() { if (require.main === module) { if (process.argv.length <= 2) { usage(); + // eslint-disable-next-line no-process-exit process.exit(1); } // argv[0] is node.js binary, argv[1] is script path diff --git a/tsconfig.json b/tsconfig.json index dd6cab4c2..186392a3b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "lib": ["es2015", "dom"], "rootDir": ".", "outDir": "build", - "noImplicitAny": true + "noImplicitAny": true, + "resolveJsonModule": true }, "include": [ "src/*.ts", diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 1703df5d1..000000000 --- a/tslint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "gts/tslint.json", - "rules": { - "ban-ts-ignore": false, - "ban": false - } -} diff --git a/webpack.config.js b/webpack.config.js index 55a8ced6d..7cecf9522 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,38 +17,41 @@ const path = require('path'); module.exports = { - entry: './src/fallback.ts', - output: { - library: "Gax", - filename: "./gax.js" + entry: './src/fallback.ts', + output: { + library: 'Gax', + filename: './gax.js', + }, + resolve: { + extensions: ['.ts', '.js', '.json'], + alias: { + '../../package.json': path.resolve(__dirname, 'package.json'), + '../../protos/operations.json': path.resolve( + __dirname, + 'protos/operations.json' + ), + '../../protos/status.json': path.resolve(__dirname, 'protos/status.json'), }, - resolve: { - extensions: ['.ts', '.js', '.json'], - alias: { - '../../package.json': path.resolve(__dirname, 'package.json'), - '../../protos/operations.json': path.resolve(__dirname, 'protos/operations.json'), - '../../protos/status.json': path.resolve(__dirname, 'protos/status.json'), + }, + module: { + rules: [ + { + test: /\.ts$/, + use: 'ts-loader', + exclude: /node_modules/, }, - }, - module: { - rules: [ - { - test: /\.ts$/, - use: 'ts-loader', - exclude: /node_modules/, - }, - { - test: /node_modules[\\\/]retry-request[\\\/]/, - use: 'null-loader', - }, - { - test: /node_modules[\/]google-auth-library/, - use: 'null-loader', - } - ], - }, - node: { - fs: 'empty', - }, - mode: 'production' -} + { + test: /node_modules[\\/]retry-request[\\/]/, + use: 'null-loader', + }, + { + test: /node_modules[\\/]google-auth-library/, + use: 'null-loader', + }, + ], + }, + node: { + fs: 'empty', + }, + mode: 'production', +};