From 6ee2c8795e86c3fc0318d028207f83885ae2cb32 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 19:59:47 -0700 Subject: [PATCH 1/7] adding lint command and modifying lint options --- package.json | 6 +++++- tslint.json | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index fc9e0feb1..07bf51c93 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json", "build": "tsc -p tsconfig.release.json", "format": "prettier --write '**/*.ts'", + "lint": "tslint --project tsconfig.json --config tslint.json", "posttest": "npm run format", "test": "mocha -r ts-node/register ./spec/index.spec.ts" }, @@ -56,7 +57,10 @@ "prettier": "^1.17.1", "sinon": "^7.3.2", "ts-node": "^8.2.0", - "typescript": "^3.5.1" + "typescript": "^3.5.1", + "tslint": "^5.16.0", + "tslint-no-unused-expression-chai": "^0.1.4", + "tslint-plugin-prettier": "^2.0.0" }, "peerDependencies": { "firebase-admin": "^8.0.0" diff --git a/tslint.json b/tslint.json index 72dce24d8..ff750e717 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,6 @@ { - "extends": "tslint:recommended", + "defaultSeverity": "warning", + "extends": ["tslint:recommended", "tslint-no-unused-expression-chai"], "rules": { "quotemark": [true, "single", "avoid-escape"], "interface-name": [false], @@ -8,6 +9,7 @@ "whitespace": [true], "member-access": [false], "no-console": [false], - "no-namespace": [false] + "no-namespace": [false], + "trailing-comma": [true, { "functions": "never" }] } } From 931ac523d66dbffcc90c6896db5329faaddb58f0 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 22:59:52 -0700 Subject: [PATCH 2/7] one additional format fix --- integration_test/functions/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integration_test/functions/src/index.ts b/integration_test/functions/src/index.ts index e2a109a2c..1ee1a903f 100644 --- a/integration_test/functions/src/index.ts +++ b/integration_test/functions/src/index.ts @@ -52,7 +52,9 @@ function callScheduleTrigger(functionName: string, region: string) { { method: 'POST', host: 'cloudscheduler.googleapis.com', - path: `projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`, + path: `projects/${ + firebaseConfig.projectId + }/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`, headers: { 'Content-Type': 'application/json', }, @@ -197,7 +199,9 @@ export const integrationTests: any = functions resp .status(500) .send( - `FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}` + `FAIL - details at https://${ + process.env.GCLOUD_PROJECT + }.firebaseio.com/testRuns/${testId}` ); }); }); From 39252ec6c5fec69f03c355a9581e3e584c2c3e96 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Thu, 13 Jun 2019 20:13:16 -0700 Subject: [PATCH 3/7] order deps in package.json, remove unnecessary [] from tslint --- package.json | 6 +++--- tslint.json | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 07bf51c93..2f2b38325 100644 --- a/package.json +++ b/package.json @@ -57,10 +57,10 @@ "prettier": "^1.17.1", "sinon": "^7.3.2", "ts-node": "^8.2.0", - "typescript": "^3.5.1", - "tslint": "^5.16.0", + "tslint": "^5.17.0", "tslint-no-unused-expression-chai": "^0.1.4", - "tslint-plugin-prettier": "^2.0.0" + "tslint-plugin-prettier": "^2.0.0", + "typescript": "^3.5.1" }, "peerDependencies": { "firebase-admin": "^8.0.0" diff --git a/tslint.json b/tslint.json index ff750e717..9b6dff93b 100644 --- a/tslint.json +++ b/tslint.json @@ -3,13 +3,13 @@ "extends": ["tslint:recommended", "tslint-no-unused-expression-chai"], "rules": { "quotemark": [true, "single", "avoid-escape"], - "interface-name": [false], + "interface-name": false, "variable-name": [true, "check-format", "allow-leading-underscore"], "object-literal-sort-keys": false, - "whitespace": [true], - "member-access": [false], - "no-console": [false], - "no-namespace": [false], + "whitespace": true, + "member-access": false, + "no-console": false, + "no-namespace": false, "trailing-comma": [true, { "functions": "never" }] } } From 8712ee957efa07e7da56100d86ba078f5f57f115 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko <31747099+thechenky@users.noreply.github.com> Date: Thu, 13 Jun 2019 20:19:08 -0700 Subject: [PATCH 4/7] Lint spec/* files (#468) --- spec/apps.spec.ts | 36 ++++++++++++++++++----------------- spec/cloud-functions.spec.ts | 27 +++++++++++++------------- spec/config.spec.ts | 4 ++-- spec/function-builder.spec.ts | 12 ++++++------ spec/index.spec.ts | 9 +++++---- spec/testing.spec.ts | 2 +- spec/utils.spec.ts | 8 ++++---- 7 files changed, 51 insertions(+), 47 deletions(-) diff --git a/spec/apps.spec.ts b/spec/apps.spec.ts index 9cf0a35cc..13a7213cd 100644 --- a/spec/apps.spec.ts +++ b/spec/apps.spec.ts @@ -22,6 +22,7 @@ import { expect } from 'chai'; import { apps as appsNamespace } from '../src/apps'; + import * as firebase from 'firebase-admin'; import * as _ from 'lodash'; import * as sinon from 'sinon'; @@ -29,6 +30,7 @@ import * as sinon from 'sinon'; describe('apps', () => { let apps: appsNamespace.Apps; let claims; + beforeEach(() => { apps = new appsNamespace.Apps(); // mock claims intentionally contains dots, square brackets, and nested paths @@ -52,37 +54,37 @@ describe('apps', () => { clock.restore(); }); - it('should retain/release ref counters appropriately', function() { + it('should retain/release ref counters appropriately', () => { apps.retain(); - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 1, }); apps.release(); clock.tick(appsNamespace.garbageCollectionInterval); return Promise.resolve().then(() => { - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 0, }); }); }); - it('should only decrement counter after garbageCollectionInterval is up', function() { + it('should only decrement counter after garbageCollectionInterval is up', () => { apps.retain(); apps.release(); clock.tick(appsNamespace.garbageCollectionInterval / 2); - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 1, }); clock.tick(appsNamespace.garbageCollectionInterval / 2); return Promise.resolve().then(() => { - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 0, }); }); }); - it('should call _destroyApp if app no longer used', function() { - let spy = sinon.spy(apps, '_destroyApp'); + it('should call _destroyApp if app no longer used', () => { + const spy = sinon.spy(apps, '_destroyApp'); apps.retain(); apps.release(); clock.tick(appsNamespace.garbageCollectionInterval); @@ -91,8 +93,8 @@ describe('apps', () => { }); }); - it('should not call _destroyApp if app used again while waiting for release', function() { - let spy = sinon.spy(apps, '_destroyApp'); + it('should not call _destroyApp if app used again while waiting for release', () => { + const spy = sinon.spy(apps, '_destroyApp'); apps.retain(); apps.release(); clock.tick(appsNamespace.garbageCollectionInterval / 2); @@ -103,22 +105,22 @@ describe('apps', () => { }); }); - it('should increment ref counter for each subsequent retain', function() { + it('should increment ref counter for each subsequent retain', () => { apps.retain(); - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 1, }); apps.retain(); - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 2, }); apps.retain(); - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 3, }); }); - it('should work with staggering sets of retain/release', function() { + it('should work with staggering sets of retain/release', () => { apps.retain(); apps.release(); clock.tick(appsNamespace.garbageCollectionInterval / 2); @@ -128,14 +130,14 @@ describe('apps', () => { return Promise.resolve() .then(() => { // Counters are still 1 due second set of retain/release - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 1, }); clock.tick(appsNamespace.garbageCollectionInterval / 2); }) .then(() => { // It's now been a full interval since the second set of retain/release - expect(apps['_refCounter']).to.deep.equal({ + expect(_.get(apps, '_refCounter')).to.deep.equal({ __admin__: 0, }); }); diff --git a/spec/cloud-functions.spec.ts b/spec/cloud-functions.spec.ts index 194ce790b..c0b0e518c 100644 --- a/spec/cloud-functions.spec.ts +++ b/spec/cloud-functions.spec.ts @@ -20,14 +20,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import * as _ from 'lodash'; import { expect } from 'chai'; +import * as _ from 'lodash'; + import { + Change, Event, EventContext, makeCloudFunction, MakeCloudFunctionArgs, - Change, } from '../src/cloud-functions'; describe('makeCloudFunction', () => { @@ -41,7 +42,7 @@ describe('makeCloudFunction', () => { }; it('should put a __trigger on the returned CloudFunction', () => { - let cf = makeCloudFunction({ + const cf = makeCloudFunction({ provider: 'mock.provider', eventType: 'mock.event', service: 'service', @@ -58,7 +59,7 @@ describe('makeCloudFunction', () => { }); it('should have legacy event type in __trigger if provided', () => { - let cf = makeCloudFunction(cloudFunctionArgs); + const cf = makeCloudFunction(cloudFunctionArgs); expect(cf.__trigger).to.deep.equal({ eventTrigger: { eventType: 'providers/provider/eventTypes/event', @@ -69,11 +70,11 @@ describe('makeCloudFunction', () => { }); it('should construct the right context for event', () => { - let args: any = _.assign({}, cloudFunctionArgs, { + const args: any = _.assign({}, cloudFunctionArgs, { handler: (data: any, context: EventContext) => context, }); - let cf = makeCloudFunction(args); - let test: Event = { + const cf = makeCloudFunction(args); + const test: Event = { context: { eventId: '00000', timestamp: '2016-11-04T21:29:03.496Z', @@ -99,12 +100,12 @@ describe('makeCloudFunction', () => { }); it('should throw error when context.params accessed in handler environment', () => { - let args: any = _.assign({}, cloudFunctionArgs, { + const args: any = _.assign({}, cloudFunctionArgs, { handler: (data: any, context: EventContext) => context, triggerResource: () => null, }); - let cf = makeCloudFunction(args); - let test: Event = { + const cf = makeCloudFunction(args); + const test: Event = { context: { eventId: '00000', timestamp: '2016-11-04T21:29:03.496Z', @@ -179,7 +180,7 @@ describe('makeAuth and makeAuthType', () => { }; }, }; - let cf = makeCloudFunction(args); + const cf = makeCloudFunction(args); it('should construct correct auth and authType for admin user', () => { const testEvent = { @@ -311,7 +312,7 @@ describe('Change', () => { describe('fromJSON', () => { it('should create a Change object with a `before` and `after`', () => { - let created = Change.fromJSON({ + const created = Change.fromJSON({ before: { foo: 'bar' }, after: { foo: 'faz' }, }); @@ -325,7 +326,7 @@ describe('Change', () => { _.set(input, 'another', 'value'); return input as T; } - let created = Change.fromJSON( + const created = Change.fromJSON( { before: { foo: 'bar' }, after: { foo: 'faz' }, diff --git a/spec/config.spec.ts b/spec/config.spec.ts index 90ff64620..64963be4e 100644 --- a/spec/config.spec.ts +++ b/spec/config.spec.ts @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import * as mockRequire from 'mock-require'; import { expect } from 'chai'; +import * as mockRequire from 'mock-require'; import { config, firebaseConfig } from '../src/config'; describe('config()', () => { @@ -34,7 +34,7 @@ describe('config()', () => { it('loads config values from .runtimeconfig.json', () => { mockRequire('../../../.runtimeconfig.json', { foo: 'bar', firebase: {} }); - let loaded = config(); + const loaded = config(); expect(loaded).to.not.have.property('firebase'); expect(loaded).to.have.property('foo', 'bar'); }); diff --git a/spec/function-builder.spec.ts b/spec/function-builder.spec.ts index 615d9fe9c..cddb2d10b 100644 --- a/spec/function-builder.spec.ts +++ b/spec/function-builder.spec.ts @@ -34,7 +34,7 @@ describe('FunctionBuilder', () => { }); it('should allow supported region to be set', () => { - let fn = functions + const fn = functions .region('us-east1') .auth.user() .onCreate(user => user); @@ -43,7 +43,7 @@ describe('FunctionBuilder', () => { }); it('should allow multiple supported regions to be set', () => { - let fn = functions + const fn = functions .region('us-east1', 'us-central1') .auth.user() .onCreate(user => user); @@ -52,7 +52,7 @@ describe('FunctionBuilder', () => { }); it('should allow all supported regions to be set', () => { - let fn = functions + const fn = functions .region( 'us-central1', 'us-east1', @@ -75,7 +75,7 @@ describe('FunctionBuilder', () => { }); it('should allow valid runtime options to be set', () => { - let fn = functions + const fn = functions .runWith({ timeoutSeconds: 90, memory: '256MB', @@ -88,7 +88,7 @@ describe('FunctionBuilder', () => { }); it('should allow both supported region and valid runtime options to be set', () => { - let fn = functions + const fn = functions .region('europe-west2') .runWith({ timeoutSeconds: 90, @@ -103,7 +103,7 @@ describe('FunctionBuilder', () => { }); it('should allow both valid runtime options and supported region to be set in reverse order', () => { - let fn = functions + const fn = functions .runWith({ timeoutSeconds: 90, memory: '256MB', diff --git a/spec/index.spec.ts b/spec/index.spec.ts index 5efe47fce..6d56878da 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -28,19 +28,20 @@ import * as nock from 'nock'; nock.disableNetConnect(); import 'mocha'; -import './utils.spec'; + import './apps.spec'; import './cloud-functions.spec'; import './config.spec'; -import './setup.spec'; -import './testing.spec'; import './function-builder.spec'; import './providers/analytics.spec'; import './providers/auth.spec'; +import './providers/crashlytics.spec'; import './providers/database.spec'; import './providers/firestore.spec'; import './providers/https.spec'; import './providers/pubsub.spec'; import './providers/remoteConfig.spec'; import './providers/storage.spec'; -import './providers/crashlytics.spec'; +import './setup.spec'; +import './testing.spec'; +import './utils.spec'; diff --git a/spec/testing.spec.ts b/spec/testing.spec.ts index 4df5362df..e4bc73d55 100644 --- a/spec/testing.spec.ts +++ b/spec/testing.spec.ts @@ -26,7 +26,7 @@ import * as testing from '../src/testing'; // TODO(rjh): As actual testing methods become available, replace this with actual tests. describe('testing', () => { - it('should be accessible through the entrypoint', function() { + it('should be accessible through the entrypoint', () => { expect(testing.whereAreTheBugs()).to.not.equal('Earth'); }); }); diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index cedf43597..57634dd72 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -20,8 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import { normalizePath, pathParts, valAt, applyChange } from '../src/utils'; import { expect } from 'chai'; +import { applyChange, normalizePath, pathParts, valAt } from '../src/utils'; describe('utils', () => { describe('.normalizePath(path: string)', () => { @@ -71,9 +71,9 @@ describe('utils', () => { }); it('should return the merged value of two objects', () => { - let from = { a: { b: 'foo', c: 23, d: 444 }, d: { e: 42 } }; - let to: any = { a: { b: 'bar', c: null }, d: null, e: { f: 'g' } }; - let result = { a: { b: 'bar', d: 444 }, e: { f: 'g' } }; + const from = { a: { b: 'foo', c: 23, d: 444 }, d: { e: 42 } }; + const to: any = { a: { b: 'bar', c: null }, d: null, e: { f: 'g' } }; + const result = { a: { b: 'bar', d: 444 }, e: { f: 'g' } }; expect(applyChange(from, to)).to.deep.equal(result); }); }); From 3b29d70c80b309c838fa6ab1c95b190fc728984c Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 19:59:47 -0700 Subject: [PATCH 5/7] adding lint command and modifying lint options --- package.json | 6 +++++- tslint.json | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index fc9e0feb1..07bf51c93 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json", "build": "tsc -p tsconfig.release.json", "format": "prettier --write '**/*.ts'", + "lint": "tslint --project tsconfig.json --config tslint.json", "posttest": "npm run format", "test": "mocha -r ts-node/register ./spec/index.spec.ts" }, @@ -56,7 +57,10 @@ "prettier": "^1.17.1", "sinon": "^7.3.2", "ts-node": "^8.2.0", - "typescript": "^3.5.1" + "typescript": "^3.5.1", + "tslint": "^5.16.0", + "tslint-no-unused-expression-chai": "^0.1.4", + "tslint-plugin-prettier": "^2.0.0" }, "peerDependencies": { "firebase-admin": "^8.0.0" diff --git a/tslint.json b/tslint.json index 72dce24d8..ff750e717 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,6 @@ { - "extends": "tslint:recommended", + "defaultSeverity": "warning", + "extends": ["tslint:recommended", "tslint-no-unused-expression-chai"], "rules": { "quotemark": [true, "single", "avoid-escape"], "interface-name": [false], @@ -8,6 +9,7 @@ "whitespace": [true], "member-access": [false], "no-console": [false], - "no-namespace": [false] + "no-namespace": [false], + "trailing-comma": [true, { "functions": "never" }] } } From f6b2572ba45b69257bb437b22a4fd99aa606be6a Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Wed, 12 Jun 2019 22:59:52 -0700 Subject: [PATCH 6/7] one additional format fix --- integration_test/functions/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integration_test/functions/src/index.ts b/integration_test/functions/src/index.ts index e2a109a2c..1ee1a903f 100644 --- a/integration_test/functions/src/index.ts +++ b/integration_test/functions/src/index.ts @@ -52,7 +52,9 @@ function callScheduleTrigger(functionName: string, region: string) { { method: 'POST', host: 'cloudscheduler.googleapis.com', - path: `projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`, + path: `projects/${ + firebaseConfig.projectId + }/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`, headers: { 'Content-Type': 'application/json', }, @@ -197,7 +199,9 @@ export const integrationTests: any = functions resp .status(500) .send( - `FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}` + `FAIL - details at https://${ + process.env.GCLOUD_PROJECT + }.firebaseio.com/testRuns/${testId}` ); }); }); From ee752f474651625dd4cb1cfb810a69614afdad14 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko Date: Thu, 13 Jun 2019 20:13:16 -0700 Subject: [PATCH 7/7] order deps in package.json, remove unnecessary [] from tslint --- package.json | 6 +++--- tslint.json | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 07bf51c93..2f2b38325 100644 --- a/package.json +++ b/package.json @@ -57,10 +57,10 @@ "prettier": "^1.17.1", "sinon": "^7.3.2", "ts-node": "^8.2.0", - "typescript": "^3.5.1", - "tslint": "^5.16.0", + "tslint": "^5.17.0", "tslint-no-unused-expression-chai": "^0.1.4", - "tslint-plugin-prettier": "^2.0.0" + "tslint-plugin-prettier": "^2.0.0", + "typescript": "^3.5.1" }, "peerDependencies": { "firebase-admin": "^8.0.0" diff --git a/tslint.json b/tslint.json index ff750e717..9b6dff93b 100644 --- a/tslint.json +++ b/tslint.json @@ -3,13 +3,13 @@ "extends": ["tslint:recommended", "tslint-no-unused-expression-chai"], "rules": { "quotemark": [true, "single", "avoid-escape"], - "interface-name": [false], + "interface-name": false, "variable-name": [true, "check-format", "allow-leading-underscore"], "object-literal-sort-keys": false, - "whitespace": [true], - "member-access": [false], - "no-console": [false], - "no-namespace": [false], + "whitespace": true, + "member-access": false, + "no-console": false, + "no-namespace": false, "trailing-comma": [true, { "functions": "never" }] } }