Skip to content
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

chore: upgrade to typescript-eslint v8 #5478

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions api/src/diag/ComponentLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ export class DiagComponentLogger implements DiagLogger {
this._namespace = props.namespace || 'DiagComponentLogger';
}

public debug(...args: any[]): void {
public debug(...args: unknown[]): void {
return logProxy('debug', this._namespace, args);
}

public error(...args: any[]): void {
public error(...args: unknown[]): void {
return logProxy('error', this._namespace, args);
}

public info(...args: any[]): void {
public info(...args: unknown[]): void {
return logProxy('info', this._namespace, args);
}

public warn(...args: any[]): void {
public warn(...args: unknown[]): void {
return logProxy('warn', this._namespace, args);
}

public verbose(...args: any[]): void {
public verbose(...args: unknown[]): void {
return logProxy('verbose', this._namespace, args);
}
}

function logProxy(
funcName: keyof DiagLogger,
namespace: string,
args: any
args: unknown[]
): void {
const logger = getGlobal('diag');
// shortcut if logger not set
Expand Down
3 changes: 3 additions & 0 deletions api/src/propagation/TextMapPropagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Context } from '../context/types';
*
* @since 1.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface TextMapPropagator<Carrier = any> {
/**
* Injects values from a given `Context` into a carrier.
Expand Down Expand Up @@ -79,6 +80,7 @@ export interface TextMapPropagator<Carrier = any> {
*
* @since 1.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface TextMapSetter<Carrier = any> {
/**
* Callback used to set a key/value pair on an object.
Expand All @@ -99,6 +101,7 @@ export interface TextMapSetter<Carrier = any> {
*
* @since 1.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface TextMapGetter<Carrier = any> {
/**
* Get a list of all keys available on the carrier.
Expand Down
6 changes: 5 additions & 1 deletion api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ export class NoopTracer implements Tracer {
}
}

function isSpanContext(spanContext: any): spanContext is SpanContext {
function isSpanContext(spanContext: unknown): spanContext is SpanContext {
return (
spanContext !== null &&
typeof spanContext === 'object' &&
'spanId' in spanContext &&
typeof spanContext['spanId'] === 'string' &&
'traceId' in spanContext &&
typeof spanContext['traceId'] === 'string' &&
'traceFlags' in spanContext &&
typeof spanContext['traceFlags'] === 'number'
);
}
18 changes: 5 additions & 13 deletions eslint.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
"projectService": true
},
rules: {
"@typescript-eslint/no-floating-promises": "error",
Expand All @@ -49,11 +49,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}],
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
"@typescript-eslint/no-empty-function": ["off"],
"@typescript-eslint/ban-types": ["warn", {
"types": {
"Function": null,
}
}],
"@typescript-eslint/no-unsafe-function-type": ["warn"],
"@typescript-eslint/no-shadow": ["warn"],
"no-restricted-syntax": ["error", "ExportAllDeclaration"],
"prefer-rest-params": "off",
Expand All @@ -64,20 +60,16 @@ module.exports = {
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
"projectService": true
},
rules: {
"no-empty": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-types": ["warn", {
"types": {
"Function": null,
}
}],
"@typescript-eslint/no-unsafe-function-type": ["warn"],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-shadow": ["off"],
"@typescript-eslint/no-floating-promises": ["off"],
"@typescript-eslint/no-non-null-assertion": ["off"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
// TODO: Investigate this call/signature – it was inherited from very old
// code and the `this: {}` is highly suspicious, and likely isn't doing
// anything useful. There is probably a more precise cast we can do here.
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
return (original as Function).call({}, call);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ function clientStreamAndUnaryHandler<RequestType, ResponseType>(
// TODO: Investigate this call/signature – it was inherited from very old
// code and the `this: {}` is highly suspicious, and likely isn't doing
// anything useful. There is probably a more precise cast we can do here.
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
return (original as Function).call({}, call, patchedCallback);
}

Expand Down Expand Up @@ -215,15 +215,15 @@ export function handleUntracedServerFunction<RequestType, ResponseType>(
// TODO: Investigate this call/signature – it was inherited from very old
// code and the `this: {}` is highly suspicious, and likely isn't doing
// anything useful. There is probably a more precise cast we can do here.
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
return (originalFunc as Function).call({}, call, callback);
case 'serverStream':
case 'server_stream':
case 'bidi':
// TODO: Investigate this call/signature – it was inherited from very old
// code and the `this: {}` is highly suspicious, and likely isn't doing
// anything useful. There is probably a more precise cast we can do here.
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
return (originalFunc as Function).call({}, call);
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,38 +149,44 @@ export async function startServer(proto: any, port: number) {

call.sendMetadata(serverMetadata);

call.request.num <= MAX_ERROR_STATUS
? callback(
getError(
'Unary Method with Metadata Error',
call.request.num
) as ServiceError
)
: callback(null, { num: call.request.num });
if (call.request.num <= MAX_ERROR_STATUS) {
callback(
getError(
'Unary Method with Metadata Error',
call.request.num
) as ServiceError
);
} else {
callback(null, { num: call.request.num });
}
},

// This method returns the request
unaryMethod(
call: ServerUnaryCall<any, any>,
callback: requestCallback<any>
) {
call.request.num <= MAX_ERROR_STATUS
? callback(
getError('Unary Method Error', call.request.num) as ServiceError
)
: callback(null, { num: call.request.num });
if (call.request.num <= MAX_ERROR_STATUS) {
callback(
getError('Unary Method Error', call.request.num) as ServiceError
);
} else {
callback(null, { num: call.request.num });
}
},

// This method returns the request
camelCaseMethod(
call: ServerUnaryCall<any, any>,
callback: requestCallback<any>
) {
call.request.num <= MAX_ERROR_STATUS
? callback(
getError('Unary Method Error', call.request.num) as ServiceError
)
: callback(null, { num: call.request.num });
if (call.request.num <= MAX_ERROR_STATUS) {
callback(
getError('Unary Method Error', call.request.num) as ServiceError
);
} else {
callback(null, { num: call.request.num });
}
},

// This method sums the requests
Expand All @@ -199,9 +205,11 @@ export async function startServer(proto: any, port: number) {
}
});
call.on('end', () => {
hasError
? callback(getError('Client Stream Method Error', code) as any)
: callback(null, { num: sum });
if (hasError) {
callback(getError('Client Stream Method Error', code) as any);
} else {
callback(null, { num: sum });
}
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
'http',
['*'],
(moduleExports: Http): Http => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';
if (!this.getConfig().disableOutgoingRequestInstrumentation) {
const patchedRequest = this._wrap(
Expand All @@ -248,7 +249,9 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
if (isESM) {
// To handle `import http from 'http'`, which returns the default
// export, we need to set `module.default.*`.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(moduleExports as any).default.request = patchedRequest;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(moduleExports as any).default.get = patchedGet;
}
}
Expand Down Expand Up @@ -280,6 +283,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
'https',
['*'],
(moduleExports: Https): Https => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';
if (!this.getConfig().disableOutgoingRequestInstrumentation) {
const patchedRequest = this._wrap(
Expand All @@ -295,7 +299,9 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
if (isESM) {
// To handle `import https from 'https'`, which returns the default
// export, we need to set `module.default.*`.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(moduleExports as any).default.request = patchedRequest;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(moduleExports as any).default.get = patchedGet;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
ParsedRequestOptions,
SemconvStability,
} from './internal-types';
// eslint-disable-next-line @typescript-eslint/no-require-imports
import forwardedParse = require('forwarded-parse');

/**
Expand Down Expand Up @@ -376,7 +377,7 @@ export const getRequestInfo = (
try {
const parsedUrl = new URL(optionsParsed.path, origin);
pathname = parsedUrl.pathname || '/';
} catch (e) {
} catch {
pathname = '/';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export abstract class InstrumentationBase<
});
const version = JSON.parse(json).version;
return typeof version === 'string' ? version : undefined;
} catch (error) {
} catch {
diag.warn('Failed extracting version', baseDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export interface InstrumentationConfig {
*/
export interface ShimWrapped extends Function {
__wrapped: boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
__unwrap: Function;
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
__original: Function;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FooInstrumentation extends InstrumentationBase {
}

describe('autoLoader', () => {
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
let unload: Function | undefined;

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function getJaegerExporter() {
// environments. By delaying the require statement to here, we only crash when
// the exporter is actually used in such an environment.
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
return new JaegerExporter();
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BoundedQueueExportPromiseHandler implements IExportPromiseHandler {
this._sendingPromises.push(promise);
const popPromise = () => {
const index = this._sendingPromises.indexOf(promise);
this._sendingPromises.splice(index, 1);
void this._sendingPromises.splice(index, 1);
};
promise.then(popPromise, popPromise);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function validateUserProvidedUrl(url: string | undefined): string | undefined {
try {
new URL(url);
return url;
} catch (e) {
} catch {
throw new Error(
`Configuration: Could not parse user-provided export URL: '${url}'`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HttpExporterTransport implements IExporterTransport {
const {
sendWithHttp,
createHttpAgent,
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('./http-transport-utils');

utils = this._utils = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function createInsecureCredentials(): ChannelCredentials {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const {
credentials,
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return credentials.createInsecure();
}
Expand All @@ -52,7 +52,7 @@ export function createSslCredentials(
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const {
credentials,
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return credentials.createSsl(rootCert, privateKey, certChain);
}
Expand All @@ -61,7 +61,7 @@ export function createEmptyMetadata(): Metadata {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const {
Metadata,
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return new Metadata();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export class GrpcExporterTransport implements IExporterTransport {
// Lazy require to ensure that grpc is not loaded before instrumentations can wrap it
const {
createServiceClientConstructor,
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('./create-service-client-constructor');

try {
Expand Down
Loading