Skip to content

Commit 9611fd7

Browse files
renovate[bot]renovate-botFeiyang1
authored
Update typescript-eslint monorepo to v3 (major) (firebase#3524)
* Update typescript-eslint monorepo to v3 * Update typescript-eslint monorepo to v3 * fix lint * fix more lint * remove reference to the removed file * revert file deletion Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Feiyang1 <[email protected]>
1 parent e749ab8 commit 9611fd7

File tree

29 files changed

+196
-63
lines changed

29 files changed

+196
-63
lines changed

config/.eslintrc.js

+37-3
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,29 @@ 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 for the following reasons:
150+
It provides no type safety when calling the value, which means it's easy to provide the wrong arguments.
151+
It accepts class declarations, which will fail when called, as they are called without the new keyword.`
152+
},
153+
'extendDefaults': false
154+
}
155+
],
156+
'@typescript-eslint/naming-convention': [
157+
'error',
158+
{
159+
'selector': 'class',
160+
'format': ['PascalCase']
161+
},
162+
{
163+
'selector': 'interface',
164+
'format': ['PascalCase'],
165+
'custom': {
166+
'regex': '^I[A-Z]',
167+
'match': false
132168
}
133169
}
134170
],
135-
'@typescript-eslint/class-name-casing': 'error',
136-
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
137171
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
138172
'@typescript-eslint/explicit-member-accessibility': [
139173
'error',

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
"@types/sinon-chai": "3.2.4",
8484
"@types/tmp": "0.2.0",
8585
"@types/yargs": "15.0.5",
86-
"@typescript-eslint/eslint-plugin": "2.34.0",
87-
"@typescript-eslint/eslint-plugin-tslint": "2.34.0",
88-
"@typescript-eslint/parser": "2.34.0",
86+
"@typescript-eslint/eslint-plugin": "3.10.1",
87+
"@typescript-eslint/eslint-plugin-tslint": "3.10.1",
88+
"@typescript-eslint/parser": "3.10.1",
8989
"babel-loader": "8.1.0",
9090
"chai": "4.2.0",
9191
"chai-as-promised": "7.1.1",

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

+1-1
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

+2-2
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

+5-5
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

+1-1
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

+1
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

+17
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/util/util.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export function each(obj: object, fn: (k: string, v: unknown) => void) {
428428
export const bindCallback = function (
429429
callback: (a: unknown) => void,
430430
context?: object | null
431-
): Function {
431+
): (a: unknown) => void {
432432
return context ? callback.bind(context) : callback;
433433
};
434434

@@ -609,6 +609,7 @@ export const exceptionGuard = function (fn: () => void) {
609609
* @param {...*} varArgs Arbitrary args to be passed to opt_onComplete
610610
*/
611611
export const callUserCallback = function (
612+
// eslint-disable-next-line @typescript-eslint/ban-types
612613
callback?: Function | null,
613614
...varArgs: unknown[]
614615
) {
@@ -665,7 +666,7 @@ export const exportPropGetter = function (
665666
* @return {number|Object} The setTimeout() return value.
666667
*/
667668
export const setTimeoutNonBlocking = function (
668-
fn: Function,
669+
fn: () => void,
669670
time: number
670671
): number | object {
671672
const timeout: number | object = setTimeout(fn, time);

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

+1-1
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

+1-1
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/database/test/helpers/EventAccumulator.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class EventAccumulator {
3737
reject;
3838
private onResetFxn;
3939
private onEventFxn;
40+
// eslint-disable-next-line @typescript-eslint/ban-types
4041
constructor(public condition: Function) {
4142
this.promise = new Promise((resolve, reject) => {
4243
this.resolve = resolve;
@@ -52,6 +53,7 @@ export class EventAccumulator {
5253
this.resolve(this.eventData);
5354
}
5455
}
56+
// eslint-disable-next-line @typescript-eslint/ban-types
5557
reset(condition?: Function) {
5658
this.eventData = [];
5759
this.promise = new Promise((resolve, reject) => {
@@ -65,9 +67,11 @@ export class EventAccumulator {
6567
this.condition = condition;
6668
}
6769
}
70+
// eslint-disable-next-line @typescript-eslint/ban-types
6871
onEvent(cb: Function) {
6972
this.onEventFxn = cb;
7073
}
74+
// eslint-disable-next-line @typescript-eslint/ban-types
7175
onReset(cb: Function) {
7276
this.onResetFxn = cb;
7377
}

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

+1-1
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/firestore/test/util/equality_matcher.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface Equatable<T> {
3232
*/
3333
export interface CustomMatcher<T> {
3434
equalsFn: (left: T, right: T) => boolean;
35+
// eslint-disable-next-line @typescript-eslint/ban-types
3536
forType: Function;
3637
}
3738

packages/functions/src/api/error.ts

+1-1
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

+4-4
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

+2-2
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

+1
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

+1-1
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

+2
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

+1
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

+2-1
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

0 commit comments

Comments
 (0)