Skip to content

Commit 4553b29

Browse files
chore: Fix lint warnings in core package (#2405)
Co-authored-by: Daniel Dyla <[email protected]>
1 parent 3fc8bc9 commit 4553b29

File tree

9 files changed

+40
-35
lines changed

9 files changed

+40
-35
lines changed

packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
* https://w3c.github.io/baggage/
4444
*/
4545
export class HttpBaggagePropagator implements TextMapPropagator {
46-
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
46+
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
4747
const baggage = propagation.getBaggage(context);
4848
if (!baggage || isTracingSuppressed(context)) return;
4949
const keyPairs = getKeyPairs(baggage)

packages/opentelemetry-core/src/baggage/utils.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,34 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { Baggage, baggageEntryMetadataFromString } from '@opentelemetry/api';
16+
import { Baggage, BaggageEntryMetadata, baggageEntryMetadataFromString } from '@opentelemetry/api';
1717
import {
1818
BAGGAGE_ITEMS_SEPARATOR,
1919
BAGGAGE_PROPERTIES_SEPARATOR,
2020
BAGGAGE_KEY_PAIR_SEPARATOR,
2121
BAGGAGE_MAX_TOTAL_LENGTH,
2222
} from './constants';
2323

24-
export const serializeKeyPairs = (keyPairs: string[]) => {
24+
type ParsedBaggageKeyValue = { key: string, value: string, metadata: BaggageEntryMetadata | undefined };
25+
26+
export function serializeKeyPairs(keyPairs: string[]): string {
2527
return keyPairs.reduce((hValue: string, current: string) => {
26-
const value = `${hValue}${
27-
hValue !== '' ? BAGGAGE_ITEMS_SEPARATOR : ''
28-
}${current}`;
28+
const value = `${hValue}${hValue !== '' ? BAGGAGE_ITEMS_SEPARATOR : ''
29+
}${current}`;
2930
return value.length > BAGGAGE_MAX_TOTAL_LENGTH ? hValue : value;
3031
}, '');
31-
};
32+
}
3233

33-
export const getKeyPairs = (baggage: Baggage): string[] => {
34+
export function getKeyPairs(baggage: Baggage): string[] {
3435
return baggage
3536
.getAllEntries()
3637
.map(
3738
([key, value]) =>
3839
`${encodeURIComponent(key)}=${encodeURIComponent(value.value)}`
3940
);
40-
};
41+
}
4142

42-
export const parsePairKeyValue = (entry: string) => {
43+
export function parsePairKeyValue(entry: string): ParsedBaggageKeyValue | undefined {
4344
const valueProps = entry.split(BAGGAGE_PROPERTIES_SEPARATOR);
4445
if (valueProps.length <= 0) return;
4546
const keyPairPart = valueProps.shift();
@@ -55,13 +56,13 @@ export const parsePairKeyValue = (entry: string) => {
5556
);
5657
}
5758
return { key, value, metadata };
58-
};
59+
}
5960

6061
/**
6162
* Parse a string serialized in the baggage HTTP Format (without metadata):
6263
* https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md
6364
*/
64-
export const parseKeyPairsIntoRecord = (value?: string) => {
65+
export function parseKeyPairsIntoRecord(value?: string): Record<string, string> {
6566
if (typeof value !== 'string' || value.length === 0) return {};
6667
return value
6768
.split(BAGGAGE_ITEMS_SEPARATOR)
@@ -70,7 +71,8 @@ export const parseKeyPairsIntoRecord = (value?: string) => {
7071
})
7172
.filter(keyPair => keyPair !== undefined && keyPair.value.length > 0)
7273
.reduce<Record<string, string>>((headers, keyPair) => {
74+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7375
headers[keyPair!.key] = keyPair!.value;
7476
return headers;
7577
}, {});
76-
};
78+
}

packages/opentelemetry-core/src/common/attributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function sanitizeAttributes(attributes: unknown): SpanAttributes {
2222
return out;
2323
}
2424

