Skip to content

Commit ee61062

Browse files
authored
Enable linting and fix lint issues for app, util and logger (#1845)
* add eslint rules * fix firebase/app lint issues * fix firebas/util lint issues * add eslint deps to util * fix firebase/logger lint issues * [AUTOMATED]: Prettier Code Styling * remove intermediate merge messages * add missing code during merge * rename parameter
1 parent 7a15e7e commit ee61062

35 files changed

+343
-291
lines changed

config/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"**/test/**/*.ts"
2121
],
2222
"rules": {
23-
"no-unused-expressions": "off"
23+
"no-unused-expressions": "off",
24+
"@typescript-eslint/no-explicit-any": "off"
2425
}
2526
}
2627
],

packages/app/index.rn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { createFirebaseNamespace } from './src/firebaseNamespace';
2424
* some of our tests because of duplicate symbols, we are using require syntax
2525
* here
2626
*/
27+
// eslint-disable-next-line
2728
const { AsyncStorage } = require('react-native');
2829

2930
const _firebase = createFirebaseNamespace() as _FirebaseNamespace;

packages/app/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (isBrowser() && 'firebase' in self) {
2929
Firebase library is only loaded once.
3030
`);
3131

32+
// eslint-disable-next-line
3233
const sdkVersion = ((self as any).firebase as FirebaseNamespace).SDK_VERSION;
3334
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
3435
logger.warn(`

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts'",
1919
"build": "rollup -c",
2020
"dev": "rollup -c -w",
21-
"test": "run-p test:browser test:node",
21+
"test": "run-p lint test:browser test:node",
2222
"test:browser": "karma start --single-run",
2323
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
2424
"test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --opts ../../config/mocha.node.opts",

packages/app/src/firebaseApp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface ServicesCache {
3838

3939
// An array to capture listeners before the true auth functions
4040
// exist
41-
let tokenListeners: any[] = [];
41+
let tokenListeners: Array<(token: string | null) => void> = [];
4242

4343
/**
4444
* Global context object for a collection of services using
@@ -175,6 +175,7 @@ export class FirebaseAppImpl implements FirebaseApp {
175175
* Callback function used to extend an App instance at the time
176176
* of service instance creation.
177177
*/
178+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178179
private extendApp(props: { [name: string]: any }): void {
179180
// Copy the object onto the FirebaseAppImpl prototype
180181
deepExtend(this, props);

packages/app/src/firebaseNamespace.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export function createFirebaseNamespace(): FirebaseNamespace {
3232
const namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
3333
(namespace as _FirebaseNamespace).INTERNAL = {
3434
...(namespace as _FirebaseNamespace).INTERNAL,
35-
createFirebaseNamespace: createFirebaseNamespace,
36-
extendNamespace: extendNamespace,
37-
createSubscribe: createSubscribe,
38-
ErrorFactory: ErrorFactory,
39-
deepExtend: deepExtend
35+
createFirebaseNamespace,
36+
extendNamespace,
37+
createSubscribe,
38+
ErrorFactory,
39+
deepExtend
4040
};
4141

4242
/**

packages/app/src/firebaseNamespaceCore.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ import {
2929
FirebaseServiceNamespace,
3030
AppHook
3131
} from '@firebase/app-types/private';
32-
import { deepExtend, patchProperty } from '@firebase/util';
32+
import { deepExtend, contains } from '@firebase/util';
3333
import { FirebaseAppImpl } from './firebaseApp';
3434
import { ERROR_FACTORY, AppError } from './errors';
3535
import { FirebaseAppLiteImpl } from './lite/firebaseAppLite';
3636
import { DEFAULT_ENTRY_NAME } from './constants';
3737
import { version } from '../../firebase/package.json';
3838

39-
function contains(obj: object, key: string) {
40-
return Object.prototype.hasOwnProperty.call(obj, key);
41-
}
42-
4339
/**
4440
* Because auth can't share code with other components, we attach the utility functions
4541
* in an internal namespace to share code.
@@ -60,9 +56,11 @@ export function createFirebaseNamespaceCore(
6056
// as the firebase namespace.
6157
// @ts-ignore
6258
__esModule: true,
63-
initializeApp: initializeApp,
64-
app: app as any,
65-
apps: null as any,
59+
initializeApp,
60+
// @ts-ignore
61+
app,
62+
// @ts-ignore
63+
apps: null,
6664
SDK_VERSION: version,
6765
INTERNAL: {
6866
registerService,
@@ -82,7 +80,7 @@ export function createFirebaseNamespaceCore(
8280
//
8381
// import * as firebase from 'firebase';
8482
// which becomes: var firebase = require('firebase');
85-
patchProperty(namespace, 'default', namespace);
83+
namespace['default'] = namespace;
8684

8785
// firebase.apps is a read-only getter.
8886
Object.defineProperty(namespace, 'apps', {
@@ -105,12 +103,12 @@ export function createFirebaseNamespaceCore(
105103
function app(name?: string): FirebaseApp {
106104
name = name || DEFAULT_ENTRY_NAME;
107105
if (!contains(apps, name)) {
108-
throw ERROR_FACTORY.create(AppError.NO_APP, { name: name });
106+
throw ERROR_FACTORY.create(AppError.NO_APP, { name });
109107
}
110108
return apps[name];
111109
}
112110

113-
patchProperty(app, 'App', firebaseAppImpl);
111+
app['App'] = firebaseAppImpl;
114112
/**
115113
* Create a new App instance (name must be unique).
116114
*/
@@ -119,7 +117,10 @@ export function createFirebaseNamespaceCore(
119117
config?: FirebaseAppConfig
120118
): FirebaseApp;
121119
function initializeApp(options: FirebaseOptions, name?: string): FirebaseApp;
122-
function initializeApp(options: FirebaseOptions, rawConfig = {}) {
120+
function initializeApp(
121+
options: FirebaseOptions,
122+
rawConfig = {}
123+
): FirebaseApp {
123124
if (typeof rawConfig !== 'object' || rawConfig === null) {
124125
const name = rawConfig;
125126
rawConfig = { name };
@@ -138,7 +139,7 @@ export function createFirebaseNamespaceCore(
138139
}
139140

140141
if (contains(apps, name)) {
141-
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { name: name });
142+
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { name });
142143
}
143144

144145
const app = new firebaseAppImpl(
@@ -177,7 +178,7 @@ export function createFirebaseNamespaceCore(
177178
): FirebaseServiceNamespace<FirebaseService> {
178179
// Cannot re-register a service that already exists
179180
if (factories[name]) {
180-
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { name: name });
181+
throw ERROR_FACTORY.create(AppError.DUPLICATE_SERVICE, { name });
181182
}
182183

183184
// Capture the service factory for later service instantiation
@@ -194,12 +195,12 @@ export function createFirebaseNamespaceCore(
194195
}
195196

196197
// The Service namespace is an accessor function ...
197-
function serviceNamespace(appArg: FirebaseApp = app()) {
198+
function serviceNamespace(appArg: FirebaseApp = app()): FirebaseService {
198199
if (typeof appArg[name] !== 'function') {
199200
// Invalid argument.
200201
// This happens in the following case: firebase.storage('gs:/')
201202
throw ERROR_FACTORY.create(AppError.INVALID_APP_ARGUMENT, {
202-
name: name
203+
name
203204
});
204205
}
205206

@@ -224,7 +225,7 @@ export function createFirebaseNamespaceCore(
224225
return serviceNamespace;
225226
}
226227

227-
function callAppHooks(app: FirebaseApp, eventName: string) {
228+
function callAppHooks(app: FirebaseApp, eventName: string): void {
228229
for (const serviceName of Object.keys(factories)) {
229230
// Ignore virtual services
230231
const factoryName = useAsService(app, serviceName);

packages/app/src/lite/firebaseAppLite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class FirebaseAppLiteImpl implements FirebaseApp {
157157
* Callback function used to extend an App instance at the time
158158
* of service instance creation.
159159
*/
160-
private extendApp(props: { [name: string]: any }): void {
160+
private extendApp(props: { [name: string]: unknown }): void {
161161
// Copy the object onto the FirebaseAppImpl prototype
162162
deepExtend(this, props);
163163
}

packages/app/src/lite/firebaseNamespaceLite.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
_FirebaseApp,
2121
_FirebaseNamespace,
2222
FirebaseServiceFactory,
23-
AppHook
23+
AppHook,
24+
FirebaseServiceNamespace,
25+
FirebaseService
2426
} from '@firebase/app-types/private';
2527
import { FirebaseAppLiteImpl } from './firebaseAppLite';
2628
import { createFirebaseNamespaceCore } from '../firebaseNamespaceCore';
@@ -41,10 +43,10 @@ export function createFirebaseNamespaceLite(): FirebaseNamespace {
4143
function registerServiceForLite(
4244
name: string,
4345
createService: FirebaseServiceFactory,
44-
serviceProperties?: { [prop: string]: any },
46+
serviceProperties?: { [prop: string]: unknown },
4547
appHook?: AppHook,
4648
allowMultipleInstances?: boolean
47-
) {
49+
): FirebaseServiceNamespace<FirebaseService> {
4850
// only allow performance to register with firebase lite
4951
if (name !== 'performance' && name !== 'installations') {
5052
throw Error(`${name} cannot register with the standalone perf instance`);

packages/app/test/firebaseApp.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { assert } from 'chai';
2828
executeFirebaseTests();
2929
executeFirebaseLiteTests();
3030

31-
function executeFirebaseTests() {
31+
function executeFirebaseTests(): void {
3232
firebaseAppTests('Firebase App Tests', createFirebaseNamespace);
3333

3434
describe('Firebase Service Registration', () => {
@@ -40,24 +40,24 @@ function executeFirebaseTests() {
4040
it('Register App Hook', done => {
4141
const events = ['create', 'delete'];
4242
let hookEvents = 0;
43-
let app: FirebaseApp;
4443
(firebase as _FirebaseNamespace).INTERNAL.registerService(
4544
'test',
4645
(app: FirebaseApp) => {
4746
return new TestService(app);
4847
},
4948
undefined,
50-
(event: string, app: FirebaseApp) => {
49+
(event: string, _app: FirebaseApp) => {
5150
assert.equal(event, events[hookEvents]);
5251
hookEvents += 1;
5352
if (hookEvents === events.length) {
5453
done();
5554
}
5655
}
5756
);
58-
app = firebase.initializeApp({});
57+
const app = firebase.initializeApp({});
5958
// Ensure the hook is called synchronously
6059
assert.equal(hookEvents, 1);
60+
// tslint:disable-next-line:no-floating-promises
6161
app.delete();
6262
});
6363

@@ -140,7 +140,7 @@ function executeFirebaseTests() {
140140
return new TestService(app);
141141
},
142142
undefined,
143-
(event: string, app: FirebaseApp) => {
143+
(event: string, _app: FirebaseApp) => {
144144
assert.equal(event, events[hookEvents]);
145145
hookEvents += 1;
146146
if (hookEvents === events.length) {
@@ -150,6 +150,7 @@ function executeFirebaseTests() {
150150
);
151151
// Ensure the hook is called synchronously
152152
assert.equal(hookEvents, 1);
153+
// tslint:disable-next-line:no-floating-promises
153154
app.delete();
154155
});
155156

@@ -221,6 +222,7 @@ function executeFirebaseTests() {
221222
);
222223
assert.strictEqual(service, service2);
223224
});
225+
224226
it(`Should pass null to the factory method if using default instance`, () => {
225227
// Register Multi Instance Service
226228
(firebase as _FirebaseNamespace).INTERNAL.registerService(
@@ -235,11 +237,8 @@ function executeFirebaseTests() {
235237
}
236238
);
237239
firebase.initializeApp({});
238-
239-
// Capture a given service ref
240-
const serviceIdentifier = 'custom instance identifier';
241-
const service = (firebase.app() as any).testService();
242240
});
241+
243242
it(`Should extend INTERNAL per app instance`, () => {
244243
let counter: number = 0;
245244
(firebase as _FirebaseNamespace).INTERNAL.registerService(
@@ -280,7 +279,7 @@ function executeFirebaseTests() {
280279
});
281280
}
282281

283-
function executeFirebaseLiteTests() {
282+
function executeFirebaseLiteTests(): void {
284283
firebaseAppTests('Firebase App Lite Tests', createFirebaseNamespaceLite);
285284

286285
describe('Firebase Lite Service Registration', () => {
@@ -291,14 +290,13 @@ function executeFirebaseLiteTests() {
291290
});
292291

293292
it('should allow Performance service to register', () => {
294-
let app: FirebaseApp;
295293
(firebase as _FirebaseNamespace).INTERNAL.registerService(
296294
'performance',
297295
(app: FirebaseApp) => {
298296
return new TestService(app);
299297
}
300298
);
301-
app = firebase.initializeApp({});
299+
const app = firebase.initializeApp({});
302300
const perf = (app as any).performance();
303301
assert.isTrue(perf instanceof TestService);
304302
});
@@ -316,7 +314,7 @@ function executeFirebaseLiteTests() {
316314
});
317315
}
318316

319-
function firebaseAppTests(testName, firebaseNamespaceFactory) {
317+
function firebaseAppTests(testName, firebaseNamespaceFactory): void {
320318
describe(testName, () => {
321319
let firebase: FirebaseNamespace;
322320

packages/database/src/realtime/WebSocketConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class WebSocketConnection implements Transport {
270270
if (this.frames.length == this.totalFrames) {
271271
const fullMess = this.frames.join('');
272272
this.frames = null;
273-
const jsonMess = jsonEval(fullMess);
273+
const jsonMess = jsonEval(fullMess) as object;
274274

275275
//handle the message
276276
this.onMessage(jsonMess);

packages/logger/.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/logger/index.ts

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

1818
import { instances, LogLevel } from './src/logger';
1919

20-
export function setLogLevel(level: LogLevel) {
20+
export function setLogLevel(level: LogLevel): void {
2121
instances.forEach(inst => {
2222
inst.logLevel = level;
2323
});

packages/logger/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
"dist"
1111
],
1212
"scripts": {
13+
"lint": "eslint -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
14+
"lint:fix": "eslint --fix -c .eslintrc.json '**/*.ts' --ignore-path '../../.gitignore'",
1315
"build": "rollup -c",
1416
"dev": "rollup -c -w",
15-
"test": "run-p test:browser test:node",
17+
"test": "run-p lint test:browser test:node",
1618
"test:browser": "karma start --single-run",
1719
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
1820
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --opts ../../config/mocha.node.opts",
@@ -40,7 +42,11 @@
4042
"ts-loader": "5.4.5",
4143
"ts-node": "8.1.0",
4244
"typescript": "3.4.5",
43-
"webpack": "4.30.0"
45+
"webpack": "4.30.0",
46+
"eslint": "5.16.0",
47+
"@typescript-eslint/parser": "1.9.0",
48+
"@typescript-eslint/eslint-plugin": "1.9.0",
49+
"@typescript-eslint/eslint-plugin-tslint": "1.9.0"
4450
},
4551
"repository": {
4652
"directory": "packages/logger",

0 commit comments

Comments
 (0)