Skip to content

Commit bc7594e

Browse files
committed
chore: fix some lint errors
1 parent 0e90b5c commit bc7594e

File tree

12 files changed

+85
-62
lines changed

12 files changed

+85
-62
lines changed

eslint.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ const tseslint = require("typescript-eslint");
55

66
module.exports = tseslint.config(
77
eslint.configs.recommended,
8-
...tseslint.configs.strict
8+
...tseslint.configs.strict,
9+
{
10+
ignores: ["node_modules/", "lib/", "**/*.js"],
11+
}
912
);

src/common/process.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface ProcessOptions {
44
id: string;
55
fieldDependencyArray?: string[];
66
shouldBackfill?: (data: Record<string, FirestoreField>) => boolean;
7-
errorFn?: (e: unknown) => string | void | Promise<string | void>;
7+
errorFn?: (e: unknown) => string | undefined | Promise<string | undefined>;
88
batchFn?: (
99
data: Record<string, FirestoreField>[]
1010
) => Promise<Record<string, FirestoreField>[]>;
@@ -18,7 +18,9 @@ type ProcessFunction = (
1818
data: Record<string, FirestoreField>
1919
) => Record<string, FirestoreField> | Promise<Record<string, FirestoreField>>;
2020
type ShouldBackfillFunction = (data: Record<string, FirestoreField>) => boolean;
21-
type ErrorFunction = (e: unknown) => string | void | Promise<string | void>;
21+
type ErrorFunction = (
22+
e: unknown
23+
) => string | undefined | Promise<string | undefined>;
2224
type BatchFunction = (
2325
data: Record<string, FirestoreField>[]
2426
) => Promise<Record<string, FirestoreField>[]>;

src/distributed-tasks/firestore_backfill/handler_from_process.test.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import * as admin from "firebase-admin";
24
import { Process } from "../../common/process";
35
import { getValidDocs } from "./handler_from_process";
@@ -10,7 +12,9 @@ admin.initializeApp({
1012
projectId: "demo-gcp",
1113
});
1214

13-
const firestoreObserver = jest.fn((_x: any) => {});
15+
const firestoreObserver = jest.fn((x: any) => {
16+
console.debug("firestoreObserver", x);
17+
});
1418

1519
describe.skip("getValidDocs", () => {
1620
let unsubscribe: (() => void) | undefined;
@@ -55,7 +59,10 @@ describe.skip("getValidDocs", () => {
5559

5660
const process = new Process((data) => data, {
5761
id: "testProcess",
58-
shouldBackfill: (data) => true,
62+
shouldBackfill: (data) => {
63+
console.debug("shouldBackfill", data);
64+
return true;
65+
},
5966
});
6067

6168
const documentIds = ["doc1", "doc2", "doc3"];

src/distributed-tasks/firestore_backfill/handler_from_process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export async function getValidDocs(
8484
//@ts-ignore
8585
const docs = await transaction.getAll<DocumentData>(...refs);
8686

87-
for (let doc of docs) {
87+
for (const doc of docs) {
8888
const data = doc.data();
8989
if (!process.shouldBackfill || !process.shouldBackfill(data)) {
9090
functions.logger.warn(

src/distributed-tasks/firestore_backfill/metadata_document.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import * as admin from "firebase-admin";
24
import { Timestamp } from "firebase-admin/firestore";
35
import fetch from "node-fetch";
@@ -16,8 +18,9 @@ admin.initializeApp({
1618
projectId: "demo-gcp",
1719
});
1820

19-
const firestoreObserver = jest.fn((_x: any) => {});
20-
let collectionName: string;
21+
const firestoreObserver = jest.fn((x: any) => {
22+
console.debug("firestoreObserver", x);
23+
});
2124

2225
describe("createMetadataDoc", () => {
2326
let unsubscribe: (() => void) | undefined;
@@ -182,8 +185,8 @@ describe("getMetadataDoc", () => {
182185
const metadataDoc = await getMetadataDoc(metadataDocumentPath, metadata);
183186

184187
expect(metadataDoc).not.toBeNull();
185-
expect(metadataDoc!.exists).toBeTruthy();
186-
expect(metadataDoc!.data()).toEqual(metadata);
188+
expect(metadataDoc?.exists).toBeTruthy();
189+
expect(metadataDoc?.data()).toEqual(metadata);
187190
});
188191

189192
test("should return null if metadata doc does not exist", async () => {

src/distributed-tasks/firestore_backfill/metadata_document.ts

-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,5 @@ export const updateOrCreateMetadataDoc = async (
7171

7272
const doc = await createMetadataDoc(metadataDocumentPath, metadata);
7373

74-
shouldBackfill = shouldBackfill;
75-
7674
return { path: doc.path, shouldBackfill };
7775
};

src/distributed-tasks/firestore_backfill/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import { FirestoreField } from "../../common/types";
24

35
export interface FirestoreBackfillOptions {
46
queueName: string;
57
metadataDocumentPath: string;
68
collectionName: string;
9+
// TODO: remove any
710
shouldDoBackfill: (data: Record<string, any>) => Promise<boolean>;
811
extensionInstanceId?: string;
912
metadata?: Record<string, FirestoreField>;

src/distributed-tasks/handler.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ export function taskThreadTaskHandler<P>(
5656
);
5757

5858
const tasksDocSnap = await admin.firestore().doc(tasksDoc).get();
59-
const { totalLength } = tasksDocSnap.data() as any;
60-
let { processedLength } = tasksDocSnap.data() as any;
59+
// TODO: validate this
60+
const { totalLength } = tasksDocSnap.data() as { totalLength: number };
61+
let { processedLength } = tasksDocSnap.data() as {
62+
processedLength: number;
63+
};
6164

6265
processedLength += success;
6366

src/distributed-tasks/trigger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function taskThreadTrigger<P>({
4343
extensionInstanceId,
4444
taskParams,
4545
}: BackfillTrigger<P>) {
46-
let runtime = extensionInstanceId ? getExtensions().runtime() : undefined;
46+
const runtime = extensionInstanceId ? getExtensions().runtime() : undefined;
4747

4848
const queue = getFunctions().taskQueue(queueName, extensionInstanceId);
4949

0 commit comments

Comments
 (0)