Skip to content

Commit c74f19c

Browse files
authored
Fix linting issues and type safety checks (google#2366)
1 parent 14bc738 commit c74f19c

File tree

72 files changed

+204
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+204
-295
lines changed

functions/src/common/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { DecodedIdToken, getAuth } from 'firebase-admin/auth';
1818
import { DocumentSnapshot } from 'firebase-admin/firestore';
19-
import { https, Response } from 'firebase-functions/v1';
19+
import { Response, https } from 'firebase-functions/v1';
2020
import { EmulatorIdToken } from '../handlers';
2121
import { GroundProtos } from '@ground/proto';
2222
import { registry } from '@ground/lib';

functions/src/common/context.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { Datastore } from './datastore';
1818
import { MailService } from './mail-service';
19-
import { initializeApp, getApp } from 'firebase-admin/app';
19+
import { getApp, initializeApp } from 'firebase-admin/app';
2020
import { getFirestore } from 'firebase-admin/firestore';
2121

2222
let datastore: Datastore | undefined;
@@ -25,7 +25,7 @@ let mailService: MailService | undefined;
2525
export function initializeFirebaseApp() {
2626
try {
2727
getApp();
28-
} catch (e) {
28+
} catch {
2929
initializeApp();
3030
}
3131
}
@@ -39,9 +39,8 @@ export function getDatastore(): Datastore {
3939

4040
export async function getMailService(): Promise<MailService | undefined> {
4141
if (mailService) return mailService;
42-
const mailServerConfig = await MailService.getMailServerConfig(
43-
getDatastore()
44-
);
42+
const mailServerConfig =
43+
await MailService.getMailServerConfig(getDatastore());
4544
if (!mailServerConfig) return;
4645
mailService = new MailService(mailServerConfig);
4746
return mailService;

functions/src/common/datastore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { registry } from '@ground/lib';
2121
import { GroundProtos } from '@ground/proto';
2222

2323
import Pb = GroundProtos.ground.v1beta1;
24-
import { leftOuterJoinSorted, QueryIterator } from './query-iterator';
24+
import { QueryIterator, leftOuterJoinSorted } from './query-iterator';
2525

2626
const l = registry.getFieldIds(Pb.LocationOfInterest);
2727
const sb = registry.getFieldIds(Pb.Submission);

functions/src/common/query-iterator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export class QueryIterator implements AsyncIterator<QueryDocumentSnapshot> {
3434
* @param query The Firestore query to iterate over.
3535
* @param pageSize The number of documents to fetch in each batch.
3636
*/
37-
constructor(private query: Query, private pageSize: number) {}
37+
constructor(
38+
private query: Query,
39+
private pageSize: number
40+
) {}
3841

3942
/**
4043
* Fetches the next batch of documents and returns the next document in the iterator.

functions/src/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import cors from 'cors';
1818
import { DecodedIdToken } from 'firebase-admin/auth';
19-
import { https, Response } from 'firebase-functions';
19+
import { Response, https } from 'firebase-functions';
2020
import { getDecodedIdToken } from './common/auth';
2121
import { INTERNAL_SERVER_ERROR, UNAUTHORIZED } from 'http-status-codes';
2222
import cookieParser from 'cookie-parser';

functions/src/import-geojson.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import JSONStream from 'jsonstream-ts';
2222
import { canImport } from './common/auth';
2323
import { DecodedIdToken } from 'firebase-admin/auth';
2424
import { GroundProtos } from '@ground/proto';
25-
import { toDocumentData, toGeometryPb, isGeometryValid } from '@ground/lib';
25+
import { isGeometryValid, toDocumentData, toGeometryPb } from '@ground/lib';
2626
import { Feature, GeoJsonProperties } from 'geojson';
2727
import { ErrorHandler } from './handlers';
2828

functions/src/on-create-loi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ async function fetchWhispProperties(
120120
headers: Headers,
121121
body: Body
122122
): Promise<Properties> {
123-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
124123
const response = await fetch(url, {
125124
method: 'POST',
126125
headers,

functions/src/on-create-passlist-entry.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import {
2121
stubAdminApi,
2222
} from '@ground/lib/testing/firestore';
2323
import { resetDatastore } from './common/context';
24-
import { Firestore } from 'firebase-admin/firestore';
24+
import { Firestore, QueryDocumentSnapshot } from 'firebase-admin/firestore';
25+
import firebaseFunctionsTest from 'firebase-functions-test';
2526
import * as functions from './index';
2627
import * as context from './common/context';
2728
import { MailService } from './common/mail-service';
2829

29-
const test = require('firebase-functions-test')();
30+
const test = firebaseFunctionsTest();
3031

3132
describe('onCreatePasslistEntry()', () => {
3233
let mockFirestore: Firestore;
@@ -65,7 +66,9 @@ describe('onCreatePasslistEntry()', () => {
6566

6667
it('passlist notification email template exists', async () => {
6768
await mockFirestore.collection('passlists').add({});
68-
await test.wrap(functions.onCreatePasslistEntry)(newDocumentSnapshot({}));
69+
await test.wrap(functions.onCreatePasslistEntry)(
70+
newDocumentSnapshot({}) as QueryDocumentSnapshot
71+
);
6972
expect(getMailServiceMock).not.toHaveBeenCalled();
7073
});
7174

@@ -84,7 +87,7 @@ describe('onCreatePasslistEntry()', () => {
8487
mockFirestore.doc('config/mail/templates/passlisted').set(mail);
8588
mockFirestore.doc(`passlists/${mail.to}`).set({});
8689
await test.wrap(functions.onCreatePasslistEntry)(
87-
newDocumentSnapshot({}),
90+
newDocumentSnapshot({}) as QueryDocumentSnapshot,
8891
newEventContext({ entryId: mail.to })
8992
);
9093
expect(getMailServiceMock).toHaveBeenCalled();

functions/src/on-write-submission.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
*/
1616

1717
import {
18-
stubAdminApi,
19-
newEventContext,
20-
newDocumentSnapshot,
21-
newCountQuery,
2218
createMockFirestore,
19+
newCountQuery,
20+
newDocumentSnapshot,
21+
newEventContext,
22+
stubAdminApi,
2323
} from '@ground/lib/testing/firestore';
2424
import * as functions from './index';
2525
import { loi } from './common/datastore';
26-
import { Firestore } from 'firebase-admin/firestore';
26+
import { DocumentSnapshot, Firestore } from 'firebase-admin/firestore';
27+
import firebaseFunctionsTest from 'firebase-functions-test';
2728
import { resetDatastore } from './common/context';
2829
import { registry } from '@ground/lib';
2930
import { GroundProtos } from '@ground/proto';
3031

31-
const test = require('firebase-functions-test')();
32+
const test = firebaseFunctionsTest();
3233

3334
import Pb = GroundProtos.ground.v1beta1;
3435
const l = registry.getFieldIds(Pb.LocationOfInterest);
@@ -77,7 +78,7 @@ describe('onWriteSubmission()', () => {
7778
installSubmissionCountSpy(SUBMISSIONS_PATH, LOI_ID, 2);
7879

7980
await test.wrap(functions.onWriteSubmission)(
80-
{ before: undefined, after: SUBMISSION },
81+
{ before: null as unknown as DocumentSnapshot, after: SUBMISSION },
8182
CONTEXT
8283
);
8384

@@ -89,7 +90,7 @@ describe('onWriteSubmission()', () => {
8990
installSubmissionCountSpy(SUBMISSIONS_PATH, LOI_ID, 1);
9091

9192
await test.wrap(functions.onWriteSubmission)(
92-
{ before: SUBMISSION, after: undefined },
93+
{ before: SUBMISSION, after: null as unknown as DocumentSnapshot },
9394
CONTEXT
9495
);
9596

@@ -101,7 +102,10 @@ describe('onWriteSubmission()', () => {
101102
installSubmissionCountSpy(SUBMISSIONS_PATH, LOI_ID, 1);
102103

103104
await test.wrap(functions.onWriteSubmission)(
104-
{ before: undefined, after: undefined },
105+
{
106+
before: null as unknown as DocumentSnapshot,
107+
after: null as unknown as DocumentSnapshot,
108+
},
105109
CONTEXT
106110
);
107111

@@ -119,7 +123,7 @@ describe('onWriteSubmission()', () => {
119123

120124
await expectAsync(
121125
test.wrap(functions.onWriteSubmission)(
122-
{ before: undefined, after: SUBMISSION },
126+
{ before: null as unknown as DocumentSnapshot, after: SUBMISSION },
123127
CONTEXT
124128
)
125129
).toBeRejected();

functions/src/profile-refresh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { getDatastore } from './common/context';
1818
import { CallableRequest, HttpsError } from 'firebase-functions/v2/https';
1919
import { getAuth } from 'firebase-admin/auth';
2020

21-
type ProfileRefreshResponse = String | HttpsError;
21+
type ProfileRefreshResponse = string | HttpsError;
2222
type ProfileRefreshRequest = CallableRequest<ProfileRefreshResponse>;
2323

2424
/**

0 commit comments

Comments
 (0)