Skip to content

Commit 875bd92

Browse files
committed
fix rxfire lint issues
1 parent 57d2537 commit 875bd92

File tree

11 files changed

+39
-30
lines changed

11 files changed

+39
-30
lines changed

packages/rxfire/auth/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
// auth is used as a namespace to access types
19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1820
import { auth, User } from 'firebase';
1921
import { Observable, from, of } from 'rxjs';
2022
import { switchMap } from 'rxjs/operators';

packages/rxfire/database/fromRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { database } from 'firebase';
1919
import { Observable } from 'rxjs';
20-
import { map, delay, share } from 'rxjs/operators';
20+
import { delay } from 'rxjs/operators';
2121
import { ListenEvent, QueryChange } from './interfaces';
2222

2323
/**

packages/rxfire/database/list/audit-trail.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { stateChanges } from './index';
2424

2525
interface LoadedMetadata {
2626
data: QueryChange;
27-
lastKeyToLoad: any;
27+
lastKeyToLoad: unknown;
2828
}
2929

3030
export function auditTrail(
@@ -59,7 +59,7 @@ function loadedData(query: database.Query): Observable<LoadedMetadata> {
5959
function waitForLoaded(
6060
query: database.Query,
6161
snap$: Observable<QueryChange[]>
62-
) {
62+
): Observable<QueryChange[]> {
6363
const loaded$ = loadedData(query);
6464
return loaded$.pipe(
6565
withLatestFrom(snap$),
@@ -75,7 +75,7 @@ function waitForLoaded(
7575
// This is the magical part, only emit when the last load key
7676
// in the dataset has been loaded by a child event. At this point
7777
// we can assume the dataset is "whole".
78-
skipWhile(meta => meta.loadedKeys.indexOf(meta.lastKeyToLoad) === -1),
78+
skipWhile(meta => meta.loadedKeys.indexOf(meta.lastKeyToLoad as string | null) === -1),
7979
// Pluck off the meta data because the user only cares
8080
// to iterate through the snapshots
8181
map(meta => meta.changes)

packages/rxfire/database/list/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { fromRef } from '../fromRef';
2323
import { switchMap, scan, distinctUntilChanged, map } from 'rxjs/operators';
2424
import { changeToData } from '../object';
2525

26-
export function stateChanges(query: database.Query, events?: ListenEvent[]) {
26+
export function stateChanges(query: database.Query, events?: ListenEvent[]): Observable<QueryChange> {
2727
events = validateEventsArray(events);
2828
const childEvent$ = events.map(event => fromRef(query, event));
2929
return merge(...childEvent$);
@@ -69,7 +69,7 @@ export function listVal<T>(
6969
);
7070
}
7171

72-
function positionFor(changes: QueryChange[], key: string | null) {
72+
function positionFor(changes: QueryChange[], key: string | null):number {
7373
const len = changes.length;
7474
for (let i = 0; i < len; i++) {
7575
if (changes[i].snapshot.key === key) {
@@ -79,7 +79,7 @@ function positionFor(changes: QueryChange[], key: string | null) {
7979
return -1;
8080
}
8181

82-
function positionAfter(changes: QueryChange[], prevKey?: string) {
82+
function positionAfter(changes: QueryChange[], prevKey?: string): number {
8383
if (prevKey == null) {
8484
return 0;
8585
} else {
@@ -92,7 +92,7 @@ function positionAfter(changes: QueryChange[], prevKey?: string) {
9292
}
9393
}
9494

95-
function buildView(current: QueryChange[], change: QueryChange) {
95+
function buildView(current: QueryChange[], change: QueryChange): QueryChange[] {
9696
const { snapshot, prevKey, event } = change;
9797
const { key } = snapshot;
9898
const currentKeyPosition = positionFor(current, key);
@@ -117,7 +117,7 @@ function buildView(current: QueryChange[], change: QueryChange) {
117117
if (currentKeyPosition > -1) {
118118
// check that the previouskey is what we expect, else reorder
119119
const previous = current[currentKeyPosition - 1];
120-
if (((previous && previous.snapshot.key) || null) != prevKey) {
120+
if (((previous && previous.snapshot.key) || null) !== prevKey) {
121121
current = current.filter(x => x.snapshot.key !== snapshot.key);
122122
current.splice(afterPreviousKeyPosition, 0, change);
123123
}

packages/rxfire/database/object/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function objectVal<T>(
4343
);
4444
}
4545

46-
export function changeToData(change: QueryChange, keyField?: string) {
46+
export function changeToData(change: QueryChange, keyField?: string): {} {
4747
return {
4848
...change.snapshot.val(),
4949
...(keyField ? { [keyField]: change.snapshot.key } : null)

packages/rxfire/firestore/collection/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { firestore } from 'firebase/app';
1919
import { fromCollectionRef } from '../fromRef';
20-
import { Observable } from 'rxjs';
20+
import { Observable, MonoTypeOperatorFunction } from 'rxjs';
2121
import { map, filter, scan } from 'rxjs/operators';
2222
import { snapToData } from '../document';
2323

@@ -32,7 +32,9 @@ const ALL_EVENTS: firestore.DocumentChangeType[] = [
3232
* are specified by the event filter. If the document change type is not
3333
* in specified events array, it will not be emitted.
3434
*/
35-
const filterEvents = (events?: firestore.DocumentChangeType[]) =>
35+
const filterEvents = (
36+
events?: firestore.DocumentChangeType[]
37+
): MonoTypeOperatorFunction<firestore.DocumentChange[]> =>
3638
filter((changes: firestore.DocumentChange[]) => {
3739
let hasChange = false;
3840
for (let i = 0; i < changes.length; i++) {
@@ -67,7 +69,7 @@ function processIndividualChange(
6769
case 'added':
6870
if (
6971
combined[change.newIndex] &&
70-
combined[change.newIndex].doc.id == change.doc.id
72+
combined[change.newIndex].doc.id === change.doc.id
7173
) {
7274
// Skip duplicate emissions. This is rare.
7375
// TODO: Investigate possible bug in SDK.
@@ -78,7 +80,7 @@ function processIndividualChange(
7880
case 'modified':
7981
if (
8082
combined[change.oldIndex] == null ||
81-
combined[change.oldIndex].doc.id == change.doc.id
83+
combined[change.oldIndex].doc.id === change.doc.id
8284
) {
8385
// When an item changes position we first remove it
8486
// and then add it's new position
@@ -93,11 +95,12 @@ function processIndividualChange(
9395
case 'removed':
9496
if (
9597
combined[change.oldIndex] &&
96-
combined[change.oldIndex].doc.id == change.doc.id
98+
combined[change.oldIndex].doc.id === change.doc.id
9799
) {
98100
combined.splice(change.oldIndex, 1);
99101
}
100102
break;
103+
default: // ignore
101104
}
102105
return combined;
103106
}
@@ -113,7 +116,7 @@ function processDocumentChanges(
113116
current: firestore.DocumentChange[],
114117
changes: firestore.DocumentChange[],
115118
events: firestore.DocumentChangeType[] = ALL_EVENTS
116-
) {
119+
): firestore.DocumentChange[] {
117120
changes.forEach(change => {
118121
// skip unwanted change types
119122
if (events.indexOf(change.type) > -1) {
@@ -131,7 +134,7 @@ function processDocumentChanges(
131134
export function collectionChanges(
132135
query: firestore.Query,
133136
events: firestore.DocumentChangeType[] = ALL_EVENTS
134-
) {
137+
): Observable<firestore.DocumentChange[]> {
135138
return fromCollectionRef(query).pipe(
136139
map(snapshot => snapshot.docChanges()),
137140
filterEvents(events),
@@ -143,7 +146,7 @@ export function collectionChanges(
143146
* Return a stream of document snapshots on a query. These results are in sort order.
144147
* @param query
145148
*/
146-
export function collection(query: firestore.Query) {
149+
export function collection(query: firestore.Query): Observable<firestore.QueryDocumentSnapshot[]> {
147150
return fromCollectionRef(query).pipe(map(changes => changes.docs));
148151
}
149152

@@ -154,7 +157,7 @@ export function collection(query: firestore.Query) {
154157
export function sortedChanges(
155158
query: firestore.Query,
156159
events?: firestore.DocumentChangeType[]
157-
) {
160+
): Observable<firestore.DocumentChange[]> {
158161
return collectionChanges(query, events).pipe(
159162
scan(
160163
(

packages/rxfire/firestore/document/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { fromDocRef } from '../fromRef';
2020
import { map } from 'rxjs/operators';
2121
import { Observable } from 'rxjs';
2222

23-
export function doc(ref: firestore.DocumentReference) {
23+
export function doc(ref: firestore.DocumentReference): Observable<firestore.DocumentSnapshot> {
2424
return fromDocRef(ref);
2525
}
2626

@@ -38,7 +38,7 @@ export function docData<T>(
3838
export function snapToData(
3939
snapshot: firestore.DocumentSnapshot,
4040
idField?: string
41-
) {
41+
): {} {
4242
return {
4343
...snapshot.data(),
4444
...(idField ? { [idField]: snapshot.id } : null)

packages/rxfire/firestore/fromRef.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@
1818
import { firestore } from 'firebase/app';
1919
import { Observable } from 'rxjs';
2020

21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2122
function _fromRef(ref: any): Observable<any> {
2223
return new Observable(subscriber => {
2324
const unsubscribe = ref.onSnapshot(subscriber);
2425
return { unsubscribe };
2526
});
2627
}
2728

28-
export function fromRef(ref: firestore.DocumentReference | firestore.Query) {
29+
export function fromRef(ref: firestore.DocumentReference | firestore.Query): Observable<{}> {
2930
return _fromRef(ref);
3031
}
3132

3233
export function fromDocRef(
3334
ref: firestore.DocumentReference
3435
): Observable<firestore.DocumentSnapshot> {
35-
return fromRef(ref);
36+
return fromRef(ref) as Observable<firestore.DocumentSnapshot>;
3637
}
3738

3839
export function fromCollectionRef(
3940
ref: firestore.Query
4041
): Observable<firestore.QuerySnapshot> {
41-
return fromRef(ref);
42+
return fromRef(ref) as Observable<firestore.QuerySnapshot>;
4243
}

packages/rxfire/functions/index.ts

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

18+
// function is used as a namespace to access types
19+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1820
import { functions } from 'firebase/app';
19-
import { Observable, from } from 'rxjs';
21+
import { from, Observable } from 'rxjs';
2022
import { map } from 'rxjs/operators';
2123

22-
export function httpsCallable<T = any, R = any>(
24+
export function httpsCallable<T, R>(
2325
functions: functions.Functions,
2426
name: string
25-
) {
27+
): (data: T) => Observable<R> {
2628
const callable = functions.httpsCallable(name);
2729
return (data: T) => {
2830
return from(callable(data)).pipe(map(r => r.data as R));

packages/rxfire/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"url": "https://github.com/firebase/firebase-js-sdk.git"
2222
},
2323
"scripts": {
24-
"lint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore' '.gitignore'",
25-
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore' '.gitignore'",
24+
"lint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
25+
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
2626
"build": "rollup -c",
2727
"dev": "rollup -c -w",
2828
"prepare": "yarn build",

packages/rxfire/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"declaration": true
56
},
67
"exclude": [
78
"dist/**/*"

0 commit comments

Comments
 (0)