grpc-js: allow any for linting globally

The any type is purposely used. All functions validate their input at runtime.
This commit is contained in:
Patrick Remy 2020-04-09 11:52:24 +02:00
parent 75b486b345
commit 16ec0f0f64
No known key found for this signature in database
GPG Key ID: FE25C0B14C0500CD
21 changed files with 14 additions and 63 deletions

View File

@ -0,0 +1,7 @@
{
"root": true,
"extends": "./node_modules/gts",
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}

View File

@ -69,7 +69,6 @@ export interface MetadataListener {
}
export interface MessageListener {
// tslint:disable-next-line no-any
(message: any, next: (message: any) => void): void;
}
@ -90,7 +89,6 @@ export type Listener = Partial<FullListener>;
*/
export interface InterceptingListener {
onReceiveMetadata(metadata: Metadata): void;
// tslint:disable-next-line no-any
onReceiveMessage(message: any): void;
onReceiveStatus(status: StatusObject): void;
}
@ -117,7 +115,6 @@ export class InterceptingListenerImpl implements InterceptingListener {
this.nextListener.onReceiveMetadata(metadata);
});
}
// tslint:disable-next-line no-any
onReceiveMessage(message: any): void {
/* If this listener processes messages asynchronously, the last message may
* be reordered with respect to the status */

View File

@ -20,7 +20,6 @@ import { ConnectionOptions, createSecureContext, PeerCertificate } from 'tls';
import { CallCredentials } from './call-credentials';
import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers';
// tslint:disable-next-line:no-any
function verifyIsBufferOrNull(obj: any, friendlyName: string): void {
if (obj && !(obj instanceof Buffer)) {
throw new TypeError(`${friendlyName}, if provided, must be a Buffer.`);

View File

@ -64,7 +64,6 @@ export interface MetadataRequester {
}
export interface MessageRequester {
// tslint:disable-next-line no-any
(message: any, next: (message: any) => void): void;
}
@ -189,7 +188,6 @@ const defaultRequester: FullRequester = {
};
export interface InterceptorOptions extends CallOptions {
// tslint:disable-next-line no-any
method_definition: ClientMethodDefinition<any, any>;
}
@ -197,9 +195,7 @@ export interface InterceptingCallInterface {
cancelWithStatus(status: Status, details: string): void;
getPeer(): string;
start(metadata: Metadata, listener?: Partial<InterceptingListener>): void;
// tslint:disable-next-line no-any
sendMessageWithContext(context: MessageContext, message: any): void;
// tslint:disable-next-line no-any
sendMessage(message: any): void;
startRead(): void;
halfClose(): void;
@ -283,7 +279,6 @@ export class InterceptingCall implements InterceptingCallInterface {
this.nextCall.start(md, finalInterceptingListener);
});
}
// tslint:disable-next-line no-any
sendMessageWithContext(context: MessageContext, message: any): void {
this.processingMessage = true;
this.requester.sendMessage(message, finalMessage => {
@ -294,7 +289,6 @@ export class InterceptingCall implements InterceptingCallInterface {
}
});
}
// tslint:disable-next-line no-any
sendMessage(message: any): void {
this.sendMessageWithContext({}, message);
}
@ -343,7 +337,6 @@ function getCall(channel: Channel, path: string, options: CallOptions): Call {
* object and handles serialization and deseraizliation.
*/
class BaseInterceptingCall implements InterceptingCallInterface {
// tslint:disable-next-line no-any
constructor(
protected call: Call,
protected methodDefinition: ClientMethodDefinition<any, any>
@ -357,7 +350,6 @@ class BaseInterceptingCall implements InterceptingCallInterface {
setCredentials(credentials: CallCredentials): void {
this.call.setCredentials(credentials);
}
// tslint:disable-next-line no-any
sendMessageWithContext(context: MessageContext, message: any): void {
let serialized: Buffer;
try {
@ -367,7 +359,6 @@ class BaseInterceptingCall implements InterceptingCallInterface {
this.call.cancelWithStatus(Status.INTERNAL, 'Serialization failure');
}
}
// tslint:disable-next-line no-any
sendMessage(message: any) {
this.sendMessageWithContext({}, message);
}
@ -381,7 +372,6 @@ class BaseInterceptingCall implements InterceptingCallInterface {
interceptingListener?.onReceiveMetadata?.(metadata);
},
onReceiveMessage: message => {
// tslint:disable-next-line no-any
let deserialized: any;
try {
deserialized = this.methodDefinition.responseDeserialize(message);
@ -418,7 +408,6 @@ class BaseInterceptingCall implements InterceptingCallInterface {
*/
class BaseUnaryInterceptingCall extends BaseInterceptingCall
implements InterceptingCallInterface {
// tslint:disable-next-line no-any
constructor(call: Call, methodDefinition: ClientMethodDefinition<any, any>) {
super(call, methodDefinition);
}
@ -427,7 +416,6 @@ class BaseUnaryInterceptingCall extends BaseInterceptingCall
const wrapperListener: InterceptingListener = {
onReceiveMetadata:
listener?.onReceiveMetadata?.bind(listener) ?? (metadata => {}),
// tslint:disable-next-line no-any
onReceiveMessage: (message: any) => {
receivedMessage = true;
listener?.onReceiveMessage?.(message);
@ -450,8 +438,6 @@ class BaseUnaryInterceptingCall extends BaseInterceptingCall
*/
class BaseStreamingInterceptingCall extends BaseInterceptingCall
implements InterceptingCallInterface {}
// tslint:disable-next-line no-any
function getBottomInterceptingCall(
channel: Channel,
options: InterceptorOptions,
@ -474,7 +460,6 @@ export interface Interceptor {
}
export interface InterceptorProvider {
// tslint:disable-next-line no-any
(methodDefinition: ClientMethodDefinition<any, any>): Interceptor;
}
@ -484,8 +469,6 @@ export interface InterceptorArguments {
callInterceptors: Interceptor[];
callInterceptorProviders: InterceptorProvider[];
}
// tslint:disable-next-line no-any
export function getInterceptingCall(
interceptorArgs: InterceptorArguments,
methodDefinition: ClientMethodDefinition<any, any>,

View File

@ -306,7 +306,6 @@ export class Client {
onReceiveMetadata: metadata => {
emitter.emit('metadata', metadata);
},
// tslint:disable-next-line no-any
onReceiveMessage(message: any) {
if (responseMessage != null) {
call.cancelWithStatus(Status.INTERNAL, 'Too many responses received');
@ -418,7 +417,6 @@ export class Client {
onReceiveMetadata: metadata => {
emitter.emit('metadata', metadata);
},
// tslint:disable-next-line no-any
onReceiveMessage(message: any) {
if (responseMessage != null) {
call.cancelWithStatus(Status.INTERNAL, 'Too many responses received');
@ -536,7 +534,6 @@ export class Client {
onReceiveMetadata(metadata: Metadata) {
stream.emit('metadata', metadata);
},
// tslint:disable-next-line no-any
onReceiveMessage(message: any) {
if (stream.push(message)) {
call.startRead();

View File

@ -62,15 +62,15 @@ if (!semver.satisfies(process.version, supportedNodeVersions)) {
}
interface IndexedObject {
[key: string]: any; // tslint:disable-line no-any
[key: number]: any; // tslint:disable-line no-any
[key: string]: any;
[key: number]: 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]; // tslint:disable-line no-any
const property: any = source[propName];
if (typeof property === 'function') {
result[propName] = property;
}
@ -245,18 +245,14 @@ export {
export { handleBidiStreamingCall, handleServerStreamingCall, handleUnaryCall };
/* tslint:disable:no-any */
export type Call =
| ClientUnaryCall
| ClientReadableStream<any>
| ClientWritableStream<any>
| ClientDuplexStream<any, any>;
/* tslint:enable:no-any */
/**** Unimplemented function stubs ****/
/* tslint:disable:no-any variable-name */
export const loadObject = (value: any, options: any) => {
throw new Error(
'Not available in this library. Use @grpc/proto-loader and loadPackageDefinition instead'

View File

@ -21,10 +21,6 @@
* 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 */
/* tslint:disable:no-any */
export interface RoundRobinConfig {}
export interface XdsConfig {

View File

@ -47,8 +47,6 @@ export const setLogger = (logger: Partial<Console>): void => {
export const setLoggerVerbosity = (verbosity: LogVerbosity): void => {
_logVerbosity = verbosity;
};
// tslint:disable-next-line no-any
export const log = (severity: LogVerbosity, ...args: any[]): void => {
if (severity >= _logVerbosity && typeof _logger.error === 'function') {
_logger.error(...args);

View File

@ -50,7 +50,6 @@ export interface MethodDefinition<RequestType, ResponseType>
ServerMethodDefinition<RequestType, ResponseType> {}
export interface ServiceDefinition {
// tslint:disable-next-line no-any
[index: string]: MethodDefinition<any, any>;
}
@ -165,7 +164,6 @@ function partial(
serialize: Function,
deserialize: Function
): Function {
// tslint:disable-next-line:no-any
return function(this: any, ...args: any[]) {
return fn.call(this, path, serialize, deserialize, ...args);
};

View File

@ -18,8 +18,6 @@
import { Duplex, Readable, Writable } from 'stream';
import { EmitterAugmentation1 } from './events';
// tslint:disable:no-any
export type WriteCallback = (error: Error | null | undefined) => void;
export interface IntermediateObjectReadable<T> extends Readable {

View File

@ -174,7 +174,6 @@ export class ServerWritableStreamImpl<RequestType, ResponseType>
async _write(
chunk: ResponseType,
encoding: string,
// tslint:disable-next-line:no-any
callback: (...args: any[]) => void
) {
try {
@ -201,7 +200,6 @@ export class ServerWritableStreamImpl<RequestType, ResponseType>
callback(null);
}
// tslint:disable-next-line:no-any
end(metadata?: any) {
if (metadata) {
this.trailingMetadata = metadata;
@ -671,7 +669,6 @@ export class Http2ServerCallStream<
}
}
// tslint:disable:no-any
type UntypedServerCall = Http2ServerCallStream<any, any>;
function handleExpiredDeadline(call: UntypedServerCall) {

View File

@ -67,7 +67,6 @@ function getUnimplementedStatusResponse(
};
}
// tslint:disable:no-any
type UntypedUnaryHandler = UnaryHandler<any, any>;
type UntypedClientStreamingHandler = ClientStreamingHandler<any, any>;
type UntypedServerStreamingHandler = ServerStreamingHandler<any, any>;
@ -113,7 +112,7 @@ function getDefaultHandler(handlerType: HandlerType, methodName: string) {
export class Server {
private http2ServerList: (http2.Http2Server | http2.Http2SecureServer)[] = [];
private handlers: Map<string, UntypedHandler> = new Map<
string,
UntypedHandler
@ -261,7 +260,7 @@ export class Server {
} else {
addr = address
}
const http2Server = setupServer();
return new Promise<number|Error>((resolve, reject) => {
function onError(err: Error): void {
@ -380,7 +379,6 @@ 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.
// tslint:disable-next-line:no-any
session.destroy(http2.constants.NGHTTP2_CANCEL as any);
});
this.sessions.clear();

View File

@ -22,10 +22,6 @@
* 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 */
/* tslint:disable:no-any */
import * as lbconfig from './load-balancing-config';
import * as os from 'os';

View File

@ -63,7 +63,6 @@ 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 */
// tslint:disable-next-line:forin
for (const channelTarget in this.pool) {
const subchannelObjArray = this.pool[channelTarget];

View File

@ -73,7 +73,6 @@ 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<T>(
fn: (...args: any[]) => T
): (...args: any[]) => T {

View File

@ -49,7 +49,6 @@ class CallCredentialsMock implements CallCredentials {
}
}
// tslint:disable-next-line:no-any
const readFile: (...args: any[]) => Promise<Buffer> = promisify(fs.readFile);
// A promise which resolves to loaded files in the form { ca, key, cert }
const pFixtures = Promise.all(

View File

@ -15,8 +15,6 @@
*
*/
// 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';

View File

@ -16,7 +16,6 @@
*/
// 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';

View File

@ -16,7 +16,6 @@
*/
// Allow `any` data type for testing runtime type checking.
// tslint:disable no-any
import * as assert from 'assert';
import * as path from 'path';

View File

@ -16,7 +16,6 @@
*/
// Allow `any` data type for testing runtime type checking.
// tslint:disable no-any
import * as assert from 'assert';
import { join } from 'path';

View File

@ -16,7 +16,6 @@
*/
// 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';
@ -39,13 +38,13 @@ describe('Server', () => {
describe('constructor', () => {
it('should work with no arguments', () => {
assert.doesNotThrow(() => {
new Server(); // tslint:disable-line:no-unused-expression
new Server();
});
});
it('should work with an empty object argument', () => {
assert.doesNotThrow(() => {
new Server({}); // tslint:disable-line:no-unused-expression
new Server({});
});
});