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: Fix lint warnings in instrumentation package #2404

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function parseInstrumentationOptions(
): AutoLoaderResult {
let instrumentations: Instrumentation[] = [];
for (let i = 0, j = options.length; i < j; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const option = options[i] as any;
if (Array.isArray(option)) {
const results = parseInstrumentationOptions(option);
Expand All @@ -53,7 +54,7 @@ export function enableInstrumentations(
instrumentations: Instrumentation[],
tracerProvider?: TracerProvider,
meterProvider?: MeterProvider
) {
): void {
for (let i = 0, j = instrumentations.length; i < j; i++) {
const instrumentation = instrumentations[i];
if (tracerProvider) {
Expand All @@ -76,6 +77,6 @@ export function enableInstrumentations(
* Disable instrumentations
* @param instrumentations
*/
export function disableInstrumentations(instrumentations: Instrumentation[]) {
export function disableInstrumentations(instrumentations: Instrumentation[]): void {
instrumentations.forEach(instrumentation => instrumentation.disable());
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,31 @@ export abstract class InstrumentationAbstract<T = any>
* Sets MeterProvider to this plugin
* @param meterProvider
*/
public setMeterProvider(meterProvider: MeterProvider) {
public setMeterProvider(meterProvider: MeterProvider): void {
this._meter = meterProvider.getMeter(
this.instrumentationName,
this.instrumentationVersion
);
}

/* Returns InstrumentationConfig */
public getConfig() {
public getConfig(): types.InstrumentationConfig {
return this._config;
}

/**
* Sets InstrumentationConfig to this plugin
* @param InstrumentationConfig
*/
public setConfig(config: types.InstrumentationConfig = {}) {
public setConfig(config: types.InstrumentationConfig = {}): void {
this._config = Object.assign({}, config);
}

/**
* Sets TraceProvider to this plugin
* @param tracerProvider
*/
public setTracerProvider(tracerProvider: TracerProvider) {
public setTracerProvider(tracerProvider: TracerProvider): void {
this._tracer = tracerProvider.getTracer(
this.instrumentationName,
this.instrumentationVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export abstract class InstrumentationBase<T = any>
} else {
// internal file
const files = module.files ?? [];
const file = files.find(file => file.name === name);
const file = files.find(f => f.name === name);
if (file && isSupported(file.supportedVersions, version, module.includePrerelease)) {
file.moduleExports = exports;
if (this._enabled) {
Expand All @@ -113,7 +113,7 @@ export abstract class InstrumentationBase<T = any>
return exports;
}

public enable() {
public enable(): void {
if (this._enabled) {
return;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export abstract class InstrumentationBase<T = any>
}
}

public disable() {
public disable(): void {
if (!this._enabled) {
return;
}
Expand All @@ -172,7 +172,7 @@ export abstract class InstrumentationBase<T = any>
}
}

public isEnabled() {
public isEnabled(): boolean {
return this._enabled;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface InstrumentationModuleDefinition<T> {
supportedVersions: string[];

/** Module internal files to be patched */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
files: InstrumentationModuleFile<any>[];

/** If set to true, the includePrerelease check will be included when calling semver.satisfies */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ export interface InstrumentationConfig {
* This interface defines the params that are be added to the wrapped function
* using the "shimmer.wrap"
*/
export interface ShimWrapped {
export interface ShimWrapped extends Function {
__wrapped: boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
__unwrap: Function;
// eslint-disable-next-line @typescript-eslint/ban-types
__original: Function;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function safeExecuteInTheMiddleAsync<T>(
* Checks if certain function has been already wrapped
* @param func
*/
export function isWrapped(func: any) {
export function isWrapped(func: unknown): func is ShimWrapped {
return (
typeof func === 'function' &&
typeof (func as ShimWrapped).__original === 'function' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FooInstrumentation extends InstrumentationBase {
}

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

afterEach(() => {
Expand Down