Skip to content

Commit 7043422

Browse files
authored
migrate Firestore to eslint (#1859)
* migrate Firestore to eslint * [AUTOMATED]: Prettier Code Styling * replace tslint suppresion with eslint ones * disable no used var for params in firestore * [AUTOMATED]: Prettier Code Styling * enable no-console for test files * disable no-floating-promises for test files * 1. enable no-duplicate-imports 2. update deps * address mike's comments * [AUTOMATED]: Prettier Code Styling * move comments to the same line as the suppression * [AUTOMATED]: Prettier Code Styling * remove unneeded comment * revert local changes * enable no-explicit-any in test files * fix lint issues after rebasing with master * [AUTOMATED]: Prettier Code Styling * move protobufjs to devdeps * [AUTOMATED]: Prettier Code Styling * remove leftover suppression
1 parent 0551030 commit 7043422

File tree

89 files changed

+546
-520
lines changed

Some content is hidden

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

89 files changed

+546
-520
lines changed

packages/firestore/.eslintrc.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,30 @@
22
"extends": "../../config/.eslintrc.json",
33
"parserOptions": {
44
"project": "tsconfig.json"
5-
}
5+
},
6+
"plugins": [
7+
"import"
8+
],
9+
"rules": {
10+
"no-console":[ "error", { "allow": ["warn", "error"] }],
11+
"import/no-default-export": "error",
12+
"@typescript-eslint/no-unused-vars": [
13+
"error",
14+
{
15+
"varsIgnorePattern": "^_",
16+
"args": "none"
17+
}
18+
]
19+
},
20+
"overrides": [
21+
{
22+
"files": [
23+
"**/*.test.ts",
24+
"**/test/**/*.ts"
25+
],
26+
"rules": {
27+
"@typescript-eslint/no-explicit-any": "error"
28+
}
29+
}
30+
]
631
}

packages/firestore/index.node.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import firebase from '@firebase/app';
1919
import { FirebaseNamespace } from '@firebase/app-types';
2020
import * as types from '@firebase/firestore-types';
21-
import { Firestore } from './src/api/database';
2221
import { configureForFirebase } from './src/platform/config';
2322
import './src/platform_node/node_init';
2423

packages/firestore/package.json

Lines changed: 6 additions & 5 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:emulator",
@@ -33,6 +32,7 @@
3332
"@firebase/logger": "0.1.17",
3433
"@firebase/webchannel-wrapper": "0.2.21",
3534
"@grpc/proto-loader": "^0.5.0",
35+
"@firebase/util": "0.2.20",
3636
"grpc": "1.20.3",
3737
"tslib": "1.9.3"
3838
},
@@ -82,7 +82,8 @@
8282
"eslint": "5.16.0",
8383
"@typescript-eslint/parser": "1.10.2",
8484
"@typescript-eslint/eslint-plugin": "1.10.2",
85-
"@typescript-eslint/eslint-plugin-tslint": "1.10.2"
85+
"@typescript-eslint/eslint-plugin-tslint": "1.10.2",
86+
"eslint-plugin-import": "2.17.3"
8687
},
8788
"repository": {
8889
"directory": "packages/firestore",
@@ -99,4 +100,4 @@
99100
],
100101
"reportDir": "./coverage/node"
101102
}
102-
}
103+
}

