Skip to content

Commit 0f6c02e

Browse files
authored
chore: Enabling more ESLint checks and fixing errors (#797)
1 parent c0e6ae1 commit 0f6c02e

Some content is hidden

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

49 files changed

+175
-150
lines changed

.eslintrc.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ module.exports = {
2828
rules: {
2929
// Following checks are temporarily disabled. We shall incrementally enable them in the
3030
// future, fixing any violations as we go.
31-
"@typescript-eslint/no-explicit-any": 0,
32-
"@typescript-eslint/no-use-before-define": 0,
33-
"@typescript-eslint/explicit-function-return-type": 0,
34-
"@typescript-eslint/camelcase": 0,
35-
"@typescript-eslint/no-non-null-assertion": 0,
36-
"@typescript-eslint/no-var-requires": 0,
37-
"@typescript-eslint/ban-types": 0,
38-
"no-useless-escape": 0,
39-
"no-prototype-builtins": 0,
31+
'@typescript-eslint/no-non-null-assertion': 0,
32+
33+
// Disabled checks
34+
'@typescript-eslint/no-explicit-any': 0,
35+
'@typescript-eslint/no-use-before-define': 0,
4036

4137
// Required checks
42-
"indent": ["error", 2]
38+
'indent': ['error', 2],
39+
'@typescript-eslint/explicit-function-return-type': [
40+
'error',
41+
{
42+
'allowExpressions': true,
43+
'allowTypedFunctionExpressions': true,
44+
'allowHigherOrderFunctions': true
45+
}
46+
],
4347
}
4448
};

src/auth/action-code-settings-builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class ActionCodeSettingsBuilder {
169169
};
170170
// Remove all null and undefined fields from request.
171171
for (const key in request) {
172-
if (request.hasOwnProperty(key)) {
172+
if (Object.prototype.hasOwnProperty.call(request, key)) {
173173
if (typeof request[key] === 'undefined' || request[key] === null) {
174174
delete request[key];
175175
}

src/auth/auth-api-request.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class TenantAwareAuthResourceUrlBuilder extends AuthResourceUrlBuilder {
187187
*
188188
* @param {any} request The providerUserInfo request object.
189189
*/
190-
function validateProviderUserInfo(request: any) {
190+
function validateProviderUserInfo(request: any): void {
191191
const validKeys = {
192192
rawId: true,
193193
providerId: true,
@@ -247,7 +247,7 @@ function validateProviderUserInfo(request: any) {
247247
* @param {any} request The create/edit request object.
248248
* @param {boolean=} uploadAccountRequest Whether to validate as an uploadAccount request.
249249
*/
250-
function validateCreateEditRequest(request: any, uploadAccountRequest = false) {
250+
function validateCreateEditRequest(request: any, uploadAccountRequest = false): void {
251251
// Hash set of whitelisted parameters.
252252
const validKeys = {
253253
displayName: true,
@@ -370,7 +370,7 @@ function validateCreateEditRequest(request: any, uploadAccountRequest = false) {
370370
const invalidClaims: string[] = [];
371371
// Check for any invalid claims.
372372
RESERVED_CLAIMS.forEach((blacklistedClaim) => {
373-
if (developerClaims.hasOwnProperty(blacklistedClaim)) {
373+
if (Object.prototype.hasOwnProperty.call(developerClaims, blacklistedClaim)) {
374374
invalidClaims.push(blacklistedClaim);
375375
}
376376
});

src/auth/auth-config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ export class EmailSignInConfig implements EmailSignInProviderConfig {
179179
public static buildServerRequest(options: EmailSignInProviderConfig): EmailSignInConfigServerRequest {
180180
const request: EmailSignInConfigServerRequest = {};
181181
EmailSignInConfig.validate(options);
182-
if (options.hasOwnProperty('enabled')) {
182+
if (Object.prototype.hasOwnProperty.call(options, 'enabled')) {
183183
request.allowPasswordSignup = options.enabled;
184184
}
185-
if (options.hasOwnProperty('passwordRequired')) {
185+
if (Object.prototype.hasOwnProperty.call(options, 'passwordRequired')) {
186186
request.enableEmailLinkSignin = !options.passwordRequired;
187187
}
188188
return request;
@@ -193,7 +193,7 @@ export class EmailSignInConfig implements EmailSignInProviderConfig {
193193
*
194194
* @param {any} options The options object to validate.
195195
*/
196-
private static validate(options: EmailSignInProviderConfig) {
196+
private static validate(options: EmailSignInProviderConfig): void {
197197
// TODO: Validate the request.
198198
const validKeys = {
199199
enabled: true,
@@ -349,7 +349,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
349349
* @param {SAMLAuthProviderRequest} options The options object to validate.
350350
* @param {boolean=} ignoreMissingFields Whether to ignore missing fields.
351351
*/
352-
public static validate(options: SAMLAuthProviderRequest, ignoreMissingFields = false) {
352+
public static validate(options: SAMLAuthProviderRequest, ignoreMissingFields = false): void {
353353
const validKeys = {
354354
enabled: true,
355355
displayName: true,
@@ -590,7 +590,7 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
590590
* @param {OIDCAuthProviderRequest} options The options object to validate.
591591
* @param {boolean=} ignoreMissingFields Whether to ignore missing fields.
592592
*/
593-
public static validate(options: OIDCAuthProviderRequest, ignoreMissingFields = false) {
593+
public static validate(options: OIDCAuthProviderRequest, ignoreMissingFields = false): void {
594594
const validKeys = {
595595
enabled: true,
596596
displayName: true,

src/auth/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export class BaseAuth<T extends AbstractAuthRequestHandler> {
444444
providerConfigs,
445445
};
446446
// Delete result.pageToken if undefined.
447-
if (response.hasOwnProperty('nextPageToken')) {
447+
if (Object.prototype.hasOwnProperty.call(response, 'nextPageToken')) {
448448
result.pageToken = response.nextPageToken;
449449
}
450450
return result;

src/auth/credential.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class ServiceAccountCredential implements Credential {
132132
].join(' '),
133133
};
134134

135+
// eslint-disable-next-line @typescript-eslint/no-var-requires
135136
const jwt = require('jsonwebtoken');
136137
// This method is actually synchronous so we can capture and return the buffer.
137138
return jwt.sign(claims, this.privateKey, {
@@ -189,6 +190,7 @@ class ServiceAccount {
189190
throw new FirebaseAppError(AppErrorCodes.INVALID_CREDENTIAL, errorMessage);
190191
}
191192

193+
// eslint-disable-next-line @typescript-eslint/no-var-requires
192194
const forge = require('node-forge');
193195
try {
194196
forge.pki.privateKeyFromPem(this.privateKey);
@@ -386,7 +388,7 @@ export function isApplicationDefault(credential?: Credential): boolean {
386388
* @param key Name of the property to copy.
387389
* @param alt Alternative name of the property to copy.
388390
*/
389-
function copyAttr(to: {[key: string]: any}, from: {[key: string]: any}, key: string, alt: string) {
391+
function copyAttr(to: {[key: string]: any}, from: {[key: string]: any}, key: string, alt: string): void {
390392
const tmp = from[key] || from[alt];
391393
if (typeof tmp !== 'undefined') {
392394
to[key] = tmp;

src/auth/tenant.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class Tenant {
9595
* @param {any} request The tenant options object to validate.
9696
* @param {boolean} createRequest Whether this is a create request.
9797
*/
98-
private static validate(request: any, createRequest: boolean) {
98+
private static validate(request: any, createRequest: boolean): void {
9999
const validKeys = {
100100
displayName: true,
101101
emailSignInConfig: true,

src/auth/token-generator.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class ServiceAccountSigner implements CryptoSigner {
101101
* @inheritDoc
102102
*/
103103
public sign(buffer: Buffer): Promise<Buffer> {
104-
const crypto = require('crypto');
104+
const crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-var-requires
105105
const sign = crypto.createSign('RSA-SHA256');
106106
sign.update(buffer);
107107
return Promise.resolve(sign.sign(this.credential.privateKey));
@@ -285,7 +285,7 @@ export class FirebaseTokenGenerator {
285285
if (typeof developerClaims !== 'undefined') {
286286
for (const key in developerClaims) {
287287
/* istanbul ignore else */
288-
if (developerClaims.hasOwnProperty(key)) {
288+
if (Object.prototype.hasOwnProperty.call(developerClaims, key)) {
289289
if (BLACKLISTED_CLAIMS.indexOf(key) !== -1) {
290290
throw new FirebaseAuthError(
291291
AuthClientErrorCode.INVALID_ARGUMENT,
@@ -311,6 +311,7 @@ export class FirebaseTokenGenerator {
311311
uid,
312312
};
313313
if (this.tenantId) {
314+
// eslint-disable-next-line @typescript-eslint/camelcase
314315
body.tenant_id = this.tenantId;
315316
}
316317
if (Object.keys(claims).length > 0) {
@@ -324,9 +325,9 @@ export class FirebaseTokenGenerator {
324325
});
325326
}
326327

327-
private encodeSegment(segment: object | Buffer) {
328+
private encodeSegment(segment: object | Buffer): string {
328329
const buffer: Buffer = (segment instanceof Buffer) ? segment : Buffer.from(JSON.stringify(segment));
329-
return toWebSafeBase64(buffer).replace(/\=+$/, '');
330+
return toWebSafeBase64(buffer).replace(/=+$/, '');
330331
}
331332

332333
/**

src/auth/token-verifier.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class FirebaseTokenVerifier {
214214
}
215215

216216
return this.fetchPublicKeys().then((publicKeys) => {
217-
if (!publicKeys.hasOwnProperty(header.kid)) {
217+
if (!Object.prototype.hasOwnProperty.call(publicKeys, header.kid)) {
218218
return Promise.reject(
219219
new FirebaseAuthError(
220220
AuthClientErrorCode.INVALID_ARGUMENT,
@@ -299,7 +299,7 @@ export class FirebaseTokenVerifier {
299299
// error responses.
300300
throw new HttpError(resp);
301301
}
302-
if (resp.headers.hasOwnProperty('cache-control')) {
302+
if (Object.prototype.hasOwnProperty.call(resp.headers, 'cache-control')) {
303303
const cacheControlHeader: string = resp.headers['cache-control'];
304304
const parts = cacheControlHeader.split(',');
305305
parts.forEach((part) => {

src/database/database.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export class DatabaseService implements FirebaseServiceInterface {
7777

7878
let db: Database = this.INTERNAL.databases[dbUrl];
7979
if (typeof db === 'undefined') {
80-
const rtdb = require('@firebase/database');
81-
const { version } = require('../../package.json');
80+
const rtdb = require('@firebase/database'); // eslint-disable-line @typescript-eslint/no-var-requires
81+
const { version } = require('../../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires
8282
db = rtdb.initStandalone(this.appInternal, dbUrl, version).instance;
8383

8484
const rulesClient = new DatabaseRulesClient(this.app, dbUrl);

src/firebase-app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class FirebaseAppInternals {
189189
*
190190
* @param {function(string)} listener The listener that will be called with each new token.
191191
*/
192-
public addAuthTokenListener(listener: (token: string) => void) {
192+
public addAuthTokenListener(listener: (token: string) => void): void {
193193
this.tokenListeners_.push(listener);
194194
if (this.cachedToken_) {
195195
listener(this.cachedToken_.accessToken);
@@ -201,7 +201,7 @@ export class FirebaseAppInternals {
201201
*
202202
* @param {function(string)} listener The listener to remove.
203203
*/
204-
public removeAuthTokenListener(listener: (token: string) => void) {
204+
public removeAuthTokenListener(listener: (token: string) => void): void {
205205
this.tokenListeners_ = this.tokenListeners_.filter((other) => other !== listener);
206206
}
207207

src/firebase-namespace.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export class FirebaseNamespaceInternals {
237237
* @param {FirebaseApp} app The FirebaseApp instance whose app hooks to call.
238238
* @param {string} eventName The event name representing which app hooks to call.
239239
*/
240-
private callAppHooks_(app: FirebaseApp, eventName: string) {
240+
private callAppHooks_(app: FirebaseApp, eventName: string): void {
241241
Object.keys(this.serviceFactories).forEach((serviceName) => {
242242
if (this.appHooks_[serviceName]) {
243243
this.appHooks_[serviceName](eventName, app);
@@ -340,6 +340,8 @@ export class FirebaseNamespace {
340340
const fn: FirebaseServiceNamespace<Database> = (app?: FirebaseApp) => {
341341
return this.ensureApp(app).database();
342342
};
343+
344+
// eslint-disable-next-line @typescript-eslint/no-var-requires
343345
return Object.assign(fn, require('@firebase/database'));
344346
}
345347

@@ -375,6 +377,8 @@ export class FirebaseNamespace {
375377
let fn: FirebaseServiceNamespace<Firestore> = (app?: FirebaseApp) => {
376378
return this.ensureApp(app).firestore();
377379
};
380+
381+
// eslint-disable-next-line @typescript-eslint/no-var-requires
378382
const firestore = require('@google-cloud/firestore');
379383

380384
fn = Object.assign(fn, firestore.Firestore);

src/firestore/firestore.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ export function getFirestoreOptions(app: FirebaseApp): Settings {
7373

7474
const projectId: string | null = utils.getExplicitProjectId(app);
7575
const credential = app.options.credential;
76+
// eslint-disable-next-line @typescript-eslint/no-var-requires
7677
const { version: firebaseVersion } = require('../../package.json');
7778
if (credential instanceof ServiceAccountCredential) {
7879
return {
7980
credentials: {
80-
private_key: credential.privateKey,
81-
client_email: credential.clientEmail,
81+
private_key: credential.privateKey, // eslint-disable-line @typescript-eslint/camelcase
82+
client_email: credential.clientEmail, // eslint-disable-line @typescript-eslint/camelcase
8283
},
8384
// When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
8485
// guaranteed to be available.

src/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { Bucket } from '@google-cloud/storage';
1818
import * as _firestore from '@google-cloud/firestore';
1919
import { Agent } from 'http';
2020

21+
/* eslint-disable @typescript-eslint/ban-types */
22+
2123
/**
2224
* `admin` is a global namespace from which all Firebase Admin
2325
* services are accessed.

0 commit comments

Comments
 (0)