Skip to content

Commit 3dd9bcf

Browse files
authored
Firestore: Add "max-line-length" and "ordered-imports" tslint rules. (#1238)
This enforces a maximum line length (of 100) and import ordering via tslint rules and fixes all violations. The line length violations were fixed manually. Prettier already targets a line length of 80 for code (but this isn't a strict limit) so mostly I just split string literals and long comments, but I did have to use tslint:disable in one place since prettier was formatting at > 100 chars. The import ordering violations were fixed automatically via yarn lint:fix.
1 parent 1e948e6 commit 3dd9bcf

File tree

86 files changed

+314
-294
lines changed

Some content is hidden

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

86 files changed

+314
-294
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
// Ruler can't be specified via editorconfig
3-
"editor.rulers": [80],
3+
"editor.rulers": [100],
44

55
"search.exclude": {
66
// Exclude gulp build outputs from search results

packages/firestore/src/api/credentials.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { FirebaseApp } from '@firebase/app-types';
18+
import { _FirebaseApp } from '@firebase/app-types/private';
1719
import { User } from '../auth/user';
1820
import { assert } from '../util/assert';
1921
import { Code, FirestoreError } from '../util/error';
20-
import { FirebaseApp } from '@firebase/app-types';
21-
import { _FirebaseApp } from '@firebase/app-types/private';
2222

2323
// TODO(mikelehen): This should be split into multiple files and probably
2424
// moved to an auth/ folder to match other platforms.

packages/firestore/src/api/database.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import * as firestore from '@firebase/firestore-types';
1818

1919
import { FirebaseApp } from '@firebase/app-types';
2020
import { FirebaseService } from '@firebase/app-types/private';
21-
import { FieldPath as ExternalFieldPath } from './field_path';
2221
import { DatabaseId, DatabaseInfo } from '../core/database_info';
2322
import { ListenOptions } from '../core/event_manager';
2423
import { FirestoreClient } from '../core/firestore_client';
@@ -57,19 +56,20 @@ import {
5756
validateBetweenNumberOfArgs,
5857
validateDefined,
5958
validateExactNumberOfArgs,
60-
validateNamedOptionalType,
6159
validateNamedOptionalPropertyEquals,
60+
validateNamedOptionalType,
6261
validateNamedType,
6362
validateOptionalArgType,
63+
validateOptionalArrayElements,
6464
validateOptionNames,
65-
valueDescription,
66-
validateOptionalArrayElements
65+
valueDescription
6766
} from '../util/input_validation';
6867
import * as log from '../util/log';
6968
import { LogLevel } from '../util/log';
7069
import { AnyJs, AutoId } from '../util/misc';
7170
import * as objUtils from '../util/obj';
7271
import { Rejecter, Resolver } from '../util/promise';
72+
import { FieldPath as ExternalFieldPath } from './field_path';
7373

7474
import {
7575
CredentialsProvider,
@@ -2076,7 +2076,8 @@ function validateSetOptions(
20762076
if (options.mergeFields !== undefined && options.merge !== undefined) {
20772077
throw new FirestoreError(
20782078
Code.INVALID_ARGUMENT,
2079-
`Invalid options passed to function ${methodName}(): You cannot specify both "merge" and "mergeFields".`
2079+
`Invalid options passed to function ${methodName}(): You cannot specify both "merge" ` +
2080+
`and "mergeFields".`
20802081
);
20812082
}
20822083

packages/firestore/src/api/observer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { AnyJs } from '../util/misc';
1817
import { JsonObject } from '../model/field_value';
18+
import { AnyJs } from '../util/misc';
1919

2020
/**
2121
* Observer/Subscribe interfaces.

packages/firestore/src/api/user_data_converter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ import { Dict } from '../util/obj';
5151
import { SortedMap } from '../util/sorted_map';
5252
import * as typeUtils from '../util/types';
5353

54+
import {
55+
ArrayRemoveTransformOperation,
56+
ArrayUnionTransformOperation,
57+
ServerTimestampTransform
58+
} from '../model/transform_operation';
5459
import { Blob } from './blob';
5560
import {
5661
FieldPath as ExternalFieldPath,
5762
fromDotSeparatedString
5863
} from './field_path';
5964
import {
65+
ArrayRemoveFieldValueImpl,
66+
ArrayUnionFieldValueImpl,
6067
DeleteFieldValueImpl,
6168
FieldValueImpl,
62-
ServerTimestampFieldValueImpl,
63-
ArrayUnionFieldValueImpl,
64-
ArrayRemoveFieldValueImpl
69+
ServerTimestampFieldValueImpl
6570
} from './field_value';
6671
import { GeoPoint } from './geo_point';
67-
import {
68-
ServerTimestampTransform,
69-
ArrayUnionTransformOperation,
70-
ArrayRemoveTransformOperation
71-
} from '../model/transform_operation';
7272

7373
const RESERVED_FIELD_REGEX = /^__.*__$/;
7474

packages/firestore/src/core/event_manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { assert } from '../util/assert';
18+
import { EventHandler } from '../util/misc';
19+
import { ObjectMap } from '../util/obj_map';
1720
import { Query } from './query';
1821
import { SyncEngine, SyncEngineListener } from './sync_engine';
1922
import { OnlineState, TargetId } from './types';
2023
import { DocumentViewChange } from './view_snapshot';
2124
import { ChangeType, ViewSnapshot } from './view_snapshot';
22-
import { assert } from '../util/assert';
23-
import { EventHandler } from '../util/misc';
24-
import { ObjectMap } from '../util/obj_map';
2525

2626
/**
2727
* Holds the listeners and the last received ViewSnapshot for a query being

packages/firestore/src/core/firestore_client.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616

1717
import { CredentialsProvider } from '../api/credentials';
1818
import { User } from '../auth/user';
19-
import {
20-
EventManager,
21-
ListenOptions,
22-
Observer,
23-
QueryListener
24-
} from './event_manager';
25-
import { SyncEngine } from './sync_engine';
26-
import { View, ViewDocumentChanges } from './view';
2719
import { EagerGarbageCollector } from '../local/eager_garbage_collector';
2820
import { GarbageCollector } from '../local/garbage_collector';
2921
import { IndexedDbPersistence } from '../local/indexeddb_persistence';
@@ -47,20 +39,28 @@ import { AsyncQueue } from '../util/async_queue';
4739
import { Code, FirestoreError } from '../util/error';
4840
import { debug } from '../util/log';
4941
import { Deferred } from '../util/promise';
42+
import {
43+
EventManager,
44+
ListenOptions,
45+
Observer,
46+
QueryListener
47+
} from './event_manager';
48+
import { SyncEngine } from './sync_engine';
49+
import { View, ViewDocumentChanges } from './view';
5050

51-
import { DatabaseId, DatabaseInfo } from './database_info';
52-
import { Query } from './query';
53-
import { Transaction } from './transaction';
54-
import { OnlineStateSource } from './types';
55-
import { ViewSnapshot } from './view_snapshot';
51+
import { PersistenceSettings } from '../api/database';
5652
import {
5753
MemorySharedClientState,
5854
SharedClientState,
5955
WebStorageSharedClientState
6056
} from '../local/shared_client_state';
61-
import { AutoId } from '../util/misc';
62-
import { PersistenceSettings } from '../api/database';
6357
import { assert } from '../util/assert';
58+
import { AutoId } from '../util/misc';
59+
import { DatabaseId, DatabaseInfo } from './database_info';
60+
import { Query } from './query';
61+
import { Transaction } from './transaction';
62+
import { OnlineStateSource } from './types';
63+
import { ViewSnapshot } from './view_snapshot';
6464

6565
const LOG_TAG = 'FirestoreClient';
6666

packages/firestore/src/core/listen_sequence.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import { ListenSequenceNumber } from './types';
1818

1919
/**
20-
* `SequenceNumberSyncer` defines the methods required to keep multiple instances of a `ListenSequence` in sync.
20+
* `SequenceNumberSyncer` defines the methods required to keep multiple instances of a
21+
* `ListenSequence` in sync.
2122
*/
2223
export interface SequenceNumberSyncer {
2324
// Notify the syncer that a new sequence number has been used.
@@ -32,8 +33,8 @@ export interface SequenceNumberSyncer {
3233
/**
3334
* `ListenSequence` is a monotonic sequence. It is initialized with a minimum value to
3435
* exceed. All subsequent calls to next will return increasing values. If provided with a
35-
* `SequenceNumberSyncer`, it will additionally bump its next value when told of a new value, as well as write out
36-
* sequence numbers that it produces via `next()`.
36+
* `SequenceNumberSyncer`, it will additionally bump its next value when told of a new value, as
37+
* well as write out sequence numbers that it produces via `next()`.
3738
*/
3839
export class ListenSequence {
3940
static readonly INVALID: ListenSequenceNumber = -1;

packages/firestore/src/core/query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import { Document } from '../model/document';
1818
import { DocumentKey } from '../model/document_key';
1919
import {
20+
ArrayValue,
2021
DoubleValue,
2122
FieldValue,
2223
NullValue,
23-
RefValue,
24-
ArrayValue
24+
RefValue
2525
} from '../model/field_value';
2626
import { FieldPath, ResourcePath } from '../model/path';
2727
import { assert, fail } from '../util/assert';

packages/firestore/src/core/sync_engine.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import { PersistencePromise } from '../local/persistence_promise';
2121
import { QueryData, QueryPurpose } from '../local/query_data';
2222
import { ReferenceSet } from '../local/reference_set';
2323
import {
24-
MaybeDocumentMap,
2524
documentKeySet,
26-
DocumentKeySet
25+
DocumentKeySet,
26+
MaybeDocumentMap
2727
} from '../model/collections';
2828
import { MaybeDocument, NoDocument } from '../model/document';
2929
import { DocumentKey } from '../model/document_key';
@@ -41,6 +41,15 @@ import { Deferred } from '../util/promise';
4141
import { SortedMap } from '../util/sorted_map';
4242
import { isNullOrUndefined } from '../util/types';
4343

44+
import { isPrimaryLeaseLostError } from '../local/indexeddb_persistence';
45+
import { ClientId, SharedClientState } from '../local/shared_client_state';
46+
import {
47+
QueryTargetState,
48+
SharedClientStateSyncer
49+
} from '../local/shared_client_state_syncer';
50+
import * as objUtils from '../util/obj';
51+
import { SortedSet } from '../util/sorted_set';
52+
import { ListenSequence } from './listen_sequence';
4453
import { Query } from './query';
4554
import { SnapshotVersion } from './snapshot_version';
4655
import { TargetIdGenerator } from './target_id_generator';
@@ -61,15 +70,6 @@ import {
6170
ViewDocumentChanges
6271
} from './view';
6372
import { ViewSnapshot } from './view_snapshot';
64-
import {
65-
SharedClientStateSyncer,
66-
QueryTargetState
67-
} from '../local/shared_client_state_syncer';
68-
import { ClientId, SharedClientState } from '../local/shared_client_state';
69-
import { SortedSet } from '../util/sorted_set';
70-
import * as objUtils from '../util/obj';
71-
import { isPrimaryLeaseLostError } from '../local/indexeddb_persistence';
72-
import { ListenSequence } from './listen_sequence';
7373

7474
const LOG_TAG = 'SyncEngine';
7575

@@ -247,6 +247,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
247247
.then(remoteKeys => {
248248
const view = new View(query, remoteKeys);
249249
const viewDocChanges = view.computeInitialChanges(docs);
250+
// tslint:disable-next-line:max-line-length Prettier formats this exceed 100 characters.
250251
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(
251252
queryData.targetId,
252253
current && this.onlineState !== OnlineState.Offline

packages/firestore/src/core/target_id_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { TargetId } from './types';
1817
import { assert } from '../util/assert';
18+
import { TargetId } from './types';
1919

2020
const RESERVED_BITS = 1;
2121

packages/firestore/src/core/transaction.ts

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

1717
import { ParsedSetData, ParsedUpdateData } from '../api/user_data_converter';
18-
import { SnapshotVersion } from './snapshot_version';
1918
import { documentVersionMap } from '../model/collections';
20-
import { NoDocument, Document } from '../model/document';
19+
import { Document, NoDocument } from '../model/document';
2120
import { MaybeDocument } from '../model/document';
2221
import { DocumentKey } from '../model/document_key';
2322
import { DeleteMutation, Mutation, Precondition } from '../model/mutation';
2423
import { Datastore } from '../remote/datastore';
25-
import { Code, FirestoreError } from '../util/error';
2624
import { fail } from '../util/assert';
25+
import { Code, FirestoreError } from '../util/error';
26+
import { SnapshotVersion } from './snapshot_version';
2727

2828
/**
2929
* Internal transaction object responsible for accumulating the mutations to

packages/firestore/src/core/view_snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { DocumentSet } from '../model/document_set';
2020
import { fail } from '../util/assert';
2121
import { SortedMap } from '../util/sorted_map';
2222

23-
import { Query } from './query';
2423
import { DocumentKeySet } from '../model/collections';
24+
import { Query } from './query';
2525

2626
export enum ChangeType {
2727
Added,

packages/firestore/src/local/indexeddb_mutation_queue.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import { SortedSet } from '../util/sorted_set';
2929

3030
import * as EncodedResourcePath from './encoded_resource_path';
3131
import { GarbageCollector } from './garbage_collector';
32+
import {
33+
IndexedDbPersistence,
34+
IndexedDbTransaction
35+
} from './indexeddb_persistence';
3236
import {
3337
DbDocumentMutation,
3438
DbDocumentMutationKey,
@@ -42,10 +46,6 @@ import { MutationQueue } from './mutation_queue';
4246
import { PersistenceTransaction } from './persistence';
4347
import { PersistencePromise } from './persistence_promise';
4448
import { SimpleDbStore, SimpleDbTransaction } from './simple_db';
45-
import {
46-
IndexedDbPersistence,
47-
IndexedDbTransaction
48-
} from './indexeddb_persistence';
4949

5050
/** A mutation queue for a specific user, backed by IndexedDB. */
5151
export class IndexedDbMutationQueue implements MutationQueue {
@@ -510,7 +510,8 @@ export class IndexedDbMutationQueue implements MutationQueue {
510510
.next(() => {
511511
assert(
512512
danglingMutationReferences.length === 0,
513-
'Document leak -- detected dangling mutation references when queue is empty. Dangling keys: ' +
513+
'Document leak -- detected dangling mutation references when queue is empty. ' +
514+
'Dangling keys: ' +
514515
danglingMutationReferences.map(p => p.canonicalString())
515516
);
516517
});

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@ import { assert, fail } from '../util/assert';
2121
import { Code, FirestoreError } from '../util/error';
2222
import * as log from '../util/log';
2323

24+
import { ListenSequence, SequenceNumberSyncer } from '../core/listen_sequence';
25+
import { Platform } from '../platform/platform';
26+
import { AsyncQueue, TimerId } from '../util/async_queue';
27+
import { CancelablePromise } from '../util/promise';
2428
import { IndexedDbMutationQueue } from './indexeddb_mutation_queue';
2529
import {
26-
IndexedDbQueryCache,
27-
getHighestListenSequenceNumber
30+
getHighestListenSequenceNumber,
31+
IndexedDbQueryCache
2832
} from './indexeddb_query_cache';
2933
import { IndexedDbRemoteDocumentCache } from './indexeddb_remote_document_cache';
3034
import {
3135
ALL_STORES,
32-
DbClientMetadataKey,
3336
DbClientMetadata,
37+
DbClientMetadataKey,
3438
DbPrimaryClient,
3539
DbPrimaryClientKey,
36-
SCHEMA_VERSION,
3740
DbTargetGlobal,
41+
SCHEMA_VERSION,
3842
SchemaConverter
3943
} from './indexeddb_schema';
4044
import { LocalSerializer } from './local_serializer';
@@ -47,12 +51,8 @@ import {
4751
import { PersistencePromise } from './persistence_promise';
4852
import { QueryCache } from './query_cache';
4953
import { RemoteDocumentCache } from './remote_document_cache';
50-
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
51-
import { Platform } from '../platform/platform';
52-
import { AsyncQueue, TimerId } from '../util/async_queue';
5354
import { ClientId } from './shared_client_state';
54-
import { CancelablePromise } from '../util/promise';
55-
import { ListenSequence, SequenceNumberSyncer } from '../core/listen_sequence';
55+
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
5656

5757
const LOG_TAG = 'IndexedDbPersistence';
5858

0 commit comments

Comments
 (0)