Skip to content

Commit 5cf29e1

Browse files
committed
chore: Apply eslint rules (or add ignores)
1 parent 44876ee commit 5cf29e1

36 files changed

+275
-251
lines changed

jest.setup.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
import { getCurrentHub } from '@sentry/core';
23
import { Transport } from '@sentry/types';
34

4-
import { Session } from './src/session/Session';
55
import { Replay } from './src';
6+
import { Session } from './src/session/Session';
67

78
// @ts-ignore TS error, this is replaced in prod builds bc of rollup
89
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';
@@ -40,10 +41,8 @@ type SentReplayExpected = {
4041
events?: string | Uint8Array;
4142
};
4243

43-
const toHaveSameSession = function (
44-
received: jest.Mocked<Replay>,
45-
expected: undefined | Session
46-
) {
44+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
45+
const toHaveSameSession = function (received: jest.Mocked<Replay>, expected: undefined | Session) {
4746
const pass = this.equals(received.session?.id, expected?.id) as boolean;
4847

4948
const options = {
@@ -54,13 +53,7 @@ const toHaveSameSession = function (
5453
return {
5554
pass,
5655
message: () =>
57-
this.utils.matcherHint(
58-
'toHaveSameSession',
59-
undefined,
60-
undefined,
61-
options
62-
) +
63-
'\n\n' +
56+
`${this.utils.matcherHint('toHaveSameSession', undefined, undefined, options)}\n\n` +
6457
`Expected: ${pass ? 'not ' : ''}${this.utils.printExpected(expected)}\n` +
6558
`Received: ${this.utils.printReceived(received.session)}`,
6659
};
@@ -70,23 +63,17 @@ const toHaveSameSession = function (
7063
* Checks the last call to `fetch` and ensures a replay was uploaded by
7164
* checking the `fetch()` request's body.
7265
*/
66+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7367
const toHaveSentReplay = function (
7468
_received: jest.Mocked<Replay>,
75-
expected?:
76-
| SentReplayExpected
77-
| { sample: SentReplayExpected; inverse: boolean }
69+
expected?: SentReplayExpected | { sample: SentReplayExpected; inverse: boolean },
7870
) {
79-
const { calls } = (
80-
getCurrentHub().getClient()?.getTransport()?.send as MockTransport
81-
).mock;
71+
const { calls } = (getCurrentHub().getClient()?.getTransport()?.send as MockTransport).mock;
8272
const lastCall = calls[calls.length - 1]?.[0];
8373

8474
const envelopeHeader = lastCall?.[0];
8575
const envelopeItems = lastCall?.[1] || [[], []];
86-
const [
87-
[replayEventHeader, replayEventPayload],
88-
[recordingHeader, recordingPayload] = [],
89-
] = envelopeItems;
76+
const [[replayEventHeader, replayEventPayload], [recordingHeader, recordingPayload] = []] = envelopeItems;
9077

9178
// @ts-ignore recordingPayload is always a string in our tests
9279
const [recordingPayloadHeader, events] = recordingPayload?.split('\n') || [];
@@ -100,39 +87,28 @@ const toHaveSentReplay = function (
10087
replayEventPayload: replayEventPayload,
10188
// @ts-ignore Custom envelope
10289
recordingHeader: recordingHeader,
103-
recordingPayloadHeader:
104-
recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
90+
recordingPayloadHeader: recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
10591
events,
10692
};
10793

108-
const isObjectContaining =
109-
expected && 'sample' in expected && 'inverse' in expected;
94+
const isObjectContaining = expected && 'sample' in expected && 'inverse' in expected;
11095
const expectedObj = isObjectContaining
11196
? (expected as { sample: SentReplayExpected }).sample
11297
: (expected as SentReplayExpected);
11398

11499
if (isObjectContaining) {
115-
console.warn(
116-
'`expect.objectContaining` is unnecessary when using the `toHaveSentReplay` matcher'
117-
);
100+
console.warn('`expect.objectContaining` is unnecessary when using the `toHaveSentReplay` matcher');
118101
}
119102

120103
const results = expected
121104
? Object.entries(actualObj)
122105
.map(([key, val]: [keyof SentReplayExpected, any]) => {
123-
return [
124-
!expectedObj?.[key] || this.equals(expectedObj[key], val),
125-
key,
126-
expectedObj?.[key],
127-
val,
128-
];
106+
return [!expectedObj?.[key] || this.equals(expectedObj[key], val), key, expectedObj?.[key], val];
129107
})
130108
.filter(([passed]) => !passed)
131109
: [];
132110

133-
const payloadPassed = Boolean(
134-
lastCall && (!expected || results.length === 0)
135-
);
111+
const payloadPassed = Boolean(lastCall && (!expected || results.length === 0));
136112

137113
const options = {
138114
isNot: this.isNot,
@@ -148,22 +124,13 @@ const toHaveSentReplay = function (
148124
? allPass
149125
? 'Expected Replay to not have been sent, but a request was attempted'
150126
: 'Expected Replay to have been sent, but a request was not attempted'
151-
: this.utils.matcherHint(
152-
'toHaveSentReplay',
153-
undefined,
154-
undefined,
155-
options
156-
) +
157-
'\n\n' +
158-
results
127+
: `${this.utils.matcherHint('toHaveSentReplay', undefined, undefined, options)}\n\n${results
159128
.map(
160129
([, key, expected, actual]) =>
161-
`Expected (key: ${key}): ${
162-
payloadPassed ? 'not ' : ''
163-
}${this.utils.printExpected(expected)}\n` +
164-
`Received (key: ${key}): ${this.utils.printReceived(actual)}`
130+
`Expected (key: ${key}): ${payloadPassed ? 'not ' : ''}${this.utils.printExpected(expected)}\n` +
131+
`Received (key: ${key}): ${this.utils.printReceived(actual)}`,
165132
)
166-
.join('\n'),
133+
.join('\n')}`,
167134
};
168135
};
169136

src/coreHandlers/getBreadcrumbHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { InstrumentationTypeBreadcrumb } from '../types';
2-
32
import { handleDom } from './handleDom';
43
import { handleScope } from './handleScope';
54

5+
// TODO: Add return type
6+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
67
export function getBreadcrumbHandler(type: InstrumentationTypeBreadcrumb) {
78
if (type === 'scope') {
89
return handleScope;

src/coreHandlers/getSpanHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { InstrumentationTypeSpan } from '../types';
2-
32
import { handleFetch } from './handleFetch';
43
import { handleHistory } from './handleHistory';
54
import { handleXhr } from './handleXhr';
65

6+
// TODO: Add return type
7+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
78
export function getSpanHandler(type: InstrumentationTypeSpan) {
89
if (type === 'fetch') {
910
return handleFetch;

src/coreHandlers/handleDom.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { Breadcrumb } from '@sentry/types';
12
import { htmlTreeAsString } from '@sentry/utils';
23
import { record } from 'rrweb';
34

45
import { createBreadcrumb } from '../util/createBreadcrumb';
56

6-
export function handleDom(handlerData: any) {
7+
export function handleDom(handlerData: any): Breadcrumb | null {
78
// Taken from https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/breadcrumbs.ts#L112
89
let target;
910
let targetNode;
1011

1112
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
1213
try {
14+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1315
targetNode = (handlerData.event.target as Node) || (handlerData.event as unknown as Node);
1416
target = htmlTreeAsString(targetNode);
1517
} catch (e) {
@@ -21,6 +23,7 @@ export function handleDom(handlerData: any) {
2123
}
2224

2325
return createBreadcrumb({
26+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2427
category: `ui.${handlerData.name}`,
2528
message: target,
2629
data: {

src/coreHandlers/handleScope.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { createBreadcrumb } from '../util/createBreadcrumb';
44

55
let _LAST_BREADCRUMB: null | Breadcrumb = null;
66

7-
export function handleScope(scope: Scope) {
8-
//@ts-ignore using private val
7+
export function handleScope(scope: Scope): Breadcrumb | null {
8+
// TODO: remove ignores here
9+
// @ts-ignore using private val
10+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
911
const newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
1012

1113
// Listener can be called when breadcrumbs have not changed, so we store the
@@ -17,7 +19,9 @@ export function handleScope(scope: Scope) {
1719
_LAST_BREADCRUMB = newBreadcrumb;
1820

1921
if (
22+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2023
['fetch', 'xhr', 'sentry.event', 'sentry.transaction'].includes(newBreadcrumb.category) ||
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2125
newBreadcrumb.category?.startsWith('ui.')
2226
) {
2327
return null;

src/createPerformanceEntry.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { browserPerformanceTimeOrigin } from '@sentry/utils';
22
import { record } from 'rrweb';
33

4-
import { isIngestHost } from './util/isIngestHost';
54
import { AllPerformanceEntry } from './types';
5+
import { isIngestHost } from './util/isIngestHost';
66

77
export interface ReplayPerformanceEntry {
88
/**
@@ -45,24 +45,26 @@ const ENTRY_TYPES: Record<string, (entry: AllPerformanceEntry) => null | ReplayP
4545
['largest-contentful-paint']: createLargestContentfulPaint,
4646
};
4747

48-
export function createPerformanceEntries(entries: AllPerformanceEntry[]) {
48+
export function createPerformanceEntries(entries: AllPerformanceEntry[]): ReplayPerformanceEntry[] {
4949
return entries.map(createPerformanceEntry).filter(Boolean) as ReplayPerformanceEntry[];
5050
}
5151

52-
function createPerformanceEntry(entry: AllPerformanceEntry) {
52+
function createPerformanceEntry(entry: AllPerformanceEntry): ReplayPerformanceEntry | null {
5353
if (ENTRY_TYPES[entry.entryType] === undefined) {
5454
return null;
5555
}
5656

5757
return ENTRY_TYPES[entry.entryType](entry);
5858
}
5959

60-
function getAbsoluteTime(time: number) {
60+
function getAbsoluteTime(time: number): number {
6161
// browserPerformanceTimeOrigin can be undefined if `performance` or
6262
// `performance.now` doesn't exist, but this is already checked by this integration
6363
return ((browserPerformanceTimeOrigin || window.performance.timeOrigin) + time) / 1000;
6464
}
6565

66+
// TODO: type definition!
67+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
6668
function createPaintEntry(entry: PerformancePaintTiming) {
6769
const { duration, entryType, name, startTime } = entry;
6870

@@ -75,6 +77,8 @@ function createPaintEntry(entry: PerformancePaintTiming) {
7577
};
7678
}
7779

80+
// TODO: type definition!
81+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7882
function createNavigationEntry(entry: PerformanceNavigationTiming) {
7983
// TODO: There looks to be some more interesting bits in here (domComplete, domContentLoaded)
8084
const { entryType, name, duration, domComplete, startTime, transferSize, type } = entry;
@@ -95,6 +99,9 @@ function createNavigationEntry(entry: PerformanceNavigationTiming) {
9599
},
96100
};
97101
}
102+
103+
// TODO: type definition!
104+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
98105
function createResourceEntry(entry: PerformanceResourceTiming) {
99106
const { entryType, initiatorType, name, responseEnd, startTime, encodedBodySize, transferSize } = entry;
100107

@@ -120,6 +127,8 @@ function createResourceEntry(entry: PerformanceResourceTiming) {
120127
};
121128
}
122129

130+
// TODO: type definition!
131+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
123132
function createLargestContentfulPaint(entry: PerformanceEntry & { size: number; element: Node }) {
124133
const { duration, entryType, startTime, size } = entry;
125134

@@ -139,6 +148,8 @@ function createLargestContentfulPaint(entry: PerformanceEntry & { size: number;
139148
};
140149
}
141150

151+
// TODO: type definition!
152+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
142153
export function createMemoryEntry(memoryEntry: MemoryInfo) {
143154
const { jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize } = memoryEntry;
144155
// we don't want to use `getAbsoluteTime` because it adds the event time to the

0 commit comments

Comments
 (0)