Skip to content

Update typescript-eslint monorepo to v3 (major) #3524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const path = require('path');

module.exports = {
Expand Down Expand Up @@ -128,12 +145,29 @@ module.exports = {
'Object': "Use {} or 'object' instead.",
'String': "Use 'string' instead.",
'Number': "Use 'number' instead.",
'Boolean': "Use 'boolean' instead."
'Boolean': "Use 'boolean' instead.",
'Function': `Avoid the Function type, as it provides little safety for the following reasons:
It provides no type safety when calling the value, which means it's easy to provide the wrong arguments.
It accepts class declarations, which will fail when called, as they are called without the new keyword.`
},
'extendDefaults': false
}
],
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'class',
'format': ['PascalCase']
},
{
'selector': 'interface',
'format': ['PascalCase'],
'custom': {
'regex': '^I[A-Z]',
'match': false
}
}
],
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/explicit-member-accessibility': [
'error',
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
"@types/sinon-chai": "3.2.4",
"@types/tmp": "0.2.0",
"@types/yargs": "15.0.5",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/eslint-plugin-tslint": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
"@typescript-eslint/eslint-plugin": "3.10.1",
"@typescript-eslint/eslint-plugin-tslint": "3.10.1",
"@typescript-eslint/parser": "3.10.1",
"babel-loader": "8.1.0",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/functions-exp/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function _errorForResponse(

details = errorJSON.details;
if (details !== undefined) {
details = decode(details as {} | null);
details = decode(details);
}
}
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/functions-exp/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function encode(data: unknown): unknown {
return data.map(x => encode(x));
}
if (typeof data === 'function' || typeof data === 'object') {
return mapValues(data as object, x => encode(x));
return mapValues(data!, x => encode(x));
}
// If we got this far, the data is not encodable.
throw new Error('Data cannot be encoded in JSON: ' + data);
Expand Down Expand Up @@ -99,7 +99,7 @@ export function decode(json: unknown): unknown {
return json.map(x => decode(x));
}
if (typeof json === 'function' || typeof json === 'object') {
return mapValues(json as object, x => decode(x as {} | null));
return mapValues(json!, x => decode(x));
}
// Anything else is safe to return.
return json;
Expand Down
10 changes: 5 additions & 5 deletions packages-exp/functions-exp/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class FunctionsService implements _FirebaseService {
readonly contextProvider: ContextProvider;
emulatorOrigin: string | null = null;
cancelAllRequests: Promise<void>;
deleteService!: Function;
deleteService!: () => Promise<void>;

/**
* Creates a new Functions service for the given app.
Expand All @@ -90,7 +90,7 @@ export class FunctionsService implements _FirebaseService {
// Cancels all ongoing requests when resolved.
this.cancelAllRequests = new Promise(resolve => {
this.deleteService = () => {
return resolve();
return Promise.resolve(resolve());
};
});
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export function httpsCallable(
*/
async function postJSON(
url: string,
body: {},
body: unknown,
headers: Headers
): Promise<HttpResponse> {
headers.append('Content-Type', 'application/json');
Expand All @@ -176,7 +176,7 @@ async function postJSON(
json: null
};
}
let json: {} | null = null;
let json: HttpResponseBody | null = null;
try {
json = await response.json();
} catch (e) {
Expand Down Expand Up @@ -254,7 +254,7 @@ async function call(
}

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

return { data: decodedData };
}
2 changes: 1 addition & 1 deletion packages/analytics/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function getOrCreateDataLayer(dataLayerName: string): DataLayer {
function wrapGtag(
gtagCore: Gtag,
initializedIdPromisesMap: { [gaId: string]: Promise<void> }
): Function {
): Gtag {
return (
command: 'config' | 'set' | 'event',
idOrNameOrParams: string | ControlParams,
Expand Down
1 change: 1 addition & 0 deletions packages/analytics/testing/get-fake-firebase-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function getFakeApp(measurementId?: string): FirebaseApp {

export function getFakeInstallations(
fid: string = 'fid-1234',
// eslint-disable-next-line @typescript-eslint/ban-types
onFidResolve?: Function
): FirebaseInstallations {
return {
Expand Down
17 changes: 17 additions & 0 deletions packages/database/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
Expand Down
5 changes: 3 additions & 2 deletions packages/database/src/core/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export function each(obj: object, fn: (k: string, v: unknown) => void) {
export const bindCallback = function (
callback: (a: unknown) => void,
context?: object | null
): Function {
): (a: unknown) => void {
return context ? callback.bind(context) : callback;
};

Expand Down Expand Up @@ -609,6 +609,7 @@ export const exceptionGuard = function (fn: () => void) {
* @param {...*} varArgs Arbitrary args to be passed to opt_onComplete
*/
export const callUserCallback = function (
// eslint-disable-next-line @typescript-eslint/ban-types
callback?: Function | null,
...varArgs: unknown[]
) {
Expand Down Expand Up @@ -665,7 +666,7 @@ export const exportPropGetter = function (
* @return {number|Object} The setTimeout() return value.
*/
export const setTimeoutNonBlocking = function (
fn: Function,
fn: () => void,
time: number
): number | object {
const timeout: number | object = setTimeout(fn, time);
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/view/CompleteChildSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface CompleteChildSource {
* @constructor
* @implements CompleteChildSource
*/
// eslint-disable-next-line @typescript-eslint/class-name-casing
// eslint-disable-next-line @typescript-eslint/naming-convention
export class NoCompleteChildSource_ implements CompleteChildSource {
/**
* @inheritDoc
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/realtime/BrowserPollConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class BrowserPollConnection implements Transport {
}
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface IFrameElement extends HTMLIFrameElement {
doc: Document;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/database/test/helpers/EventAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class EventAccumulator {
reject;
private onResetFxn;
private onEventFxn;
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(public condition: Function) {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
Expand All @@ -52,6 +53,7 @@ export class EventAccumulator {
this.resolve(this.eventData);
}
}
// eslint-disable-next-line @typescript-eslint/ban-types
reset(condition?: Function) {
this.eventData = [];
this.promise = new Promise((resolve, reject) => {
Expand All @@ -65,9 +67,11 @@ export class EventAccumulator {
this.condition = condition;
}
}
// eslint-disable-next-line @typescript-eslint/ban-types
onEvent(cb: Function) {
this.onEventFxn = cb;
}
// eslint-disable-next-line @typescript-eslint/ban-types
onReset(cb: Function) {
this.onResetFxn = cb;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/protos/firestore_proto_api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/*
eslint-disable
camelcase, @typescript-eslint/no-explicit-any,
@typescript-eslint/interface-name-prefix, @typescript-eslint/class-name-casing
@typescript-eslint/naming-convention
*/
export declare type ApiClientHookFactory = any;
export declare type PromiseRequestService = any;
Expand Down
1 change: 1 addition & 0 deletions packages/firestore/test/util/equality_matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Equatable<T> {
*/
export interface CustomMatcher<T> {
equalsFn: (left: T, right: T) => boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
forType: Function;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/api/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function _errorForResponse(

details = errorJSON.details;
if (details !== undefined) {
details = serializer.decode(details as {} | null);
details = serializer.decode(details);
}
}
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions packages/functions/src/api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
private readonly serializer = new Serializer();
private emulatorOrigin: string | null = null;
private cancelAllRequests: Promise<void>;
private deleteService!: Function;
private deleteService!: () => void;

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

INTERNAL = {
delete: (): Promise<void> => {
return this.deleteService();
return Promise.resolve(this.deleteService());
}
};

Expand Down Expand Up @@ -183,7 +183,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
json: null
};
}
let json: {} | null = null;
let json: HttpResponseBody | null = null;
try {
json = await response.json();
} catch (e) {
Expand Down Expand Up @@ -269,7 +269,7 @@ export class Service implements FirebaseFunctions, FirebaseService {
}

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

return { data: decodedData };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/functions/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Serializer {
return data.map(x => this.encode(x));
}
if (typeof data === 'function' || typeof data === 'object') {
return mapValues(data as object, x => this.encode(x));
return mapValues(data!, x => this.encode(x));
}
// If we got this far, the data is not encodable.
throw new Error('Data cannot be encoded in JSON: ' + data);
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Serializer {
return json.map(x => this.decode(x));
}
if (typeof json === 'function' || typeof json === 'object') {
return mapValues(json as object, x => this.decode(x as {} | null));
return mapValues(json!, x => this.decode(x));
}
// Anything else is safe to return.
return json;
Expand Down
1 change: 1 addition & 0 deletions packages/messaging/src/controllers/sw-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const DATA_MESSAGE: MessagePayloadInternal = {

describe('SwController', () => {
let addEventListenerStub: Stub<typeof self.addEventListener>;
// eslint-disable-next-line @typescript-eslint/ban-types
let eventListenerMap: Map<string, Function>;
let swController: SwController;
let firebaseDependencies: FirebaseInternalDependencies;
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/controllers/sw-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class SwController implements FirebaseMessaging, FirebaseService {
}

onBackgroundMessage(
nextOrObserver: NextFn<object> | Observer<object>
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
this.isOnBackgroundMessageUsed = true;
this.bgMessageHandler = nextOrObserver;
Expand Down
2 changes: 2 additions & 0 deletions packages/performance/src/services/api_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { consoleLogger } from '../utils/console_logger';
declare global {
interface Window {
PerformanceObserver: typeof PerformanceObserver;
// eslint-disable-next-line @typescript-eslint/ban-types
perfMetrics?: { onFirstInputDelay: Function };
}
}
Expand All @@ -45,6 +46,7 @@ export class Api {
/** PreformanceObserver constructor function. */
private readonly PerformanceObserver: typeof PerformanceObserver;
private readonly windowLocation: Location;
// eslint-disable-next-line @typescript-eslint/ban-types
readonly onFirstInputDelay?: Function;
readonly localStorage?: Storage;
readonly document: Document;
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/implementation/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* microtask, i.e. as soon as possible after the current script returns back
* into browser code.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function async(f: Function): Function {
return (...argsToForward: unknown[]) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand Down
3 changes: 2 additions & 1 deletion packages/storage/src/implementation/backoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export { id };
*/
export function start(
f: (p1: (success: boolean) => void, canceled: boolean) => void,
callback: Function,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (...args: any[]) => unknown,
timeout: number
): id {
// TODO(andysoto): make this code cleaner (probably refactor into an actual
Expand Down
Loading