Skip to content

Commit 57d2537

Browse files
committed
enable eslint in rxfire
1 parent 1b1827c commit 57d2537

File tree

7 files changed

+69
-36
lines changed

7 files changed

+69
-36
lines changed

packages/rxfire/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../config/.eslintrc.json",
3+
"parserOptions": {
4+
"project": "tsconfig.json"
5+
}
6+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function waitForLoaded(
6767
// We can use both datasets to form an array of the latest values.
6868
map(([loaded, changes]) => {
6969
// Store the last key in the data set
70-
let lastKeyToLoad = loaded.lastKeyToLoad;
70+
const lastKeyToLoad = loaded.lastKeyToLoad;
7171
// Store all child keys loaded at this point
7272
const loadedKeys = changes.map(change => change.snapshot.key);
7373
return { changes, lastKeyToLoad, loadedKeys };

packages/rxfire/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
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'",
2426
"build": "rollup -c",
2527
"dev": "rollup -c -w",
2628
"prepare": "yarn build",
27-
"test": "yarn test:browser",
29+
"test": "run-p lint test:browser",
2830
"test:browser": "karma start --single-run",
2931
"test:browser:debug": "karma start --browsers=Chrome --auto-watch"
3032
},
@@ -67,7 +69,11 @@
6769
"ts-node": "8.1.0",
6870
"tslint": "5.16.0",
6971
"webpack": "4.30.0",
70-
"yargs": "13.2.2"
72+
"yargs": "13.2.2",
73+
"eslint": "5.16.0",
74+
"@typescript-eslint/parser": "1.9.0",
75+
"@typescript-eslint/eslint-plugin": "1.9.0",
76+
"@typescript-eslint/eslint-plugin-tslint": "1.9.0"
7177
},
7278
"typings": "dist/index.d.ts",
7379
"files": [

packages/rxfire/storage/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,32 @@ import { storage } from 'firebase/app';
1919
import { Observable, from } from 'rxjs';
2020
import { map } from 'rxjs/operators';
2121

22-
export function fromTask(task: storage.UploadTask) {
22+
export function fromTask(task: storage.UploadTask): Observable<storage.UploadTaskSnapshot> {
2323
return new Observable<storage.UploadTaskSnapshot>(subscriber => {
24-
const progress = (snap: storage.UploadTaskSnapshot) =>
24+
const progress = (snap: storage.UploadTaskSnapshot): void =>
2525
subscriber.next(snap);
26-
const error = (e: Error) => subscriber.error(e);
27-
const complete = () => subscriber.complete();
26+
const error = (e: Error): void => subscriber.error(e);
27+
const complete = (): void => subscriber.complete();
2828
task.on('state_changed', progress, error, complete);
2929
return () => task.cancel();
3030
});
3131
}
3232

33-
export function getDownloadURL(ref: storage.Reference) {
33+
export function getDownloadURL(ref: storage.Reference): Observable<string> {
3434
return from(ref.getDownloadURL());
3535
}
3636

37-
export function getMetadata(ref: storage.Reference) {
37+
// TODO: fix storage typing in firebase, then apply the same fix here
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
export function getMetadata(ref: storage.Reference): Observable<any> {
3840
return from(ref.getMetadata());
3941
}
4042

4143
export function put(
4244
ref: storage.Reference,
43-
data: any,
45+
data: unknown,
4446
metadata?: storage.UploadMetadata
45-
) {
47+
): Observable<storage.UploadTaskSnapshot> {
4648
return fromTask(ref.put(data, metadata));
4749
}
4850

@@ -51,11 +53,16 @@ export function putString(
5153
data: string,
5254
format?: storage.StringFormat,
5355
metadata?: storage.UploadMetadata
54-
) {
56+
): Observable<storage.UploadTaskSnapshot> {
5557
return fromTask(ref.putString(data, format, metadata));
5658
}
5759

58-
export function percentage(task: storage.UploadTask) {
60+
export function percentage(
61+
task: storage.UploadTask
62+
): Observable<{
63+
progress: number;
64+
snapshot: storage.UploadTaskSnapshot;
65+
}> {
5966
return fromTask(task).pipe(
6067
map(s => ({
6168
progress: (s.bytesTransferred / s.totalBytes) * 100,

packages/rxfire/test/database.test.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@
1515
* limitations under the License.
1616
*/
1717

18+
// tslint:disable:no-floating-promises
19+
1820
import { expect } from 'chai';
21+
// app/database is used as namespaces to access types
22+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1923
import { initializeApp, database, app } from 'firebase';
2024
import { fromRef } from '../database/fromRef';
21-
import { list, ListenEvent, objectVal, listVal } from '../database';
25+
import { list, ListenEvent, objectVal, listVal, QueryChange } from '../database';
2226
import { take, skip, switchMap } from 'rxjs/operators';
23-
import { BehaviorSubject } from 'rxjs';
27+
import { BehaviorSubject, Observable } from 'rxjs';
2428
import { auditTrail } from '../database/list/audit-trail';
2529

30+
// eslint-disable-next-line @typescript-eslint/no-require-imports
2631
export const TEST_PROJECT = require('../../../config/project.json');
2732

28-
const rando = () =>
33+
const rando = (): string =>
2934
Math.random()
3035
.toString(36)
3136
.substring(5);
3237

33-
let batch = (items: { name: string; key: string }[]) => {
38+
let batch = (items: { name: string; key: string }[]): Readonly<{}> => {
3439
let batch: { [key: string]: unknown } = {};
3540
items.forEach(item => {
3641
batch[item.key] = item;
@@ -42,14 +47,17 @@ let batch = (items: { name: string; key: string }[]) => {
4247
describe('RxFire Database', () => {
4348
let app: app.App;
4449
let database: database.Database;
45-
let ref = (path: string) => {
50+
const ref = (path: string): database.Reference => {
4651
app!.database().goOffline();
4752
return app!.database().ref(path);
4853
};
4954

5055
function prepareList(
5156
opts: { events?: ListenEvent[]; skipnumber: number } = { skipnumber: 0 }
52-
) {
57+
): {
58+
snapChanges: Observable<QueryChange[]>;
59+
ref: database.Reference;
60+
} {
5361
const { events, skipnumber } = opts;
5462
const aref = ref(rando());
5563
const snapChanges = list(aref, events);
@@ -215,7 +223,7 @@ describe('RxFire Database', () => {
215223
sub.unsubscribe();
216224
done();
217225
});
218-
itemRef.child(key).setPriority(-100, () => {});
226+
itemRef.child(key).setPriority(-100, () => { });
219227
});
220228

221229
/**
@@ -385,7 +393,7 @@ describe('RxFire Database', () => {
385393
it('should process a new child_removed event', done => {
386394
const aref = ref(rando());
387395
const obs = list(aref, [ListenEvent.added, ListenEvent.removed]);
388-
const sub = obs
396+
const _sub = obs
389397
.pipe(
390398
skip(1),
391399
take(1)
@@ -408,7 +416,7 @@ describe('RxFire Database', () => {
408416
it('should process a new child_changed event', done => {
409417
const aref = ref(rando());
410418
const obs = list(aref, [ListenEvent.added, ListenEvent.changed]);
411-
const sub = obs
419+
const _sub = obs
412420
.pipe(
413421
skip(1),
414422
take(1)
@@ -431,7 +439,7 @@ describe('RxFire Database', () => {
431439
it('should process a new child_moved event', done => {
432440
const aref = ref(rando());
433441
const obs = list(aref, [ListenEvent.added, ListenEvent.moved]);
434-
const sub = obs
442+
const _sub = obs
435443
.pipe(
436444
skip(1),
437445
take(1)
@@ -445,7 +453,7 @@ describe('RxFire Database', () => {
445453
.add(done);
446454
app.database().goOnline();
447455
aref.set(itemsObj).then(() => {
448-
aref.child(items[0].key).setPriority('a', () => {});
456+
aref.child(items[0].key).setPriority('a', () => { });
449457
});
450458
});
451459

@@ -472,7 +480,7 @@ describe('RxFire Database', () => {
472480
*/
473481
it('should handle multiple subscriptions (hot)', done => {
474482
const { snapChanges, ref } = prepareList();
475-
const sub = snapChanges.subscribe(() => {}).add(done);
483+
const sub = snapChanges.subscribe(() => { }).add(done);
476484
snapChanges
477485
.pipe(take(1))
478486
.subscribe(actions => {
@@ -490,7 +498,7 @@ describe('RxFire Database', () => {
490498
const { snapChanges, ref } = prepareList();
491499
snapChanges
492500
.pipe(take(1))
493-
.subscribe(() => {})
501+
.subscribe(() => { })
494502
.add(() => {
495503
snapChanges
496504
.pipe(take(1))
@@ -567,7 +575,7 @@ describe('RxFire Database', () => {
567575
*/
568576
it('should handle dynamic queries that return empty sets', done => {
569577
let count = 0;
570-
let namefilter$ = new BehaviorSubject<number | null>(null);
578+
const namefilter$ = new BehaviorSubject<number | null>(null);
571579
const aref = ref(rando());
572580
aref.set(itemsObj);
573581
namefilter$
@@ -606,7 +614,10 @@ describe('RxFire Database', () => {
606614

607615
function prepareAuditTrail(
608616
opts: { events?: ListenEvent[]; skipnumber: number } = { skipnumber: 0 }
609-
) {
617+
): {
618+
changes: Observable<QueryChange[]>;
619+
ref: database.Reference;
620+
} {
610621
const { events, skipnumber } = opts;
611622
const aref = ref(rando());
612623
aref.set(itemsObj);

packages/rxfire/test/firestore.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
18+
// tslint:disable:no-floating-promises
19+
1720
import { expect } from 'chai';
21+
// app is used as namespaces to access types
22+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1823
import { initializeApp, firestore, app } from 'firebase/app';
1924
import 'firebase/firestore';
2025
import {
@@ -27,9 +32,10 @@ import {
2732
} from '../firestore';
2833
import { map, take, skip } from 'rxjs/operators';
2934

35+
// eslint-disable-next-line @typescript-eslint/no-require-imports
3036
export const TEST_PROJECT = require('../../../config/project.json');
3137

32-
const createId = () =>
38+
const createId = (): string =>
3339
Math.random()
3440
.toString(36)
3541
.substring(5);
@@ -38,7 +44,7 @@ const createId = () =>
3844
* Create a collection with a random name. This helps sandbox offline tests and
3945
* makes sure tests don't interfere with each other as they run.
4046
*/
41-
const createRandomCol = (firestore: firestore.Firestore) =>
47+
const createRandomCol = (firestore: firestore.Firestore): firestore.CollectionReference =>
4248
firestore.collection(createId());
4349

4450
/**
@@ -52,7 +58,7 @@ const unwrapChange = map((changes: firestore.DocumentChange[]) => {
5258
* Create an environment for the tests to run in. The information is returned
5359
* from the function for use within the test.
5460
*/
55-
const seedTest = (firestore: firestore.Firestore) => {
61+
const seedTest = (firestore: firestore.Firestore):any => {
5662
const colRef = createRandomCol(firestore);
5763
const davidDoc = colRef.doc('david');
5864
davidDoc.set({ name: 'David' });
@@ -159,7 +165,6 @@ describe('RxFire Firestore', () => {
159165
);
160166

161167
addedChanges.subscribe(data => {
162-
debugger;
163168
const expectedNames = [
164169
{ name: 'David', type: 'added' },
165170
{ name: 'Shannon', type: 'added' }

packages/rxfire/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
5-
"declaration": true
4+
"outDir": "dist"
65
},
76
"exclude": [
8-
"dist/**/*",
9-
"test/**/*"
7+
"dist/**/*"
108
]
119
}

0 commit comments

Comments
 (0)