Skip to content

Commit abfe405

Browse files
committed
migrate Firestore to eslint
1 parent 15fee3b commit abfe405

File tree

82 files changed

+406
-480
lines changed

Some content is hidden

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

82 files changed

+406
-480
lines changed

config/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
],
2222
"rules": {
2323
"no-unused-expressions": "off",
24-
"@typescript-eslint/no-explicit-any": "off"
24+
"@typescript-eslint/no-explicit-any": "off",
25+
"@typescript-eslint/tslint/config": "off"
2526
}
2627
}
2728
],

packages/firestore/index.node.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
import firebase from '@firebase/app';
1919
import './src/platform_node/node_init';
20-
import { Firestore } from './src/api/database';
2120
import { configureForFirebase } from './src/platform/config';
2221
import * as types from '@firebase/firestore-types';
2322

24-
export function registerFirestore(instance) {
23+
export function registerFirestore(instance): void {
2524
configureForFirebase(instance);
2625
}
2726

packages/firestore/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { configureForFirebase } from './src/platform/config';
2222

2323
import * as types from '@firebase/firestore-types';
2424

25-
export function registerFirestore(instance) {
25+
export function registerFirestore(instance): void {
2626
configureForFirebase(instance);
2727
}
2828

packages/firestore/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"build": "rollup -c",
88
"build:console": "node tools/console.build.js",
99
"dev": "rollup -c -w",
10-
"lint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
11-
"lint:fix": "tslint --fix -p tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
12-
"lint:eslint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
10+
"lint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
11+
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
1312
"prettier": "prettier --write 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'",
1413
"test": "run-s lint test:all",
1514
"test:all": "run-p test:browser test:node",

packages/firestore/src/api/blob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class Blob {
137137
// For our internal TypeScript code PublicBlob doesn't exist as a type, and so
138138
// we need to use Blob as type and export it too.
139139
// tslint:disable-next-line:variable-name We're treating this as a class name.
140-
export let PublicBlob = makeConstructorPrivate(
140+
export const PublicBlob = makeConstructorPrivate(
141141
Blob,
142142
'Use Blob.fromUint8Array() or Blob.fromBase64String() instead.'
143143
);

packages/firestore/src/api/credentials.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ export class EmptyCredentialsProvider implements CredentialsProvider {
104104
*/
105105
private changeListener: CredentialChangeListener | null = null;
106106

107-
constructor() {}
108-
109107
getToken(): Promise<Token | null> {
110108
return Promise.resolve<Token | null>(null);
111109
}

packages/firestore/src/api/database.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class FirestoreSettings {
158158
readonly forceLongPolling: boolean;
159159

160160
// Can be a google-auth-library or gapi client.
161-
// tslint:disable-next-line:no-any
161+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
162162
credentials?: any;
163163

164164
constructor(settings: PrivateSettings) {
@@ -480,7 +480,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
480480

481481
const databaseInfo = this.makeDatabaseInfo();
482482

483-
const preConverter = (value: unknown) => {
483+
const preConverter = (value: unknown): unknown => {
484484
if (value instanceof DocumentReference) {
485485
const thisDb = this._config.databaseId;
486486
const otherDb = value.firestore._config.databaseId;
@@ -1116,7 +1116,7 @@ export class DocumentReference implements firestore.DocumentReference {
11161116
options: ListenOptions,
11171117
observer: PartialObserver<firestore.DocumentSnapshot>
11181118
): Unsubscribe {
1119-
let errHandler = (err: Error) => {
1119+
let errHandler = (err: Error): void => {
11201120
console.error('Uncaught Error in onSnapshot:', err);
11211121
};
11221122
if (observer.error) {
@@ -1387,15 +1387,6 @@ export class DocumentSnapshot implements firestore.DocumentSnapshot {
13871387

13881388
export class QueryDocumentSnapshot extends DocumentSnapshot
13891389
implements firestore.QueryDocumentSnapshot {
1390-
constructor(
1391-
firestore: Firestore,
1392-
key: DocumentKey,
1393-
document: Document,
1394-
fromCache: boolean,
1395-
hasPendingWrites: boolean
1396-
) {
1397-
super(firestore, key, document, fromCache, hasPendingWrites);
1398-
}
13991390

14001391
data(options?: SnapshotOptions): firestore.DocumentData {
14011392
const data = super.data(options);
@@ -1829,7 +1820,7 @@ export class Query implements firestore.Query {
18291820
options: ListenOptions,
18301821
observer: PartialObserver<firestore.QuerySnapshot>
18311822
): Unsubscribe {
1832-
let errHandler = (err: Error) => {
1823+
let errHandler = (err: Error): void => {
18331824
console.error('Uncaught Error in onSnapshot:', err);
18341825
};
18351826
if (observer.error) {
@@ -1851,7 +1842,7 @@ export class Query implements firestore.Query {
18511842
asyncObserver,
18521843
options
18531844
);
1854-
return () => {
1845+
return (): void => {
18551846
asyncObserver.mute();
18561847
firestoreClient.unlisten(internalListener);
18571848
};

packages/firestore/src/api/user_data_converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class ParseContext {
220220
return context;
221221
}
222222

223-
childContextForArray(index: number): ParseContext {
223+
childContextForArray(_index: number): ParseContext {
224224
// TODO(b/34871131): We don't support array paths right now; so make path
225225
// null.
226226
return new ParseContext(

packages/firestore/src/core/event_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class EventManager implements SyncEngineListener {
7272

7373
listener.applyOnlineStateChange(this.onlineState);
7474

75-
if (queryInfo.viewSnap) listener.onViewSnapshot(queryInfo.viewSnap);
75+
if (queryInfo.viewSnap) {listener.onViewSnapshot(queryInfo.viewSnap);}
7676

7777
if (firstListen) {
7878
return this.syncEngine.listen(query).then(targetId => {

packages/firestore/src/core/firestore_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,12 @@ export class FirestoreClient {
429429
serializer
430430
);
431431

432-
const remoteStoreOnlineStateChangedHandler = onlineState =>
432+
const remoteStoreOnlineStateChangedHandler = (onlineState): void =>
433433
this.syncEngine.applyOnlineStateChange(
434434
onlineState,
435435
OnlineStateSource.RemoteStore
436436
);
437-
const sharedClientStateOnlineStateChangedHandler = onlineState =>
437+
const sharedClientStateOnlineStateChangedHandler = (onlineState): void =>
438438
this.syncEngine.applyOnlineStateChange(
439439
onlineState,
440440
OnlineStateSource.SharedClientState

packages/firestore/src/core/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class Query {
310310
let comparedOnKeyField = false;
311311
for (const orderBy of this.orderBy) {
312312
const comp = orderBy.compare(d1, d2);
313-
if (comp !== 0) return comp;
313+
if (comp !== 0) {return comp;}
314314
comparedOnKeyField = comparedOnKeyField || orderBy.field.isKeyField();
315315
}
316316
// Assert that we actually compared by key

packages/firestore/src/core/sync_engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
388388
): Promise<T> {
389389
assert(retries >= 0, 'Got negative number of retries for transaction.');
390390
const transaction = this.remoteStore.createTransaction();
391-
const wrappedUpdateFunction = () => {
391+
const wrappedUpdateFunction = (): Promise<T> => {
392392
try {
393393
const userPromise = updateFunction(transaction);
394394
if (

packages/firestore/src/core/view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export class View {
468468
}
469469

470470
function compareChangeType(c1: ChangeType, c2: ChangeType): number {
471-
const order = (change: ChangeType) => {
471+
const order = (change: ChangeType): 0 | 1 | 2 => {
472472
switch (change) {
473473
case ChangeType.Added:
474474
return 1;

packages/firestore/src/core/view_snapshot.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export class DocumentChangeSet {
5050
DocumentKey.comparator
5151
);
5252

53-
constructor() {}
54-
5553
track(change: DocumentViewChange): void {
5654
const key = change.doc.key;
5755
const oldChange = this.changeMap.get(key);

packages/firestore/src/local/indexeddb_mutation_queue.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ export class IndexedDbMutationQueue implements MutationQueue {
165165
// mutation batch.
166166
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=701972
167167

168-
// tslint:disable-next-line:no-any We write an empty object to obtain key
168+
// We write an empty object to obtain key
169+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
169170
return mutationStore.add({} as any).next(batchId => {
170171
assert(typeof batchId === 'number', 'Auto-generated key is not a number');
171172

@@ -244,7 +245,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
244245
transaction: PersistenceTransaction,
245246
batchId: BatchId
246247
): PersistencePromise<MutationBatch | null> {
247-
return this.getMutationQueueMetadata(transaction).next(metadata => {
248+
return this.getMutationQueueMetadata(transaction).next(_metadata => {
248249
const nextBatchId = batchId + 1;
249250

250251
const range = IDBKeyRange.lowerBound([this.userId, nextBatchId]);

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ export class IndexedDbTransaction extends PersistenceTransaction {
168168
* TODO(b/114226234): Remove `synchronizeTabs` section when multi-tab is no
169169
* longer optional.
170170
*/
171-
export type MultiClientParams = {
171+
export interface MultiClientParams {
172172
sequenceNumberSyncer: SequenceNumberSyncer;
173-
};
173+
}
174174
export class IndexedDbPersistence implements Persistence {
175175
static getStore<Key extends IDBValidKey, Value>(
176176
txn: PersistenceTransaction,
@@ -1311,7 +1311,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
13111311
{
13121312
index: DbTargetDocument.documentTargetsIndex
13131313
},
1314-
([targetId, docKey], { path, sequenceNumber }) => {
1314+
([targetId, _docKey], { path, sequenceNumber }) => {
13151315
if (targetId === 0) {
13161316
// if nextToReport is valid, report it, this is a new key so the
13171317
// last one must not be a member of any targets.

packages/firestore/src/local/indexeddb_query_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class IndexedDbQueryCache implements QueryCache {
330330
let result = documentKeySet();
331331

332332
return store
333-
.iterate({ range, keysOnly: true }, (key, _, control) => {
333+
.iterate({ range, keysOnly: true }, (key, _, _control) => {
334334
const path = EncodedResourcePath.decode(key[1]);
335335
const docKey = new DocumentKey(path);
336336
result = result.add(docKey);
@@ -357,7 +357,7 @@ export class IndexedDbQueryCache implements QueryCache {
357357
keysOnly: true,
358358
range
359359
},
360-
([targetId, path], _, control) => {
360+
([targetId, _path], _, control) => {
361361
// Having a sentinel row for a document does not count as containing that document;
362362
// For the query cache, containing the document means the document is part of some
363363
// target.

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
213213

214214
const promises: Array<PersistencePromise<void>> = [];
215215
return documentsStore
216-
.iterate((key, doc) => {
216+
.iterate((key, _doc) => {
217217
const path = new ResourcePath(key);
218218
const docSentinelKey = sentinelKey(path);
219219
promises.push(
@@ -246,7 +246,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
246246

247247
// Helper to add an index entry iff we haven't already written it.
248248
const cache = new MemoryCollectionParentIndex();
249-
const addEntry = collectionPath => {
249+
const addEntry = (collectionPath): PersistencePromise<void> | undefined => {
250250
if (cache.add(collectionPath)) {
251251
const collectionId = collectionPath.lastSegment();
252252
const parentPath = collectionPath.popLast();
@@ -270,7 +270,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
270270
.store<DbDocumentMutationKey, DbDocumentMutation>(
271271
DbDocumentMutation.store
272272
)
273-
.iterate({ keysOnly: true }, ([userID, encodedPath, batchId], _) => {
273+
.iterate({ keysOnly: true }, ([_userID, encodedPath, _batchId], _) => {
274274
const path = decode(encodedPath);
275275
return addEntry(path.popLast());
276276
});

packages/firestore/src/local/local_store.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export class LocalStore {
458458
(targetId: TargetId, change: TargetChange) => {
459459
// Do not ref/unref unassigned targetIds - it may lead to leaks.
460460
let queryData = this.queryDataByTarget[targetId];
461-
if (!queryData) return;
461+
if (!queryData) {return;}
462462

463463
// When a global snapshot contains updates (either add or modify) we
464464
// can completely trust these updates as authoritative and blindly
@@ -514,7 +514,7 @@ export class LocalStore {
514514

515515
let changedDocs = maybeDocumentMap();
516516
let updatedKeys = documentKeySet();
517-
remoteEvent.documentUpdates.forEach((key, doc) => {
517+
remoteEvent.documentUpdates.forEach((key, _doc) => {
518518
updatedKeys = updatedKeys.add(key);
519519
});
520520

@@ -616,10 +616,10 @@ export class LocalStore {
616616
change: TargetChange
617617
): boolean {
618618
// Avoid clearing any existing value
619-
if (newQueryData.resumeToken.length === 0) return false;
619+
if (newQueryData.resumeToken.length === 0) {return false;}
620620

621621
// Any resume token is interesting if there isn't one already.
622-
if (oldQueryData.resumeToken.length === 0) return true;
622+
if (oldQueryData.resumeToken.length === 0) {return true;}
623623

624624
// Don't allow resume token changes to be buffered indefinitely. This
625625
// allows us to be reasonably up-to-date after a crash and avoids needing
@@ -629,7 +629,7 @@ export class LocalStore {
629629
const timeDelta =
630630
newQueryData.snapshotVersion.toMicroseconds() -
631631
oldQueryData.snapshotVersion.toMicroseconds();
632-
if (timeDelta >= this.RESUME_TOKEN_MAX_AGE_MICROS) return true;
632+
if (timeDelta >= this.RESUME_TOKEN_MAX_AGE_MICROS) {return true;}
633633

634634
// Otherwise if the only thing that has changed about a target is its resume
635635
// token it's not worth persisting. Note that the RemoteStore keeps an

packages/firestore/src/local/lru_garbage_collector.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export interface LruDelegate {
8686
* Describes an object whose keys are active target ids. We do not care about the type of the
8787
* values.
8888
*/
89-
export type ActiveTargets = {
89+
export interface ActiveTargets {
9090
[id: number]: unknown;
91-
};
91+
}
9292

9393
// The type and comparator for the items contained in the SortedSet used in
9494
// place of a priority queue for the RollingSequenceNumberBuffer.
@@ -154,12 +154,12 @@ class RollingSequenceNumberBuffer {
154154
* has not hit the threshold). If collection ran, the other fields will be
155155
* filled in with the details of the results.
156156
*/
157-
export type LruResults = {
157+
export interface LruResults {
158158
readonly didRun: boolean;
159159
readonly sequenceNumbersCollected: number;
160160
readonly targetsRemoved: number;
161161
readonly documentsRemoved: number;
162-
};
162+
}
163163

164164
const GC_DID_NOT_RUN: LruResults = {
165165
didRun: false,
@@ -373,12 +373,11 @@ export class LruGarbageCollector {
373373
let upperBoundSequenceNumber: number;
374374
let sequenceNumbersToCollect, targetsRemoved: number;
375375
// Timestamps for various pieces of the process
376-
let startTs: number,
377-
countedTargetsTs: number,
376+
let countedTargetsTs: number,
378377
foundUpperBoundTs: number,
379378
removedTargetsTs: number,
380379
removedDocumentsTs: number;
381-
startTs = Date.now();
380+
const startTs = Date.now();
382381
return this.calculateTargetCount(txn, this.params.percentileToCollect)
383382
.next(sequenceNumbers => {
384383
// Cap at the configured max

0 commit comments

Comments
 (0)