From b80c025f106052fd25554c64314b3b3520e829b5 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sat, 11 Apr 2020 22:12:29 -0700 Subject: [PATCH] build!: drop support for node.js 8.x --- .eslintrc.yml | 15 -- .prettierrc | 8 - conformance-test/v4SignedUrl.ts | 2 +- package.json | 20 +- samples/deleteFile.js | 5 +- samples/deleteNotification.js | 5 +- samples/disableRequesterPays.js | 2 +- samples/downloadEncryptedFile.js | 4 +- samples/downloadFile.js | 5 +- samples/downloadFileUsingRequesterPays.js | 7 +- samples/enableRequesterPays.js | 2 +- samples/getRequesterPaysStatus.js | 6 +- samples/hmacKeyActivate.js | 4 +- samples/hmacKeyCreate.js | 4 +- samples/hmacKeyDeactivate.js | 4 +- samples/hmacKeyDelete.js | 2 +- samples/hmacKeyGet.js | 2 +- samples/makePublic.js | 5 +- samples/moveFile.js | 5 +- samples/notifications.js | 41 ++- samples/printFileAcl.js | 5 +- samples/releaseEventBasedHold.js | 9 +- samples/releaseTemporaryHold.js | 9 +- samples/rotateEncryptionKey.js | 2 +- samples/setEventBasedHold.js | 9 +- samples/setTemporarydHold.js | 9 +- samples/system-test/buckets.test.js | 12 +- samples/system-test/encryption.test.js | 10 +- samples/system-test/hmacKey.test.js | 6 +- samples/system-test/iam.test.js | 6 +- samples/system-test/requesterPays.test.js | 12 +- samples/uploadEncryptedFile.js | 4 +- samples/viewBucketIamMembers.js | 4 +- src/acl.ts | 6 +- src/bucket.ts | 22 +- src/file.ts | 45 ++-- src/iam.ts | 5 +- src/notification.ts | 2 +- src/signer.ts | 6 +- src/storage.ts | 3 +- src/util.ts | 7 +- system-test/storage.ts | 73 +++--- test/acl.ts | 13 +- test/bucket.ts | 99 +++---- test/channel.ts | 8 +- test/file.ts | 300 ++++++++++------------ test/hmacKey.ts | 23 +- test/iam.ts | 8 +- test/index.ts | 17 +- test/notification.ts | 7 +- test/signer.ts | 28 +- tslint.json | 3 - 52 files changed, 388 insertions(+), 532 deletions(-) delete mode 100644 .eslintrc.yml delete mode 100644 .prettierrc delete mode 100644 tslint.json 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/.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/conformance-test/v4SignedUrl.ts b/conformance-test/v4SignedUrl.ts index 55453609c..f263ddd45 100644 --- a/conformance-test/v4SignedUrl.ts +++ b/conformance-test/v4SignedUrl.ts @@ -92,7 +92,7 @@ const testFile = fs.readFileSync( 'utf-8' ); -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any const testCases = JSON.parse(testFile); const v4SignedUrlCases: V4SignedURLTestCase[] = testCases.signingV4Tests; const v4SignedPolicyCases: V4SignedPolicyTestCase[] = diff --git a/package.json b/package.json index e1a1944f7..9e412a057 100644 --- a/package.json +++ b/package.json @@ -5,17 +5,14 @@ "license": "Apache-2.0", "author": "Google Inc.", "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "repository": "googleapis/nodejs-storage", "main": "./build/src/index.js", "types": "./build/src/index.d.ts", "files": [ "build/src", - "!build/src/**/*.map", - "AUTHORS", - "CONTRIBUTORS", - "COPYING" + "!build/src/**/*.map" ], "keywords": [ "google apis client", @@ -38,13 +35,13 @@ "presystem-test": "npm run compile", "test": "c8 mocha build/test", "pretest": "npm run compile", - "lint": "eslint samples/ && gts check", + "lint": "gts check", "samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../", "all-test": "npm test && npm run system-test && npm run samples-test", "check": "gts check", "clean": "gts clean", "compile": "tsc -p .", - "fix": "gts fix && eslint --fix '**/*.js'", + "fix": "gts fix", "prepare": "npm run compile", "docs-test": "linkinator docs", "predocs-test": "npm run docs", @@ -98,13 +95,9 @@ "@types/xdg-basedir": "^2.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", "form-data": "^3.0.0", "grpc": "^1.22.2", - "gts": "^1.0.0", + "gts": "^2.0.0", "jsdoc": "^3.6.2", "jsdoc-fresh": "^1.0.1", "jsdoc-region-tag": "^1.0.2", @@ -113,11 +106,10 @@ "nock": "~12.0.0", "node-fetch": "^2.2.0", "normalize-newline": "^3.0.0", - "prettier": "^1.7.0", "proxyquire": "^2.1.3", "sinon": "^9.0.0", "tmp": "^0.1.0", - "typescript": "3.6.4", + "typescript": "^3.8.3", "uuid": "^7.0.0", "yargs": "^15.0.0" } diff --git a/samples/deleteFile.js b/samples/deleteFile.js index 196e0023d..85035665c 100644 --- a/samples/deleteFile.js +++ b/samples/deleteFile.js @@ -36,10 +36,7 @@ function main(bucketName = 'my-bucket', filename = 'test.txt') { async function deleteFile() { // Deletes the file from the bucket - await storage - .bucket(bucketName) - .file(filename) - .delete(); + await storage.bucket(bucketName).file(filename).delete(); console.log(`gs://${bucketName}/${filename} deleted.`); } diff --git a/samples/deleteNotification.js b/samples/deleteNotification.js index 242fd7aee..8a9e5b9b5 100644 --- a/samples/deleteNotification.js +++ b/samples/deleteNotification.js @@ -36,10 +36,7 @@ function main(bucketName = 'my-bucket', notificationId = '1') { async function deleteNotification() { // Deletes the notification from the bucket - await storage - .bucket(bucketName) - .notification(notificationId) - .delete(); + await storage.bucket(bucketName).notification(notificationId).delete(); console.log(`Notification ${notificationId} deleted.`); } diff --git a/samples/disableRequesterPays.js b/samples/disableRequesterPays.js index 31bc8ab26..068744829 100644 --- a/samples/disableRequesterPays.js +++ b/samples/disableRequesterPays.js @@ -29,7 +29,7 @@ function main(bucketName = 'my-bucket') { // const bucketName = 'Name of a bucket, e.g. my-bucket'; // Imports the Google Cloud client library - const {Storage} = require(`@google-cloud/storage`); + const {Storage} = require('@google-cloud/storage'); // Creates a client const storage = new Storage(); diff --git a/samples/downloadEncryptedFile.js b/samples/downloadEncryptedFile.js index 056cf9ddf..8dfc533c0 100644 --- a/samples/downloadEncryptedFile.js +++ b/samples/downloadEncryptedFile.js @@ -24,8 +24,8 @@ const path = require('path'); function main( bucketName = 'my-bucket', - srcFilename = path.join(__dirname, `../resources`, 'test.txt'), - destFilename = `test.txt`, + srcFilename = path.join(__dirname, '../resources', 'test.txt'), + destFilename = 'test.txt', key = process.env.GOOGLE_CLOUD_KMS_KEY_US ) { // [START storage_download_encrypted_file] diff --git a/samples/downloadFile.js b/samples/downloadFile.js index 1f513426e..7cb27d65a 100644 --- a/samples/downloadFile.js +++ b/samples/downloadFile.js @@ -48,10 +48,7 @@ function main( }; // Downloads the file - await storage - .bucket(bucketName) - .file(srcFilename) - .download(options); + await storage.bucket(bucketName).file(srcFilename).download(options); console.log( `gs://${bucketName}/${srcFilename} downloaded to ${destFilename}.` diff --git a/samples/downloadFileUsingRequesterPays.js b/samples/downloadFileUsingRequesterPays.js index ced70e02c..d8ea117ea 100644 --- a/samples/downloadFileUsingRequesterPays.js +++ b/samples/downloadFileUsingRequesterPays.js @@ -40,7 +40,7 @@ function main( // const destFilename = 'Local destination of file, e.g. ./local/path/to/file.txt'; // Imports the Google Cloud client library - const {Storage} = require(`@google-cloud/storage`); + const {Storage} = require('@google-cloud/storage'); // Creates a client const storage = new Storage(); @@ -55,10 +55,7 @@ function main( }; // Downloads the file - await storage - .bucket(bucketName) - .file(srcFilename) - .download(options); + await storage.bucket(bucketName).file(srcFilename).download(options); console.log( `gs://${bucketName}/${srcFilename} downloaded to ${destFilename} using requester-pays requests.` diff --git a/samples/enableRequesterPays.js b/samples/enableRequesterPays.js index 800107b22..a93c3a513 100644 --- a/samples/enableRequesterPays.js +++ b/samples/enableRequesterPays.js @@ -28,7 +28,7 @@ function main(bucketName = 'my-bucket') { // const bucketName = 'Name of a bucket, e.g. my-bucket'; // Imports the Google Cloud client library - const {Storage} = require(`@google-cloud/storage`); + const {Storage} = require('@google-cloud/storage'); // Creates a client const storage = new Storage(); diff --git a/samples/getRequesterPaysStatus.js b/samples/getRequesterPaysStatus.js index 049716f8e..2ba1213c7 100644 --- a/samples/getRequesterPaysStatus.js +++ b/samples/getRequesterPaysStatus.js @@ -28,7 +28,7 @@ function main(bucketName = 'my-bucket') { // const bucketName = 'Name of a bucket, e.g. my-bucket'; // Imports the Google Cloud client library - const {Storage} = require(`@google-cloud/storage`); + const {Storage} = require('@google-cloud/storage'); // Creates a client const storage = new Storage(); @@ -39,9 +39,9 @@ function main(bucketName = 'my-bucket') { let status; if (metadata && metadata.billing && metadata.billing.requesterPays) { - status = `enabled`; + status = 'enabled'; } else { - status = `disabled`; + status = 'disabled'; } console.log( `Requester-pays requests are ${status} for bucket ${bucketName}.` diff --git a/samples/hmacKeyActivate.js b/samples/hmacKeyActivate.js index c1b06aaa5..40ecb9ec7 100644 --- a/samples/hmacKeyActivate.js +++ b/samples/hmacKeyActivate.js @@ -41,8 +41,8 @@ function main( const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); const [hmacKeyMetadata] = await hmacKey.setMetadata({state: 'ACTIVE'}); - console.log(`The HMAC key is now active.`); - console.log(`The HMAC key metadata is:`); + console.log('The HMAC key is now active.'); + console.log('The HMAC key metadata is:'); for (const [key, value] of Object.entries(hmacKeyMetadata)) { console.log(`${key}: ${value}`); } diff --git a/samples/hmacKeyCreate.js b/samples/hmacKeyCreate.js index d359fb6f8..cc399a0bf 100644 --- a/samples/hmacKeyCreate.js +++ b/samples/hmacKeyCreate.js @@ -43,8 +43,8 @@ function main( }); console.log(`The base64 encoded secret is: ${secret}`); - console.log(`Do not miss that secret, there is no API to recover it.`); - console.log(`The HMAC key metadata is:`); + console.log('Do not miss that secret, there is no API to recover it.'); + console.log('The HMAC key metadata is:'); for (const [key, value] of Object.entries(hmacKey.metadata)) { console.log(`${key}: ${value}`); } diff --git a/samples/hmacKeyDeactivate.js b/samples/hmacKeyDeactivate.js index 33374519a..bc16a23f1 100644 --- a/samples/hmacKeyDeactivate.js +++ b/samples/hmacKeyDeactivate.js @@ -41,8 +41,8 @@ function main( const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); const [hmacKeyMetadata] = await hmacKey.setMetadata({state: 'INACTIVE'}); - console.log(`The HMAC key is now inactive.`); - console.log(`The HMAC key metadata is:`); + console.log('The HMAC key is now inactive.'); + console.log('The HMAC key metadata is:'); for (const [key, value] of Object.entries(hmacKeyMetadata)) { console.log(`${key}: ${value}`); } diff --git a/samples/hmacKeyDelete.js b/samples/hmacKeyDelete.js index 4a49e3db8..7d752b772 100644 --- a/samples/hmacKeyDelete.js +++ b/samples/hmacKeyDelete.js @@ -42,7 +42,7 @@ function main( await hmacKey.delete(); console.log( - `The key is deleted, though it may still appear in getHmacKeys() results.` + 'The key is deleted, though it may still appear in getHmacKeys() results.' ); } // [END storage_delete_hmac_key] diff --git a/samples/hmacKeyGet.js b/samples/hmacKeyGet.js index d2f002aad..5bc0d6ba0 100644 --- a/samples/hmacKeyGet.js +++ b/samples/hmacKeyGet.js @@ -42,7 +42,7 @@ function main( // Populate the hmacKey object with metadata from server. await hmacKey.getMetadata(); - console.log(`The HMAC key metadata is:`); + console.log('The HMAC key metadata is:'); for (const [key, value] of Object.entries(hmacKey.metadata)) { console.log(`${key}: ${value}`); } diff --git a/samples/makePublic.js b/samples/makePublic.js index c0b7ba296..6099a30f6 100644 --- a/samples/makePublic.js +++ b/samples/makePublic.js @@ -36,10 +36,7 @@ function main(bucketName = 'my-bucket', filename = 'test.txt') { async function makePublic() { // Makes the file public - await storage - .bucket(bucketName) - .file(filename) - .makePublic(); + await storage.bucket(bucketName).file(filename).makePublic(); console.log(`gs://${bucketName}/${filename} is now public.`); } diff --git a/samples/moveFile.js b/samples/moveFile.js index 00f3aca6b..0c565bcbc 100644 --- a/samples/moveFile.js +++ b/samples/moveFile.js @@ -41,10 +41,7 @@ function main( async function moveFile() { // Moves the file within the bucket - await storage - .bucket(bucketName) - .file(srcFilename) - .move(destFilename); + await storage.bucket(bucketName).file(srcFilename).move(destFilename); console.log( `gs://${bucketName}/${srcFilename} moved to gs://${bucketName}/${destFilename}.` diff --git a/samples/notifications.js b/samples/notifications.js index d1d084f36..e3631c8a1 100644 --- a/samples/notifications.js +++ b/samples/notifications.js @@ -113,59 +113,56 @@ async function deleteNotification(bucketName, notificationId) { // const notificationId = 'ID of notification to delete, e.g. 1'; // Deletes the notification from the bucket - await storage - .bucket(bucketName) - .notification(notificationId) - .delete(); + await storage.bucket(bucketName).notification(notificationId).delete(); console.log(`Notification ${notificationId} deleted.`); // [END storage_delete_notification] } -require(`yargs`) +require('yargs') .demand(1) .command( - `create `, - `Creates a new notification`, + 'create ', + 'Creates a new notification', {}, opts => createNotification(opts.bucketName, opts.topic) ) .command( - `list `, - `Lists notifications for a given bucket.`, + 'list ', + 'Lists notifications for a given bucket.', {}, opts => listNotifications(opts.bucketName) ) .command( - `get-metadata `, - `Gets metadata for a notification.`, + 'get-metadata ', + 'Gets metadata for a notification.', {}, opts => getMetadata(opts.bucketName, opts.notificationId) ) .command( - `delete `, - `Deletes a notification from a bucket.`, + 'delete ', + 'Deletes a notification from a bucket.', {}, opts => deleteNotification(opts.bucketName, opts.notificationId) ) .example( - `node $0 create my-bucket my-topic`, - `Creates a notification subscription.` + 'node $0 create my-bucket my-topic', + 'Creates a notification subscription.' ) .example( - `node $0 list my-bucket`, - `Lists notifications associated with "my-bucket".` + 'node $0 list my-bucket', + 'Lists notifications associated with "my-bucket".' ) .example( - `node $0 get-metadata my-bucket 1`, - `Gets the metadata for notification "1" attached to "my-bucket".` + 'node $0 get-metadata my-bucket 1', + 'Gets the metadata for notification "1" attached to "my-bucket".' ) .example( - `node $0 delete my-bucket 1`, - `Deletes the notification "1" from "my-bucket".` + 'node $0 delete my-bucket 1', + 'Deletes the notification "1" from "my-bucket".' ) .wrap(120) .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/storage/docs`) + .epilogue('For more information, see https://cloud.google.com/storage/docs') .strict() .help().argv; diff --git a/samples/printFileAcl.js b/samples/printFileAcl.js index b3df6ec1f..74120cae0 100644 --- a/samples/printFileAcl.js +++ b/samples/printFileAcl.js @@ -36,10 +36,7 @@ function main(bucketName = 'my-bucket', filename = 'test.txt') { async function printFileAcl() { // Gets the ACL for the file - const [acls] = await storage - .bucket(bucketName) - .file(filename) - .acl.get(); + const [acls] = await storage.bucket(bucketName).file(filename).acl.get(); acls.forEach(acl => { console.log(`${acl.role}: ${acl.entity}`); diff --git a/samples/releaseEventBasedHold.js b/samples/releaseEventBasedHold.js index 135050dcd..65def6507 100644 --- a/samples/releaseEventBasedHold.js +++ b/samples/releaseEventBasedHold.js @@ -35,12 +35,9 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') { const storage = new Storage(); async function releaseEventBasedHold() { - await storage - .bucket(bucketName) - .file(fileName) - .setMetadata({ - eventBasedHold: false, - }); + await storage.bucket(bucketName).file(fileName).setMetadata({ + eventBasedHold: false, + }); console.log(`Event-based hold was released for ${fileName}.`); } diff --git a/samples/releaseTemporaryHold.js b/samples/releaseTemporaryHold.js index 48ad92494..3c015dbfd 100644 --- a/samples/releaseTemporaryHold.js +++ b/samples/releaseTemporaryHold.js @@ -35,12 +35,9 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') { const storage = new Storage(); async function releaseTemporaryHold() { - await storage - .bucket(bucketName) - .file(fileName) - .setMetadata({ - temporaryHold: false, - }); + await storage.bucket(bucketName).file(fileName).setMetadata({ + temporaryHold: false, + }); console.log(`Temporary hold was released for ${fileName}.`); } diff --git a/samples/rotateEncryptionKey.js b/samples/rotateEncryptionKey.js index 8684232db..c87621551 100644 --- a/samples/rotateEncryptionKey.js +++ b/samples/rotateEncryptionKey.js @@ -52,7 +52,7 @@ function main( encryptionKey: Buffer.from(newKey, 'base64'), }); - console.log(`Encryption key rotated successfully.`); + console.log('Encryption key rotated successfully.'); } rotateEncryptionKey().catch(console.error); diff --git a/samples/setEventBasedHold.js b/samples/setEventBasedHold.js index fd7a7224e..7fb1a870f 100644 --- a/samples/setEventBasedHold.js +++ b/samples/setEventBasedHold.js @@ -36,12 +36,9 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') { async function setEventBasedHold() { // Set event-based hold - await storage - .bucket(bucketName) - .file(fileName) - .setMetadata({ - eventBasedHold: true, - }); + await storage.bucket(bucketName).file(fileName).setMetadata({ + eventBasedHold: true, + }); console.log(`Event-based hold was set for ${fileName}.`); } diff --git a/samples/setTemporarydHold.js b/samples/setTemporarydHold.js index 71074419f..b71073c19 100644 --- a/samples/setTemporarydHold.js +++ b/samples/setTemporarydHold.js @@ -35,12 +35,9 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') { const storage = new Storage(); async function setTemporarydHold() { - await storage - .bucket(bucketName) - .file(fileName) - .setMetadata({ - temporaryHold: true, - }); + await storage.bucket(bucketName).file(fileName).setMetadata({ + temporaryHold: true, + }); console.log(`Temporary hold was set for ${fileName}.`); } diff --git a/samples/system-test/buckets.test.js b/samples/system-test/buckets.test.js index d86e92b29..4d8dbf428 100644 --- a/samples/system-test/buckets.test.js +++ b/samples/system-test/buckets.test.js @@ -14,7 +14,7 @@ 'use strict'; -const {Storage} = require(`@google-cloud/storage`); +const {Storage} = require('@google-cloud/storage'); const {assert} = require('chai'); const {after, it} = require('mocha'); const cp = require('child_process'); @@ -39,7 +39,7 @@ it('should create a bucket', async () => { }); it('should list buckets', () => { - const output = execSync(`node listBuckets.js`); + const output = execSync('node listBuckets.js'); assert.match(output, /Buckets:/); assert.match(output, new RegExp(bucketName)); }); @@ -64,7 +64,7 @@ it('should set a buckets default KMS key', async () => { ); }); -it(`should enable a bucket's uniform bucket-level access`, async () => { +it("should enable a bucket's uniform bucket-level access", async () => { const output = execSync( `node enableUniformBucketLevelAccess.js ${bucketName}` ); @@ -80,7 +80,7 @@ it(`should enable a bucket's uniform bucket-level access`, async () => { ); }); -it(`should get a bucket's uniform bucket-level access metadata`, async () => { +it("should get a bucket's uniform bucket-level access metadata", async () => { const output = execSync(`node getUniformBucketLevelAccess.js ${bucketName}`); assert.match( @@ -96,7 +96,7 @@ it(`should get a bucket's uniform bucket-level access metadata`, async () => { ); }); -it(`should disable a bucket's uniform bucket-level access`, async () => { +it("should disable a bucket's uniform bucket-level access", async () => { const output = execSync( `node disableUniformBucketLevelAccess.js ${bucketName}` ); @@ -112,7 +112,7 @@ it(`should disable a bucket's uniform bucket-level access`, async () => { ); }); -it(`should delete a bucket`, async () => { +it('should delete a bucket', async () => { const output = execSync(`node deleteBucket.js ${bucketName}`); assert.match(output, new RegExp(`Bucket ${bucketName} deleted.`)); const [exists] = await bucket.exists(); diff --git a/samples/system-test/encryption.test.js b/samples/system-test/encryption.test.js index e9b665bae..77445745f 100644 --- a/samples/system-test/encryption.test.js +++ b/samples/system-test/encryption.test.js @@ -29,9 +29,9 @@ const storage = new Storage(); const bucketName = `nodejs-storage-samples-${uuid.v4()}`; const bucket = storage.bucket(bucketName); -const fileName = `test.txt`; -const filePath = path.join(__dirname, `../resources`, fileName); -const downloadFilePath = path.join(__dirname, `../resources/downloaded.txt`); +const fileName = 'test.txt'; +const filePath = path.join(__dirname, '../resources', fileName); +const downloadFilePath = path.join(__dirname, '../resources/downloaded.txt'); let key; @@ -48,7 +48,7 @@ after(async () => { }); it('should generate a key', () => { - const output = execSync(`node generateEncryptionKey.js`); + const output = execSync('node generateEncryptionKey.js'); assert.match(output, /Base 64 encoded encryption key:/); const test = /^Base 64 encoded encryption key: ([^\s]+)/; key = output.match(test)[1]; @@ -78,7 +78,7 @@ it('should download a file', () => { }); it('should rotate keys', () => { - let output = execSync(`node generateEncryptionKey.js`); + let output = execSync('node generateEncryptionKey.js'); assert.match(output, /Base 64 encoded encryption key:/); const test = /^Base 64 encoded encryption key: ([^\s]+)/; const newKey = output.match(test)[1]; diff --git a/samples/system-test/hmacKey.test.js b/samples/system-test/hmacKey.test.js index a16cbcd48..9ca156a7e 100644 --- a/samples/system-test/hmacKey.test.js +++ b/samples/system-test/hmacKey.test.js @@ -14,7 +14,7 @@ 'use strict'; -const {Storage} = require(`@google-cloud/storage`); +const {Storage} = require('@google-cloud/storage'); const {assert} = require('chai'); const {before, after, describe, it} = require('mocha'); const cp = require('child_process'); @@ -72,7 +72,7 @@ describe('HMAC SA Key samples', () => { assert.include(output, 'The HMAC key is now active.'); }); - it(`should delete HMAC key`, async () => { + it('should delete HMAC key', async () => { // Deactivate then delete execSync( `node hmacKeyDeactivate.js ${hmacKey.metadata.accessId} ${SERVICE_ACCOUNT_PROJECT}` @@ -82,7 +82,7 @@ describe('HMAC SA Key samples', () => { ); assert.include( output, - `The key is deleted, though it may still appear in getHmacKeys() results.` + 'The key is deleted, though it may still appear in getHmacKeys() results.' ); }); }); diff --git a/samples/system-test/iam.test.js b/samples/system-test/iam.test.js index 054eca818..40d91bc87 100644 --- a/samples/system-test/iam.test.js +++ b/samples/system-test/iam.test.js @@ -69,7 +69,7 @@ it('should add conditional binding to a bucket', async () => { output, `Added the following member(s) with role ${roleName} to ${bucketName}:` ); - assert.include(output, `with condition:`); + assert.include(output, 'with condition:'); assert.include(output, `Title: ${title}`); assert.include(output, `Description: ${description}`); assert.include(output, `Expression: ${expression}`); @@ -79,7 +79,7 @@ it('should list members of a role on a bucket', async () => { const output = execSync(`node viewBucketIamMembers.js ${bucketName}`); assert.match(output, new RegExp(`Bindings for bucket ${bucketName}:`)); assert.match(output, new RegExp(`Role: ${roleName}`)); - assert.match(output, new RegExp(`Members:`)); + assert.match(output, new RegExp('Members:')); assert.match(output, new RegExp(`user:${userEmail}`)); }); @@ -99,5 +99,5 @@ it('should remove conditional binding to a bucket', async () => { const output = execSync( `node removeBucketConditionalBinding.js ${bucketName} ${roleName} '${title}' '${description}' '${expression}'` ); - assert.include(output, `Conditional Binding was removed.`); + assert.include(output, 'Conditional Binding was removed.'); }); diff --git a/samples/system-test/requesterPays.test.js b/samples/system-test/requesterPays.test.js index bd308262c..1da740471 100644 --- a/samples/system-test/requesterPays.test.js +++ b/samples/system-test/requesterPays.test.js @@ -49,7 +49,7 @@ after(async () => { await bucket.delete().catch(console.error); }); -it.skip(`should error on requester-pays requests if they are disabled`, () => { +it.skip('should error on requester-pays requests if they are disabled', () => { const result = execSync( `node downloadFileUsingRequesterPays.js ${projectId} ${bucketName} ${fileName} ${downloadFilePath}` ); @@ -60,7 +60,7 @@ it.skip(`should error on requester-pays requests if they are disabled`, () => { ); }); -it(`should fetch requester-pays status on a default bucket`, () => { +it('should fetch requester-pays status on a default bucket', () => { const out = execSync(`node getRequesterPaysStatus.js ${bucketName}`); assert.include( out, @@ -68,7 +68,7 @@ it(`should fetch requester-pays status on a default bucket`, () => { ); }); -it(`should enable requester-pays requests`, () => { +it('should enable requester-pays requests', () => { const out = execSync(`node enableRequesterPays.js ${bucketName}`); assert.include( out, @@ -76,7 +76,7 @@ it(`should enable requester-pays requests`, () => { ); }); -it(`should fetch requester-pays status on a modified bucket`, () => { +it('should fetch requester-pays status on a modified bucket', () => { const out = execSync(`node getRequesterPaysStatus.js ${bucketName}`); assert.include( out, @@ -84,7 +84,7 @@ it(`should fetch requester-pays status on a modified bucket`, () => { ); }); -it(`should download a file using requester-pays requests`, () => { +it('should download a file using requester-pays requests', () => { const out = execSync( `node downloadFileUsingRequesterPays.js ${projectId} ${bucketName} ${fileName} ${downloadFilePath}` ); @@ -95,7 +95,7 @@ it(`should download a file using requester-pays requests`, () => { fs.statSync(downloadFilePath); }); -it(`should disable requester-pays requests`, () => { +it('should disable requester-pays requests', () => { const out = execSync(`node disableRequesterPays.js ${bucketName}`); assert.include( out, diff --git a/samples/uploadEncryptedFile.js b/samples/uploadEncryptedFile.js index 6b811bcc0..57d22ddd6 100644 --- a/samples/uploadEncryptedFile.js +++ b/samples/uploadEncryptedFile.js @@ -15,8 +15,8 @@ const path = require('path'); function main( bucketName = 'my-bucket', - srcFilename = path.join(__dirname, `../resources`, 'test.txt'), - destFilename = `test.txt`, + srcFilename = path.join(__dirname, '../resources', 'test.txt'), + destFilename = 'test.txt', key = process.env.GOOGLE_CLOUD_KMS_KEY_US ) { // [START storage_upload_encrypted_file] diff --git a/samples/viewBucketIamMembers.js b/samples/viewBucketIamMembers.js index 9954d7f78..08b74f002 100644 --- a/samples/viewBucketIamMembers.js +++ b/samples/viewBucketIamMembers.js @@ -38,7 +38,7 @@ function main(bucketName = 'my-bucket') { console.log(`Bindings for bucket ${bucketName}:`); for (const binding of bindings) { console.log(` Role: ${binding.role}`); - console.log(` Members:`); + console.log(' Members:'); const members = binding.members; for (const member of members) { @@ -47,7 +47,7 @@ function main(bucketName = 'my-bucket') { const condition = binding.condition; if (condition) { - console.log(` Condiiton:`); + console.log(' Condiiton:'); console.log(` Title: ${condition.title}`); console.log(` Description: ${condition.description}`); console.log(` Expression: ${condition.expression}`); diff --git a/src/acl.ts b/src/acl.ts index 31984864a..1240b600b 100644 --- a/src/acl.ts +++ b/src/acl.ts @@ -293,7 +293,7 @@ class AclRoleAccessorMethods { const entities = AclRoleAccessorMethods.entities; const roleGroup = role.toLowerCase() + 's'; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (this as any)[roleGroup] = entities.reduce((acc, entity) => { const isPrefix = entity.charAt(entity.length - 1) === '-'; @@ -306,7 +306,7 @@ class AclRoleAccessorMethods { // Wrap the parent accessor method (e.g. `add` or `delete`) to avoid the // more complex API of specifying an `entity` and `role`. - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (acc as any)[method] = ( entityId: string, options: {}, @@ -343,7 +343,7 @@ class AclRoleAccessorMethods { args.push(callback); } - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any return (this as any)[accessMethod].apply(this, args); }; }); diff --git a/src/bucket.ts b/src/bucket.ts index 5f220c01a..103e888cf 100644 --- a/src/bucket.ts +++ b/src/bucket.ts @@ -20,7 +20,6 @@ import { ExistsCallback, GetConfig, Metadata, - MetadataResponse, ResponseBody, ServiceObject, util, @@ -36,9 +35,10 @@ import * as path from 'path'; import pLimit from 'p-limit'; import {promisify} from 'util'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const snakeize = require('snakeize'); -import {Acl, AddAclCallback} from './acl'; +import {Acl} from './acl'; import {Channel} from './channel'; import { File, @@ -185,7 +185,7 @@ export interface DeleteFilesCallback { export type DeleteLabelsResponse = [Metadata]; -export interface DeleteLabelsCallback extends SetLabelsCallback {} +export type DeleteLabelsCallback = SetLabelsCallback; export type DisableRequesterPaysResponse = [Metadata]; @@ -205,7 +205,7 @@ export interface BucketExistsOptions extends GetConfig { export type BucketExistsResponse = [boolean]; -export interface BucketExistsCallback extends ExistsCallback {} +export type BucketExistsCallback = ExistsCallback; export interface GetBucketOptions extends GetConfig { userProject?: string; @@ -1249,7 +1249,7 @@ class Bucket extends ServiceObject { return this.file(file); }; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any sources = (sources as any).map(convertToFile); const destinationFile = convertToFile(destination); callback = callback || util.noop; @@ -1536,7 +1536,7 @@ class Bucket extends ServiceObject { const topicIsObject = topic !== null && typeof topic === 'object'; if (topicIsObject && util.isCustomType(topic, 'pubsub/topic')) { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any topic = (topic as any).name; } @@ -2180,7 +2180,7 @@ class Bucket extends ServiceObject { }, (err, resp) => { if (err) { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (callback as any)(err, null, null, resp); return; } @@ -2208,7 +2208,7 @@ class Bucket extends ServiceObject { pageToken: resp.nextPageToken, }); } - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (callback as any)(null, files, nextQuery, resp); } ); @@ -3400,7 +3400,7 @@ class Bucket extends ServiceObject { optionsOrCallback?: UploadOptions | UploadCallback, callback?: UploadCallback ): Promise | void { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any if ((global as any)['GCLOUD_SANDBOX_ENV']) { return; } @@ -3421,7 +3421,7 @@ class Bucket extends ServiceObject { if (options.destination instanceof File) { newFile = options.destination; } else if ( - options.destination != null && + options.destination !== null && typeof options.destination === 'string' ) { // Use the string as the name of the file. @@ -3444,7 +3444,7 @@ class Bucket extends ServiceObject { options.metadata.contentType = contentType; } - if (options.resumable != null && typeof options.resumable === 'boolean') { + if (options.resumable !== null && typeof options.resumable === 'boolean') { upload(); } else { // Determine if the upload should be resumable if it's over the threshold. diff --git a/src/file.ts b/src/file.ts index b49aa709b..d5f36070f 100644 --- a/src/file.ts +++ b/src/file.ts @@ -29,10 +29,12 @@ import * as crypto from 'crypto'; import * as dateFormat from 'date-and-time'; import * as extend from 'extend'; import * as fs from 'fs'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const hashStreamValidation = require('hash-stream-validation'); import * as mime from 'mime'; import * as once from 'onetime'; import * as os from 'os'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const pumpify = require('pumpify'); import * as resumableUpload from 'gcs-resumable-upload'; import {Duplex, Writable, Readable} from 'stream'; @@ -59,6 +61,7 @@ import { Duplexify, DuplexifyConstructor, } from '@google-cloud/common/build/src/util'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const duplexify: DuplexifyConstructor = require('duplexify'); import {normalize, objectKeyToLowercase} from './util'; import {GaxiosError, Headers, request as gaxiosRequest} from 'gaxios'; @@ -94,13 +97,11 @@ export interface GetSignedPolicyOptions { contentLengthRange?: {min?: number; max?: number}; } -export interface GenerateSignedPostPolicyV2Options - extends GetSignedPolicyOptions {} +export type GenerateSignedPostPolicyV2Options = GetSignedPolicyOptions; export type GenerateSignedPostPolicyV2Response = GetSignedPolicyResponse; -export interface GenerateSignedPostPolicyV2Callback - extends GetSignedPolicyCallback {} +export type GenerateSignedPostPolicyV2Callback = GetSignedPolicyCallback; export interface PolicyFields { [key: string]: string; @@ -220,7 +221,7 @@ export interface MakeFilePrivateOptions { export type MakeFilePrivateResponse = [Metadata]; -export interface MakeFilePrivateCallback extends SetFileMetadataCallback {} +export type MakeFilePrivateCallback = SetFileMetadataCallback; export interface IsPublicCallback { (err: Error | null, resp?: boolean): void; @@ -255,7 +256,7 @@ export interface EncryptionKeyOptions { kmsKeyName?: string; } -export interface RotateEncryptionKeyCallback extends CopyCallback {} +export type RotateEncryptionKeyCallback = CopyCallback; export type RotateEncryptionKeyResponse = CopyResponse; @@ -348,7 +349,7 @@ export interface CreateReadStreamOptions { decompress?: boolean; } -export interface SaveOptions extends CreateWriteStreamOptions {} +export type SaveOptions = CreateWriteStreamOptions; export interface SaveCallback { (err?: Error | null): void; @@ -479,11 +480,11 @@ class File extends ServiceObject { const requestQueryObject: {generation?: number; userProject?: string} = {}; let generation: number; - if (options.generation != null) { + if (options.generation !== null) { if (typeof options.generation === 'string') { generation = Number(options.generation); } else { - generation = options.generation; + generation = options.generation!; } if (!isNaN(generation)) { requestQueryObject.generation = generation; @@ -779,16 +780,16 @@ class File extends ServiceObject { }); this.bucket = bucket; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any this.storage = (bucket as any).parent as Storage; // @TODO Can this duplicate code from above be avoided? - if (options.generation != null) { + if (options.generation !== null) { let generation: number; if (typeof options.generation === 'string') { generation = Number(options.generation); } else { - generation = options.generation; + generation = options.generation!; } if (!isNaN(generation)) { this.generation = generation; @@ -967,6 +968,7 @@ class File extends ServiceObject { options = optionsOrCallback; } + // eslint-disable-next-line no-prototype-builtins if (options.hasOwnProperty('keepAcl')) { // TODO: remove keepAcl from interface in next major. emitWarning(); @@ -1185,7 +1187,7 @@ class File extends ServiceObject { typeof options.start === 'number' || typeof options.end === 'number'; const tailRequest = options.end! < 0; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let validateStream: any; // Created later, if necessary. // TODO: remove `through2` dependency in favor of native PassThrough @@ -1199,7 +1201,7 @@ class File extends ServiceObject { let refreshedMetadata = false; if (typeof options.validation === 'string') { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (options as any).validation = (options.validation as string).toLowerCase(); crc32c = options.validation === 'crc32c'; md5 = options.validation === 'md5'; @@ -1259,7 +1261,7 @@ class File extends ServiceObject { }) .on('response', res => { throughStream.emit('response', res); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any util.handleResp(null, res, null, onResponse as any); }) .resume(); @@ -1308,7 +1310,7 @@ class File extends ServiceObject { if (throughStreams.length === 1) { rawResponseStream = - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any rawResponseStream.pipe(throughStreams[0]) as any; } else if (throughStreams.length > 1) { rawResponseStream = rawResponseStream.pipe( @@ -1692,7 +1694,7 @@ class File extends ServiceObject { * // The file upload is complete. * }); */ - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any createWriteStream(options: CreateWriteStreamOptions = {}): Writable { options = Object.assign({metadata: {}}, options); @@ -2045,7 +2047,7 @@ class File extends ServiceObject { ); this.encryptionKeyHash = crypto .createHash('sha256') - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .update(this.encryptionKeyBase64, 'base64' as any) .digest('base64'); @@ -2979,7 +2981,7 @@ class File extends ServiceObject { const query = { predefinedAcl: options.strict ? 'private' : 'projectPrivate', - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any; if (options.userProject) { @@ -3312,9 +3314,11 @@ class File extends ServiceObject { this.copy(newFile, callback!); } - // tslint:disable:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any save(data: any, options?: SaveOptions): Promise; + // eslint-disable-next-line @typescript-eslint/no-explicit-any save(data: any, callback: SaveCallback): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any save(data: any, options: SaveOptions, callback: SaveCallback): void; /** * @typedef {object} SaveOptions @@ -3365,6 +3369,7 @@ class File extends ServiceObject { * file.save(contents).then(function() {}); */ save( + // eslint-disable-next-line @typescript-eslint/no-explicit-any data: any, optionsOrCallback?: SaveOptions | SaveCallback, callback?: SaveCallback diff --git a/src/iam.ts b/src/iam.ts index fc23f2536..657cc62d3 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -248,7 +248,10 @@ class Iam { qs.userProject = options.userProject; } - if (options.requestedPolicyVersion != null) { + if ( + options.requestedPolicyVersion !== null && + options.requestedPolicyVersion !== undefined + ) { qs.optionsRequestedPolicyVersion = options.requestedPolicyVersion; } diff --git a/src/notification.ts b/src/notification.ts index a0b5f0683..9f8cf4f54 100644 --- a/src/notification.ts +++ b/src/notification.ts @@ -333,7 +333,7 @@ class Notification extends ServiceObject { args.push(onCreate); - // tslint:disable-next-line no-any + // eslint-disable-next-line this.create.apply(this, args as any); return; } diff --git a/src/signer.ts b/src/signer.ts index fa7271d5f..af83e483f 100644 --- a/src/signer.ts +++ b/src/signer.ts @@ -170,7 +170,7 @@ export class URLSigner { this.bucket.name, config.file ); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any signedUrl.search = qsStringify(query as any); return signedUrl.href; }); @@ -278,7 +278,7 @@ export class URLSigner { ...(config.queryParams || {}), }; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const canonicalQueryParams = this.getCanonicalQueryParams(queryParams); const canonicalRequest = this.getCanonicalRequest( @@ -343,7 +343,7 @@ export class URLSigner { .sort((a, b) => a[0].localeCompare(b[0])); return sortedHeaders - .filter(([_, value]) => value !== undefined) + .filter(([, value]) => value !== undefined) .map(([headerName, value]) => { // - Convert Array (multi-valued header) into string, delimited by // ',' (no space). diff --git a/src/storage.ts b/src/storage.ts index ab1e03305..479938ad6 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -599,7 +599,7 @@ export class Storage extends Service { metadata = metadataOrCallback as CreateBucketRequest; } - const body = Object.assign({}, metadata, {name}) as { + const body = (Object.assign({}, metadata, {name}) as {}) as { [index: string]: string | {}; }; @@ -1091,6 +1091,7 @@ export class Storage extends Service { const camelCaseResponse = {} as {[index: string]: string}; for (const prop in resp) { + // eslint-disable-next-line no-prototype-builtins if (resp.hasOwnProperty(prop)) { const camelCaseProp = prop.replace(/_(\w)/g, (_, match) => match.toUpperCase() diff --git a/src/util.ts b/src/util.ts index e9725b9bb..19d0b77ed 100644 --- a/src/util.ts +++ b/src/util.ts @@ -48,12 +48,7 @@ export function objectEntries(obj: {[key: string]: T}): Array<[string, T]> { export function fixedEncodeURIComponent(str: string): string { return encodeURIComponent(str).replace( /[!'()*]/g, - c => - '%' + - c - .charCodeAt(0) - .toString(16) - .toUpperCase() + c => '%' + c.charCodeAt(0).toString(16).toUpperCase() ); } diff --git a/system-test/storage.ts b/system-test/storage.ts index 337518657..b24cfe463 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -13,11 +13,12 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, after, afterEach} from 'mocha'; import * as crypto from 'crypto'; import * as fs from 'fs'; -import fetch, {Request} from 'node-fetch'; +import fetch from 'node-fetch'; import * as FormData from 'form-data'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const normalizeNewline = require('normalize-newline'); import pLimit from 'p-limit'; import {promisify} from 'util'; @@ -25,14 +26,7 @@ import * as path from 'path'; import * as through from 'through2'; import * as tmp from 'tmp'; import * as uuid from 'uuid'; -import { - util, - ApiError, - InstanceResponseCallback, - BodyResponseCallback, - MetadataResponse, - Metadata, -} from '@google-cloud/common'; +import {util, ApiError, Metadata} from '@google-cloud/common'; import { Storage, Bucket, @@ -51,7 +45,6 @@ import { MakeBucketPrivateCallback, SetBucketMetadataOptions, SetBucketMetadataCallback, - DeleteFileCallback, SaveCallback, DownloadOptions, DownloadCallback, @@ -91,14 +84,13 @@ import { GetNotificationMetadataCallback, DeleteNotificationOptions, DeleteNotificationCallback, - Iam, } from '../src'; import * as nock from 'nock'; interface ErrorCallbackFunction { (err: Error | null): void; } -const {PubSub} = require('@google-cloud/pubsub'); +import {PubSub} from '@google-cloud/pubsub'; // When set to true, skips all tests that is not compatible for // running inside VPCSC. @@ -106,7 +98,7 @@ const RUNNING_IN_VPCSC = !!process.env['GOOGLE_CLOUD_TESTS_IN_VPCSC']; // block all attempts to chat with the metadata server (kokoro runs on GCE) nock('http://metadata.google.internal') - .get(url => true) + .get(() => true) .replyWithError({code: 'ENOTFOUND'}) .persist(); @@ -121,9 +113,9 @@ describe('storage', () => { const pubsub = new PubSub({ projectId: process.env.PROJECT_ID, }); - // tslint:disable-next-line no-any + // 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 const FILES: {[index: string]: any} = { logo: { path: path.join( @@ -175,6 +167,7 @@ describe('storage', () => { let storageWithoutAuth: Storage; let GOOGLE_APPLICATION_CREDENTIALS: string | undefined; + // eslint-disable-next-line @typescript-eslint/no-unused-vars let GOOGLE_CLOUD_PROJECT: string | undefined; before(done => { @@ -193,6 +186,7 @@ describe('storage', () => { delete process.env.GOOGLE_CLOUD_PROJECT; delete require.cache[require.resolve('../src')]; + // eslint-disable-next-line @typescript-eslint/no-var-requires const {Storage} = require('../src'); storageWithoutAuth = new Storage(); }); @@ -203,7 +197,7 @@ describe('storage', () => { }); describe('public data', () => { - before(function() { + before(function () { if (RUNNING_IN_VPCSC) this.skip(); }); @@ -452,7 +446,7 @@ describe('storage', () => { }); it('should get access controls', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.acl.get(done as any, (err, accessControls) => { assert.ifError(err); assert(Array.isArray(accessControls)); @@ -461,7 +455,7 @@ describe('storage', () => { }); it('should not expose default api', () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.strictEqual(typeof (file as any).default, 'undefined'); }); @@ -879,7 +873,7 @@ describe('storage', () => { }); describe('unicode validation', () => { - before(function() { + before(function () { if (RUNNING_IN_VPCSC) this.skip(); }); @@ -1686,7 +1680,7 @@ describe('storage', () => { USER_PROJECT_OPTIONS ); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function createFileAsync(fileObject: any) { return fileObject.file.save( fileObject.contents, @@ -1726,7 +1720,7 @@ describe('storage', () => { it( 'bucket#get', doubleTest((options: GetBucketOptions, done: GetBucketCallback) => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any bucketNonWhitelist.get(options, done as any); }) ); @@ -1734,7 +1728,7 @@ describe('storage', () => { it( 'bucket#getMetadata', doubleTest((options: GetBucketOptions, done: GetBucketCallback) => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any bucketNonWhitelist.get(options, done as any); }) ); @@ -2363,14 +2357,14 @@ describe('storage', () => { }); }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function upload(opts: any, callback: ErrorCallbackFunction) { const ws = file.createWriteStream(); let sizeStreamed = 0; fs.createReadStream(FILES.big.path) .pipe( - through(function(chunk, enc, next) { + through(function (chunk, enc, next) { sizeStreamed += chunk.length; if (opts.interrupt && sizeStreamed >= fileSize / 2) { @@ -2395,7 +2389,7 @@ describe('storage', () => { it('should write/read/remove from a buffer', done => { tmp.setGracefulCleanup(); - tmp.file(function _tempFileCreated(err, tmpFilePath) { + tmp.file((err, tmpFilePath) => { assert.ifError(err); const file = bucket.file('MyBuffer'); @@ -2952,7 +2946,7 @@ describe('storage', () => { }); describe('second service account', () => { - before(async function() { + before(async function () { if (!SECOND_SERVICE_ACCOUNT) { this.skip(); } @@ -2960,14 +2954,14 @@ describe('storage', () => { }); it('should create key for a second service account', async () => { - const _ = await storage.createHmacKey(SECOND_SERVICE_ACCOUNT!, { + await storage.createHmacKey(SECOND_SERVICE_ACCOUNT!, { projectId: HMAC_PROJECT, }); }); it('get HMAC keys for both service accounts', async () => { // Create a key for the first service account - const _ = await storage.createHmacKey(SERVICE_ACCOUNT!, { + await storage.createHmacKey(SERVICE_ACCOUNT!, { projectId: HMAC_PROJECT, }); @@ -3392,7 +3386,7 @@ describe('storage', () => { file = bucket.file('LogoToSign.jpg'); }); - beforeEach(function() { + beforeEach(function () { if (!storage.projectId) { this.skip(); } @@ -3447,7 +3441,7 @@ describe('storage', () => { describe('notifications', () => { let notification: Notification; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let subscription: any; before(() => { @@ -3470,10 +3464,10 @@ describe('storage', () => { .then(() => { return bucket.getNotifications(); }) - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .then((data: any) => { return Promise.all( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any data[0].map((notification: any) => { return notification.delete(); }) @@ -3525,7 +3519,7 @@ describe('storage', () => { }); it('should emit events to a subscription', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any subscription.on('error', done).on('message', (message: any) => { const attrs = message.attributes; assert.strictEqual(attrs.eventType, 'OBJECT_FINALIZE'); @@ -3621,16 +3615,13 @@ describe('storage', () => { return file.delete(); } - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function deleteTopicAsync(topic: any) { return topic.delete(); } function shortUUID() { - return uuid - .v1() - .split('-') - .shift(); + return uuid.v1().split('-').shift(); } function generateName() { @@ -3650,7 +3641,7 @@ describe('storage', () => { async function deleteAllTopicsAsync() { const [topics] = await pubsub.getTopics(); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const filteredTopics = (topics as any[]).filter(topic => { return topic.name.indexOf(TESTS_PREFIX) > -1; }); @@ -3701,7 +3692,7 @@ describe('storage', () => { ); } - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any function createFileAsync(fileObject: any) { return fileObject.file.save(fileObject.contents); } diff --git a/test/acl.ts b/test/acl.ts index d5d08d004..d78f2227e 100644 --- a/test/acl.ts +++ b/test/acl.ts @@ -14,12 +14,11 @@ import {DecorateRequestOptions, Metadata, util} from '@google-cloud/common'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach} from 'mocha'; import * as proxyquire from 'proxyquire'; -// tslint:disable-next-line:variable-name no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let Acl: any; -// tslint:disable-next-line:variable-name let AclRoleAccessorMethods: Function; describe('storage/acl', () => { let promisified = false; @@ -32,9 +31,9 @@ describe('storage/acl', () => { }, }; - // tslint:disable-next-line:variable-name + // eslint-disable-next-line @typescript-eslint/no-var-requires const {Storage} = require('../src'); - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let acl: any; const ERROR = new Error('Error.'); @@ -493,11 +492,11 @@ describe('storage/acl', () => { }); describe('storage/AclRoleAccessorMethods', () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let aclEntity: any; beforeEach(() => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any aclEntity = new (AclRoleAccessorMethods as any)(); }); diff --git a/test/bucket.ts b/test/bucket.ts index 1bec82976..ce630ddda 100644 --- a/test/bucket.ts +++ b/test/bucket.ts @@ -21,12 +21,13 @@ import { } from '@google-cloud/common'; 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 mime from 'mime-types'; import pLimit from 'p-limit'; import * as path from 'path'; import * as proxyquire from 'proxyquire'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const snakeize = require('snakeize'); import * as stream from 'stream'; import * as through from 'through2'; @@ -59,6 +60,7 @@ class FakeFile { createWriteStream: Function; isSameFile = () => false; constructor(bucket: Bucket, name: string, options?: FileOptions) { + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; this.bucket = bucket; this.name = name; @@ -138,9 +140,9 @@ class FakeAcl { } class FakeIam { - calledWith_: IArguments; - constructor() { - this.calledWith_ = arguments; + calledWith_: Array<{}>; + constructor(...args: Array<{}>) { + this.calledWith_ = args; } } @@ -148,6 +150,7 @@ class FakeServiceObject extends ServiceObject { calledWith_: IArguments; constructor(config: ServiceObjectConfig) { super(config); + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } @@ -157,9 +160,9 @@ const fakeSigner = { }; describe('Bucket', () => { - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Bucket: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let bucket: any; const STORAGE = { @@ -999,7 +1002,7 @@ describe('Bucket', () => { return () => {}; }; - bucket.getFiles = (query: {}) => Promise.resolve([[]]); + bucket.getFiles = () => Promise.resolve([[]]); bucket.deleteFiles({}, assert.ifError); }); @@ -1031,7 +1034,7 @@ describe('Bucket', () => { it('should execute callback with error from getting files', done => { const error = new Error('Error.'); - bucket.getFiles = (query: {}) => { + bucket.getFiles = () => { return Promise.reject(error); }; @@ -1045,11 +1048,11 @@ describe('Bucket', () => { const error = new Error('Error.'); const files = [bucket.file('1'), bucket.file('2')].map(file => { - file.delete = (query: {}) => Promise.reject(error); + file.delete = () => Promise.reject(error); return file; }); - bucket.getFiles = (query: {}) => { + bucket.getFiles = () => { return Promise.resolve([files]); }; @@ -1063,11 +1066,11 @@ describe('Bucket', () => { const error = new Error('Error.'); const files = [bucket.file('1'), bucket.file('2')].map(file => { - file.delete = (query: {}) => Promise.reject(error); + file.delete = () => Promise.reject(error); return file; }); - bucket.getFiles = (query: {}) => { + bucket.getFiles = () => { return Promise.resolve([files]); }; @@ -1430,7 +1433,7 @@ describe('Bucket', () => { it('should strip excess slashes from a directory', done => { const directory = 'directory-name///'; bucket.request = (reqOpts: DecorateRequestOptions) => { - assert.strictEqual(reqOpts.qs.prefix, `directory-name/`); + assert.strictEqual(reqOpts.qs.prefix, 'directory-name/'); done(); }; bucket.getFiles({directory}, assert.ifError); @@ -1748,7 +1751,7 @@ describe('Bucket', () => { getSignedUrl: signerGetSignedUrlStub, }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any urlSignerStub = (sandbox.stub as any)(fakeSigner, 'URLSigner').returns( signer ); @@ -1792,7 +1795,7 @@ describe('Bucket', () => { }); it('should error if action is null', () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any SIGNED_URL_CONFIG.action = null as any; assert.throws(() => { @@ -1808,7 +1811,7 @@ describe('Bucket', () => { }); it('should error for an invalid action', () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any SIGNED_URL_CONFIG.action = 'watch' as any; assert.throws(() => { @@ -1977,28 +1980,17 @@ describe('Bucket', () => { }); it('should not make files public by default', done => { - bucket.acl.add = (opts: {}) => { - return Promise.resolve(); - }; - - bucket.acl.default.add = (opts: {}) => { - return Promise.resolve(); - }; - + bucket.acl.add = () => Promise.resolve(); + bucket.acl.default.add = () => Promise.resolve(); bucket.makeAllFilesPublicPrivate_ = () => { throw new Error('Please, no. I do not want to be called.'); }; - bucket.makePublic(done); }); it('should execute callback with error', done => { const error = new Error('Error.'); - - bucket.acl.add = (opts: {}) => { - return Promise.reject(error); - }; - + bucket.acl.add = () => Promise.reject(error); bucket.makePublic((err: Error) => { assert.strictEqual(err, error); done(); @@ -2050,7 +2042,7 @@ describe('Bucket', () => { ) => { assert.strictEqual(reqOpts.qs.userProject, USER_PROJECT); done(); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any; bucket.request({}, assert.ifError); @@ -2069,7 +2061,7 @@ describe('Bucket', () => { assert.strictEqual(reqOpts.qs, options.qs); assert.strictEqual(reqOpts.qs.userProject, USER_PROJECT); done(); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any; bucket.request(options, assert.ifError); @@ -2088,7 +2080,7 @@ describe('Bucket', () => { ) => { assert.strictEqual(reqOpts.qs.userProject, fakeUserProject); done(); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any; bucket.request(options, assert.ifError); @@ -2261,10 +2253,10 @@ describe('Bucket', () => { }); it('should return early in snippet sandbox', () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (global as any)['GCLOUD_SANDBOX_ENV'] = true; const returnValue = bucket.upload(filepath, assert.ifError); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any delete (global as any)['GCLOUD_SANDBOX_ENV']; assert.strictEqual(returnValue, undefined); }); @@ -2504,7 +2496,7 @@ describe('Bucket', () => { return () => {}; }; - bucket.getFiles = (options: {}) => Promise.resolve([[]]); + bucket.getFiles = () => Promise.resolve([[]]); bucket.makeAllFilesPublicPrivate_({}, assert.ifError); }); @@ -2517,11 +2509,7 @@ describe('Bucket', () => { }; return file; }); - - bucket.getFiles = (options: {}) => { - return Promise.resolve([files]); - }; - + bucket.getFiles = () => Promise.resolve([files]); bucket.makeAllFilesPublicPrivate_({public: true}, (err: Error) => { assert.ifError(err); assert.strictEqual(timesCalled, files.length); @@ -2536,17 +2524,14 @@ describe('Bucket', () => { let timesCalled = 0; const files = [bucket.file('1'), bucket.file('2')].map(file => { - file.makePrivate = (options_: {}) => { + file.makePrivate = () => { timesCalled++; return Promise.resolve(); }; return file; }); - bucket.getFiles = (options_: {}) => { - return Promise.resolve([files]); - }; - + bucket.getFiles = () => Promise.resolve([files]); bucket.makeAllFilesPublicPrivate_(options, (err: Error) => { assert.ifError(err); assert.strictEqual(timesCalled, files.length); @@ -2556,11 +2541,7 @@ describe('Bucket', () => { it('should execute callback with error from getting files', done => { const error = new Error('Error.'); - - bucket.getFiles = (options: {}) => { - return Promise.reject(error); - }; - + bucket.getFiles = () => Promise.reject(error); bucket.makeAllFilesPublicPrivate_({}, (err: Error) => { assert.strictEqual(err, error); done(); @@ -2569,16 +2550,11 @@ describe('Bucket', () => { it('should execute callback with error from changing file', done => { const error = new Error('Error.'); - const files = [bucket.file('1'), bucket.file('2')].map(file => { file.makePublic = () => Promise.reject(error); return file; }); - - bucket.getFiles = (options: {}) => { - return Promise.resolve([files]); - }; - + bucket.getFiles = () => Promise.resolve([files]); bucket.makeAllFilesPublicPrivate_({public: true}, (err: Error) => { assert.strictEqual(err, error); done(); @@ -2587,16 +2563,11 @@ describe('Bucket', () => { it('should execute callback with queued errors', done => { const error = new Error('Error.'); - const files = [bucket.file('1'), bucket.file('2')].map(file => { file.makePublic = () => Promise.reject(error); return file; }); - - bucket.getFiles = (options: {}) => { - return Promise.resolve([files]); - }; - + bucket.getFiles = () => Promise.resolve([files]); bucket.makeAllFilesPublicPrivate_( { public: true, @@ -2620,7 +2591,7 @@ describe('Bucket', () => { return file; }); - bucket.getFiles = (options: {}) => { + bucket.getFiles = () => { const files = successFiles.concat(errorFiles); return Promise.resolve([files]); }; diff --git a/test/channel.ts b/test/channel.ts index 997487506..aaa975c51 100644 --- a/test/channel.ts +++ b/test/channel.ts @@ -22,12 +22,11 @@ import { ServiceObjectConfig, } from '@google-cloud/common'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach} from 'mocha'; import * as proxyquire from 'proxyquire'; let promisified = false; const fakePromisify = { - // tslint:disable-next-line:variable-name promisifyAll(Class: Function) { if (Class.name === 'Channel') { promisified = true; @@ -39,6 +38,7 @@ class FakeServiceObject extends ServiceObject { calledWith_: IArguments; constructor(config: ServiceObjectConfig) { super(config); + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } @@ -48,9 +48,9 @@ describe('Channel', () => { const ID = 'channel-id'; const RESOURCE_ID = 'resource-id'; - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Channel: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let channel: any; before(() => { diff --git a/test/file.ts b/test/file.ts index cf0f5ad99..72b40e6d9 100644 --- a/test/file.ts +++ b/test/file.ts @@ -21,7 +21,7 @@ import { } from '@google-cloud/common'; import {PromisifyAllOptions} from '@google-cloud/promisify'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import * as crypto from 'crypto'; import * as dateFormat from 'date-and-time'; import * as duplexify from 'duplexify'; @@ -39,13 +39,13 @@ import * as gaxios from 'gaxios'; import { Bucket, + // eslint-disable-next-line @typescript-eslint/no-unused-vars File, FileOptions, GetFileMetadataOptions, PolicyDocument, SetFileMetadataOptions, GetSignedUrlConfig, - GetSignedPolicyOptions, GenerateSignedPostPolicyV2Options, GenerateSignedPostPolicyV2Callback, } from '../src'; @@ -54,19 +54,16 @@ import { GenerateSignedPostPolicyV4Options, STORAGE_POST_POLICY_BASE_URL, } from '../src/file'; -import {fixedEncodeURIComponent} from '../src/util'; let promisified = false; let makeWritableStreamOverride: Function | null; let handleRespOverride: Function | null; const fakeUtil = Object.assign({}, util, { - handleResp() { - (handleRespOverride || util.handleResp).apply(null, arguments); + handleResp(...args: Array<{}>) { + (handleRespOverride || util.handleResp)(...args); }, - - makeWritableStream() { - const args = arguments; - (makeWritableStreamOverride || util.makeWritableStream).apply(null, args); + makeWritableStream(...args: Array<{}>) { + (makeWritableStreamOverride || util.makeWritableStream)(...args); }, }); @@ -88,27 +85,23 @@ const fakeFs = extend(true, {}, fsCached); const zlibCached = extend(true, {}, zlib); let createGunzipOverride: Function | null; const fakeZlib = extend(true, {}, zlib, { - createGunzip() { - return (createGunzipOverride || zlibCached.createGunzip).apply( - null, - arguments - ); + createGunzip(...args: Array<{}>) { + return (createGunzipOverride || zlibCached.createGunzip)(...args); }, }); let hashStreamValidationOverride: Function | null; +// eslint-disable-next-line @typescript-eslint/no-var-requires const hashStreamValidation = require('hash-stream-validation'); -function fakeHashStreamValidation() { - return (hashStreamValidationOverride || hashStreamValidation).apply( - null, - arguments - ); +function fakeHashStreamValidation(...args: Array<{}>) { + return (hashStreamValidationOverride || hashStreamValidation)(...args); } +// eslint-disable-next-line @typescript-eslint/no-var-requires const osCached = extend(true, {}, require('os')); const fakeOs = extend(true, {}, osCached); -// tslint:disable-next-line: no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let resumableUploadOverride: any; function fakeResumableUpload() { return () => { @@ -125,7 +118,7 @@ Object.assign(fakeResumableUpload, { createURI = resumableUploadOverride.createURI; } - return createURI.apply(null, args); + return createURI(...args); }, }); Object.assign(fakeResumableUpload, { @@ -134,7 +127,7 @@ Object.assign(fakeResumableUpload, { if (resumableUploadOverride && resumableUploadOverride.upload) { upload = resumableUploadOverride.upload; } - return upload.apply(null, args); + return upload(...args); }, }); @@ -142,12 +135,14 @@ class FakeServiceObject extends ServiceObject { calledWith_: IArguments; constructor(config: ServiceObjectConfig) { super(config); + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } -// tslint:disable-next-line: no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let xdgConfigOverride: any; +// eslint-disable-next-line @typescript-eslint/no-var-requires const xdgBasedirCached = require('xdg-basedir'); const fakeXdgBasedir = extend(true, {}, xdgBasedirCached); Object.defineProperty(fakeXdgBasedir, 'config', { @@ -163,21 +158,21 @@ const fakeSigner = { }; describe('File', () => { - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let File: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let file: any; const FILE_NAME = 'file-name.png'; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let directoryFile: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let specialCharsFile: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let STORAGE: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let BUCKET: any; before(() => { @@ -201,13 +196,13 @@ describe('File', () => { extend(true, fakeFs, fsCached); extend(true, fakeOs, osCached); xdgConfigOverride = null; - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any FakeServiceObject.prototype.request = util.noop as any; STORAGE = { createBucket: util.noop, request: util.noop, - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeAuthenticatedRequest(req: {}, callback: any) { if (callback) { (callback.onAuthenticated || callback)(null, req); @@ -323,15 +318,13 @@ describe('File', () => { it('should set a custom encryption key', done => { const key = 'key'; - const setEncryptionKey = File.prototype.setEncryptionKey; File.prototype.setEncryptionKey = (key_: {}) => { File.prototype.setEncryptionKey = setEncryptionKey; assert.strictEqual(key_, key); done(); }; - - const _file = new File(BUCKET, FILE_NAME, {encryptionKey: key}); + new File(BUCKET, FILE_NAME, {encryptionKey: key}); }); describe('userProject', () => { @@ -358,17 +351,17 @@ describe('File', () => { describe('copy', () => { describe('depricate `keepAcl`', () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line let STORAGE2: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line let BUCKET2: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let file2: any; beforeEach(() => { STORAGE2 = { createBucket: util.noop, request: util.noop, - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeAuthenticatedRequest(req: {}, callback: any) { if (callback) { (callback.onAuthenticated || callback)(null, req); @@ -614,7 +607,7 @@ describe('File', () => { describe('destination types', () => { function assertPathEquals( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file: any, expectedPath: string, callback: Function @@ -646,7 +639,7 @@ describe('File', () => { it('should allow a "gs://..." string', done => { const newFileName = 'gs://other-bucket/new-file-name.png'; - const expectedPath = `/rewriteTo/b/other-bucket/o/new-file-name.png`; + const expectedPath = '/rewriteTo/b/other-bucket/o/new-file-name.png'; assertPathEquals(file, expectedPath, done); file.copy(newFileName); }); @@ -714,7 +707,7 @@ describe('File', () => { reqOpts: DecorateRequestOptions, callback: Function ) => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.copy = (newFile_: {}, options: any) => { assert.notStrictEqual(options, fakeOptions); assert.strictEqual(options.userProject, fakeOptions.userProject); @@ -737,7 +730,7 @@ describe('File', () => { reqOpts: DecorateRequestOptions, callback: Function ) => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.copy = (newFile_: {}, options: any) => { assert.strictEqual( options.destinationKmsKeyName, @@ -850,12 +843,9 @@ describe('File', () => { class FakeSuccessfulRequest extends FakeRequest { constructor(req?: DecorateRequestOptions) { super(req); - - const self = this; - setImmediate(() => { const stream = new FakeRequest(); - self.emit('response', stream); + this.emit('response', stream); }); } } @@ -876,11 +866,8 @@ describe('File', () => { class FakeFailedRequest extends FakeRequest { constructor(_req?: DecorateRequestOptions) { super(_req); - - const self = this; - setImmediate(() => { - self.emit('error', error); + this.emit('error', error); }); } } @@ -1120,7 +1107,7 @@ describe('File', () => { it('should emit errors from the request stream', done => { const error = new Error('Error.'); const rawResponseStream = through(); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (rawResponseStream as any).toJSON = () => { return {headers: {}}; }; @@ -1157,7 +1144,7 @@ describe('File', () => { it('should not handle both error and end events', done => { const error = new Error('Error.'); const rawResponseStream = through(); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (rawResponseStream as any).toJSON = () => { return {headers: {}}; }; @@ -1186,11 +1173,9 @@ describe('File', () => { callback(); }; - let errorReceived = false; file .createReadStream({validation: false}) .on('error', (err: Error) => { - errorReceived = true; assert.strictEqual(err, error); rawResponseStream.emit('end'); setImmediate(done); @@ -1425,10 +1410,7 @@ describe('File', () => { file.requestStream = getFakeSuccessfulRequest(data); - file - .createReadStream(fakeOptions) - .on('error', done) - .resume(); + file.createReadStream(fakeOptions).on('error', done).resume(); }); it('should destroy stream from failed metadata fetch', done => { @@ -1460,7 +1442,7 @@ describe('File', () => { it('should emit an error if crc32c validation fails', done => { file.requestStream = getFakeSuccessfulRequest('bad-data'); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeValidationStream as any).test = () => false; file .createReadStream({validation: 'crc32c'}) @@ -1473,7 +1455,7 @@ describe('File', () => { it('should validate with md5', done => { file.requestStream = getFakeSuccessfulRequest(data); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeValidationStream as any).test = () => true; file .createReadStream({validation: 'md5'}) @@ -1484,7 +1466,7 @@ describe('File', () => { it('should emit an error if md5 validation fails', done => { file.requestStream = getFakeSuccessfulRequest('bad-data'); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeValidationStream as any).test = () => false; file .createReadStream({validation: 'md5'}) @@ -1514,7 +1496,7 @@ describe('File', () => { it('should ignore a data mismatch if validation: false', done => { file.requestStream = getFakeSuccessfulRequest(data); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeValidationStream as any).test = () => false; file .createReadStream({validation: false}) @@ -1525,7 +1507,7 @@ describe('File', () => { describe('destroying the through stream', () => { beforeEach(() => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (fakeValidationStream as any).test = () => false; }); @@ -1653,7 +1635,7 @@ describe('File', () => { describe('createResumableUpload', () => { it('should not require options', done => { resumableUploadOverride = { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any createURI(opts: any, callback: Function) { assert.strictEqual(opts.metadata, undefined); callback(); @@ -1681,7 +1663,7 @@ describe('File', () => { file.kmsKeyName = 'kms-key-name'; resumableUploadOverride = { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any createURI(opts: any, callback: Function) { const bucket = file.bucket; const storage = bucket.storage; @@ -1882,7 +1864,7 @@ describe('File', () => { metadata: METADATA, }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.deepStrictEqual(options.metadata, METADATA); done(); @@ -1894,7 +1876,7 @@ describe('File', () => { it('should alias contentType to metadata object', done => { const contentType = 'text/html'; const writable = file.createWriteStream({contentType}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.strictEqual(options.metadata.contentType, contentType); done(); @@ -1905,7 +1887,7 @@ describe('File', () => { it('should detect contentType with contentType:auto', done => { const writable = file.createWriteStream({contentType: 'auto'}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.strictEqual(options.metadata.contentType, 'image/png'); done(); @@ -1916,7 +1898,7 @@ describe('File', () => { it('should set encoding with gzip:true', done => { const writable = file.createWriteStream({gzip: true}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.strictEqual(options.metadata.contentEncoding, 'gzip'); done(); @@ -1931,7 +1913,7 @@ describe('File', () => { contentType: 'text/html', // (compressible) }); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.strictEqual(options.metadata.contentEncoding, 'gzip'); done(); @@ -1942,7 +1924,7 @@ describe('File', () => { it('should not set encoding with gzip:auto & non-compressible', done => { const writable = file.createWriteStream({gzip: 'auto'}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.startResumableUpload_ = (stream: {}, options: any) => { assert.strictEqual(options.metadata.contentEncoding, undefined); done(); @@ -2198,7 +2180,7 @@ describe('File', () => { file.generation = 123; resumableUploadOverride = { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any upload(opts: any) { assert.strictEqual(opts.bucket, file.bucket.name); assert.strictEqual(opts.file, file.name); @@ -2310,7 +2292,7 @@ describe('File', () => { describe('with destination', () => { it('should write the file to a destination if provided', done => { tmp.setGracefulCleanup(); - tmp.file(function _tempFileCreated(err, tmpFilePath) { + tmp.file((err, tmpFilePath) => { assert.ifError(err); const fileContents = 'abcdefghijklmnopqrstuvwxyz'; @@ -2337,7 +2319,7 @@ describe('File', () => { it('should execute callback with error', done => { tmp.setGracefulCleanup(); - tmp.file(function _tempFileCreated(err, tmpFilePath) { + tmp.file((err, tmpFilePath) => { assert.ifError(err); const error = new Error('Error.'); @@ -2395,7 +2377,7 @@ describe('File', () => { (err: Error, expirationDate: {}, apiResponse_: {}) => { assert.strictEqual( err.message, - `An expiration time is not available.` + 'An expiration time is not available.' ); assert.strictEqual(expirationDate, null); assert.strictEqual(apiResponse_, apiResponse); @@ -2468,7 +2450,7 @@ describe('File', () => { return Promise.resolve('signature'); }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.generateSignedPostPolicyV2( CONFIG, (err: Error, signedPolicy: PolicyDocument) => { @@ -2546,7 +2528,7 @@ describe('File', () => { const policy = JSON.parse(signedPolicy.string); assert( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any policy.conditions.some((condition: any) => { return condition.success_action_redirect === redirectUrl; }) @@ -2571,7 +2553,7 @@ describe('File', () => { const policy = JSON.parse(signedPolicy.string); assert( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any policy.conditions.some((condition: any) => { return condition.success_action_status === successStatus; }) @@ -2870,7 +2852,7 @@ describe('File', () => { 'hex' ); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.generateSignedPostPolicyV4( CONFIG, (err: Error, res: SignedPostPolicyV4Output) => { @@ -3154,7 +3136,7 @@ describe('File', () => { () => {} ); }, - {message: `Max allowed expiration is seven days (604800 seconds).`} + {message: 'Max allowed expiration is seven days (604800 seconds).'} ); }); }); @@ -3179,7 +3161,7 @@ describe('File', () => { getSignedUrl: signerGetSignedUrlStub, }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any urlSignerStub = (sandbox.stub as any)(fakeSigner, 'URLSigner').returns( signer ); @@ -3230,7 +3212,7 @@ describe('File', () => { }); it('should error if action is null', () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any SIGNED_URL_CONFIG.action = null as any; assert.throws(() => { @@ -3246,7 +3228,7 @@ describe('File', () => { }); it('should error for an invalid action', () => { - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any SIGNED_URL_CONFIG.action = 'watch' as any; assert.throws(() => { @@ -3260,67 +3242,55 @@ describe('File', () => { 'another-header': 'value', }; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.strictEqual(getSignedUrlArgs[0]['method'], 'POST'); - assert.deepStrictEqual(getSignedUrlArgs[0]['extensionHeaders'], { - 'another-header': 'value', - 'x-goog-resumable': 'start', - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.strictEqual(getSignedUrlArgs[0]['method'], 'POST'); + assert.deepStrictEqual(getSignedUrlArgs[0]['extensionHeaders'], { + 'another-header': 'value', + 'x-goog-resumable': 'start', + }); + done(); + }); }); it('should add response-content-type query parameter', done => { SIGNED_URL_CONFIG.responseType = 'application/json'; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { - 'response-content-type': 'application/json', - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { + 'response-content-type': 'application/json', + }); + done(); + }); }); it('should respect promptSaveAs argument', done => { const filename = 'fname.txt'; SIGNED_URL_CONFIG.promptSaveAs = filename; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { - 'response-content-disposition': - 'attachment; filename="' + filename + '"', - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { + 'response-content-disposition': + 'attachment; filename="' + filename + '"', + }); + done(); + }); }); it('should add response-content-disposition query parameter', done => { const disposition = 'attachment; filename="fname.ext"'; SIGNED_URL_CONFIG.responseDisposition = disposition; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { - 'response-content-disposition': disposition, - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { + 'response-content-disposition': disposition, + }); + done(); + }); }); it('should ignore promptSaveAs if set', done => { @@ -3329,33 +3299,27 @@ describe('File', () => { SIGNED_URL_CONFIG.promptSaveAs = saveAs; SIGNED_URL_CONFIG.responseDisposition = disposition; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { - 'response-content-disposition': disposition, - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { + 'response-content-disposition': disposition, + }); + done(); + }); }); it('should add generation to query parameter', done => { file.generation = '246680131'; - file.getSignedUrl( - SIGNED_URL_CONFIG, - (err: Error | null, _signedUrl: string) => { - assert.ifError(err); - const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; - assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { - generation: file.generation, - }); - done(); - } - ); + file.getSignedUrl(SIGNED_URL_CONFIG, (err: Error | null) => { + assert.ifError(err); + const getSignedUrlArgs = signerGetSignedUrlStub.getCall(0).args; + assert.deepStrictEqual(getSignedUrlArgs[0]['queryParams'], { + generation: file.generation, + }); + done(); + }); }); }); @@ -3501,7 +3465,7 @@ describe('File', () => { describe('move', () => { describe('copy to destination', () => { function assertCopyFile( - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file: any, expectedDestination: string, callback: Function @@ -3565,7 +3529,7 @@ describe('File', () => { file.copy = (destination: {}, options: {}, callback: Function) => { callback(null, newFile, copyApiResponse); }; - file.delete = ({}, callback: Function) => { + file.delete = (_: {}, callback: Function) => { callback(); }; @@ -3674,7 +3638,7 @@ describe('File', () => { const callback = () => {}; const expectedReturnValue = {}; - file.parent.request = function( + file.parent.request = function ( reqOpts: DecorateRequestOptions, callback_: Function ) { @@ -3838,7 +3802,7 @@ describe('File', () => { }); it('should convert camelCase to snake_case', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.copy = (newFile: {}, options: any) => { assert.strictEqual(options.storageClass, 'CAMEL_CASE'); done(); @@ -3848,7 +3812,7 @@ describe('File', () => { }); it('should convert hyphenate to snake_case', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any file.copy = (newFile: {}, options: any) => { assert.strictEqual(options.storageClass, 'HYPHENATED_CLASS'); done(); @@ -3911,11 +3875,11 @@ describe('File', () => { describe('setEncryptionKey', () => { const KEY = crypto.randomBytes(32); - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any const KEY_BASE64 = Buffer.from(KEY as any).toString('base64'); const KEY_HASH = crypto .createHash('sha256') - // tslint:disable-next-line:no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .update(KEY_BASE64, 'base64' as any) .digest('base64'); let _file: {}; @@ -3981,7 +3945,7 @@ describe('File', () => { file.kmsKeyName = 'kms-key-name'; resumableUploadOverride = { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any upload(opts: any) { const bucket = file.bucket; const storage = bucket.storage; @@ -4106,7 +4070,7 @@ describe('File', () => { public: true, }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options_: any) => { assert.strictEqual(options_.metadata, options.metadata); assert.deepStrictEqual(options_.request, { @@ -4126,7 +4090,7 @@ describe('File', () => { }); it('should set predefinedAcl when public: true', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options_: any) => { assert.strictEqual(options_.request.qs.predefinedAcl, 'publicRead'); done(); @@ -4136,7 +4100,7 @@ describe('File', () => { }); it('should set predefinedAcl when private: true', done => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options_: any) => { assert.strictEqual(options_.request.qs.predefinedAcl, 'private'); done(); @@ -4147,7 +4111,7 @@ describe('File', () => { it('should send query.ifGenerationMatch if File has one', done => { const versionedFile = new File(BUCKET, 'new-file.txt', {generation: 1}); - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options: any) => { assert.strictEqual(options.request.qs.ifGenerationMatch, 1); done(); @@ -4158,7 +4122,7 @@ describe('File', () => { it('should send query.kmsKeyName if File has one', done => { file.kmsKeyName = 'kms-key-name'; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options: any) => { assert.strictEqual(options.request.qs.kmsKeyName, file.kmsKeyName); done(); @@ -4171,7 +4135,7 @@ describe('File', () => { const options = { userProject: 'user-project-id', }; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any makeWritableStreamOverride = (stream: {}, options_: any) => { assert.strictEqual( options_.request.qs.userProject, @@ -4202,7 +4166,7 @@ describe('File', () => { file.startSimpleUpload_(stream); stream.on('error', (err: Error) => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.strictEqual((stream as any).destroyed, true); assert.strictEqual(err, error); done(); @@ -4257,7 +4221,7 @@ describe('File', () => { it('should call the parent setUserProject function', done => { const userProject = 'grape-spaceship-123'; - file.parent.setUserProject = function(userProject_: string) { + file.parent.setUserProject = function (userProject_: string) { assert.strictEqual(this, file); assert.strictEqual(userProject_, userProject); done(); diff --git a/test/hmacKey.ts b/test/hmacKey.ts index ef6ac0fd8..2b54a0229 100644 --- a/test/hmacKey.ts +++ b/test/hmacKey.ts @@ -15,33 +15,26 @@ import * as sinon from 'sinon'; import * as proxyquire from 'proxyquire'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import {util, ServiceObject} from '@google-cloud/common'; -// tslint:disable-next-line: no-any -let sandbox: sinon.SinonSandbox; -// tslint:disable-next-line: no-any +const sandbox = sinon.createSandbox(); +// eslint-disable-next-line @typescript-eslint/no-explicit-any let STORAGE: any; -// tslint:disable-next-line: no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any let hmacKey: any; const ACCESS_ID = 'fake-access-id'; describe('HmacKey', () => { - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); + afterEach(() => sandbox.restore()); describe('initialization', () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let serviceObjectSpy: sinon.SinonSpy; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let commonModule: any; - // tslint:disable-next-line: no-any variable-name + // eslint-disable-next-line @typescript-eslint/no-explicit-any let HmacKey: any; beforeEach(() => { diff --git a/test/iam.ts b/test/iam.ts index 5cdb25888..ee3f43712 100644 --- a/test/iam.ts +++ b/test/iam.ts @@ -14,16 +14,16 @@ import {DecorateRequestOptions, util} from '@google-cloud/common'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach} from 'mocha'; import * as proxyquire from 'proxyquire'; describe('storage/iam', () => { - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Iam: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let iam: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let BUCKET_INSTANCE: any; let promisified = false; const fakePromisify = { diff --git a/test/index.ts b/test/index.ts index 800d9b67c..81316157d 100644 --- a/test/index.ts +++ b/test/index.ts @@ -20,18 +20,18 @@ import { util, } from '@google-cloud/common'; import {PromisifyAllOptions} from '@google-cloud/promisify'; - import arrify = require('arrify'); import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach, afterEach} from 'mocha'; import * as proxyquire from 'proxyquire'; - +// eslint-disable-next-line @typescript-eslint/no-unused-vars import {Bucket} from '../src'; import {GetFilesOptions} from '../src/bucket'; import sinon = require('sinon'); import {HmacKey} from '../src/hmacKey'; import {HmacKeyResourceResponse} from '../src/storage'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const hmacKeyModule = require('../src/hmacKey'); class FakeChannel { @@ -84,11 +84,11 @@ const fakePromisify = { describe('Storage', () => { const PROJECT_ID = 'project-id'; - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Storage: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let storage: any; - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Bucket: any; before(() => { @@ -137,6 +137,7 @@ describe('Storage', () => { ]); assert.deepStrictEqual( calledWith.packageJson, + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../package.json') ); }); @@ -727,7 +728,7 @@ describe('Storage', () => { }); describe('getHmacKeys', () => { - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let storageRequestStub: sinon.SinonStub; const SERVICE_ACCOUNT_EMAIL = 'service-account@gserviceaccount.com'; const ACCESS_ID = 'some-access-id'; @@ -822,7 +823,7 @@ describe('Storage', () => { storage.getHmacKeys( query, - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any (err: Error, _hmacKeys: [], nextQuery: any) => { assert.ifError(err); assert.deepStrictEqual(nextQuery, expectedNextQuery); diff --git a/test/notification.ts b/test/notification.ts index e7cd8168d..bfb6696f1 100644 --- a/test/notification.ts +++ b/test/notification.ts @@ -19,7 +19,7 @@ import { util, } from '@google-cloud/common'; import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, before, beforeEach} from 'mocha'; import * as proxyquire from 'proxyquire'; import {Bucket} from '../src'; @@ -28,14 +28,15 @@ class FakeServiceObject extends ServiceObject { calledWith_: IArguments; constructor(config: ServiceObjectConfig) { super(config); + // eslint-disable-next-line prefer-rest-params this.calledWith_ = arguments; } } describe('Notification', () => { - // tslint:disable-next-line:variable-name no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let Notification: any; - // tslint:disable-next-line: no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any let notification: any; let promisified = false; const fakeUtil = Object.assign({}, util); diff --git a/test/signer.ts b/test/signer.ts index 568e0f4e7..0965f3076 100644 --- a/test/signer.ts +++ b/test/signer.ts @@ -15,6 +15,7 @@ import * as assert from 'assert'; import * as dateFormat from 'date-and-time'; import * as crypto from 'crypto'; import * as sinon from 'sinon'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import { URLSigner, @@ -51,7 +52,7 @@ describe('signer', () => { beforeEach(() => { authClient = { - sign: async (_blobToSign: string) => 'signature', + sign: async () => 'signature', getCredentials: async () => ({client_email: CLIENT_EMAIL}), }; bucket = {name: BUCKET_NAME}; @@ -92,7 +93,7 @@ describe('signer', () => { describe('version', () => { it('should default to v2 if version is not given', async () => { const v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves({}); @@ -111,7 +112,7 @@ describe('signer', () => { ...CONFIG, }; const v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves({}); @@ -139,7 +140,7 @@ describe('signer', () => { ...CONFIG, }; const v4 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV4') .resolves({}); @@ -157,7 +158,7 @@ describe('signer', () => { }); it('should error for an invalid version', () => { - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any CONFIG.version = 'v42' as any; assert.throws( @@ -170,11 +171,11 @@ describe('signer', () => { describe('expires', () => { it('should parse Date object into expiration seconds', async () => { const parseExpires = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .spy(signer, 'parseExpires'); const v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves({}); @@ -190,7 +191,7 @@ describe('signer', () => { let v2: sinon.SinonStub; beforeEach(() => { v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves({}); }); @@ -239,6 +240,7 @@ describe('signer', () => { }); describe('composing signed URL', () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars let v2: sinon.SinonStub; const query = { GoogleAccessId: CLIENT_EMAIL, @@ -248,7 +250,7 @@ describe('signer', () => { beforeEach(() => { v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves(query); }); @@ -274,7 +276,7 @@ describe('signer', () => { const signedUrl = await signer.getSignedUrl(CONFIG); const v2 = sandbox - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves({}); @@ -317,8 +319,8 @@ describe('signer', () => { 'X-Goog-Foo': 'value', 'X-Goog-Bar': 'azAZ!*()*%', }; - const v2 = sandbox - // tslint:disable-next-line no-any + sandbox + // eslint-disable-next-line @typescript-eslint/no-explicit-any .stub(signer, 'getSignedUrlV2') .resolves(query); @@ -843,7 +845,7 @@ describe('signer', () => { }; const canonical = signer.getCanonicalQueryParams(query); - const EXPECTED = `A=foo&B=bar`; + const EXPECTED = 'A=foo&B=bar'; assert.strictEqual(canonical, EXPECTED); }); }); 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" -}