Skip to content

Commit a0dc008

Browse files
committed
fix lint
1 parent cb1d505 commit a0dc008

File tree

25 files changed

+92
-180
lines changed

25 files changed

+92
-180
lines changed

config/.eslintrc.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
const path = require('path');
219

320
module.exports = {
@@ -128,12 +145,27 @@ module.exports = {
128145
'Object': "Use {} or 'object' instead.",
129146
'String': "Use 'string' instead.",
130147
'Number': "Use 'number' instead.",
131-
'Boolean': "Use 'boolean' instead."
148+
'Boolean': "Use 'boolean' instead.",
149+
'Function': 'Avoid the Function type, as it provides little safety'
150+
},
151+
'extendDefaults': false
152+
}
153+
],
154+
'@typescript-eslint/naming-convention': [
155+
'error',
156+
{
157+
'selector': 'class',
158+
'format': ['PascalCase']
159+
},
160+
{
161+
'selector': 'interface',
162+
'format': ['PascalCase'],
163+
'custom': {
164+
'regex': '^I[A-Z]',
165+
'match': false
132166
}
133167
}
134168
],
135-
'@typescript-eslint/class-name-casing': 'error',
136-
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
137169
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
138170
'@typescript-eslint/explicit-member-accessibility': [
139171
'error',

packages-exp/functions-exp/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function _errorForResponse(
151151

152152
details = errorJSON.details;
153153
if (details !== undefined) {
154-
details = decode(details as {} | null);
154+
details = decode(details);
155155
}
156156
}
157157
} catch (e) {

packages-exp/functions-exp/src/serializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function encode(data: unknown): unknown {
6060
return data.map(x => encode(x));
6161
}
6262
if (typeof data === 'function' || typeof data === 'object') {
63-
return mapValues(data as object, x => encode(x));
63+
return mapValues(data!, x => encode(x));
6464
}
6565
// If we got this far, the data is not encodable.
6666
throw new Error('Data cannot be encoded in JSON: ' + data);
@@ -99,7 +99,7 @@ export function decode(json: unknown): unknown {
9999
return json.map(x => decode(x));
100100
}
101101
if (typeof json === 'function' || typeof json === 'object') {
102-
return mapValues(json as object, x => decode(x as {} | null));
102+
return mapValues(json!, x => decode(x));
103103
}
104104
// Anything else is safe to return.
105105
return json;

packages-exp/functions-exp/src/service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class FunctionsService implements _FirebaseService {
7474
readonly contextProvider: ContextProvider;
7575
emulatorOrigin: string | null = null;
7676
cancelAllRequests: Promise<void>;
77-
deleteService!: Function;
77+
deleteService!: () => Promise<void>;
7878

7979
/**
8080
* Creates a new Functions service for the given app.
@@ -90,7 +90,7 @@ export class FunctionsService implements _FirebaseService {
9090
// Cancels all ongoing requests when resolved.
9191
this.cancelAllRequests = new Promise(resolve => {
9292
this.deleteService = () => {
93-
return resolve();
93+
return Promise.resolve(resolve());
9494
};
9595
});
9696
}
@@ -154,7 +154,7 @@ export function httpsCallable(
154154
*/
155155
async function postJSON(
156156
url: string,
157-
body: {},
157+
body: unknown,
158158
headers: Headers
159159
): Promise<HttpResponse> {
160160
headers.append('Content-Type', 'application/json');
@@ -176,7 +176,7 @@ async function postJSON(
176176
json: null
177177
};
178178
}
179-
let json: {} | null = null;
179+
let json: HttpResponseBody | null = null;
180180
try {
181181
json = await response.json();
182182
} catch (e) {
@@ -254,7 +254,7 @@ async function call(
254254
}
255255

256256
// Decode any special types, such as dates, in the returned data.
257-
const decodedData = decode(responseData as {} | null);
257+
const decodedData = decode(responseData);
258258

259259
return { data: decodedData };
260260
}

packages/analytics/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function getOrCreateDataLayer(dataLayerName: string): DataLayer {
9595
function wrapGtag(
9696
gtagCore: Gtag,
9797
initializedIdPromisesMap: { [gaId: string]: Promise<void> }
98-
): Function {
98+
): Gtag {
9999
return (
100100
command: 'config' | 'set' | 'event',
101101
idOrNameOrParams: string | ControlParams,

packages/analytics/testing/get-fake-firebase-services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function getFakeApp(measurementId?: string): FirebaseApp {
4242

4343
export function getFakeInstallations(
4444
fid: string = 'fid-1234',
45+
// eslint-disable-next-line @typescript-eslint/ban-types
4546
onFidResolve?: Function
4647
): FirebaseInstallations {
4748
return {

packages/database/.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
module.exports = {
219
extends: '../../config/.eslintrc.js',
320
parserOptions: {

packages/database/src/core/view/CompleteChildSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface CompleteChildSource {
5656
* @constructor
5757
* @implements CompleteChildSource
5858
*/
59-
// eslint-disable-next-line @typescript-eslint/class-name-casing
59+
// eslint-disable-next-line @typescript-eslint/naming-convention
6060
export class NoCompleteChildSource_ implements CompleteChildSource {
6161
/**
6262
* @inheritDoc

packages/database/src/realtime/BrowserPollConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ export class BrowserPollConnection implements Transport {
400400
}
401401
}
402402

403-
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
403+
// eslint-disable-next-line @typescript-eslint/naming-convention
404404
export interface IFrameElement extends HTMLIFrameElement {
405405
doc: Document;
406406
}

packages/firestore/src/protos/firestore_proto_api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/*
2020
eslint-disable
2121
camelcase, @typescript-eslint/no-explicit-any,
22-
@typescript-eslint/interface-name-prefix, @typescript-eslint/class-name-casing
22+
@typescript-eslint/naming-convention
2323
*/
2424
export declare type ApiClientHookFactory = any;
2525
export declare type PromiseRequestService = any;

packages/functions/src/api/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function _errorForResponse(
158158

159159
details = errorJSON.details;
160160
if (details !== undefined) {
161-
details = serializer.decode(details as {} | null);
161+
details = serializer.decode(details);
162162
}
163163
}
164164
} catch (e) {

packages/functions/src/api/service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
8585
private readonly serializer = new Serializer();
8686
private emulatorOrigin: string | null = null;
8787
private cancelAllRequests: Promise<void>;
88-
private deleteService!: Function;
88+
private deleteService!: () => void;
8989

9090
/**
9191
* Creates a new Functions service for the given app and (optional) region.
@@ -113,7 +113,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
113113

114114
INTERNAL = {
115115
delete: (): Promise<void> => {
116-
return this.deleteService();
116+
return Promise.resolve(this.deleteService());
117117
}
118118
};
119119

@@ -183,7 +183,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
183183
json: null
184184
};
185185
}
186-
let json: {} | null = null;
186+
let json: HttpResponseBody | null = null;
187187
try {
188188
json = await response.json();
189189
} catch (e) {
@@ -269,7 +269,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
269269
}
270270

271271
// Decode any special types, such as dates, in the returned data.
272-
const decodedData = this.serializer.decode(responseData as {} | null);
272+
const decodedData = this.serializer.decode(responseData);
273273

274274
return { data: decodedData };
275275
}

packages/functions/src/serializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class Serializer {
5858
return data.map(x => this.encode(x));
5959
}
6060
if (typeof data === 'function' || typeof data === 'object') {
61-
return mapValues(data as object, x => this.encode(x));
61+
return mapValues(data!, x => this.encode(x));
6262
}
6363
// If we got this far, the data is not encodable.
6464
throw new Error('Data cannot be encoded in JSON: ' + data);
@@ -93,7 +93,7 @@ export class Serializer {
9393
return json.map(x => this.decode(x));
9494
}
9595
if (typeof json === 'function' || typeof json === 'object') {
96-
return mapValues(json as object, x => this.decode(x as {} | null));
96+
return mapValues(json!, x => this.decode(x));
9797
}
9898
// Anything else is safe to return.
9999
return json;

packages/messaging/src/controllers/sw-controller.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const DATA_MESSAGE: MessagePayloadInternal = {
7979

8080
describe('SwController', () => {
8181
let addEventListenerStub: Stub<typeof self.addEventListener>;
82+
// eslint-disable-next-line @typescript-eslint/ban-types
8283
let eventListenerMap: Map<string, Function>;
8384
let swController: SwController;
8485
let firebaseDependencies: FirebaseInternalDependencies;

packages/messaging/src/controllers/sw-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class SwController implements FirebaseMessaging, FirebaseService {
9696
}
9797

9898
onBackgroundMessage(
99-
nextOrObserver: NextFn<object> | Observer<object>
99+
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
100100
): Unsubscribe {
101101
this.isOnBackgroundMessageUsed = true;
102102
this.bgMessageHandler = nextOrObserver;

packages/performance/src/services/api_service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { consoleLogger } from '../utils/console_logger';
2121
declare global {
2222
interface Window {
2323
PerformanceObserver: typeof PerformanceObserver;
24+
// eslint-disable-next-line @typescript-eslint/ban-types
2425
perfMetrics?: { onFirstInputDelay: Function };
2526
}
2627
}
@@ -45,6 +46,7 @@ export class Api {
4546
/** PreformanceObserver constructor function. */
4647
private readonly PerformanceObserver: typeof PerformanceObserver;
4748
private readonly windowLocation: Location;
49+
// eslint-disable-next-line @typescript-eslint/ban-types
4850
readonly onFirstInputDelay?: Function;
4951
readonly localStorage?: Storage;
5052
readonly document: Document;

packages/storage/src/implementation/async.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* microtask, i.e. as soon as possible after the current script returns back
2121
* into browser code.
2222
*/
23+
// eslint-disable-next-line @typescript-eslint/ban-types
2324
export function async(f: Function): Function {
2425
return (...argsToForward: unknown[]) => {
2526
// eslint-disable-next-line @typescript-eslint/no-floating-promises

packages/storage/src/implementation/backoff.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export { id };
3131
*/
3232
export function start(
3333
f: (p1: (success: boolean) => void, canceled: boolean) => void,
34-
callback: Function,
34+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35+
callback: (...args: any[]) => unknown,
3536
timeout: number
3637
): id {
3738
// TODO(andysoto): make this code cleaner (probably refactor into an actual

packages/storage/src/implementation/request.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class NetworkRequest<T> implements Request<T> {
6464
private additionalRetryCodes_: number[];
6565
private pendingXhr_: XhrIo | null = null;
6666
private backoffId_: backoff.id | null = null;
67-
private resolve_: Function | null = null;
68-
private reject_: Function | null = null;
67+
private resolve_!: (value?: T | PromiseLike<T> | undefined) => void;
68+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69+
private reject_!: (reason?: any) => void;
6970
private canceled_: boolean = false;
7071
private appDelete_: boolean = false;
7172
private callback_: (p1: XhrIo, p2: string) => T;
@@ -170,8 +171,8 @@ class NetworkRequest<T> implements Request<T> {
170171
requestWentThrough: boolean,
171172
status: RequestEndStatus
172173
): void {
173-
const resolve = self.resolve_ as Function;
174-
const reject = self.reject_ as Function;
174+
const resolve = self.resolve_;
175+
const reject = self.reject_;
175176
const xhr = status.xhr as XhrIo;
176177
if (status.wasSuccessCode) {
177178
try {

packages/storage/src/implementation/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function isJustDef<T>(p: T | null | undefined): p is T | null {
2626
return p !== void 0;
2727
}
2828

29+
// eslint-disable-next-line @typescript-eslint/ban-types
2930
export function isFunction(p: unknown): p is Function {
3031
return typeof p === 'function';
3132
}

packages/storage/test/unit/task.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ describe('Firebase Storage > Upload Task', () => {
328328
blob
329329
);
330330

331+
// eslint-disable-next-line @typescript-eslint/ban-types
331332
let resolve: Function, reject: Function;
332333
const promise = new Promise<void>((innerResolve, innerReject) => {
333334
resolve = innerResolve;

packages/storage/test/unit/testshared.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export function makeFakeApp(bucketArg?: string): FirebaseApp {
5252
return app as FirebaseApp;
5353
}
5454

55-
export function makeFakeAuthProvider(
56-
token: {} | null
57-
): Provider<FirebaseAuthInternalName> {
55+
export function makeFakeAuthProvider(token: {
56+
accessToken: string;
57+
}): Provider<FirebaseAuthInternalName> {
5858
const provider = new Provider(
5959
'auth-internal',
6060
new ComponentContainer('storage-container')
@@ -113,6 +113,7 @@ export function fakeXhrIo(headers: Headers, status: number = 200): XhrIo {
113113
/**
114114
* Binds ignoring types. Used to test calls involving improper arguments.
115115
*/
116+
// eslint-disable-next-line @typescript-eslint/ban-types
116117
export function bind(f: Function, ctx: any, ...args: any[]): () => void {
117118
return () => {
118119
f.apply(ctx, args);

packages/util/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ export * from './src/obj';
2828
export * from './src/query';
2929
export * from './src/sha1';
3030
export * from './src/subscribe';
31-
export * from './src/validation';
3231
export * from './src/utf8';

packages/util/src/subscribe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ObserverProxy<T> implements Observer<T> {
126126
* call to subscribe().
127127
*/
128128
subscribe(
129-
nextOrObserver?: PartialObserver<T> | Function,
129+
nextOrObserver?: NextFn<T> | PartialObserver<T>,
130130
error?: ErrorFn,
131131
complete?: CompleteFn
132132
): Unsubscribe {
@@ -261,6 +261,7 @@ class ObserverProxy<T> implements Observer<T> {
261261
}
262262

263263
/** Turn synchronous function into one called asynchronously. */
264+
// eslint-disable-next-line @typescript-eslint/ban-types
264265
export function async(fn: Function, onError?: ErrorFn): Function {
265266
return (...args: unknown[]) => {
266267
Promise.resolve(true)

0 commit comments

Comments
 (0)