From 544a061b1b6d7fdc4051486c2b8ae5d14e1ec141 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Fri, 10 Apr 2020 23:26:07 -0700 Subject: [PATCH] fix: remove eslint, update gax, fix generated protos, run the generator (#955) Run the latest version of the generator, update google-gax, update gts, and remove direct dependencies on eslint. --- .eslintignore | 1 - .eslintrc.yml | 15 ---- .gitignore | 1 + .prettierignore | 8 +- .prettierrc | 8 -- codecov.yaml | 4 - package.json | 19 ++-- samples/.eslintrc.yml | 1 - samples/getTopicPolicy.js | 2 +- samples/listenForErrors.js | 4 +- samples/listenForOrderedMessages.js | 2 +- samples/publishWithRetrySettings.js | 5 +- samples/setSubscriptionPolicy.js | 2 +- samples/setTopicPolicy.js | 2 +- samples/subscribeWithFlowControlSettings.js | 2 +- samples/synchronousPullWithLeaseManagement.js | 2 +- samples/system-test/subscriptions.test.js | 32 +++---- samples/system-test/topics.test.js | 10 +-- samples/testSubscriptionPermissions.js | 2 +- samples/testTopicPermissions.js | 2 +- src/.eslintrc.yml | 3 - src/helper.ts | 4 +- src/index.ts | 7 +- src/lease-manager.ts | 2 - src/message-queues.ts | 1 + src/message-stream.ts | 1 + src/publisher/index.ts | 4 +- src/publisher/message-queues.ts | 4 +- src/publisher/publish-error.ts | 1 + src/pubsub.ts | 6 +- src/pull-retry.ts | 1 + src/snapshot.ts | 6 +- src/subscriber.ts | 3 - src/subscription.ts | 4 +- src/topic.ts | 3 +- src/v1/publisher_client.ts | 18 ++-- src/v1/subscriber_client.ts | 16 ++-- synth.metadata | 13 +-- synth.py | 4 +- system-test/install.ts | 2 + system-test/pubsub.ts | 18 ++-- test/.eslintrc.yml | 3 - test/histogram.ts | 2 +- test/iam.ts | 6 +- test/lease-manager.ts | 89 ++++++++++--------- test/message-queues.ts | 13 +-- test/message-stream.ts | 15 ++-- test/publisher/index.ts | 4 +- test/publisher/message-batch.ts | 2 +- test/publisher/message-queues.ts | 16 ++-- test/publisher/publish-error.ts | 3 +- test/pubsub.ts | 72 +++++++-------- test/pull-retry.ts | 6 +- test/snapshot.ts | 3 +- test/subscriber.ts | 14 +-- test/subscription.ts | 25 +++--- test/topic.ts | 17 ++-- tsconfig.json | 2 +- tslint.json | 3 - webpack.config.js | 12 +-- 60 files changed, 250 insertions(+), 302 deletions(-) delete mode 100644 .eslintrc.yml delete mode 100644 .prettierrc delete mode 100644 codecov.yaml delete mode 100644 src/.eslintrc.yml delete mode 100644 test/.eslintrc.yml delete mode 100644 tslint.json diff --git a/.eslintignore b/.eslintignore index 09b31fe73..37f7a7343 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,4 @@ **/node_modules -src/**/doc/* build/ docs/ protos/ 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/.gitignore b/.gitignore index 5d32b2378..783162def 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ system-test/*key.json .DS_Store package-lock.json __pycache__ +.vscode diff --git a/.prettierignore b/.prettierignore index f6fac98b0..910e984a1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ -node_modules/* -samples/node_modules/* -src/**/doc/* +**/node_modules +build/ +docs/ +.coverage/ +protos/ 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/codecov.yaml b/codecov.yaml deleted file mode 100644 index 5724ea947..000000000 --- a/codecov.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -codecov: - ci: - - source.cloud.google.com diff --git a/package.json b/package.json index f392202fe..c6b4c6c3b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "author": "Google Inc.", "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "repository": "googleapis/nodejs-pubsub", "main": "./build/src/index.js", @@ -31,7 +31,7 @@ "system-test": "mocha build/system-test --timeout 600000", "samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../", "test": "c8 mocha build/test", - "lint": "gts check", + "lint": "gts fix", "predocs": "npm run compile", "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", @@ -42,7 +42,8 @@ "pretest": "npm run compile", "docs-test": "linkinator docs", "predocs-test": "npm run docs", - "benchwrapper": "node bin/benchwrapper.js" + "benchwrapper": "node bin/benchwrapper.js", + "prelint": "cd samples; npm link ../; npm install" }, "dependencies": { "@google-cloud/paginator": "^3.0.0", @@ -55,7 +56,7 @@ "async-each": "^1.0.1", "extend": "^3.0.2", "google-auth-library": "^6.0.0", - "google-gax": "^2.0.0", + "google-gax": "^2.1.0", "is-stream-ended": "^0.1.4", "lodash.snakecase": "^4.1.1", "p-defer": "^3.0.0", @@ -76,12 +77,9 @@ "@types/uuid": "^7.0.0", "c8": "^7.0.0", "codecov": "^3.0.0", - "eslint": "^6.0.0", - "eslint-config-prettier": "^6.0.0", - "eslint-plugin-node": "^11.0.0", - "eslint-plugin-prettier": "^3.0.0", + "execa": "^4.0.0", "grpc": "^1.24.0", - "gts": "^1.0.0", + "gts": "^2.0.0", "jsdoc": "^3.6.2", "jsdoc-fresh": "^1.0.1", "jsdoc-region-tag": "^1.0.2", @@ -91,10 +89,9 @@ "mv": "^2.1.1", "ncp": "^2.0.0", "null-loader": "^3.0.0", - "prettier": "^1.18.2", "proxyquire": "^2.0.0", "sinon": "^9.0.0", - "source-map-support": "^0.5.9", + "tmp": "^0.1.0", "ts-loader": "^6.2.1", "typescript": "3.6.4", "uuid": "^7.0.0", diff --git a/samples/.eslintrc.yml b/samples/.eslintrc.yml index 0aa37ac63..282535f55 100644 --- a/samples/.eslintrc.yml +++ b/samples/.eslintrc.yml @@ -1,4 +1,3 @@ --- rules: no-console: off - node/no-missing-require: off diff --git a/samples/getTopicPolicy.js b/samples/getTopicPolicy.js index 1a7d3eabc..719674aa0 100644 --- a/samples/getTopicPolicy.js +++ b/samples/getTopicPolicy.js @@ -43,7 +43,7 @@ function main(topicName = 'YOUR_TOPIC_NAME') { async function getTopicPolicy() { // Retrieves the IAM policy for the topic const [policy] = await pubSubClient.topic(topicName).iam.getPolicy(); - console.log(`Policy for topic: %j.`, policy.bindings); + console.log('Policy for topic: %j.', policy.bindings); } getTopicPolicy().catch(console.error); diff --git a/samples/listenForErrors.js b/samples/listenForErrors.js index 895afbcf9..4dcee0a17 100644 --- a/samples/listenForErrors.js +++ b/samples/listenForErrors.js @@ -48,7 +48,7 @@ async function main(subscriptionName = 'YOUR_SUBSCRIPTION_NAME', timeout = 10) { const subscription = pubSubClient.subscription(subscriptionName); // Create an event handler to handle messages - const messageHandler = function(message) { + const messageHandler = function (message) { // Do something with the message console.log(`Message: ${message}`); @@ -57,7 +57,7 @@ async function main(subscriptionName = 'YOUR_SUBSCRIPTION_NAME', timeout = 10) { }; // Create an event handler to handle errors - const errorHandler = function(error) { + const errorHandler = function (error) { // Do something with the error console.error(`ERROR: ${error}`); throw error; diff --git a/samples/listenForOrderedMessages.js b/samples/listenForOrderedMessages.js index 04afba3cc..f4124a6c1 100644 --- a/samples/listenForOrderedMessages.js +++ b/samples/listenForOrderedMessages.js @@ -64,7 +64,7 @@ async function main( const subscription = pubSubClient.subscription(subscriptionName); // Create an event handler to handle messages - const messageHandler = function(message) { + const messageHandler = function (message) { // Buffer the message in an object (for later ordering) outstandingMessages[message.attributes.counterId] = message; diff --git a/samples/publishWithRetrySettings.js b/samples/publishWithRetrySettings.js index 6be0d0067..3560a61b1 100644 --- a/samples/publishWithRetrySettings.js +++ b/samples/publishWithRetrySettings.js @@ -50,7 +50,10 @@ function main( }); async function publishWithRetrySettings() { - const formattedTopic = publisherClient.projectTopicPath(projectId, topicName); + const formattedTopic = publisherClient.projectTopicPath( + projectId, + topicName + ); // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); diff --git a/samples/setSubscriptionPolicy.js b/samples/setSubscriptionPolicy.js index a9bf843b3..d01104e1f 100644 --- a/samples/setSubscriptionPolicy.js +++ b/samples/setSubscriptionPolicy.js @@ -62,7 +62,7 @@ function main(subscriptionName = 'YOUR_SUBSCRIPTION_NAME') { .subscription(subscriptionName) .iam.setPolicy(newPolicy); - console.log(`Updated policy for subscription: %j`, updatedPolicy.bindings); + console.log('Updated policy for subscription: %j', updatedPolicy.bindings); } setSubscriptionPolicy().catch(console.error); diff --git a/samples/setTopicPolicy.js b/samples/setTopicPolicy.js index dd9101833..e32b8efcf 100644 --- a/samples/setTopicPolicy.js +++ b/samples/setTopicPolicy.js @@ -61,7 +61,7 @@ function main(topicName = 'YOUR_TOPIC_NAME') { const [updatedPolicy] = await pubSubClient .topic(topicName) .iam.setPolicy(newPolicy); - console.log(`Updated policy for topic: %j`, updatedPolicy.bindings); + console.log('Updated policy for topic: %j', updatedPolicy.bindings); } setTopicPolicy().catch(console.error); diff --git a/samples/subscribeWithFlowControlSettings.js b/samples/subscribeWithFlowControlSettings.js index 820971f8a..ee964611e 100644 --- a/samples/subscribeWithFlowControlSettings.js +++ b/samples/subscribeWithFlowControlSettings.js @@ -78,7 +78,7 @@ function main( message.ack(); }; - subscription.on(`message`, messageHandler); + subscription.on('message', messageHandler); setTimeout(() => { subscription.close(); diff --git a/samples/synchronousPullWithLeaseManagement.js b/samples/synchronousPullWithLeaseManagement.js index 42db36abb..55326a238 100644 --- a/samples/synchronousPullWithLeaseManagement.js +++ b/samples/synchronousPullWithLeaseManagement.js @@ -100,7 +100,7 @@ function main( console.log(`Acknowledged: "${message.message.data}".`); // Exit after the message is acknowledged. waiting = false; - console.log(`Done.`); + console.log('Done.'); } else { // If the message is not yet processed.. const modifyAckRequest = { diff --git a/samples/system-test/subscriptions.test.js b/samples/system-test/subscriptions.test.js index c24cc8c66..0fd986453 100644 --- a/samples/system-test/subscriptions.test.js +++ b/samples/system-test/subscriptions.test.js @@ -100,8 +100,8 @@ describe('subscriptions', () => { const expected = `Subscription: ${fullSubscriptionNameOne}` + `\nTopic: ${fullTopicNameOne}` + - `\nPush config: ` + - `\nAck deadline: 10s`; + '\nPush config: ' + + '\nAck deadline: 10s'; assert.include(output, expected); }); @@ -124,7 +124,7 @@ describe('subscriptions', () => { it('should listen for messages', async () => { const messageIds = await pubsub .topic(topicNameOne) - .publish(Buffer.from(`Hello, world!`)); + .publish(Buffer.from('Hello, world!')); const output = execSync( `${commandFor('listenForMessages')} ${subscriptionNameOne}` ); @@ -132,7 +132,7 @@ describe('subscriptions', () => { }); it('should listen for messages synchronously', async () => { - await pubsub.topic(topicNameOne).publish(Buffer.from(`Hello, world!`)); + await pubsub.topic(topicNameOne).publish(Buffer.from('Hello, world!')); const output = execSync( `${commandFor('synchronousPull')} ${projectId} ${subscriptionNameOne}` ); @@ -141,7 +141,7 @@ describe('subscriptions', () => { }); it('should listen for messages synchronously with lease management', async () => { - await pubsub.topic(topicNameOne).publish(Buffer.from(`Hello, world!`)); + await pubsub.topic(topicNameOne).publish(Buffer.from('Hello, world!')); const output = execSync( `${commandFor( 'synchronousPullWithLeaseManagement' @@ -153,7 +153,7 @@ describe('subscriptions', () => { it('should listen to messages with flow control', async () => { const topicTwo = pubsub.topic(topicNameTwo); await topicTwo.subscription(subscriptionNameFour).get({autoCreate: true}); - await topicTwo.publish(Buffer.from(`Hello, world!`)); + await topicTwo.publish(Buffer.from('Hello, world!')); const output = execSync( `${commandFor( @@ -162,7 +162,7 @@ describe('subscriptions', () => { ); assert.include( output, - `ready to receive messages at a controlled volume of 5 messages.` + 'ready to receive messages at a controlled volume of 5 messages.' ); const [subscriptions] = await pubsub.topic(topicNameTwo).getSubscriptions(); assert(subscriptions.some(s => s.name === fullSubscriptionNameFour)); @@ -170,7 +170,7 @@ describe('subscriptions', () => { it('should listen for error messages', () => { assert.throws( - () => execSync(`node listenForErrors nonexistent-subscription`), + () => execSync('node listenForErrors nonexistent-subscription'), /Resource not found/ ); }); @@ -184,7 +184,7 @@ describe('subscriptions', () => { spy.calls.push(args); log(...args); }; - const expected = `Hello, world!`; + const expected = 'Hello, world!'; const expectedBuffer = Buffer.from(expected); const publishedMessageIds = []; const topicTwo = pubsub.topic(topicNameTwo); @@ -207,7 +207,7 @@ describe('subscriptions', () => { ); assert.strictEqual(spy.calls.length, 1); assert.deepStrictEqual(spy.calls[0], [ - `* %d %j %j`, + '* %d %j %j', publishedMessageIds[1], expected, {counterId: '1'}, @@ -222,13 +222,13 @@ describe('subscriptions', () => { ); assert.strictEqual(spy.calls.length, 3); assert.deepStrictEqual(spy.calls[1], [ - `* %d %j %j`, + '* %d %j %j', publishedMessageIds[2], expected, {counterId: '2'}, ]); assert.deepStrictEqual(spy.calls[2], [ - `* %d %j %j`, + '* %d %j %j', publishedMessageIds[0], expected, {counterId: '3'}, @@ -244,13 +244,13 @@ describe('subscriptions', () => { const policy = results[0]; assert.deepStrictEqual(policy.bindings, [ { - role: `roles/pubsub.editor`, - members: [`group:cloud-logs@google.com`], + role: 'roles/pubsub.editor', + members: ['group:cloud-logs@google.com'], condition: null, }, { - role: `roles/pubsub.viewer`, - members: [`allUsers`], + role: 'roles/pubsub.viewer', + members: ['allUsers'], condition: null, }, ]); diff --git a/samples/system-test/topics.test.js b/samples/system-test/topics.test.js index f7b961031..bf80b8f28 100644 --- a/samples/system-test/topics.test.js +++ b/samples/system-test/topics.test.js @@ -60,7 +60,7 @@ describe('topics', () => { const _pullOneMessage = subscriptionObj => { return new Promise((resolve, reject) => { const timeoutHandler = setTimeout(() => { - reject(new Error(`_pullOneMessage timed out`)); + reject(new Error('_pullOneMessage timed out')); }, 55000); subscriptionObj.once('error', reject).once('message', message => { @@ -208,13 +208,13 @@ describe('topics', () => { const [policy] = results; assert.deepStrictEqual(policy.bindings, [ { - role: `roles/pubsub.editor`, - members: [`group:cloud-logs@google.com`], + role: 'roles/pubsub.editor', + members: ['group:cloud-logs@google.com'], condition: null, }, { - role: `roles/pubsub.viewer`, - members: [`allUsers`], + role: 'roles/pubsub.viewer', + members: ['allUsers'], condition: null, }, ]); diff --git a/samples/testSubscriptionPermissions.js b/samples/testSubscriptionPermissions.js index 7d3bb9ff5..4cd4eba39 100644 --- a/samples/testSubscriptionPermissions.js +++ b/samples/testSubscriptionPermissions.js @@ -51,7 +51,7 @@ function main(subscriptionName = 'YOUR_SUBSCRIPTION_NAME') { .subscription(subscriptionName) .iam.testPermissions(permissionsToTest); - console.log(`Tested permissions for subscription: %j`, permissions); + console.log('Tested permissions for subscription: %j', permissions); } testSubscriptionPermissions().catch(console.error); diff --git a/samples/testTopicPermissions.js b/samples/testTopicPermissions.js index 28e2c3dc6..5bd019a97 100644 --- a/samples/testTopicPermissions.js +++ b/samples/testTopicPermissions.js @@ -52,7 +52,7 @@ function main(topicName = 'YOUR_TOPIC_NAME') { .topic(topicName) .iam.testPermissions(permissionsToTest); - console.log(`Tested permissions for topic: %j`, permissions); + console.log('Tested permissions for topic: %j', permissions); } testTopicPermissions().catch(console.error); diff --git a/src/.eslintrc.yml b/src/.eslintrc.yml deleted file mode 100644 index 46afd9525..000000000 --- a/src/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - node/no-missing-require: off diff --git a/src/helper.ts b/src/helper.ts index 3c90ff06f..c81bffa7b 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -22,6 +22,7 @@ import * as path from 'path'; import * as gapicConfig from './iam_policy_service_client_config.json'; import {ProjectIdCallback} from 'google-auth-library'; import * as protosTypes from '../protos/protos'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const {version} = require('../../package.json'); /** * Google Cloud IAM Client. @@ -95,7 +96,7 @@ export class IamClient { const iamPolicyStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.iam.v1.IAMPolicy') - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (protos as any).google.iam.v1.IAMPolicy, opts ) as Promise<{[method: string]: Function}>; @@ -114,6 +115,7 @@ export class IamClient { if (this._terminated) { return Promise.reject('The client has already been closed.'); } + // eslint-disable-next-line prefer-spread return stub[methodName].apply(stub, args); }, (err: Error | null | undefined) => () => { diff --git a/src/index.ts b/src/index.ts index f6bfd2789..5aa450837 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,11 +76,9 @@ * @property {constructor} SubscriberClient * Reference to {@link v1.SubscriberClient}. */ -const v1 = require('./v1'); +import * as v1 from './v1'; export {v1}; - -export {ServiceError} from '@grpc/grpc-js'; -export {CallOptions} from 'google-gax'; +export {ServiceError, CallOptions} from 'google-gax'; export { Policy, GetPolicyCallback, @@ -150,6 +148,7 @@ export { if (process.env.DEBUG_GRPC) { console.info('gRPC logging set to verbose'); + // eslint-disable-next-line const {setLogger, setLogVerbosity, logVerbosity} = require('@grpc/grpc-js'); setLogger(console); setLogVerbosity(logVerbosity.DEBUG); diff --git a/src/lease-manager.ts b/src/lease-manager.ts index 518a98688..716a48102 100644 --- a/src/lease-manager.ts +++ b/src/lease-manager.ts @@ -15,8 +15,6 @@ */ import {EventEmitter} from 'events'; -import {freemem} from 'os'; - import {Message, Subscriber} from './subscriber'; import {defaultOptions} from './default-options'; diff --git a/src/message-queues.ts b/src/message-queues.ts index 455c33eac..9d3c00374 100644 --- a/src/message-queues.ts +++ b/src/message-queues.ts @@ -15,6 +15,7 @@ */ import {CallOptions} from 'google-gax'; +// eslint-disable-next-line node/no-extraneous-import import {Metadata, ServiceError, status} from '@grpc/grpc-js'; import defer = require('p-defer'); diff --git a/src/message-stream.ts b/src/message-stream.ts index ddac12de7..87c95a1ce 100644 --- a/src/message-stream.ts +++ b/src/message-stream.ts @@ -22,6 +22,7 @@ import { ServiceError, status, StatusObject, + // eslint-disable-next-line node/no-extraneous-import } from '@grpc/grpc-js'; import * as isStreamEnded from 'is-stream-ended'; import {PassThrough} from 'stream'; diff --git a/src/publisher/index.ts b/src/publisher/index.ts index 7386dba5e..4e9ca41ba 100644 --- a/src/publisher/index.ts +++ b/src/publisher/index.ts @@ -19,9 +19,9 @@ import * as extend from 'extend'; import {CallOptions} from 'google-gax'; import {BatchPublishOptions} from './message-batch'; -import {Queue, OrderedQueue, PublishDone} from './message-queues'; +import {Queue, OrderedQueue} from './message-queues'; import {Topic} from '../topic'; -import {RequestCallback, EmptyCallback, EmptyResponse} from '../pubsub'; +import {RequestCallback, EmptyCallback} from '../pubsub'; import {google} from '../../protos/protos'; import {defaultOptions} from '../default-options'; diff --git a/src/publisher/message-queues.ts b/src/publisher/message-queues.ts index c7365ac7a..1b372d1c9 100644 --- a/src/publisher/message-queues.ts +++ b/src/publisher/message-queues.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import {ServiceError} from '@grpc/grpc-js'; +import {ServiceError} from 'google-gax'; import {EventEmitter} from 'events'; import {BatchPublishOptions, MessageBatch} from './message-batch'; import {PublishError} from './publish-error'; -import {Publisher, PubsubMessage, PublishCallback, BATCH_LIMITS} from './'; +import {Publisher, PubsubMessage, PublishCallback} from './'; import {google} from '../../protos/protos'; export interface PublishDone { diff --git a/src/publisher/publish-error.ts b/src/publisher/publish-error.ts index 6a2bd6507..d59d1d27e 100644 --- a/src/publisher/publish-error.ts +++ b/src/publisher/publish-error.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +// eslint-disable-next-line node/no-extraneous-import import {ServiceError, Metadata, status} from '@grpc/grpc-js'; /** diff --git a/src/pubsub.ts b/src/pubsub.ts index bc700fb50..5e2cbc0d5 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -20,10 +20,14 @@ import {promisifyAll} from '@google-cloud/promisify'; import * as extend from 'extend'; import {GoogleAuth} from 'google-auth-library'; import * as gax from 'google-gax'; +// eslint-disable-next-line node/no-extraneous-import import * as grpc from '@grpc/grpc-js'; +// eslint-disable-next-line node/no-extraneous-import import {ServiceError, ChannelCredentials} from '@grpc/grpc-js'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const PKG = require('../../package.json'); +// eslint-disable-next-line @typescript-eslint/no-var-requires const v1 = require('./v1'); import {Snapshot} from './snapshot'; @@ -47,8 +51,6 @@ import {CallOptions} from 'google-gax'; import {Transform} from 'stream'; import {google} from '../protos/protos'; -const opts = {} as gax.GrpcClientOptions; - /** * Project ID placeholder. * @type {string} diff --git a/src/pull-retry.ts b/src/pull-retry.ts index f55679e12..cd4d77842 100644 --- a/src/pull-retry.ts +++ b/src/pull-retry.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +// eslint-disable-next-line node/no-extraneous-import import {StatusObject, status} from '@grpc/grpc-js'; /*! diff --git a/src/snapshot.ts b/src/snapshot.ts index 68339c44d..f6e628143 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -18,7 +18,6 @@ import {promisifyAll} from '@google-cloud/promisify'; import {CallOptions} from 'google-gax'; import {google} from '../protos/protos'; - import {PubSub} from './pubsub'; import { EmptyCallback, @@ -27,7 +26,6 @@ import { ResourceCallback, } from './pubsub'; import {Subscription} from './subscription'; -import * as util from './util'; export type CreateSnapshotCallback = ResourceCallback< Snapshot, @@ -206,7 +204,7 @@ export class Snapshot { ): void | Promise { if (!(this.parent instanceof Subscription)) { throw new Error( - `This is only available if you accessed this object through Subscription#snapshot` + 'This is only available if you accessed this object through Subscription#snapshot' ); } @@ -261,7 +259,7 @@ export class Snapshot { ): void | Promise { if (!(this.parent instanceof Subscription)) { throw new Error( - `This is only available if you accessed this object through Subscription#snapshot` + 'This is only available if you accessed this object through Subscription#snapshot' ); } return this.parent.seek(this.name, gaxOpts! as CallOptions, callback!); diff --git a/src/subscriber.ts b/src/subscriber.ts index 145ef1375..deea9fc97 100644 --- a/src/subscriber.ts +++ b/src/subscriber.ts @@ -18,11 +18,8 @@ import {DateStruct, PreciseDate} from '@google-cloud/precise-date'; import {replaceProjectIdToken} from '@google-cloud/projectify'; import {promisify} from '@google-cloud/promisify'; import {EventEmitter} from 'events'; -import {ClientStub} from 'google-gax'; -import {common as protobuf} from 'protobufjs'; import {google} from '../protos/protos'; - import {Histogram} from './histogram'; import {FlowControlOptions, LeaseManager} from './lease-manager'; import {AckQueue, BatchOptions, ModAckQueue} from './message-queues'; diff --git a/src/subscription.ts b/src/subscription.ts index d83859dab..5fe5851be 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -43,10 +43,8 @@ import { } from './snapshot'; import {Subscriber, SubscriberOptions} from './subscriber'; import {Topic} from './topic'; -import {noop} from './util'; export type PushConfig = google.pubsub.v1.IPushConfig; - export type OidcToken = google.pubsub.v1.PushConfig.IOidcToken; export type SubscriptionMetadata = { @@ -1024,7 +1022,7 @@ export class Subscription extends EventEmitter { } }); - this.on('removeListener', event => { + this.on('removeListener', () => { if (this.isOpen && this.listenerCount('message') === 0) { this._subscriber.close(); } diff --git a/src/topic.ts b/src/topic.ts index 526209f8e..3cc761240 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -47,7 +47,6 @@ import { Subscription, SubscriptionOptions, } from './subscription'; -import * as util from './util'; export type TopicMetadata = google.pubsub.v1.ITopic; @@ -80,7 +79,7 @@ export type GetTopicSubscriptionsResponse = PagedResponse< google.pubsub.v1.IListTopicSubscriptionsResponse >; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type MessageOptions = PubsubMessage & {json?: any}; /** diff --git a/src/v1/publisher_client.ts b/src/v1/publisher_client.ts index ac9132508..257b403fa 100644 --- a/src/v1/publisher_client.ts +++ b/src/v1/publisher_client.ts @@ -214,7 +214,7 @@ export class PublisherClient { ['topic'], 'message_ids', gax.createByteLengthFunction( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any protoFilesRoot.lookupType('google.pubsub.v1.PubsubMessage') as any ) ), @@ -258,7 +258,7 @@ export class PublisherClient { ? (this._protos as protobuf.Root).lookupService( 'google.pubsub.v1.Publisher' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.pubsub.v1.Publisher, this._opts ) as Promise<{[method: string]: Function}>; @@ -1406,7 +1406,7 @@ export class PublisherClient { */ projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ - project, + project: project, }); } @@ -1430,8 +1430,8 @@ export class PublisherClient { */ projectTopicPath(project: string, topic: string) { return this.pathTemplates.projectTopicPathTemplate.render({ - project, - topic, + project: project, + topic: topic, }); } @@ -1468,8 +1468,8 @@ export class PublisherClient { */ snapshotPath(project: string, snapshot: string) { return this.pathTemplates.snapshotPathTemplate.render({ - project, - snapshot, + project: project, + snapshot: snapshot, }); } @@ -1504,8 +1504,8 @@ export class PublisherClient { */ subscriptionPath(project: string, subscription: string) { return this.pathTemplates.subscriptionPathTemplate.render({ - project, - subscription, + project: project, + subscription: subscription, }); } diff --git a/src/v1/subscriber_client.ts b/src/v1/subscriber_client.ts index 097a264c4..9a0801050 100644 --- a/src/v1/subscriber_client.ts +++ b/src/v1/subscriber_client.ts @@ -237,7 +237,7 @@ export class SubscriberClient { ? (this._protos as protobuf.Root).lookupService( 'google.pubsub.v1.Subscriber' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.pubsub.v1.Subscriber, this._opts ) as Promise<{[method: string]: Function}>; @@ -2066,7 +2066,7 @@ export class SubscriberClient { */ projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ - project, + project: project, }); } @@ -2090,8 +2090,8 @@ export class SubscriberClient { */ projectTopicPath(project: string, topic: string) { return this.pathTemplates.projectTopicPathTemplate.render({ - project, - topic, + project: project, + topic: topic, }); } @@ -2128,8 +2128,8 @@ export class SubscriberClient { */ snapshotPath(project: string, snapshot: string) { return this.pathTemplates.snapshotPathTemplate.render({ - project, - snapshot, + project: project, + snapshot: snapshot, }); } @@ -2164,8 +2164,8 @@ export class SubscriberClient { */ subscriptionPath(project: string, subscription: string) { return this.pathTemplates.subscriptionPathTemplate.render({ - project, - subscription, + project: project, + subscription: subscription, }); } diff --git a/synth.metadata b/synth.metadata index bfd981203..8a36b9dba 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,19 +1,12 @@ { - "updateTime": "2020-04-08T18:29:29.306214Z", + "updateTime": "2020-04-11T00:41:23.034720Z", "sources": [ - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "d398d687aad9eab4c6ceee9cd5e012fa61f7e28c", - "internalRef": "305496764" - } - }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "8cf0f5d93a70c3dcb0b4999d3152c46d4d9264bf" + "sha": "6f32150677c9784f3c3a7e1949472bd29c9d72c5", + "log": "6f32150677c9784f3c3a7e1949472bd29c9d72c5\nfix: installs test_utils from its common repo (#480)\n\n\n74ce986d3b5431eb66985e9a00c4eb45295a4020\nfix: stop recording update_time in synth.metadata (#478)\n\n\n7f8e62aa3edd225f76347a16f92e400661fdfb52\nchore(java): release-please only updates non maven versions in README (#476)\n\nPrevent release-please and synthtool from fighting over the released library version. Synthtool updates the install snippets from the samples pom.xml files so the bots fight if they are temporarily out of sync after a release.\nc7e0e517d7f46f77bebd27da2e5afcaa6eee7e25\nbuild(java): fix nightly integration test config to run integrations (#465)\n\nThis was only running the units.\nbd69a2aa7b70875f3c988e269706b22fefbef40e\nbuild(java): fix retry_with_backoff when -e option set (#475)\n\n\nd9b173c427bfa0c6cca818233562e7e8841a357c\nfix: record version of working repo in synth.metadata (#473)\n\nPartial revert of b37cf74d12e9a42b9de9e61a4f26133d7cd9c168.\nf73a541770d95a609e5be6bf6b3b220d17cefcbe\nfeat(discogapic): allow local discovery-artifact-manager (#474)\n\n\n" } } ], diff --git a/synth.py b/synth.py index 1fb6841f5..02503cefa 100644 --- a/synth.py +++ b/synth.py @@ -55,7 +55,7 @@ # TODO: it should be removed once pubsub upgrade gts 2.0.0 # fix tslint issue due to mismatch gts version with gapic-generator-typescript s.replace(client_file, '\/\/ eslint\-disable\-next\-line\ \@typescript\-eslint\/no\-explicit\-any', - '// tslint:disable-next-line no-any') + '// eslint-disable-next-line @typescript-eslint/no-explicit-any') with open('helperMethods.ts.tmpl', 'r') as helper_file: content = helper_file.read() @@ -68,5 +68,5 @@ # Node.js specific cleanup subprocess.run(['npm', 'install']) -subprocess.run(['npm', 'run', 'fix']) +subprocess.run(['npm', 'run', 'lint']) subprocess.run(['npx', 'compileProtos', 'src']) diff --git a/system-test/install.ts b/system-test/install.ts index 58495a746..d1b9705ce 100644 --- a/system-test/install.ts +++ b/system-test/install.ts @@ -17,12 +17,14 @@ import * as mv from 'mv'; import {ncp} from 'ncp'; import * as tmp from 'tmp'; import {promisify} from 'util'; +import {describe, it, after} from 'mocha'; const keep = false; const mvp = (promisify(mv) as {}) as (...args: string[]) => Promise; const ncpp = promisify(ncp); const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); const stagingPath = stagingDir.name; +// eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../package.json'); describe('📦 pack and install', () => { diff --git a/system-test/pubsub.ts b/system-test/pubsub.ts index 09447865e..d5a5fe941 100644 --- a/system-test/pubsub.ts +++ b/system-test/pubsub.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, after, beforeEach} from 'mocha'; import * as crypto from 'crypto'; import defer = require('p-defer'); import * as uuid from 'uuid'; @@ -28,7 +28,6 @@ import { } from '../src'; import {Policy, IamPermissionsMap} from '../src/iam'; import {MessageOptions} from '../src/topic'; -import {Metadata, MetadataValue} from 'google-gax'; import {google} from '../protos/protos'; type Resource = Topic | Subscription | Snapshot; @@ -39,10 +38,7 @@ const CURRENT_TIME = Date.now(); const pubsub = new PubSub(); function shortUUID() { - return uuid - .v1() - .split('-') - .shift(); + return uuid.v1().split('-').shift(); } describe('pubsub', () => { @@ -293,6 +289,7 @@ describe('pubsub', () => { const { input, expected, + // eslint-disable-next-line @typescript-eslint/no-var-requires } = require('../../system-test/fixtures/ordered-messages.json'); const publishes = input.map(({key, message}: Input) => { @@ -583,7 +580,7 @@ describe('pubsub', () => { subscription.on('error', done); - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any subscription.on('message', (message: {data: any}) => { assert.deepStrictEqual(message.data, Buffer.from('hello')); @@ -660,7 +657,7 @@ describe('pubsub', () => { // can be ran manually to test options/memory usage/etc. // tslint:disable-next-line ban - it.skip('should handle a large volume of messages', async function() { + it.skip('should handle a large volume of messages', async function () { const MESSAGES = 200000; const deferred = defer(); @@ -681,7 +678,7 @@ describe('pubsub', () => { return deferred.promise; function onmessage(message: Message) { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const testid = (message.attributes as any).testid; if (!testid) { @@ -858,7 +855,6 @@ describe('pubsub', () => { let subscription: Subscription; let snapshot: Snapshot; let messageId: string; - const snapshotName = generateSnapshotName(); beforeEach(async () => { subscription = topic.subscription(generateSubName()); @@ -903,7 +899,7 @@ describe('pubsub', () => { subscription.on('error', done); subscription.on( 'message', - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (message: {id: string; ack: () => void; publishTime: any}) => { if (message.id !== messageId) { return; diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml deleted file mode 100644 index 46afd9525..000000000 --- a/test/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - node/no-missing-require: off diff --git a/test/histogram.ts b/test/histogram.ts index fdd31d367..8a32be791 100644 --- a/test/histogram.ts +++ b/test/histogram.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach} from 'mocha'; import {Histogram} from '../src/histogram.js'; describe('Histogram', () => { diff --git a/test/iam.ts b/test/iam.ts index 183634c19..0bc0dfa87 100644 --- a/test/iam.ts +++ b/test/iam.ts @@ -14,7 +14,7 @@ import * as promisify from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach} from 'mocha'; import * as proxyquire from 'proxyquire'; import * as iamTypes from '../src/iam'; @@ -116,7 +116,7 @@ describe('IAM', () => { it('should throw an error if a policy is not supplied', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (iam as any).setPolicy(util.noop); }, /A policy object is required\./); }); @@ -149,7 +149,7 @@ describe('IAM', () => { describe('testPermissions', () => { it('should throw an error if permissions are missing', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (iam as any).testPermissions(util.noop); }, /Permissions are required\./); }); diff --git a/test/lease-manager.ts b/test/lease-manager.ts index 2f535ac1f..93d210595 100644 --- a/test/lease-manager.ts +++ b/test/lease-manager.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -33,7 +33,7 @@ class FakeSubscriber extends EventEmitter { ackDeadline = 10; isOpen = true; modAckLatency = 2000; - async modAck(message: FakeMessage, deadline: number): Promise {} + async modAck(): Promise {} } class FakeMessage { @@ -42,7 +42,7 @@ class FakeMessage { constructor() { this.received = Date.now(); } - modAck(deadline: number): void {} + modAck(): void {} } describe('LeaseManager', () => { @@ -79,8 +79,7 @@ describe('LeaseManager', () => { it('should capture any options passed in', () => { const fakeOptions = {}; const stub = sandbox.stub(LeaseManager.prototype, 'setOptions'); - const manager = new LeaseManager(subscriber, fakeOptions); - + new LeaseManager(subscriber, fakeOptions); const [options] = stub.lastCall.args; assert.strictEqual(options, fakeOptions); }); @@ -90,8 +89,8 @@ describe('LeaseManager', () => { it('should return the number of pending messages', () => { leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); - leaseManager.add(new FakeMessage() as Message); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add((new FakeMessage() as {}) as Message); assert.strictEqual(leaseManager.pending, 1); }); @@ -99,8 +98,8 @@ describe('LeaseManager', () => { describe('size', () => { it('should return the number of messages', () => { - leaseManager.add(new FakeMessage() as Message); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add((new FakeMessage() as {}) as Message); assert.strictEqual(leaseManager.size, 2); }); @@ -108,7 +107,7 @@ describe('LeaseManager', () => { describe('add', () => { it('should update the bytes/size values', () => { - const message = new FakeMessage() as Message; + const message = (new FakeMessage() as {}) as Message; leaseManager.add(message); @@ -117,7 +116,7 @@ describe('LeaseManager', () => { }); it('should dispatch the message if allowExcessMessages is true', done => { - const fakeMessage = new FakeMessage() as Message; + const fakeMessage = (new FakeMessage() as {}) as Message; leaseManager.isFull = () => true; leaseManager.setOptions({allowExcessMessages: true}); @@ -131,7 +130,7 @@ describe('LeaseManager', () => { }); it('should dispatch the message if the inventory is not full', done => { - const fakeMessage = new FakeMessage() as Message; + const fakeMessage = (new FakeMessage() as {}) as Message; leaseManager.isFull = () => false; leaseManager.setOptions({allowExcessMessages: false}); @@ -145,7 +144,7 @@ describe('LeaseManager', () => { }); it('should not dispatch the message if the inventory is full', done => { - const fakeMessage = new FakeMessage() as Message; + const fakeMessage = (new FakeMessage() as {}) as Message; leaseManager.isFull = () => true; leaseManager.setOptions({allowExcessMessages: false}); @@ -159,7 +158,7 @@ describe('LeaseManager', () => { }); it('should not dispatch the message if the sub closes', done => { - const fakeMessage = new FakeMessage() as Message; + const fakeMessage = (new FakeMessage() as {}) as Message; leaseManager.isFull = () => false; @@ -176,7 +175,7 @@ describe('LeaseManager', () => { leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); leaseManager.on('full', done); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); }); describe('extending deadlines', () => { @@ -197,7 +196,7 @@ describe('LeaseManager', () => { }); it('should schedule a lease extension', () => { - const message = new FakeMessage() as Message; + const message = (new FakeMessage() as {}) as Message; const stub = sandbox .stub(message, 'modAck') .withArgs(subscriber.ackDeadline); @@ -215,13 +214,12 @@ describe('LeaseManager', () => { // since only 1 timeout should be set, even if add messages at different // times, they should all get extended at the same time messages.forEach(message => { - leaseManager.add(message as Message); + leaseManager.add((message as {}) as Message); clock.tick(halfway); }); messages.forEach((fakeMessage, i) => { - const [deadline] = stubs[i].lastCall.args; - + const [deadline] = (stubs[i].lastCall.args as {}) as [number]; assert.strictEqual(deadline, subscriber.ackDeadline); }); }); @@ -231,7 +229,9 @@ describe('LeaseManager', () => { const badMessages = [new FakeMessage(), new FakeMessage()]; leaseManager.setOptions({maxExtension}); - badMessages.forEach(message => leaseManager.add(message as Message)); + badMessages.forEach(message => + leaseManager.add((message as {}) as Message) + ); clock.tick(halfway); // only message that shouldn't be forgotten @@ -239,7 +239,7 @@ describe('LeaseManager', () => { const removeStub = sandbox.stub(leaseManager, 'remove'); const modAckStub = sandbox.stub(goodMessage, 'modAck'); - leaseManager.add(goodMessage as Message); + leaseManager.add((goodMessage as {}) as Message); clock.tick(halfway); // make sure the expired messages were forgotten @@ -250,17 +250,18 @@ describe('LeaseManager', () => { assert.strictEqual(message, fakeMessage); }); - const [deadline] = modAckStub.lastCall.args; + const [deadline] = (modAckStub.lastCall.args as {}) as [number]; assert.strictEqual(deadline, subscriber.ackDeadline); }); it('should continuously extend the deadlines', () => { const message = new FakeMessage(); - const stub = sandbox + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const stub = (sandbox as any) .stub(message, 'modAck') .withArgs(subscriber.ackDeadline); - leaseManager.add(message as Message); + leaseManager.add((message as {}) as Message); clock.tick(expectedTimeout); assert.strictEqual(stub.callCount, 1); @@ -272,8 +273,8 @@ describe('LeaseManager', () => { describe('clear', () => { it('should completely clear out the inventory', () => { - leaseManager.add(new FakeMessage() as Message); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add((new FakeMessage() as {}) as Message); leaseManager.clear(); assert.strictEqual(leaseManager.bytes, 0); @@ -282,7 +283,7 @@ describe('LeaseManager', () => { it('should emit the free event if it was full', done => { leaseManager.setOptions({maxMessages: 1}); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); leaseManager.on('free', done); setImmediate(() => leaseManager.clear()); @@ -292,7 +293,7 @@ describe('LeaseManager', () => { const clock = sandbox.useFakeTimers(); const stub = sandbox.stub(subscriber, 'modAck').resolves(); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); leaseManager.clear(); // this would otherwise trigger a minimum of 2 modAcks @@ -307,8 +308,8 @@ describe('LeaseManager', () => { const maxMessages = 1; leaseManager.setOptions({maxMessages}); - leaseManager.add(new FakeMessage() as Message); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add((new FakeMessage() as {}) as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -318,7 +319,7 @@ describe('LeaseManager', () => { const maxBytes = message.length - 1; leaseManager.setOptions({maxBytes}); - leaseManager.add(message as Message); + leaseManager.add((message as {}) as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -329,7 +330,7 @@ describe('LeaseManager', () => { const maxBytes = message.length + 1; leaseManager.setOptions({maxMessages, maxBytes}); - leaseManager.add(message as Message); + leaseManager.add((message as {}) as Message); assert.strictEqual(leaseManager.isFull(), false); }); @@ -339,15 +340,15 @@ describe('LeaseManager', () => { it('should noop for unknown messages', () => { const message = new FakeMessage(); - leaseManager.add(message as Message); - leaseManager.remove(new FakeMessage() as Message); + leaseManager.add((message as {}) as Message); + leaseManager.remove((new FakeMessage() as {}) as Message); assert.strictEqual(leaseManager.size, 1); assert.strictEqual(leaseManager.bytes, message.length); }); it('should update the bytes/size values', () => { - const message = new FakeMessage() as Message; + const message = (new FakeMessage() as {}) as Message; leaseManager.add(message); leaseManager.remove(message); @@ -357,7 +358,7 @@ describe('LeaseManager', () => { }); it('should emit the free event if there is free space', done => { - const message = new FakeMessage() as Message; + const message = (new FakeMessage() as {}) as Message; leaseManager.setOptions({maxMessages: 1}); leaseManager.add(message); @@ -370,7 +371,7 @@ describe('LeaseManager', () => { }); it('should remove a message from the pending state', done => { - const pending = new FakeMessage() as Message; + const pending = (new FakeMessage() as {}) as Message; leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); @@ -380,7 +381,7 @@ describe('LeaseManager', () => { } }); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); leaseManager.add(pending); leaseManager.remove(pending); @@ -389,8 +390,8 @@ describe('LeaseManager', () => { }); it('should dispense a pending messages', done => { - const temp = new FakeMessage() as Message; - const pending = new FakeMessage() as Message; + const temp = (new FakeMessage() as {}) as Message; + const pending = (new FakeMessage() as {}) as Message; leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); @@ -411,7 +412,7 @@ describe('LeaseManager', () => { it('should cancel any extensions if no messages are left', () => { const clock = sandbox.useFakeTimers(); - const message = new FakeMessage() as Message; + const message = (new FakeMessage() as {}) as Message; const stub = sandbox.stub(subscriber, 'modAck').resolves(); leaseManager.add(message); @@ -427,7 +428,7 @@ describe('LeaseManager', () => { it('should allow excess messages by default', () => {}); it('should default maxBytes', () => { - const littleMessage = new FakeMessage() as Message; + const littleMessage = (new FakeMessage() as {}) as Message; const bigMessage = new FakeMessage(); leaseManager.add(littleMessage); @@ -435,7 +436,7 @@ describe('LeaseManager', () => { leaseManager.remove(littleMessage); bigMessage.length = defaultOptions.subscription.maxOutstandingBytes * 2; - leaseManager.add(bigMessage as Message); + leaseManager.add((bigMessage as {}) as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -446,7 +447,7 @@ describe('LeaseManager', () => { i++ ) { assert.strictEqual(leaseManager.isFull(), false); - leaseManager.add(new FakeMessage() as Message); + leaseManager.add((new FakeMessage() as {}) as Message); } assert.strictEqual(leaseManager.isFull(), true); diff --git a/test/message-queues.ts b/test/message-queues.ts index bb6cb4139..ebb9dfcf5 100644 --- a/test/message-queues.ts +++ b/test/message-queues.ts @@ -15,9 +15,10 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; import {CallOptions} from 'google-gax'; +// eslint-disable-next-line node/no-extraneous-import import {Metadata, ServiceError} from '@grpc/grpc-js'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -68,7 +69,7 @@ describe('MessageQueues', () => { let subscriber: FakeSubscriber; - // tslint:disable-next-line variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let MessageQueue: any; // tslint:disable-next-line variable-name let AckQueue: typeof messageTypes.AckQueue; @@ -112,7 +113,7 @@ describe('MessageQueues', () => { it('should set any provided options', () => { const fakeOptions = {}; const stub = sandbox.stub(MessageQueue.prototype, 'setOptions'); - const mq = new MessageQueue(subscriber, fakeOptions); + new MessageQueue(subscriber, fakeOptions); const [options] = stub.lastCall.args; assert.strictEqual(options, fakeOptions); @@ -327,7 +328,8 @@ describe('MessageQueues', () => { fakeError.code = 2; fakeError.metadata = new Metadata(); - const expectedMessage = `Failed to "acknowledge" for 3 message(s). Reason: Err.`; + const expectedMessage = + 'Failed to "acknowledge" for 3 message(s). Reason: Err.'; sandbox.stub(subscriber.client, 'acknowledge').rejects(fakeError); @@ -451,7 +453,8 @@ describe('MessageQueues', () => { fakeError.code = 2; fakeError.metadata = new Metadata(); - const expectedMessage = `Failed to "modifyAckDeadline" for 3 message(s). Reason: Err.`; + const expectedMessage = + 'Failed to "modifyAckDeadline" for 3 message(s). Reason: Err.'; sandbox.stub(subscriber.client, 'modifyAckDeadline').rejects(fakeError); diff --git a/test/message-stream.ts b/test/message-stream.ts index 6783aa78e..4bc71b22b 100644 --- a/test/message-stream.ts +++ b/test/message-stream.ts @@ -15,7 +15,8 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach, after} from 'mocha'; +// eslint-disable-next-line node/no-extraneous-import import {Metadata, ServiceError} from '@grpc/grpc-js'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -104,6 +105,7 @@ class FakeGrpcStream extends Duplex { _write(chunk: object, encoding: string, callback: Function): void { callback(); } + // eslint-disable-next-line @typescript-eslint/no-unused-vars _read(size: number): void {} } @@ -285,10 +287,7 @@ describe('MessageStream', () => { it('should respect the timeout option', done => { const timeout = 12345; - const expectedDeadline = now + timeout; - messageStream = new MessageStream(subscriber, {timeout}); - setImmediate(() => { assert.strictEqual(client.deadline, now + timeout); done(); @@ -300,9 +299,9 @@ describe('MessageStream', () => { describe('destroy', () => { it('should noop if already destroyed', done => { - const stub = sandbox + sandbox .stub(FakePassThrough.prototype, 'destroy') - .callsFake(function(this: Duplex) { + .callsFake(function (this: Duplex) { if (this === messageStream) { done(); } @@ -354,7 +353,7 @@ describe('MessageStream', () => { before(() => { destroy = FakePassThrough.prototype.destroy; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any FakePassThrough.prototype.destroy = false as any; }); @@ -428,7 +427,7 @@ describe('MessageStream', () => { const stub = sandbox.stub(client, 'waitForReady'); const ms = new MessageStream(subscriber); const fakeError = new Error('err'); - const expectedMessage = `Failed to connect to channel. Reason: err`; + const expectedMessage = 'Failed to connect to channel. Reason: err'; ms.on('error', (err: ServiceError) => { assert.strictEqual(err.code, 2); diff --git a/test/publisher/index.ts b/test/publisher/index.ts index 59d5ae86b..df1208ec5 100644 --- a/test/publisher/index.ts +++ b/test/publisher/index.ts @@ -16,7 +16,7 @@ import * as pfy from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -340,8 +340,6 @@ describe('Publisher', () => { maxMessages: 1001, }, }); - - const expected = 1000; assert.strictEqual(publisher.settings.batching!.maxMessages, 1000); }); }); diff --git a/test/publisher/message-batch.ts b/test/publisher/message-batch.ts index af8349843..402dc39fb 100644 --- a/test/publisher/message-batch.ts +++ b/test/publisher/message-batch.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import {randomBytes} from 'crypto'; import * as sinon from 'sinon'; diff --git a/test/publisher/message-queues.ts b/test/publisher/message-queues.ts index d889bae80..40581a0d3 100644 --- a/test/publisher/message-queues.ts +++ b/test/publisher/message-queues.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import {ServiceError} from '@grpc/grpc-js'; +import {ServiceError} from 'google-gax'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -29,6 +29,7 @@ import {PublishError} from '../../src/publisher/publish-error'; class FakeTopic { name = 'fake-topic'; + // eslint-disable-next-line @typescript-eslint/no-unused-vars request(config: RequestConfig, callback: RequestCallback): void {} } @@ -54,7 +55,9 @@ class FakeMessageBatch { this.messages = []; this.options = options; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars add(message: p.PubsubMessage, callback: p.PublishCallback): void {} + // eslint-disable-next-line @typescript-eslint/no-unused-vars canFit(message: p.PubsubMessage): boolean { return true; } @@ -78,11 +81,9 @@ class FakePublishError { describe('Message Queues', () => { const sandbox = sinon.createSandbox(); - // tslint:disable-next-line no-any variable-name + // eslint-disable-next-line @typescript-eslint/no-explicit-any let MessageQueue: any; - // tslint:disable-next-line variable-name let Queue: typeof q.Queue; - // tslint:disable-next-line variable-name let OrderedQueue: typeof q.OrderedQueue; let topic: FakeTopic; @@ -401,10 +402,7 @@ describe('Message Queues', () => { it('should publish immediately if it cannot fit the message', done => { const addStub = sandbox.stub(batch, 'add'); - sandbox - .stub(batch, 'canFit') - .withArgs(fakeMessage) - .returns(false); + sandbox.stub(batch, 'canFit').withArgs(fakeMessage).returns(false); sandbox .stub(queue, 'publish') .onCall(0) diff --git a/test/publisher/publish-error.ts b/test/publisher/publish-error.ts index 4b31cb7b2..9646feec1 100644 --- a/test/publisher/publish-error.ts +++ b/test/publisher/publish-error.ts @@ -15,7 +15,8 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach} from 'mocha'; +// eslint-disable-next-line node/no-extraneous-import import {ServiceError, Metadata} from '@grpc/grpc-js'; import {PublishError} from '../../src/publisher/publish-error'; diff --git a/test/pubsub.ts b/test/pubsub.ts index 0d5fa3cf1..fae1212aa 100644 --- a/test/pubsub.ts +++ b/test/pubsub.ts @@ -16,9 +16,11 @@ import * as pjy from '@google-cloud/projectify'; import * as promisify from '@google-cloud/promisify'; import arrify = require('arrify'); import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, after, afterEach} from 'mocha'; import * as gax from 'google-gax'; +// eslint-disable-next-line node/no-extraneous-import import * as grpc from '@grpc/grpc-js'; +// eslint-disable-next-line node/no-extraneous-import import {CallOptions, ChannelCredentials, ServiceError} from '@grpc/grpc-js'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -30,6 +32,7 @@ import * as subby from '../src/subscription'; import {Topic} from '../src/topic'; import * as util from '../src/util'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const PKG = require('../../package.json'); const sandbox = sinon.createSandbox(); @@ -38,7 +41,7 @@ sandbox.stub(grpc.credentials, 'createInsecure').returns(fakeCreds); const subscriptionCached = subby.Subscription; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let subscriptionOverride: any; function Subscription( @@ -72,22 +75,22 @@ const fakePromisify = Object.assign({}, promisify, { }); let pjyOverride: Function; -function fakePjy() { - return (pjyOverride || pjy.replaceProjectIdToken).apply(null, arguments); +function fakePjy(...args: Array<{}>) { + return (pjyOverride || pjy.replaceProjectIdToken)(...args); } class FakeSnapshot { - calledWith_: IArguments; - constructor() { - this.calledWith_ = arguments; + calledWith_: Array<{}>; + constructor(...args: Array<{}>) { + this.calledWith_ = args; } } class FakeTopic { - calledWith_: IArguments; + calledWith_: Array<{}>; getSubscriptions?: Function; - constructor() { - this.calledWith_ = arguments; + constructor(...args: Array<{}>) { + this.calledWith_ = args; } } @@ -115,12 +118,12 @@ const fakePaginator = { }; let googleAuthOverride: Function | null; -function fakeGoogleAuth() { - return (googleAuthOverride || util.noop).apply(null, arguments); +function fakeGoogleAuth(...args: Array<{}>) { + return (googleAuthOverride || util.noop)(...args); } const v1Override = {}; -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let v1ClientOverrides: any = {}; function defineOverridableClient(clientName: string) { @@ -157,10 +160,6 @@ describe('PubSub', () => { (err: Error | null): void; } - interface PostCloseTest { - (callback: PostCloseCallback): void; - } - before(() => { delete process.env.PUBSUB_EMULATOR_HOST; PubSub = proxyquire('../src/pubsub', { @@ -323,14 +322,14 @@ describe('PubSub', () => { it('should throw if no Topic is provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pubsub as any).createSubscription(); }, /A Topic is required for a new subscription\./); }); it('should throw if no subscription name is provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pubsub as any).createSubscription(TOPIC_NAME); }, /A subscription name is required./); }); @@ -347,7 +346,7 @@ describe('PubSub', () => { pubsub.request = (config, callback: Function) => { callback(null, apiResponse); }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pubsub as any).createSubscription(TOPIC, SUB_NAME, undefined, done); }); @@ -780,7 +779,7 @@ describe('PubSub', () => { return snapshot as Snapshot; }); - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pubsub.getSnapshots((err: any, snapshots: any) => { assert.ifError(err); assert.strictEqual(snapshots![0], snapshot); @@ -1006,7 +1005,7 @@ describe('PubSub', () => { return topic as Topic; }; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pubsub.getTopics((err: any, topics: any) => { assert.ifError(err); assert.strictEqual(topics![0], topic); @@ -1050,7 +1049,7 @@ describe('PubSub', () => { getProjectId: () => Promise.resolve(PROJECT_ID), }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pjyOverride = (reqOpts: any) => { return reqOpts; }; @@ -1094,7 +1093,7 @@ describe('PubSub', () => { it('should call client method with correct options', done => { const fakeClient = {}; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeClient as any).fakeMethod = (reqOpts: any, gaxOpts: CallOptions) => { assert.deepStrictEqual(CONFIG.reqOpts, reqOpts); assert.deepStrictEqual(CONFIG.gaxOpts, gaxOpts); @@ -1107,7 +1106,7 @@ describe('PubSub', () => { }); it('should replace the project id token on reqOpts', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pjyOverride = (reqOpts: any, projectId: string) => { assert.deepStrictEqual(reqOpts, CONFIG.reqOpts); assert.strictEqual(projectId, PROJECT_ID); @@ -1118,6 +1117,7 @@ describe('PubSub', () => { }); describe('getClientAsync_', () => { + // eslint-disable-next-line @typescript-eslint/class-name-casing const FAKE_CLIENT_INSTANCE = class { close() {} }; @@ -1207,7 +1207,7 @@ describe('PubSub', () => { let numTimesFakeClientInstantiated = 0; // tslint:disable-next-line only-arrow-functions - v1ClientOverrides.FakeClient = function() { + v1ClientOverrides.FakeClient = function () { numTimesFakeClientInstantiated++; return FAKE_CLIENT_INSTANCE; }; @@ -1221,7 +1221,7 @@ describe('PubSub', () => { it('should return the correct client', async () => { // tslint:disable-next-line only-arrow-functions no-any - v1ClientOverrides.FakeClient = function( + v1ClientOverrides.FakeClient = function ( options: pubsubTypes.ClientConfig ) { assert.strictEqual(options, pubsub.options); @@ -1276,7 +1276,7 @@ describe('PubSub', () => { }; beforeEach(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pjyOverride = (reqOpts: any) => { return reqOpts; }; @@ -1309,7 +1309,7 @@ describe('PubSub', () => { }); it('should replace the project id token on reqOpts', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any pjyOverride = (reqOpts: any, projectId: string) => { assert.deepStrictEqual(reqOpts, CONFIG.reqOpts); assert.strictEqual(projectId, PROJECT_ID); @@ -1334,7 +1334,7 @@ describe('PubSub', () => { }; const fakeClient = { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any fakeMethod(reqOpts: any, gaxOpts: CallOptions) { assert.strictEqual(reqOpts, replacedReqOpts); assert.strictEqual(gaxOpts, CONFIG.gaxOpts); @@ -1353,7 +1353,7 @@ describe('PubSub', () => { describe('snapshot', () => { it('should throw if a name is not provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pubsub as any).snapshot(); }, /You must supply a valid name for the snapshot\./); }); @@ -1375,14 +1375,14 @@ describe('PubSub', () => { it('should return a Subscription object', () => { // tslint:disable-next-line only-arrow-functions - subscriptionOverride = function() {}; + subscriptionOverride = function () {}; const subscription = pubsub.subscription(SUB_NAME, {}); assert(subscription instanceof subscriptionOverride); }); it('should pass specified name to the Subscription', done => { // tslint:disable-next-line only-arrow-functions - subscriptionOverride = function( + subscriptionOverride = function ( pubsub: pubsubTypes.PubSub, name: string ) { @@ -1394,7 +1394,7 @@ describe('PubSub', () => { it('should honor settings', done => { // tslint:disable-next-line only-arrow-functions - subscriptionOverride = function( + subscriptionOverride = function ( pubsub: pubsubTypes.PubSub, name: string, options: subby.SubscriptionOptions @@ -1407,7 +1407,7 @@ describe('PubSub', () => { it('should throw if a name is not provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any return (pubsub as any).subscription(); }, /A name must be specified for a subscription\./); }); @@ -1416,7 +1416,7 @@ describe('PubSub', () => { describe('topic', () => { it('should throw if a name is not provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pubsub as any).topic(); }, /A name must be specified for a topic\./); }); diff --git a/test/pull-retry.ts b/test/pull-retry.ts index 3c1c88efb..2a1ba3c82 100644 --- a/test/pull-retry.ts +++ b/test/pull-retry.ts @@ -12,8 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import assert = require('assert'); -import sinon = require('sinon'); +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {describe, it, beforeEach, afterEach} from 'mocha'; +// eslint-disable-next-line node/no-extraneous-import import {StatusObject, status} from '@grpc/grpc-js'; import {PullRetry} from '../src/pull-retry'; diff --git a/test/snapshot.ts b/test/snapshot.ts index bb6b58a66..0465a1adf 100644 --- a/test/snapshot.ts +++ b/test/snapshot.ts @@ -14,14 +14,13 @@ import * as pfy from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, before, after, afterEach} from 'mocha'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; import {PubSub, RequestConfig} from '../src/pubsub'; import * as snapTypes from '../src/snapshot'; import {Subscription} from '../src/subscription'; -import * as util from '../src/util'; let promisified = false; const fakePromisify = Object.assign({}, pfy, { diff --git a/test/subscriber.ts b/test/subscriber.ts index f4f623d2d..2c9c64b9a 100644 --- a/test/subscriber.ts +++ b/test/subscriber.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; import {common as protobuf} from 'protobufjs'; import * as proxyquire from 'proxyquire'; @@ -191,7 +191,7 @@ describe('Subscriber', () => { it('should set any options passed in', () => { const stub = sandbox.stub(Subscriber.prototype, 'setOptions'); const fakeOptions = {}; - const sub = new Subscriber(subscription, fakeOptions); + new Subscriber(subscription, fakeOptions); const [options] = stub.lastCall.args; assert.strictEqual(options, fakeOptions); @@ -203,10 +203,7 @@ describe('Subscriber', () => { const latencies: FakeHistogram = stubs.get('latencies'); const fakeLatency = 234; - sandbox - .stub(latencies, 'percentile') - .withArgs(99) - .returns(fakeLatency); + sandbox.stub(latencies, 'percentile').withArgs(99).returns(fakeLatency); const maxMilliseconds = stubs.get('modAckQueue').maxMilliseconds; const expectedLatency = fakeLatency * 1000 + maxMilliseconds; @@ -255,10 +252,7 @@ describe('Subscriber', () => { const fakeDeadline = 312123; - sandbox - .stub(histogram, 'percentile') - .withArgs(99) - .returns(fakeDeadline); + sandbox.stub(histogram, 'percentile').withArgs(99).returns(fakeDeadline); subscriber.ack(message); diff --git a/test/subscription.ts b/test/subscription.ts index 9b751ae05..582479097 100644 --- a/test/subscription.ts +++ b/test/subscription.ts @@ -14,9 +14,9 @@ import * as pfy from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import {EventEmitter} from 'events'; -import {ServiceError} from '@grpc/grpc-js'; +import {ServiceError} from 'google-gax'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -43,6 +43,7 @@ const fakePromisify = Object.assign({}, pfy, { class FakeIAM { calledWith_: IArguments; constructor() { + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } @@ -51,6 +52,7 @@ class FakeSnapshot { calledWith_: IArguments; static formatName_?: Function; constructor() { + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } @@ -62,6 +64,7 @@ class FakeSubscriber extends EventEmitter { isOpen = false; constructor() { super(); + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; subscriber = this; } @@ -71,6 +74,7 @@ class FakeSubscriber extends EventEmitter { async close(): Promise { this.isOpen = false; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars setOptions(options: SubscriberOptions): void {} } @@ -126,7 +130,7 @@ describe('Subscription', () => { }; const subscription = new Subscription(PUBSUB, SUB_NAME); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (subscription as any).request(assert.ifError); }); @@ -423,7 +427,7 @@ describe('Subscription', () => { it('should throw an error if a snapshot name is not found', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (subscription as any).createSnapshot(); }, /A name is required to create a snapshot\./); }); @@ -568,7 +572,7 @@ describe('Subscription', () => { }); it('should not remove all the listeners', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (subscription as any).removeAllListeners = () => { done(new Error('Should not be called.')); }; @@ -632,7 +636,7 @@ describe('Subscription', () => { }; sandbox.stub(subscription, 'getMetadata').callsFake(gaxOpts => { assert.strictEqual(gaxOpts, options); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.strictEqual((gaxOpts as typeof options).autoCreate, undefined); done(); }); @@ -857,7 +861,7 @@ describe('Subscription', () => { it('should throw if a name or date is not provided', () => { assert.throws(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (subscription as any).seek(); }, /Either a snapshot name or Date is needed to seek to\./); }); @@ -965,7 +969,6 @@ describe('Subscription', () => { assert.strictEqual(config.gaxOpts, gaxOpts); done(); }; - subscription.setMetadata(METADATA, gaxOpts, done); }); }); @@ -974,9 +977,7 @@ describe('Subscription', () => { it('should pass the options to the subscriber', () => { const options = {}; const stub = sandbox.stub(subscriber, 'setOptions').withArgs(options); - subscription.setOptions(options); - assert.strictEqual(stub.callCount, 1); }); }); @@ -985,8 +986,8 @@ describe('Subscription', () => { const SNAPSHOT_NAME = 'a'; it('should call through to pubsub.snapshot', done => { - // tslint:disable-next-line no-any - (PUBSUB as any).snapshot = function(name: string) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (PUBSUB as any).snapshot = function (name: string) { assert.strictEqual(this, subscription); assert.strictEqual(name, SNAPSHOT_NAME); done(); diff --git a/test/topic.ts b/test/topic.ts index 07fd5363a..858ad9104 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -14,9 +14,8 @@ import * as pfy from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; -import {CallOptions} from 'google-gax'; -import {ServiceError} from '@grpc/grpc-js'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; +import {CallOptions, ServiceError} from 'google-gax'; import * as proxyquire from 'proxyquire'; import * as sinon from 'sinon'; @@ -84,16 +83,16 @@ const fakePaginator = { }; describe('Topic', () => { - // tslint:disable-next-line no-any variable-name + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Topic: any; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let topic: typeof Topic; const PROJECT_ID = 'test-project'; const TOPIC_NAME = 'projects/' + PROJECT_ID + '/topics/test-topic'; const TOPIC_UNFORMATTED_NAME = TOPIC_NAME.split('/').pop(); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const PUBSUB: any = { Promise: {}, projectId: PROJECT_ID, @@ -264,7 +263,7 @@ describe('Topic', () => { topic.getMetadata = (gaxOpts: CallOptions) => { assert.strictEqual(gaxOpts, options); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.strictEqual((gaxOpts as any).autoCreate, undefined); done(); }; @@ -559,13 +558,13 @@ describe('Topic', () => { const apiResponse_ = {}; topic.request = - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (config: RequestConfig, callback: (...args: any[]) => void) => { callback(err_, subs_, nextQuery_, apiResponse_); }; topic.getSubscriptions( - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (err: Error, subs: boolean, nextQuery: any, apiResponse: any) => { assert.strictEqual(err, err_); assert.deepStrictEqual(subs, subs_); diff --git a/tsconfig.json b/tsconfig.json index c78f1c884..613d35597 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "outDir": "build", "resolveJsonModule": true, "lib": [ - "es2018", + "es2016", "dom" ] }, diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 617dc975b..000000000 --- a/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gts/tslint.json" -} diff --git a/webpack.config.js b/webpack.config.js index c53b4c466..16a13980c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -36,27 +36,27 @@ module.exports = { { test: /\.tsx?$/, use: 'ts-loader', - exclude: /node_modules/ + exclude: /node_modules/, }, { test: /node_modules[\\/]@grpc[\\/]grpc-js/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]grpc/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]retry-request/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]https?-proxy-agent/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]gtoken/, - use: 'null-loader' + use: 'null-loader', }, ], },