Skip to content

Commit

Permalink
Firestore: Add "max-line-length" and "ordered-imports" tslint rules. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
mikelehen committed Sep 21, 2018
1 parent 1e948e6 commit 3dd9bcf
Show file tree
Hide file tree
Showing 86 changed files with 314 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
{
// Ruler can't be specified via editorconfig
"editor.rulers": [80],
"editor.rulers": [100],

"search.exclude": {
// Exclude gulp build outputs from search results
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 14,11 @@
* limitations under the License.
*/

import { FirebaseApp } from '@firebase/app-types';
import { _FirebaseApp } from '@firebase/app-types/private';
import { User } from '../auth/user';
import { assert } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import { FirebaseApp } from '@firebase/app-types';
import { _FirebaseApp } from '@firebase/app-types/private';

// TODO(mikelehen): This should be split into multiple files and probably
// moved to an auth/ folder to match other platforms.
Expand Down
11 changes: 6 additions & 5 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,6 @@ import * as firestore from '@firebase/firestore-types';

import { FirebaseApp } from '@firebase/app-types';
import { FirebaseService } from '@firebase/app-types/private';
import { FieldPath as ExternalFieldPath } from './field_path';
import { DatabaseId, DatabaseInfo } from '../core/database_info';
import { ListenOptions } from '../core/event_manager';
import { FirestoreClient } from '../core/firestore_client';
Expand Down Expand Up @@ -57,19 56,20 @@ import {
validateBetweenNumberOfArgs,
validateDefined,
validateExactNumberOfArgs,
validateNamedOptionalType,
validateNamedOptionalPropertyEquals,
validateNamedOptionalType,
validateNamedType,
validateOptionalArgType,
validateOptionalArrayElements,
validateOptionNames,
valueDescription,
validateOptionalArrayElements
valueDescription
} from '../util/input_validation';
import * as log from '../util/log';
import { LogLevel } from '../util/log';
import { AnyJs, AutoId } from '../util/misc';
import * as objUtils from '../util/obj';
import { Rejecter, Resolver } from '../util/promise';
import { FieldPath as ExternalFieldPath } from './field_path';

import {
CredentialsProvider,
Expand Down Expand Up @@ -2076,7 2076,8 @@ function validateSetOptions(
if (options.mergeFields !== undefined && options.merge !== undefined) {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
`Invalid options passed to function ${methodName}(): You cannot specify both "merge" and "mergeFields".`
`Invalid options passed to function ${methodName}(): You cannot specify both "merge" `
`and "mergeFields".`
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/api/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 14,8 @@
* limitations under the License.
*/

import { AnyJs } from '../util/misc';
import { JsonObject } from '../model/field_value';
import { AnyJs } from '../util/misc';

/**
* Observer/Subscribe interfaces.
Expand Down
16 changes: 8 additions & 8 deletions packages/firestore/src/api/user_data_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 51,24 @@ import { Dict } from '../util/obj';
import { SortedMap } from '../util/sorted_map';
import * as typeUtils from '../util/types';

import {
ArrayRemoveTransformOperation,
ArrayUnionTransformOperation,
ServerTimestampTransform
} from '../model/transform_operation';
import { Blob } from './blob';
import {
FieldPath as ExternalFieldPath,
fromDotSeparatedString
} from './field_path';
import {
ArrayRemoveFieldValueImpl,
ArrayUnionFieldValueImpl,
DeleteFieldValueImpl,
FieldValueImpl,
ServerTimestampFieldValueImpl,
ArrayUnionFieldValueImpl,
ArrayRemoveFieldValueImpl
ServerTimestampFieldValueImpl
} from './field_value';
import { GeoPoint } from './geo_point';
import {
ServerTimestampTransform,
ArrayUnionTransformOperation,
ArrayRemoveTransformOperation
} from '../model/transform_operation';

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

Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/core/event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 14,14 @@
* limitations under the License.
*/

import { assert } from '../util/assert';
import { EventHandler } from '../util/misc';
import { ObjectMap } from '../util/obj_map';
import { Query } from './query';
import { SyncEngine, SyncEngineListener } from './sync_engine';
import { OnlineState, TargetId } from './types';
import { DocumentViewChange } from './view_snapshot';
import { ChangeType, ViewSnapshot } from './view_snapshot';
import { assert } from '../util/assert';
import { EventHandler } from '../util/misc';
import { ObjectMap } from '../util/obj_map';

/**
* Holds the listeners and the last received ViewSnapshot for a query being
Expand Down
30 changes: 15 additions & 15 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 16,6 @@

import { CredentialsProvider } from '../api/credentials';
import { User } from '../auth/user';
import {
EventManager,
ListenOptions,
Observer,
QueryListener
} from './event_manager';
import { SyncEngine } from './sync_engine';
import { View, ViewDocumentChanges } from './view';
import { EagerGarbageCollector } from '../local/eager_garbage_collector';
import { GarbageCollector } from '../local/garbage_collector';
import { IndexedDbPersistence } from '../local/indexeddb_persistence';
Expand All @@ -47,20 39,28 @@ import { AsyncQueue } from '../util/async_queue';
import { Code, FirestoreError } from '../util/error';
import { debug } from '../util/log';
import { Deferred } from '../util/promise';
import {
EventManager,
ListenOptions,
Observer,
QueryListener
} from './event_manager';
import { SyncEngine } from './sync_engine';
import { View, ViewDocumentChanges } from './view';

import { DatabaseId, DatabaseInfo } from './database_info';
import { Query } from './query';
import { Transaction } from './transaction';
import { OnlineStateSource } from './types';
import { ViewSnapshot } from './view_snapshot';
import { PersistenceSettings } from '../api/database';
import {
MemorySharedClientState,
SharedClientState,
WebStorageSharedClientState
} from '../local/shared_client_state';
import { AutoId } from '../util/misc';
import { PersistenceSettings } from '../api/database';
import { assert } from '../util/assert';
import { AutoId } from '../util/misc';
import { DatabaseId, DatabaseInfo } from './database_info';
import { Query } from './query';
import { Transaction } from './transaction';
import { OnlineStateSource } from './types';
import { ViewSnapshot } from './view_snapshot';

const LOG_TAG = 'FirestoreClient';

Expand Down
7 changes: 4 additions & 3 deletions packages/firestore/src/core/listen_sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,8 @@
import { ListenSequenceNumber } from './types';

/**
* `SequenceNumberSyncer` defines the methods required to keep multiple instances of a `ListenSequence` in sync.
* `SequenceNumberSyncer` defines the methods required to keep multiple instances of a
* `ListenSequence` in sync.
*/
export interface SequenceNumberSyncer {
// Notify the syncer that a new sequence number has been used.
Expand All @@ -32,8 33,8 @@ export interface SequenceNumberSyncer {
/**
* `ListenSequence` is a monotonic sequence. It is initialized with a minimum value to
* exceed. All subsequent calls to next will return increasing values. If provided with a
* `SequenceNumberSyncer`, it will additionally bump its next value when told of a new value, as well as write out
* sequence numbers that it produces via `next()`.
* `SequenceNumberSyncer`, it will additionally bump its next value when told of a new value, as
* well as write out sequence numbers that it produces via `next()`.
*/
export class ListenSequence {
static readonly INVALID: ListenSequenceNumber = -1;
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/core/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 17,11 @@
import { Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import {
ArrayValue,
DoubleValue,
FieldValue,
NullValue,
RefValue,
ArrayValue
RefValue
} from '../model/field_value';
import { FieldPath, ResourcePath } from '../model/path';
import { assert, fail } from '../util/assert';
Expand Down
23 changes: 12 additions & 11 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 21,9 @@ import { PersistencePromise } from '../local/persistence_promise';
import { QueryData, QueryPurpose } from '../local/query_data';
import { ReferenceSet } from '../local/reference_set';
import {
MaybeDocumentMap,
documentKeySet,
DocumentKeySet
DocumentKeySet,
MaybeDocumentMap
} from '../model/collections';
import { MaybeDocument, NoDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
Expand All @@ -41,6 41,15 @@ import { Deferred } from '../util/promise';
import { SortedMap } from '../util/sorted_map';
import { isNullOrUndefined } from '../util/types';

import { isPrimaryLeaseLostError } from '../local/indexeddb_persistence';
import { ClientId, SharedClientState } from '../local/shared_client_state';
import {
QueryTargetState,
SharedClientStateSyncer
} from '../local/shared_client_state_syncer';
import * as objUtils from '../util/obj';
import { SortedSet } from '../util/sorted_set';
import { ListenSequence } from './listen_sequence';
import { Query } from './query';
import { SnapshotVersion } from './snapshot_version';
import { TargetIdGenerator } from './target_id_generator';
Expand All @@ -61,15 70,6 @@ import {
ViewDocumentChanges
} from './view';
import { ViewSnapshot } from './view_snapshot';
import {
SharedClientStateSyncer,
QueryTargetState
} from '../local/shared_client_state_syncer';
import { ClientId, SharedClientState } from '../local/shared_client_state';
import { SortedSet } from '../util/sorted_set';
import * as objUtils from '../util/obj';
import { isPrimaryLeaseLostError } from '../local/indexeddb_persistence';
import { ListenSequence } from './listen_sequence';

const LOG_TAG = 'SyncEngine';

Expand Down Expand Up @@ -247,6 247,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
.then(remoteKeys => {
const view = new View(query, remoteKeys);
const viewDocChanges = view.computeInitialChanges(docs);
// tslint:disable-next-line:max-line-length Prettier formats this exceed 100 characters.
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(
queryData.targetId,
current && this.onlineState !== OnlineState.Offline
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/target_id_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 14,8 @@
* limitations under the License.
*/

import { TargetId } from './types';
import { assert } from '../util/assert';
import { TargetId } from './types';

const RESERVED_BITS = 1;

Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/core/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 15,15 @@
*/

import { ParsedSetData, ParsedUpdateData } from '../api/user_data_converter';
import { SnapshotVersion } from './snapshot_version';
import { documentVersionMap } from '../model/collections';
import { NoDocument, Document } from '../model/document';
import { Document, NoDocument } from '../model/document';
import { MaybeDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { DeleteMutation, Mutation, Precondition } from '../model/mutation';
import { Datastore } from '../remote/datastore';
import { Code, FirestoreError } from '../util/error';
import { fail } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import { SnapshotVersion } from './snapshot_version';

/**
* Internal transaction object responsible for accumulating the mutations to
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/view_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 20,8 @@ import { DocumentSet } from '../model/document_set';
import { fail } from '../util/assert';
import { SortedMap } from '../util/sorted_map';

import { Query } from './query';
import { DocumentKeySet } from '../model/collections';
import { Query } from './query';

export enum ChangeType {
Added,
Expand Down
11 changes: 6 additions & 5 deletions packages/firestore/src/local/indexeddb_mutation_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 29,10 @@ import { SortedSet } from '../util/sorted_set';

import * as EncodedResourcePath from './encoded_resource_path';
import { GarbageCollector } from './garbage_collector';
import {
IndexedDbPersistence,
IndexedDbTransaction
} from './indexeddb_persistence';
import {
DbDocumentMutation,
DbDocumentMutationKey,
Expand All @@ -42,10 46,6 @@ import { MutationQueue } from './mutation_queue';
import { PersistenceTransaction } from './persistence';
import { PersistencePromise } from './persistence_promise';
import { SimpleDbStore, SimpleDbTransaction } from './simple_db';
import {
IndexedDbPersistence,
IndexedDbTransaction
} from './indexeddb_persistence';

/** A mutation queue for a specific user, backed by IndexedDB. */
export class IndexedDbMutationQueue implements MutationQueue {
Expand Down Expand Up @@ -510,7 510,8 @@ export class IndexedDbMutationQueue implements MutationQueue {
.next(() => {
assert(
danglingMutationReferences.length === 0,
'Document leak -- detected dangling mutation references when queue is empty. Dangling keys: '
'Document leak -- detected dangling mutation references when queue is empty. '
'Dangling keys: '
danglingMutationReferences.map(p => p.canonicalString())
);
});
Expand Down
18 changes: 9 additions & 9 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 21,24 @@ import { assert, fail } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import * as log from '../util/log';

import { ListenSequence, SequenceNumberSyncer } from '../core/listen_sequence';
import { Platform } from '../platform/platform';
import { AsyncQueue, TimerId } from '../util/async_queue';
import { CancelablePromise } from '../util/promise';
import { IndexedDbMutationQueue } from './indexeddb_mutation_queue';
import {
IndexedDbQueryCache,
getHighestListenSequenceNumber
getHighestListenSequenceNumber,
IndexedDbQueryCache
} from './indexeddb_query_cache';
import { IndexedDbRemoteDocumentCache } from './indexeddb_remote_document_cache';
import {
ALL_STORES,
DbClientMetadataKey,
DbClientMetadata,
DbClientMetadataKey,
DbPrimaryClient,
DbPrimaryClientKey,
SCHEMA_VERSION,
DbTargetGlobal,
SCHEMA_VERSION,
SchemaConverter
} from './indexeddb_schema';
import { LocalSerializer } from './local_serializer';
Expand All @@ -47,12 51,8 @@ import {
import { PersistencePromise } from './persistence_promise';
import { QueryCache } from './query_cache';
import { RemoteDocumentCache } from './remote_document_cache';
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';
import { Platform } from '../platform/platform';
import { AsyncQueue, TimerId } from '../util/async_queue';
import { ClientId } from './shared_client_state';
import { CancelablePromise } from '../util/promise';
import { ListenSequence, SequenceNumberSyncer } from '../core/listen_sequence';
import { SimpleDb, SimpleDbStore, SimpleDbTransaction } from './simple_db';

const LOG_TAG = 'IndexedDbPersistence';

Expand Down
Loading

0 comments on commit 3dd9bcf

Please sign in to comment.