Skip to content

Commit 9694dca

Browse files
merlinnotthechenky
authored andcommitted
Run Prettier and TSLint in the CI (firebase#493)
* Run Prettier and TSLint in the CI * Specify parameters in an alphabetical order * Reformat
1 parent 81764d6 commit 9694dca

File tree

22 files changed

+125
-109
lines changed

22 files changed

+125
-109
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
cache: npm
2+
jobs:
3+
include:
4+
- name: lint
5+
script: npm run lint
6+
stage: verify
7+
- name: format
8+
script: npm run format
9+
stage: verify
110
language: node_js
211
node_js:
312
- '8'

integration_test/functions/src/database-tests.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export const databaseTests: any = functions.database
5050
.it('should have refs resources', (change, context) =>
5151
expectEq(
5252
context.resource.name,
53-
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${
54-
context.params.testId
55-
}/start`
53+
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${context.params.testId}/start`
5654
)
5755
)
5856

integration_test/functions/src/firestore-tests.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export const firestoreTests: any = functions
2222
.it('should have well-formatted resource', (snap, context) =>
2323
expectEq(
2424
context.resource.name,
25-
`projects/${
26-
process.env.GCLOUD_PROJECT
27-
}/databases/(default)/documents/tests/${context.params.documentId}`
25+
`projects/${process.env.GCLOUD_PROJECT}/databases/(default)/documents/tests/${context.params.documentId}`
2826
)
2927
)
3028

integration_test/functions/src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ function callScheduleTrigger(functionName: string, region: string) {
5252
{
5353
method: 'POST',
5454
host: 'cloudscheduler.googleapis.com',
55-
path: `projects/${
56-
firebaseConfig.projectId
57-
}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
55+
path: `projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
5856
headers: {
5957
'Content-Type': 'application/json',
6058
},
@@ -199,9 +197,7 @@ export const integrationTests: any = functions
199197
resp
200198
.status(500)
201199
.send(
202-
`FAIL - details at https://${
203-
process.env.GCLOUD_PROJECT
204-
}.firebaseio.com/testRuns/${testId}`
200+
`FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}`
205201
);
206202
});
207203
});

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
"build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
2525
"build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json",
2626
"build": "tsc -p tsconfig.release.json",
27-
"format": "prettier --write '**/*.ts'",
28-
"lint": "tslint --project tsconfig.json --config tslint.json",
29-
"posttest": "npm run format",
27+
"format": "prettier --check '**/*.ts'",
28+
"format:fix": "prettier --write '**/*.ts'",
29+
"lint": "tslint --config tslint.json --project tsconfig.json ",
30+
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
3031
"test": "mocha -r ts-node/register ./spec/index.spec.ts"
3132
},
3233
"dependencies": {
@@ -58,6 +59,7 @@
5859
"sinon": "^7.3.2",
5960
"ts-node": "^8.2.0",
6061
"tslint": "^5.17.0",
62+
"tslint-config-prettier": "^1.18.0",
6163
"tslint-no-unused-expression-chai": "^0.1.4",
6264
"tslint-plugin-prettier": "^2.0.0",
6365
"typescript": "^3.5.1"

spec/providers/auth.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import { expect } from 'chai';
2424
import * as firebase from 'firebase-admin';
2525

26+
import { Resolver } from 'dns';
2627
import { CloudFunction, Event, EventContext } from '../../src/cloud-functions';
2728
import * as functions from '../../src/index';
2829
import * as auth from '../../src/providers/auth';
29-
import { Resolver } from 'dns';
3030

3131
describe('Auth Functions', () => {
3232
const event: Event = {

src/apps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import * as _ from 'lodash';
2423
import * as firebase from 'firebase-admin';
24+
import * as _ from 'lodash';
2525
import { firebaseConfig } from './config';
2626

2727
export function apps(): apps.Apps {
@@ -65,7 +65,7 @@ export namespace apps {
6565

6666
_appAlive(appName: string): boolean {
6767
try {
68-
let app = firebase.app(appName);
68+
const app = firebase.app(appName);
6969
return !_.get(app, 'isDeleted_');
7070
} catch (e) {
7171
return false;
@@ -83,15 +83,15 @@ export namespace apps {
8383
}
8484

8585
retain() {
86-
let increment = (n?: number) => {
86+
const increment = (n?: number) => {
8787
return (n || 0) + 1;
8888
};
8989
// Increment counter for admin because function might use event.data.ref
9090
_.update(this._refCounter, '__admin__', increment);
9191
}
9292

9393
release() {
94-
let decrement = (n: number) => {
94+
const decrement = (n: number) => {
9595
return n - 1;
9696
};
9797
return delay(garbageCollectionInterval).then(() => {

src/cloud-functions.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export namespace Change {
127127
after: any,
128128
fieldMask: string
129129
) {
130-
let before = _.assign({}, after);
131-
let masks = fieldMask.split(',');
130+
const before = _.assign({}, after);
131+
const masks = fieldMask.split(',');
132132
_.forEach(masks, (mask) => {
133133
const val = _.get(sparseBefore, mask);
134134
if (typeof val === 'undefined') {
@@ -239,17 +239,17 @@ export function makeCloudFunction<EventData>({
239239
opts = {},
240240
labels = {},
241241
}: MakeCloudFunctionArgs<EventData>): CloudFunction<EventData> {
242-
let cloudFunction: any = (data: any, context: any) => {
242+
const cloudFunction: any = (data: any, context: any) => {
243243
if (legacyEventType && context.eventType === legacyEventType) {
244244
// v1beta1 event flow has different format for context, transform them to new format.
245245
context.eventType = provider + '.' + eventType;
246246
context.resource = {
247-
service: service,
247+
service,
248248
name: context.resource,
249249
};
250250
}
251251

252-
let event: Event = {
252+
const event: Event = {
253253
data,
254254
context,
255255
};
@@ -305,7 +305,7 @@ export function makeCloudFunction<EventData>({
305305
return {};
306306
}
307307

308-
let trigger: any = _.assign(optsToTrigger(opts), {
308+
const trigger: any = _.assign(optsToTrigger(opts), {
309309
eventTrigger: {
310310
resource: triggerResource(),
311311
eventType: legacyEventType || provider + '.' + eventType,
@@ -335,15 +335,15 @@ function _makeParams(
335335
// In unit testing, `resource` may be unpopulated for a test event.
336336
return {};
337337
}
338-
let triggerResource = triggerResourceGetter();
339-
let wildcards = triggerResource.match(WILDCARD_REGEX);
340-
let params: { [option: string]: any } = {};
338+
const triggerResource = triggerResourceGetter();
339+
const wildcards = triggerResource.match(WILDCARD_REGEX);
340+
const params: { [option: string]: any } = {};
341341
if (wildcards) {
342-
let triggerResourceParts = _.split(triggerResource, '/');
343-
let eventResourceParts = _.split(context.resource.name, '/');
342+
const triggerResourceParts = _.split(triggerResource, '/');
343+
const eventResourceParts = _.split(context.resource.name, '/');
344344
_.forEach(wildcards, (wildcard) => {
345-
let wildcardNoBraces = wildcard.slice(1, -1);
346-
let position = _.indexOf(triggerResourceParts, wildcard);
345+
const wildcardNoBraces = wildcard.slice(1, -1);
346+
const position = _.indexOf(triggerResourceParts, wildcard);
347347
params[wildcardNoBraces] = eventResourceParts[position];
348348
});
349349
}
@@ -371,7 +371,7 @@ function _detectAuthType(event: Event) {
371371
}
372372

373373
export function optsToTrigger(opts: DeploymentOptions) {
374-
let trigger: any = {};
374+
const trigger: any = {};
375375
if (opts.regions) {
376376
trigger.regions = opts.regions;
377377
}

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export function config(): config.Config {
3232
export namespace config {
3333
// Config type is usable as a object (dot notation allowed), and firebase
3434
// property will also code complete.
35-
export type Config = { [key: string]: any };
35+
export interface Config {
36+
[key: string]: any;
37+
}
3638

3739
/** @internal */
3840
export let singleton: config.Config;
@@ -81,7 +83,7 @@ function init() {
8183
}
8284

8385
try {
84-
let path =
86+
const path =
8587
process.env.CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json';
8688
const parsed = require(path);
8789
delete parsed.firebase;

src/encoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export function dateToTimestampProto(timeString?: string) {
2424
if (typeof timeString === 'undefined') {
2525
return;
2626
}
27-
let date = new Date(timeString);
28-
let seconds = Math.floor(date.getTime() / 1000);
27+
const date = new Date(timeString);
28+
const seconds = Math.floor(date.getTime() / 1000);
2929
let nanos = 0;
3030
if (timeString.length > 20) {
3131
const nanoString = timeString.substring(20, timeString.length - 1);

0 commit comments

Comments
 (0)