Skip to content

Commit b8ab542

Browse files
committed
chore: upgrade to typescript-eslint v8
1 parent c27fbc6 commit b8ab542

File tree

35 files changed

+379
-332
lines changed

35 files changed

+379
-332
lines changed

api/src/diag/ComponentLogger.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ export class DiagComponentLogger implements DiagLogger {
3333
this._namespace = props.namespace || 'DiagComponentLogger';
3434
}
3535

36-
public debug(...args: any[]): void {
36+
public debug(...args: unknown[]): void {
3737
return logProxy('debug', this._namespace, args);
3838
}
3939

40-
public error(...args: any[]): void {
40+
public error(...args: unknown[]): void {
4141
return logProxy('error', this._namespace, args);
4242
}
4343

44-
public info(...args: any[]): void {
44+
public info(...args: unknown[]): void {
4545
return logProxy('info', this._namespace, args);
4646
}
4747

48-
public warn(...args: any[]): void {
48+
public warn(...args: unknown[]): void {
4949
return logProxy('warn', this._namespace, args);
5050
}
5151

52-
public verbose(...args: any[]): void {
52+
public verbose(...args: unknown[]): void {
5353
return logProxy('verbose', this._namespace, args);
5454
}
5555
}
5656

5757
function logProxy(
5858
funcName: keyof DiagLogger,
5959
namespace: string,
60-
args: any
60+
args: unknown[]
6161
): void {
6262
const logger = getGlobal('diag');
6363
// shortcut if logger not set

api/src/propagation/TextMapPropagator.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Context } from '../context/types';
2929
*
3030
* @since 1.0.0
3131
*/
32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3233
export interface TextMapPropagator<Carrier = any> {
3334
/**
3435
* Injects values from a given `Context` into a carrier.
@@ -79,6 +80,7 @@ export interface TextMapPropagator<Carrier = any> {
7980
*
8081
* @since 1.0.0
8182
*/
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8284
export interface TextMapSetter<Carrier = any> {
8385
/**
8486
* Callback used to set a key/value pair on an object.
@@ -99,6 +101,7 @@ export interface TextMapSetter<Carrier = any> {
99101
*
100102
* @since 1.0.0
101103
*/
104+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
102105
export interface TextMapGetter<Carrier = any> {
103106
/**
104107
* Get a list of all keys available on the carrier.

api/src/trace/NoopTracer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ export class NoopTracer implements Tracer {
9999
}
100100
}
101101

102-
function isSpanContext(spanContext: any): spanContext is SpanContext {
102+
function isSpanContext(spanContext: unknown): spanContext is SpanContext {
103103
return (
104+
spanContext !== null &&
104105
typeof spanContext === 'object' &&
106+
'spanId' in spanContext &&
105107
typeof spanContext['spanId'] === 'string' &&
108+
'traceId' in spanContext &&
106109
typeof spanContext['traceId'] === 'string' &&
110+
'traceFlags' in spanContext &&
107111
typeof spanContext['traceFlags'] === 'number'
108112
);
109113
}

eslint.base.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
// Enable typescript-eslint for ts files.
3333
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
3434
parserOptions: {
35-
"project": "./tsconfig.json"
35+
"projectService": true
3636
},
3737
rules: {
3838
"@typescript-eslint/no-floating-promises": "error",
@@ -49,11 +49,7 @@ module.exports = {
4949
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}],
5050
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
5151
"@typescript-eslint/no-empty-function": ["off"],
52-
"@typescript-eslint/ban-types": ["warn", {
53-
"types": {
54-
"Function": null,
55-
}
56-
}],
52+
"@typescript-eslint/no-unsafe-function-type": ["warn"],
5753
"@typescript-eslint/no-shadow": ["warn"],
5854
"no-restricted-syntax": ["error", "ExportAllDeclaration"],
5955
"prefer-rest-params": "off",
@@ -64,20 +60,16 @@ module.exports = {
6460
// Enable typescript-eslint for ts files.
6561
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
6662
parserOptions: {
67-
"project": "./tsconfig.json"
63+
"projectService": true
6864
},
6965
rules: {
7066
"no-empty": "off",
7167
"@typescript-eslint/ban-ts-ignore": "off",
72-
"@typescript-eslint/ban-types": ["warn", {
73-
"types": {
74-
"Function": null,
75-
}
76-
}],
68+
"@typescript-eslint/no-unsafe-function-type": ["warn"],
7769
"@typescript-eslint/no-empty-function": "off",
7870
"@typescript-eslint/no-explicit-any": "off",
7971
"@typescript-eslint/no-unused-vars": "off",
80-
"@typescript-eslint/no-var-requires": "off",
72+
"@typescript-eslint/no-require-imports": "off",
8173
"@typescript-eslint/no-shadow": ["off"],
8274
"@typescript-eslint/no-floating-promises": ["off"],
8375
"@typescript-eslint/no-non-null-assertion": ["off"],

experimental/packages/opentelemetry-instrumentation-grpc/src/serverUtils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
111111
// TODO: Investigate this call/signature – it was inherited from very old
112112
// code and the `this: {}` is highly suspicious, and likely isn't doing
113113
// anything useful. There is probably a more precise cast we can do here.
114-
// eslint-disable-next-line @typescript-eslint/ban-types
114+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
115115
return (original as Function).call({}, call);
116116
}
117117

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

@@ -215,15 +215,15 @@ export function handleUntracedServerFunction<RequestType, ResponseType>(
215215
// TODO: Investigate this call/signature – it was inherited from very old
216216
// code and the `this: {}` is highly suspicious, and likely isn't doing
217217
// anything useful. There is probably a more precise cast we can do here.
218-
// eslint-disable-next-line @typescript-eslint/ban-types
218+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
219219
return (originalFunc as Function).call({}, call, callback);
220220
case 'serverStream':
221221
case 'server_stream':
222222
case 'bidi':
223223
// TODO: Investigate this call/signature – it was inherited from very old
224224
// code and the `this: {}` is highly suspicious, and likely isn't doing
225225
// anything useful. There is probably a more precise cast we can do here.
226-
// eslint-disable-next-line @typescript-eslint/ban-types
226+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
227227
return (originalFunc as Function).call({}, call);
228228
default:
229229
break;

experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts

+29-21
Original file line numberDiff line numberDiff line change
@@ -149,38 +149,44 @@ export async function startServer(proto: any, port: number) {
149149

150150
call.sendMetadata(serverMetadata);
151151

152-
call.request.num <= MAX_ERROR_STATUS
153-
? callback(
154-
getError(
155-
'Unary Method with Metadata Error',
156-
call.request.num
157-
) as ServiceError
158-
)
159-
: callback(null, { num: call.request.num });
152+
if (call.request.num <= MAX_ERROR_STATUS) {
153+
callback(
154+
getError(
155+
'Unary Method with Metadata Error',
156+
call.request.num
157+
) as ServiceError
158+
);
159+
} else {
160+
callback(null, { num: call.request.num });
161+
}
160162
},
161163

162164
// This method returns the request
163165
unaryMethod(
164166
call: ServerUnaryCall<any, any>,
165167
callback: requestCallback<any>
166168
) {
167-
call.request.num <= MAX_ERROR_STATUS
168-
? callback(
169-
getError('Unary Method Error', call.request.num) as ServiceError
170-
)
171-
: callback(null, { num: call.request.num });
169+
if (call.request.num <= MAX_ERROR_STATUS) {
170+
callback(
171+
getError('Unary Method Error', call.request.num) as ServiceError
172+
);
173+
} else {
174+
callback(null, { num: call.request.num });
175+
}
172176
},
173177

174178
// This method returns the request
175179
camelCaseMethod(
176180
call: ServerUnaryCall<any, any>,
177181
callback: requestCallback<any>
178182
) {
179-
call.request.num <= MAX_ERROR_STATUS
180-
? callback(
181-
getError('Unary Method Error', call.request.num) as ServiceError
182-
)
183-
: callback(null, { num: call.request.num });
183+
if (call.request.num <= MAX_ERROR_STATUS) {
184+
callback(
185+
getError('Unary Method Error', call.request.num) as ServiceError
186+
);
187+
} else {
188+
callback(null, { num: call.request.num });
189+
}
184190
},
185191

186192
// This method sums the requests
@@ -199,9 +205,11 @@ export async function startServer(proto: any, port: number) {
199205
}
200206
});
201207
call.on('end', () => {
202-
hasError
203-
? callback(getError('Client Stream Method Error', code) as any)
204-
: callback(null, { num: sum });
208+
if (hasError) {
209+
callback(getError('Client Stream Method Error', code) as any);
210+
} else {
211+
callback(null, { num: sum });
212+
}
205213
});
206214
},
207215

experimental/packages/opentelemetry-instrumentation-http/src/http.ts

+6
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
233233
'http',
234234
['*'],
235235
(moduleExports: Http): Http => {
236+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
236237
const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';
237238
if (!this.getConfig().disableOutgoingRequestInstrumentation) {
238239
const patchedRequest = this._wrap(
@@ -248,7 +249,9 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
248249
if (isESM) {
249250
// To handle `import http from 'http'`, which returns the default
250251
// export, we need to set `module.default.*`.
252+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
251253
(moduleExports as any).default.request = patchedRequest;
254+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
252255
(moduleExports as any).default.get = patchedGet;
253256
}
254257
}
@@ -280,6 +283,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
280283
'https',
281284
['*'],
282285
(moduleExports: Https): Https => {
286+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
283287
const isESM = (moduleExports as any)[Symbol.toStringTag] === 'Module';
284288
if (!this.getConfig().disableOutgoingRequestInstrumentation) {
285289
const patchedRequest = this._wrap(
@@ -295,7 +299,9 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
295299
if (isESM) {
296300
// To handle `import https from 'https'`, which returns the default
297301
// export, we need to set `module.default.*`.
302+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
298303
(moduleExports as any).default.request = patchedRequest;
304+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
299305
(moduleExports as any).default.get = patchedGet;
300306
}
301307
}

experimental/packages/opentelemetry-instrumentation-http/src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
ParsedRequestOptions,
7979
SemconvStability,
8080
} from './internal-types';
81+
// eslint-disable-next-line @typescript-eslint/no-require-imports
8182
import forwardedParse = require('forwarded-parse');
8283

8384
/**
@@ -376,7 +377,7 @@ export const getRequestInfo = (
376377
try {
377378
const parsedUrl = new URL(optionsParsed.path, origin);
378379
pathname = parsedUrl.pathname || '/';
379-
} catch (e) {
380+
} catch {
380381
pathname = '/';
381382
}
382383
}

experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export abstract class InstrumentationBase<
167167
});
168168
const version = JSON.parse(json).version;
169169
return typeof version === 'string' ? version : undefined;
170-
} catch (error) {
170+
} catch {
171171
diag.warn('Failed extracting version', baseDir);
172172
}
173173

experimental/packages/opentelemetry-instrumentation/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export interface InstrumentationConfig {
6969
*/
7070
export interface ShimWrapped extends Function {
7171
__wrapped: boolean;
72-
// eslint-disable-next-line @typescript-eslint/ban-types
72+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
7373
__unwrap: Function;
74-
// eslint-disable-next-line @typescript-eslint/ban-types
74+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
7575
__original: Function;
7676
}
7777

experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FooInstrumentation extends InstrumentationBase {
5353
}
5454

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

5959
afterEach(() => {

experimental/packages/opentelemetry-sdk-node/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function getJaegerExporter() {
119119
// environments. By delaying the require statement to here, we only crash when
120120
// the exporter is actually used in such an environment.
121121
try {
122-
// eslint-disable-next-line @typescript-eslint/no-var-requires
122+
// eslint-disable-next-line @typescript-eslint/no-require-imports
123123
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
124124
return new JaegerExporter();
125125
} catch (e) {

experimental/packages/otlp-exporter-base/src/bounded-queue-export-promise-handler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BoundedQueueExportPromiseHandler implements IExportPromiseHandler {
3939
this._sendingPromises.push(promise);
4040
const popPromise = () => {
4141
const index = this._sendingPromises.indexOf(promise);
42-
this._sendingPromises.splice(index, 1);
42+
void this._sendingPromises.splice(index, 1);
4343
};
4444
promise.then(popPromise, popPromise);
4545
}

experimental/packages/otlp-exporter-base/src/configuration/otlp-http-configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function validateUserProvidedUrl(url: string | undefined): string | undefined {
6464
try {
6565
new URL(url);
6666
return url;
67-
} catch (e) {
67+
} catch {
6868
throw new Error(
6969
`Configuration: Could not parse user-provided export URL: '${url}'`
7070
);

experimental/packages/otlp-exporter-base/src/transport/http-exporter-transport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class HttpExporterTransport implements IExporterTransport {
6464
const {
6565
sendWithHttp,
6666
createHttpAgent,
67-
// eslint-disable-next-line @typescript-eslint/no-var-requires
67+
// eslint-disable-next-line @typescript-eslint/no-require-imports
6868
} = require('./http-transport-utils');
6969

7070
utils = this._utils = {

experimental/packages/otlp-grpc-exporter-base/src/grpc-exporter-transport.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function createInsecureCredentials(): ChannelCredentials {
3939
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
4040
const {
4141
credentials,
42-
// eslint-disable-next-line @typescript-eslint/no-var-requires
42+
// eslint-disable-next-line @typescript-eslint/no-require-imports
4343
} = require('@grpc/grpc-js');
4444
return credentials.createInsecure();
4545
}
@@ -52,7 +52,7 @@ export function createSslCredentials(
5252
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
5353
const {
5454
credentials,
55-
// eslint-disable-next-line @typescript-eslint/no-var-requires
55+
// eslint-disable-next-line @typescript-eslint/no-require-imports
5656
} = require('@grpc/grpc-js');
5757
return credentials.createSsl(rootCert, privateKey, certChain);
5858
}
@@ -61,7 +61,7 @@ export function createEmptyMetadata(): Metadata {
6161
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
6262
const {
6363
Metadata,
64-
// eslint-disable-next-line @typescript-eslint/no-var-requires
64+
// eslint-disable-next-line @typescript-eslint/no-require-imports
6565
} = require('@grpc/grpc-js');
6666
return new Metadata();
6767
}
@@ -108,7 +108,7 @@ export class GrpcExporterTransport implements IExporterTransport {
108108
// Lazy require to ensure that grpc is not loaded before instrumentations can wrap it
109109
const {
110110
createServiceClientConstructor,
111-
// eslint-disable-next-line @typescript-eslint/no-var-requires
111+
// eslint-disable-next-line @typescript-eslint/no-require-imports
112112
} = require('./create-service-client-constructor');
113113

114114
try {

0 commit comments

Comments
 (0)