25+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2526
for (const [k, v] of Object.entries(attributes!)) {
2627
if (isAttributeValue(v)) {
2728
if (Array.isArray(v)) {

packages/opentelemetry-core/src/common/global-error-handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ let delegateHandler = loggingErrorHandler();
2525
* Set the global error handler
2626
* @param {ErrorHandler} handler
2727
*/
28-
export function setGlobalErrorHandler(handler: ErrorHandler) {
28+
export function setGlobalErrorHandler(handler: ErrorHandler): void {
2929
delegateHandler = handler;
3030
}
3131

3232
/**
3333
* Return the global error handler
3434
* @param {Exception} ex
3535
*/
36-
export const globalErrorHandler = (ex: Exception) => {
36+
export function globalErrorHandler(ex: Exception): void {
3737
try {
3838
delegateHandler(ex);
3939
} catch {} // eslint-disable-line no-empty
40-
};
40+
}

packages/opentelemetry-core/src/common/time.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,45 +115,45 @@ export function hrTimeDuration(
115115

116116
/**
117117
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123456Z"
118-
* @param hrTime
118+
* @param time
119119
*/
120-
export function hrTimeToTimeStamp(hrTime: api.HrTime): string {
120+
export function hrTimeToTimeStamp(time: api.HrTime): string {
121121
const precision = NANOSECOND_DIGITS;
122-
const tmp = `${'0'.repeat(precision)}${hrTime[1]}Z`;
122+
const tmp = `${'0'.repeat(precision)}${time[1]}Z`;
123123
const nanoString = tmp.substr(tmp.length - precision - 1);
124-
const date = new Date(hrTime[0] * 1000).toISOString();
124+
const date = new Date(time[0] * 1000).toISOString();
125125
return date.replace('000Z', nanoString);
126126
}
127127

128128
/**
129129
* Convert hrTime to nanoseconds.
130-
* @param hrTime
130+
* @param time
131131
*/
132-
export function hrTimeToNanoseconds(hrTime: api.HrTime): number {
133-
return hrTime[0] * SECOND_TO_NANOSECONDS + hrTime[1];
132+
export function hrTimeToNanoseconds(time: api.HrTime): number {
133+
return time[0] * SECOND_TO_NANOSECONDS + time[1];
134134
}
135135

136136
/**
137137
* Convert hrTime to milliseconds.
138-
* @param hrTime
138+
* @param time
139139
*/
140-
export function hrTimeToMilliseconds(hrTime: api.HrTime): number {
141-
return Math.round(hrTime[0] * 1e3 + hrTime[1] / 1e6);
140+
export function hrTimeToMilliseconds(time: api.HrTime): number {
141+
return Math.round(time[0] * 1e3 + time[1] / 1e6);
142142
}
143143

144144
/**
145145
* Convert hrTime to microseconds.
146-
* @param hrTime
146+
* @param time
147147
*/
148-
export function hrTimeToMicroseconds(hrTime: api.HrTime): number {
149-
return Math.round(hrTime[0] * 1e6 + hrTime[1] / 1e3);
148+
export function hrTimeToMicroseconds(time: api.HrTime): number {
149+
return Math.round(time[0] * 1e6 + time[1] / 1e3);
150150
}
151151

152152
/**
153153
* check if time is HrTime
154154
* @param value
155155
*/
156-
export function isTimeInputHrTime(value: unknown) {
156+
export function isTimeInputHrTime(value: unknown): value is api.HrTime {
157157
return (
158158
Array.isArray(value) &&
159159
value.length === 2 &&
@@ -166,7 +166,7 @@ export function isTimeInputHrTime(value: unknown) {
166166
* check if input value is a correct types.TimeInput
167167
* @param value
168168
*/
169-
export function isTimeInput(value: unknown) {
169+
export function isTimeInput(value: unknown): value is api.HrTime | number | Date {
170170
return (
171171
isTimeInputHrTime(value) ||
172172
typeof value === 'number' ||

packages/opentelemetry-core/src/common/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export interface TimeOriginLegacy {
3131
* This interface defines the params that are be added to the wrapped function
3232
* using the "shimmer.wrap"
3333
*/
34-
export interface ShimWrapped {
34+
export interface ShimWrapped extends Function {
3535
__wrapped: boolean;
36+
// eslint-disable-next-line @typescript-eslint/ban-types
3637
__unwrap: Function;
38+
// eslint-disable-next-line @typescript-eslint/ban-types
3739
__original: Function;
3840
}
3941

packages/opentelemetry-core/src/propagation/composite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class CompositePropagator implements TextMapPropagator {
6464
* @param context Context to inject
6565
* @param carrier Carrier into which context will be injected
6666
*/
67-
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
67+
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
6868
for (const propagator of this._propagators) {
6969
try {
7070
propagator.inject(context, carrier, setter);

packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function parseTraceParent(traceParent: string): SpanContext | null {
7171
* https://www.w3.org/TR/trace-context/
7272
*/
7373
export class HttpTraceContextPropagator implements TextMapPropagator {
74-
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
74+
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
7575
const spanContext = trace.getSpanContext(context);
7676
if (
7777
!spanContext ||

packages/opentelemetry-core/src/utils/wrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ShimWrapped } from '../common/types';
2020
* Checks if certain function has been already wrapped
2121
* @param func
2222
*/
23-
export function isWrapped(func: any) {
23+
export function isWrapped(func: unknown): func is ShimWrapped {
2424
return (
2525
typeof func === 'function' &&
2626
typeof (func as ShimWrapped).__original === 'function' &&

0 commit comments

Comments
 (0)