packages/firestore/src/api/blob.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ export class Blob {
136136
// instanceof checks.
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.
139-
// tslint:disable-next-line:variable-name We're treating this as a class name.
140-
export let PublicBlob = makeConstructorPrivate(
139+
export const PublicBlob = makeConstructorPrivate(
141140
Blob,
142141
'Use Blob.fromUint8Array() or Blob.fromBase64String() instead.'
143142
);

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: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ import {
7474
validateStringEnum,
7575
valueDescription
7676
} from '../util/input_validation';
77+
// eslint-disable-next-line import/no-duplicates
7778
import * as log from '../util/log';
79+
// eslint-disable-next-line import/no-duplicates
7880
import { LogLevel } from '../util/log';
7981
import { AutoId } from '../util/misc';
8082
import * as objUtils from '../util/obj';
@@ -103,11 +105,6 @@ import {
103105
UserDataConverter
104106
} from './user_data_converter';
105107

106-
// The objects that are a part of this API are exposed to third-parties as
107-
// compiled javascript so we want to flag our private members with a leading
108-
// underscore to discourage their use.
109-
// tslint:disable:strip-private-property-underscore
110-
111108
// settings() defaults:
112109
const DEFAULT_HOST = 'firestore.googleapis.com';
113110
const DEFAULT_SSL = true;
@@ -158,7 +155,7 @@ class FirestoreSettings {
158155
readonly forceLongPolling: boolean;
159156

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

164161
constructor(settings: PrivateSettings) {
@@ -298,6 +295,9 @@ class FirestoreConfig {
298295
* The root reference to the database.
299296
*/
300297
export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
298+
// The objects that are a part of this API are exposed to third-parties as
299+
// compiled javascript so we want to flag our private members with a leading
300+
// underscore to discourage their use.
301301
private readonly _config: FirestoreConfig;
302302
readonly _databaseId: DatabaseId;
303303

@@ -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,16 +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-
}
1399-
14001390
data(options?: SnapshotOptions): firestore.DocumentData {
14011391
const data = super.data(options);
14021392
assert(
@@ -1808,7 +1798,7 @@ export class Query implements firestore.Query {
18081798
options: ListenOptions,
18091799
observer: PartialObserver<firestore.QuerySnapshot>
18101800
): Unsubscribe {
1811-
let errHandler = (err: Error) => {
1801+
let errHandler = (err: Error): void => {
18121802
console.error('Uncaught Error in onSnapshot:', err);
18131803
};
18141804
if (observer.error) {
@@ -1830,7 +1820,7 @@ export class Query implements firestore.Query {
18301820
asyncObserver,
18311821
options
18321822
);
1833-
return () => {
1823+
return (): void => {
18341824
asyncObserver.mute();
18351825
firestoreClient.unlisten(internalListener);
18361826
};
@@ -2457,7 +2447,6 @@ function resultChangeType(type: ChangeType): firestore.DocumentChangeType {
24572447

24582448
// We're treating the variables as class names, so disable checking for lower
24592449
// case variable names.
2460-
// tslint:disable:variable-name
24612450
export const PublicFirestore = makeConstructorPrivate(
24622451
Firestore,
24632452
'Use firebase.firestore() instead.'
@@ -2484,4 +2473,3 @@ export const PublicCollectionReference = makeConstructorPrivate(
24842473
CollectionReference,
24852474
'Use firebase.firestore().collection() instead.'
24862475
);
2487-
// tslint:enable:variable-name

packages/firestore/src/api/field_path.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
// The objects that are a part of this API are exposed to third-parties as
2929
// compiled javascript so we want to flag our private members with a leading
3030
// underscore to discourage their use.
31-
// tslint:disable:strip-private-property-underscore
3231

3332
/**
3433
* A FieldPath refers to a field in a document. The path may consist of a single

packages/firestore/src/api/field_value.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
* An opaque base class for FieldValue sentinel objects in our public API,
3030
* with public static methods for creating said sentinel objects.
3131
*/
32-
// tslint:disable-next-line:class-as-namespace We use this as a base class.
3332
export abstract class FieldValueImpl implements firestore.FieldValue {
3433
protected constructor(readonly _methodName: string) {}
3534

@@ -109,7 +108,6 @@ export class NumericIncrementFieldValueImpl extends FieldValueImpl {
109108
// PublicFieldValue can be used interchangeably in instanceof checks.
110109
// For our internal TypeScript code PublicFieldValue doesn't exist as a type,
111110
// and so we need to use FieldValueImpl as type and export it too.
112-
// tslint:disable-next-line:variable-name We treat this as a class name.
113111
export const PublicFieldValue = makeConstructorPrivate(
114112
FieldValueImpl,
115113
'Use FieldValue.<field>() instead.'

packages/firestore/src/api/user_data_converter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import * as firestore from '@firebase/firestore-types';
2020
import { Timestamp } from '../api/timestamp';
2121
import { DatabaseId } from '../core/database_info';
2222
import { DocumentKey } from '../model/document_key';
23-
import { FieldValue, NumberValue, ObjectValue } from '../model/field_value';
2423
import {
24+
FieldValue,
25+
NumberValue,
26+
ObjectValue,
2527
ArrayValue,
2628
BlobValue,
2729
BooleanValue,
@@ -33,6 +35,7 @@ import {
3335
StringValue,
3436
TimestampValue
3537
} from '../model/field_value';
38+
3639
import {
3740
FieldMask,
3841
FieldTransform,
@@ -47,8 +50,7 @@ import { assert, fail } from '../util/assert';
4750
import { Code, FirestoreError } from '../util/error';
4851
import { isPlainObject, valueDescription } from '../util/input_validation';
4952
import { primitiveComparator } from '../util/misc';
50-
import * as objUtils from '../util/obj';
51-
import { Dict } from '../util/obj';
53+
import { Dict, forEach, isEmpty } from '../util/obj';
5254
import { SortedMap } from '../util/sorted_map';
5355
import * as typeUtils from '../util/types';
5456

@@ -394,7 +396,7 @@ export class UserDataConverter {
394396

395397
let fieldMaskPaths = new SortedSet<FieldPath>(FieldPath.comparator);
396398
let updateData = ObjectValue.EMPTY;
397-
objUtils.forEach(input as Dict<unknown>, (key, value) => {
399+
forEach(input as Dict<unknown>, (key, value) => {
398400
const path = fieldPathFromDotSeparatedString(methodName, key);
399401

400402
const childContext = context.childContextForFieldPath(path);
@@ -544,14 +546,14 @@ export class UserDataConverter {
544546
private parseObject(obj: Dict<unknown>, context: ParseContext): FieldValue {
545547
let result = new SortedMap<string, FieldValue>(primitiveComparator);
546548

547-
if (objUtils.isEmpty(obj)) {
549+
if (isEmpty(obj)) {
548550
// If we encounter an empty object, we explicitly add it to the update
549551
// mask to ensure that the server creates a map entry.
550552
if (context.path && context.path.length > 0) {
551553
context.fieldMask.push(context.path);
552554
}
553555
} else {
554-
objUtils.forEach(obj, (key: string, val: unknown) => {
556+
forEach(obj, (key: string, val: unknown) => {
555557
const parsedValue = this.parseData(
556558
val,
557559
context.childContextForField(key)

packages/firestore/src/core/event_manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import { ObjectMap } from '../util/obj_map';
2121
import { Query } from './query';
2222
import { SyncEngine, SyncEngineListener } from './sync_engine';
2323
import { OnlineState, TargetId } from './types';
24-
import { DocumentViewChange } from './view_snapshot';
25-
import { ChangeType, ViewSnapshot } from './view_snapshot';
24+
import { DocumentViewChange, ChangeType, ViewSnapshot } from './view_snapshot';
2625

2726
/**
2827
* Holds the listeners and the last received ViewSnapshot for a query being
@@ -72,7 +71,9 @@ export class EventManager implements SyncEngineListener {
7271

7372
listener.applyOnlineStateChange(this.onlineState);
7473

75-
if (queryInfo.viewSnap) listener.onViewSnapshot(queryInfo.viewSnap);
74+
if (queryInfo.viewSnap) {
75+
listener.onViewSnapshot(queryInfo.viewSnap);
76+
}
7677

7778
if (firstListen) {
7879
return this.syncEngine.listen(query).then(targetId => {

packages/firestore/src/core/firestore_client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ export class FirestoreClient {
252252
if (!this.canFallback(error)) {
253253
throw error;
254254
}
255-
256255
console.warn(
257256
'Error enabling offline persistence. Falling back to' +
258257
' persistence disabled: ' +
@@ -431,14 +430,14 @@ export class FirestoreClient {
431430

432431
const remoteStoreOnlineStateChangedHandler = (
433432
onlineState: OnlineState
434-
) =>
433+
): void =>
435434
this.syncEngine.applyOnlineStateChange(
436435
onlineState,
437436
OnlineStateSource.RemoteStore
438437
);
439438
const sharedClientStateOnlineStateChangedHandler = (
440439
onlineState: OnlineState
441-
) =>
440+
): void =>
442441
this.syncEngine.applyOnlineStateChange(
443442
onlineState,
444443
OnlineStateSource.SharedClientState

packages/firestore/src/core/query.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ 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) {
314+
return comp;
315+
}
314316
comparedOnKeyField = comparedOnKeyField || orderBy.field.isKeyField();
315317
}
316318
// Assert that we actually compared by key
@@ -632,10 +634,6 @@ export class FieldFilter extends Filter {
632634

633635
/** Filter that matches on key fields (i.e. '__name__'). */
634636
export class KeyFieldFilter extends FieldFilter {
635-
constructor(field: FieldPath, op: Operator, value: RefValue) {
636-
super(field, op, value);
637-
}
638-
639637
matches(doc: Document): boolean {
640638
const refValue = this.value as RefValue;
641639
const comparison = DocumentKey.comparator(doc.key, refValue.key);

packages/firestore/src/core/sync_engine.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
248248
.then(remoteKeys => {
249249
const view = new View(query, remoteKeys);
250250
const viewDocChanges = view.computeDocChanges(docs);
251-
// tslint:disable-next-line:max-line-length Prettier formats this exceed 100 characters.
252251
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(
253252
queryData.targetId,
254253
current && this.onlineState !== OnlineState.Offline
@@ -388,7 +387,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
388387
): Promise<T> {
389388
assert(retries >= 0, 'Got negative number of retries for transaction.');
390389
const transaction = this.remoteStore.createTransaction();
391-
const wrappedUpdateFunction = () => {
390+
const wrappedUpdateFunction = (): Promise<T> => {
392391
try {
393392
const userPromise = updateFunction(transaction);
394393
if (
@@ -976,8 +975,6 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
976975
case 'not-current': {
977976
return this.localStore.getNewDocumentChanges().then(
978977
async changes => {
979-
// tslint and prettier disagree about their preferred line length.
980-
// tslint:disable-next-line:max-line-length
981978
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(
982979
targetId,
983980
state === 'current'

packages/firestore/src/core/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import { ParsedSetData, ParsedUpdateData } from '../api/user_data_converter';
1919
import { documentVersionMap } from '../model/collections';
20-
import { Document, NoDocument } from '../model/document';
21-
import { MaybeDocument } from '../model/document';
20+
import { Document, NoDocument, MaybeDocument } from '../model/document';
21+
2222
import { DocumentKey } from '../model/document_key';
2323
import { DeleteMutation, Mutation, Precondition } from '../model/mutation';
2424
import { Datastore } from '../remote/datastore';

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;

0 commit comments

Comments
 (0)