From 53f3daa685dc2af6e64bdb00ebfdfed1233d7482 Mon Sep 17 00:00:00 2001 From: Patrick Remy Date: Fri, 10 Apr 2020 11:03:53 +0200 Subject: [PATCH] Revert "grpc-js: allow any for linting globally" This reverts commit 16ec0f0f6414687a53e9f05d4621b88162a9f1d7 and replaces tslint-disable statements by eslint-disable. --- packages/grpc-js/.eslintrc | 1 - packages/grpc-js/src/call-stream.ts | 3 +++ packages/grpc-js/src/channel-credentials.ts | 1 + packages/grpc-js/src/channel.ts | 4 ++-- packages/grpc-js/src/client-interceptors.ts | 17 +++++++++++++++++ packages/grpc-js/src/client.ts | 7 ++++++- packages/grpc-js/src/index.ts | 10 +++++++--- packages/grpc-js/src/load-balancing-config.ts | 4 ++++ packages/grpc-js/src/logging.ts | 2 ++ packages/grpc-js/src/make-client.ts | 2 ++ packages/grpc-js/src/object-stream.ts | 2 ++ packages/grpc-js/src/server-call.ts | 3 +++ packages/grpc-js/src/server.ts | 2 ++ packages/grpc-js/src/service-config.ts | 4 ++++ packages/grpc-js/src/subchannel-pool.ts | 1 + packages/grpc-js/test/common.ts | 1 + .../grpc-js/test/test-channel-credentials.ts | 1 + packages/grpc-js/test/test-resolver.ts | 2 ++ .../grpc-js/test/test-server-credentials.ts | 1 + packages/grpc-js/test/test-server-deadlines.ts | 1 + packages/grpc-js/test/test-server-errors.ts | 1 + packages/grpc-js/test/test-server.ts | 5 +++-- 22 files changed, 66 insertions(+), 9 deletions(-) diff --git a/packages/grpc-js/.eslintrc b/packages/grpc-js/.eslintrc index 6b0cac4a..7e3583cc 100644 --- a/packages/grpc-js/.eslintrc +++ b/packages/grpc-js/.eslintrc @@ -2,7 +2,6 @@ "root": true, "extends": "./node_modules/gts", "rules": { - "@typescript-eslint/no-explicit-any": "off", "node/no-unpublished-import": ["error", { "tryExtensions": [".ts", ".js", ".json", ".node"] }] diff --git a/packages/grpc-js/src/call-stream.ts b/packages/grpc-js/src/call-stream.ts index f40366ca..9ceebdbf 100644 --- a/packages/grpc-js/src/call-stream.ts +++ b/packages/grpc-js/src/call-stream.ts @@ -69,6 +69,7 @@ export interface MetadataListener { } export interface MessageListener { + // eslint-disable-next-line @typescript-eslint/no-explicit-any (message: any, next: (message: any) => void): void; } @@ -89,6 +90,7 @@ export type Listener = Partial; */ export interface InterceptingListener { onReceiveMetadata(metadata: Metadata): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage(message: any): void; onReceiveStatus(status: StatusObject): void; } @@ -115,6 +117,7 @@ export class InterceptingListenerImpl implements InterceptingListener { this.nextListener.onReceiveMetadata(metadata); }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage(message: any): void { /* If this listener processes messages asynchronously, the last message may * be reordered with respect to the status */ diff --git a/packages/grpc-js/src/channel-credentials.ts b/packages/grpc-js/src/channel-credentials.ts index 7eb76a38..e5c9bfda 100644 --- a/packages/grpc-js/src/channel-credentials.ts +++ b/packages/grpc-js/src/channel-credentials.ts @@ -20,6 +20,7 @@ import { ConnectionOptions, createSecureContext, PeerCertificate } from 'tls'; import { CallCredentials } from './call-credentials'; import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers'; +// eslint-disable-next-line @typescript-eslint/no-explicit-any function verifyIsBufferOrNull(obj: any, friendlyName: string): void { if (obj && !(obj instanceof Buffer)) { throw new TypeError(`${friendlyName}, if provided, must be a Buffer.`); diff --git a/packages/grpc-js/src/channel.ts b/packages/grpc-js/src/channel.ts index abf14926..ca6254c4 100644 --- a/packages/grpc-js/src/channel.ts +++ b/packages/grpc-js/src/channel.ts @@ -111,7 +111,7 @@ export interface Channel { method: string, deadline: Deadline, host: string | null | undefined, - parentCall: any, + parentCall: any, // eslint-disable-line @typescript-eslint/no-explicit-any propagateFlags: number | null | undefined ): Call; } @@ -460,7 +460,7 @@ export class ChannelImplementation implements Channel { method: string, deadline: Deadline, host: string | null | undefined, - parentCall: any, + parentCall: any, // eslint-disable-line @typescript-eslint/no-explicit-any propagateFlags: number | null | undefined ): Call { if (typeof method !== 'string') { diff --git a/packages/grpc-js/src/client-interceptors.ts b/packages/grpc-js/src/client-interceptors.ts index 95ea5deb..9b503c52 100644 --- a/packages/grpc-js/src/client-interceptors.ts +++ b/packages/grpc-js/src/client-interceptors.ts @@ -59,6 +59,7 @@ export interface MetadataRequester { } export interface MessageRequester { + // eslint-disable-next-line @typescript-eslint/no-explicit-any (message: any, next: (message: any) => void): void; } @@ -183,6 +184,7 @@ const defaultRequester: FullRequester = { }; export interface InterceptorOptions extends CallOptions { + // eslint-disable-next-line @typescript-eslint/no-explicit-any method_definition: ClientMethodDefinition; } @@ -190,7 +192,9 @@ export interface InterceptingCallInterface { cancelWithStatus(status: Status, details: string): void; getPeer(): string; start(metadata: Metadata, listener?: Partial): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessageWithContext(context: MessageContext, message: any): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessage(message: any): void; startRead(): void; halfClose(): void; @@ -274,6 +278,7 @@ export class InterceptingCall implements InterceptingCallInterface { this.nextCall.start(md, finalInterceptingListener); }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessageWithContext(context: MessageContext, message: any): void { this.processingMessage = true; this.requester.sendMessage(message, (finalMessage) => { @@ -284,6 +289,7 @@ export class InterceptingCall implements InterceptingCallInterface { } }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessage(message: any): void { this.sendMessageWithContext({}, message); } @@ -334,6 +340,7 @@ function getCall(channel: Channel, path: string, options: CallOptions): Call { class BaseInterceptingCall implements InterceptingCallInterface { constructor( protected call: Call, + // eslint-disable-next-line @typescript-eslint/no-explicit-any protected methodDefinition: ClientMethodDefinition ) {} cancelWithStatus(status: Status, details: string): void { @@ -345,6 +352,7 @@ class BaseInterceptingCall implements InterceptingCallInterface { setCredentials(credentials: CallCredentials): void { this.call.setCredentials(credentials); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessageWithContext(context: MessageContext, message: any): void { let serialized: Buffer; try { @@ -354,6 +362,7 @@ class BaseInterceptingCall implements InterceptingCallInterface { this.call.cancelWithStatus(Status.INTERNAL, 'Serialization failure'); } } + // eslint-disable-next-line @typescript-eslint/no-explicit-any sendMessage(message: any) { this.sendMessageWithContext({}, message); } @@ -367,6 +376,7 @@ class BaseInterceptingCall implements InterceptingCallInterface { interceptingListener?.onReceiveMetadata?.(metadata); }, onReceiveMessage: (message) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any let deserialized: any; try { deserialized = this.methodDefinition.responseDeserialize(message); @@ -403,6 +413,7 @@ class BaseInterceptingCall implements InterceptingCallInterface { */ class BaseUnaryInterceptingCall extends BaseInterceptingCall implements InterceptingCallInterface { + // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(call: Call, methodDefinition: ClientMethodDefinition) { super(call, methodDefinition); } @@ -411,6 +422,7 @@ class BaseUnaryInterceptingCall extends BaseInterceptingCall const wrapperListener: InterceptingListener = { onReceiveMetadata: listener?.onReceiveMetadata?.bind(listener) ?? ((metadata) => {}), + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage: (message: any) => { receivedMessage = true; listener?.onReceiveMessage?.(message); @@ -433,9 +445,11 @@ class BaseUnaryInterceptingCall extends BaseInterceptingCall */ class BaseStreamingInterceptingCall extends BaseInterceptingCall implements InterceptingCallInterface {} + function getBottomInterceptingCall( channel: Channel, options: InterceptorOptions, + // eslint-disable-next-line @typescript-eslint/no-explicit-any methodDefinition: ClientMethodDefinition ) { const call = getCall(channel, methodDefinition.path, options); @@ -455,6 +469,7 @@ export interface Interceptor { } export interface InterceptorProvider { + // eslint-disable-next-line @typescript-eslint/no-explicit-any (methodDefinition: ClientMethodDefinition): Interceptor; } @@ -464,8 +479,10 @@ export interface InterceptorArguments { callInterceptors: Interceptor[]; callInterceptorProviders: InterceptorProvider[]; } + export function getInterceptingCall( interceptorArgs: InterceptorArguments, + // eslint-disable-next-line @typescript-eslint/no-explicit-any methodDefinition: ClientMethodDefinition, options: CallOptions, channel: Channel diff --git a/packages/grpc-js/src/client.ts b/packages/grpc-js/src/client.ts index 511c1f4e..23930474 100644 --- a/packages/grpc-js/src/client.ts +++ b/packages/grpc-js/src/client.ts @@ -59,6 +59,7 @@ export interface UnaryCallback { (err: ServiceError | null, value?: ResponseType): void; } +/* eslint-disable @typescript-eslint/no-explicit-any */ export interface CallOptions { deadline?: Deadline; host?: string; @@ -72,6 +73,7 @@ export interface CallOptions { interceptors?: Interceptor[]; interceptor_providers?: InterceptorProvider[]; } +/* eslint-enable @typescript-eslint/no-explicit-any */ export interface CallProperties { argument?: RequestType; @@ -84,7 +86,7 @@ export interface CallProperties { } export interface CallInvocationTransformer { - (callProperties: CallProperties): CallProperties; + (callProperties: CallProperties): CallProperties; // eslint-disable-line @typescript-eslint/no-explicit-any } export type ClientOptions = Partial & { @@ -314,6 +316,7 @@ export class Client { onReceiveMetadata: (metadata) => { emitter.emit('metadata', metadata); }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage(message: any) { if (responseMessage != null) { call.cancelWithStatus(Status.INTERNAL, 'Too many responses received'); @@ -430,6 +433,7 @@ export class Client { onReceiveMetadata: (metadata) => { emitter.emit('metadata', metadata); }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage(message: any) { if (responseMessage != null) { call.cancelWithStatus(Status.INTERNAL, 'Too many responses received'); @@ -552,6 +556,7 @@ export class Client { onReceiveMetadata(metadata: Metadata) { stream.emit('metadata', metadata); }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any onReceiveMessage(message: any) { if (stream.push(message)) { call.startRead(); diff --git a/packages/grpc-js/src/index.ts b/packages/grpc-js/src/index.ts index 8324ff4c..d8f4b1cf 100644 --- a/packages/grpc-js/src/index.ts +++ b/packages/grpc-js/src/index.ts @@ -67,15 +67,15 @@ if (!semver.satisfies(process.version, supportedNodeVersions)) { } interface IndexedObject { - [key: string]: any; - [key: number]: any; + [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any + [key: number]: any; // eslint-disable-line @typescript-eslint/no-explicit-any } function mixin(...sources: IndexedObject[]) { const result: { [key: string]: Function } = {}; for (const source of sources) { for (const propName of Object.getOwnPropertyNames(source)) { - const property: any = source[propName]; + const property: any = source[propName]; // eslint-disable-line @typescript-eslint/no-explicit-any if (typeof property === 'function') { result[propName] = property; } @@ -250,14 +250,18 @@ export { export { handleBidiStreamingCall, handleServerStreamingCall, handleUnaryCall }; +/* eslint-disable @typescript-eslint/no-explicit-any */ export type Call = | ClientUnaryCall | ClientReadableStream | ClientWritableStream | ClientDuplexStream; +/* eslint-enable @typescript-eslint/no-explicit-any */ /**** Unimplemented function stubs ****/ +/* eslint-disable @typescript-eslint/no-explicit-any */ + export const loadObject = (value: any, options: any) => { throw new Error( 'Not available in this library. Use @grpc/proto-loader and loadPackageDefinition instead' diff --git a/packages/grpc-js/src/load-balancing-config.ts b/packages/grpc-js/src/load-balancing-config.ts index f2b9f3a7..eef025e6 100644 --- a/packages/grpc-js/src/load-balancing-config.ts +++ b/packages/grpc-js/src/load-balancing-config.ts @@ -21,6 +21,10 @@ * specific object type if the input has the right structure, and throws an * error otherwise. */ +/* The any type is purposely used here. All functions validate their input at + * runtime */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + export type RoundRobinConfig = {}; export interface XdsConfig { diff --git a/packages/grpc-js/src/logging.ts b/packages/grpc-js/src/logging.ts index c7a63a47..91b4e8f0 100644 --- a/packages/grpc-js/src/logging.ts +++ b/packages/grpc-js/src/logging.ts @@ -47,6 +47,8 @@ export const setLogger = (logger: Partial): void => { export const setLoggerVerbosity = (verbosity: LogVerbosity): void => { _logVerbosity = verbosity; }; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any export const log = (severity: LogVerbosity, ...args: any[]): void => { if (severity >= _logVerbosity && typeof _logger.error === 'function') { _logger.error(...args); diff --git a/packages/grpc-js/src/make-client.ts b/packages/grpc-js/src/make-client.ts index 99daef15..f7e2dacc 100644 --- a/packages/grpc-js/src/make-client.ts +++ b/packages/grpc-js/src/make-client.ts @@ -50,6 +50,7 @@ export interface MethodDefinition ServerMethodDefinition {} export interface ServiceDefinition { + // eslint-disable-next-line @typescript-eslint/no-explicit-any [index: string]: MethodDefinition; } @@ -164,6 +165,7 @@ function partial( serialize: Function, deserialize: Function ): Function { + // eslint-disable-next-line @typescript-eslint/no-explicit-any return function (this: any, ...args: any[]) { return fn.call(this, path, serialize, deserialize, ...args); }; diff --git a/packages/grpc-js/src/object-stream.ts b/packages/grpc-js/src/object-stream.ts index 8d29b786..b17058a7 100644 --- a/packages/grpc-js/src/object-stream.ts +++ b/packages/grpc-js/src/object-stream.ts @@ -18,6 +18,8 @@ import { Duplex, Readable, Writable } from 'stream'; import { EmitterAugmentation1 } from './events'; +/* eslint-disable @typescript-eslint/no-explicit-any */ + export type WriteCallback = (error: Error | null | undefined) => void; export interface IntermediateObjectReadable extends Readable { diff --git a/packages/grpc-js/src/server-call.ts b/packages/grpc-js/src/server-call.ts index 240d8b53..abc37645 100644 --- a/packages/grpc-js/src/server-call.ts +++ b/packages/grpc-js/src/server-call.ts @@ -174,6 +174,7 @@ export class ServerWritableStreamImpl async _write( chunk: ResponseType, encoding: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (...args: any[]) => void ) { try { @@ -200,6 +201,7 @@ export class ServerWritableStreamImpl callback(null); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any end(metadata?: any) { if (metadata) { this.trailingMetadata = metadata; @@ -669,6 +671,7 @@ export class Http2ServerCallStream< } } +/* eslint-disable @typescript-eslint/no-explicit-any */ type UntypedServerCall = Http2ServerCallStream; function handleExpiredDeadline(call: UntypedServerCall) { diff --git a/packages/grpc-js/src/server.ts b/packages/grpc-js/src/server.ts index af0deefc..5a8bfb55 100644 --- a/packages/grpc-js/src/server.ts +++ b/packages/grpc-js/src/server.ts @@ -70,6 +70,7 @@ function getUnimplementedStatusResponse( }; } +/* eslint-disable @typescript-eslint/no-explicit-any */ type UntypedUnaryHandler = UnaryHandler; type UntypedClientStreamingHandler = ClientStreamingHandler; type UntypedServerStreamingHandler = ServerStreamingHandler; @@ -411,6 +412,7 @@ export class Server { this.sessions.forEach((session) => { // Cast NGHTTP2_CANCEL to any because TypeScript doesn't seem to // recognize destroy(code) as a valid signature. + // eslint-disable-next-line @typescript-eslint/no-explicit-any session.destroy(http2.constants.NGHTTP2_CANCEL as any); }); this.sessions.clear(); diff --git a/packages/grpc-js/src/service-config.ts b/packages/grpc-js/src/service-config.ts index b1b0fdd4..ea5c449a 100644 --- a/packages/grpc-js/src/service-config.ts +++ b/packages/grpc-js/src/service-config.ts @@ -22,6 +22,10 @@ * specific object type if the input has the right structure, and throws an * error otherwise. */ +/* The any type is purposely used here. All functions validate their input at + * runtime */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import * as lbconfig from './load-balancing-config'; import * as os from 'os'; diff --git a/packages/grpc-js/src/subchannel-pool.ts b/packages/grpc-js/src/subchannel-pool.ts index 9f143729..0d42163d 100644 --- a/packages/grpc-js/src/subchannel-pool.ts +++ b/packages/grpc-js/src/subchannel-pool.ts @@ -63,6 +63,7 @@ export class SubchannelPool { /* These objects are created with Object.create(null), so they do not * have a prototype, which means that for (... in ...) loops over them * do not need to be filtered */ + // eslint-disable-disable-next-line:forin for (const channelTarget in this.pool) { const subchannelObjArray = this.pool[channelTarget]; diff --git a/packages/grpc-js/test/common.ts b/packages/grpc-js/test/common.ts index a3d8b9ba..24cb7165 100644 --- a/packages/grpc-js/test/common.ts +++ b/packages/grpc-js/test/common.ts @@ -72,6 +72,7 @@ export namespace assert2 { * Wraps a function to keep track of whether it was called or not. * @param fn The function to wrap. */ + // tslint:disable:no-any export function mustCall( fn: (...args: any[]) => T ): (...args: any[]) => T { diff --git a/packages/grpc-js/test/test-channel-credentials.ts b/packages/grpc-js/test/test-channel-credentials.ts index 99966941..d6028f46 100644 --- a/packages/grpc-js/test/test-channel-credentials.ts +++ b/packages/grpc-js/test/test-channel-credentials.ts @@ -49,6 +49,7 @@ class CallCredentialsMock implements CallCredentials { } } +// tslint:disable-next-line:no-any const readFile: (...args: any[]) => Promise = promisify(fs.readFile); // A promise which resolves to loaded files in the form { ca, key, cert } const pFixtures = Promise.all( diff --git a/packages/grpc-js/test/test-resolver.ts b/packages/grpc-js/test/test-resolver.ts index 57997c17..7f4900aa 100644 --- a/packages/grpc-js/test/test-resolver.ts +++ b/packages/grpc-js/test/test-resolver.ts @@ -15,6 +15,8 @@ * */ +// Allow `any` data type for testing runtime type checking. +// tslint:disable no-any import * as assert from 'assert'; import * as resolverManager from '../src/resolver'; import { ServiceConfig } from '../src/service-config'; diff --git a/packages/grpc-js/test/test-server-credentials.ts b/packages/grpc-js/test/test-server-credentials.ts index 9cc08b10..ec1740f7 100644 --- a/packages/grpc-js/test/test-server-credentials.ts +++ b/packages/grpc-js/test/test-server-credentials.ts @@ -16,6 +16,7 @@ */ // Allow `any` data type for testing runtime type checking. +// tslint:disable no-any import * as assert from 'assert'; import { readFileSync } from 'fs'; import { join } from 'path'; diff --git a/packages/grpc-js/test/test-server-deadlines.ts b/packages/grpc-js/test/test-server-deadlines.ts index 107994ba..c1152309 100644 --- a/packages/grpc-js/test/test-server-deadlines.ts +++ b/packages/grpc-js/test/test-server-deadlines.ts @@ -16,6 +16,7 @@ */ // Allow `any` data type for testing runtime type checking. +// tslint:disable no-any import * as assert from 'assert'; import * as path from 'path'; diff --git a/packages/grpc-js/test/test-server-errors.ts b/packages/grpc-js/test/test-server-errors.ts index 8e9f4520..7c611b9b 100644 --- a/packages/grpc-js/test/test-server-errors.ts +++ b/packages/grpc-js/test/test-server-errors.ts @@ -16,6 +16,7 @@ */ // Allow `any` data type for testing runtime type checking. +// tslint:disable no-any import * as assert from 'assert'; import { join } from 'path'; diff --git a/packages/grpc-js/test/test-server.ts b/packages/grpc-js/test/test-server.ts index c8d2e64a..434efbbc 100644 --- a/packages/grpc-js/test/test-server.ts +++ b/packages/grpc-js/test/test-server.ts @@ -16,6 +16,7 @@ */ // Allow `any` data type for testing runtime type checking. +// tslint:disable no-any import * as assert from 'assert'; import * as fs from 'fs'; import * as http2 from 'http2'; @@ -38,13 +39,13 @@ describe('Server', () => { describe('constructor', () => { it('should work with no arguments', () => { assert.doesNotThrow(() => { - new Server(); + new Server(); // tslint:disable-line:no-unused-expression }); }); it('should work with an empty object argument', () => { assert.doesNotThrow(() => { - new Server({}); + new Server({}); // tslint:disable-line:no-unused-expression }); });