Skip to content

Commit

Permalink
chore: fix Lint warnings in api-metrics and context-zone-peer-dep (#2390
Browse files Browse the repository at this point in the history
)

Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
alisabzevari and dyladan authored Aug 6, 2021
1 parent b69ff35 commit 08828b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
9 changes: 5 additions & 4 deletions packages/opentelemetry-api-metrics/src/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
BoundBaseObserver,
} from './types/BoundInstrument';
import { ObserverResult } from './types/ObserverResult';
import { Observation } from './types/Observation';

/**
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
Expand Down Expand Up @@ -159,23 +160,23 @@ export class NoopMetric<T> implements UnboundMetric<T> {
export class NoopCounterMetric
extends NoopMetric<BoundCounter>
implements Counter {
add(value: number, labels: Labels) {
add(value: number, labels: Labels): void {
this.bind(labels).add(value);
}
}

export class NoopValueRecorderMetric
extends NoopMetric<BoundValueRecorder>
implements ValueRecorder {
record(value: number, labels: Labels) {
record(value: number, labels: Labels): void {
this.bind(labels).record(value);
}
}

export class NoopBaseObserverMetric
extends NoopMetric<BoundBaseObserver>
implements BaseObserver {
observation() {
observation(): Observation {
return {
observer: this as BaseObserver,
value: 0,
Expand All @@ -198,7 +199,7 @@ export class NoopBoundValueRecorder implements BoundValueRecorder {
}

export class NoopBoundBaseObserver implements BoundBaseObserver {
update(_value: number) {}
update(_value: number): void {}
}

export const NOOP_METER = new NoopMeter();
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-api-metrics/src/api/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class MetricsAPI {
}

/** Remove the global meter provider */
public disable() {
public disable(): void {
delete _global[GLOBAL_METRICS_API_KEY];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Context, ContextManager, ROOT_CONTEXT } from '@opentelemetry/api';
import { Func, TargetWithEvents } from './types';
import { TargetWithEvents } from './types';
import { isListenerObject } from './util';

/* Key name to be used to save a context reference in Zone */
Expand Down Expand Up @@ -53,9 +53,10 @@ export class ZoneContextManager implements ContextManager {
* @param context A context (span) to be executed within target function
* @param target Function to be executed within the context
*/
// eslint-disable-next-line @typescript-eslint/ban-types
private _bindFunction<T extends Function>(context: Context, target: T): T {
const manager = this;
const contextWrapper = function (this: any, ...args: unknown[]) {
const contextWrapper = function (this: unknown, ...args: unknown[]) {
return manager.with(context, () => target.apply(this, args));
};
Object.defineProperty(contextWrapper, 'length', {
Expand Down Expand Up @@ -134,16 +135,16 @@ export class ZoneContextManager implements ContextManager {
*/
private _patchAddEventListener(
target: TargetWithEvents,
original: Function,
original: NonNullable<TargetWithEvents['addEventListener']>,
context: Context
) {
const contextManager = this;

return function (
this: {},
event: string,
listener: Func<void>,
opts?: any
this: TargetWithEvents,
event,
listener,
opts
) {
if (target.__ot_listeners === undefined) {
target.__ot_listeners = {};
Expand All @@ -157,7 +158,7 @@ export class ZoneContextManager implements ContextManager {
// store a weak reference of the user listener to ours
listeners.set(listener, patchedListener);
return original.call(this, event, patchedListener, opts);
};
} as TargetWithEvents['addEventListener'];
}

/**
Expand All @@ -167,9 +168,9 @@ export class ZoneContextManager implements ContextManager {
*/
private _patchRemoveEventListener(
target: TargetWithEvents,
original: Function
original: NonNullable<TargetWithEvents['removeEventListener']>
) {
return function (this: {}, event: string, listener: Func<void>) {
return function (this: TargetWithEvents, event, listener) {
if (
target.__ot_listeners === undefined ||
target.__ot_listeners[event] === undefined
Expand All @@ -180,7 +181,7 @@ export class ZoneContextManager implements ContextManager {
const patchedListener = events.get(listener);
events.delete(listener);
return original.call(this, event, patchedListener || listener);
};
} as TargetWithEvents['removeEventListener'];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-context-zone-peer-dep/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export type Func<T> = (...args: unknown[]) => T;
export interface TargetWithEvents {
addEventListener?(
event: string,
listener: (...args: any[]) => void,
listener: (...args: unknown[]) => void,
opts?: { once: boolean }
): any;
): unknown;
removeEventListener?(
event: string,
listener: (...args: any[]) => void,
listener: (...args: unknown[]) => void,
opts?: { once: boolean }
): any;
): unknown;
__ot_listeners?: { [name: string]: WeakMap<Func<void>, Func<void>> };
}

0 comments on commit 08828b4

Please sign in to comment.