Skip to content

Commit c2e6ade

Browse files
committed
ref: Enable noUncheckedIndex TS config
1 parent 60dad34 commit c2e6ade

File tree

149 files changed

+650
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+650
-589
lines changed

dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ afterAll(() => {
99
conditionalTest({ min: 16 })('complex-router', () => {
1010
test('should construct correct url with multiple parameterized routers, when param is also contain in middle layer route and express used multiple middlewares with route', done => {
1111
// parse node.js major version
12-
const [major] = process.versions.node.split('.').map(Number);
12+
const [major = 0] = process.versions.node.split('.').map(Number);
1313
// Split test result base on major node version because regex d flag is support from node 16+
1414

1515
const EXPECTED_TRANSACTION =
@@ -36,7 +36,7 @@ conditionalTest({ min: 16 })('complex-router', () => {
3636

3737
test('should construct correct url with multiple parameterized routers, when param is also contain in middle layer route and express used multiple middlewares with route and original url has query params', done => {
3838
// parse node.js major version
39-
const [major] = process.versions.node.split('.').map(Number);
39+
const [major = 0] = process.versions.node.split('.').map(Number);
4040
// Split test result base on major node version because regex d flag is support from node 16+
4141
const EXPECTED_TRANSACTION =
4242
major >= 16
@@ -62,7 +62,7 @@ conditionalTest({ min: 16 })('complex-router', () => {
6262

6363
test('should construct correct url with multiple parameterized routers, when param is also contain in middle layer route and express used multiple middlewares with route and original url ends with trailing slash and has query params', done => {
6464
// parse node.js major version
65-
const [major] = process.versions.node.split('.').map(Number);
65+
const [major = 0] = process.versions.node.split('.').map(Number);
6666
// Split test result base on major node version because regex d flag is support from node 16+
6767
const EXPECTED_TRANSACTION =
6868
major >= 16

dev-packages/node-integration-tests/suites/express/multiple-routers/middle-layer-parameterized/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ afterAll(() => {
99
conditionalTest({ min: 16 })('middle-layer-parameterized', () => {
1010
test('should construct correct url with multiple parameterized routers, when param is also contain in middle layer route', done => {
1111
// parse node.js major version
12-
const [major] = process.versions.node.split('.').map(Number);
12+
const [major = 0] = process.versions.node.split('.').map(Number);
1313
// Split test result base on major node version because regex d flag is support from node 16+
1414
const EXPECTED_TRANSACTION =
1515
major >= 16

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => {
4444
.ignore('session')
4545
.expect({
4646
event: event => {
47-
for (const frame of event.exception?.values?.[0].stacktrace?.frames || []) {
47+
for (const frame of event.exception?.values?.[0]?.stacktrace?.frames || []) {
4848
expect(frame.vars).toBeUndefined();
4949
}
5050
},

dev-packages/node-integration-tests/suites/public-api/startSpan/with-nested-spans/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('should report finished spans as children of the root transaction.', done =
1010
.expect({
1111
transaction: transaction => {
1212
const rootSpanId = transaction.contexts?.trace?.span_id;
13-
const span3Id = transaction.spans?.[1].span_id;
13+
const span3Id = transaction.spans?.[1]?.span_id;
1414

1515
expect(rootSpanId).toEqual(expect.any(String));
1616
expect(span3Id).toEqual(expect.any(String));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.test.json",
3+
}

dev-packages/node-integration-tests/utils/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ export class TestEnv {
196196
* @returns The extracted envelope.
197197
*/
198198
public async getEnvelopeRequest(options?: DataCollectorOptions): Promise<Array<Record<string, unknown>>> {
199-
return (await this.getMultipleEnvelopeRequest({ ...options, count: 1 }))[0];
199+
const requests = await this.getMultipleEnvelopeRequest({ ...options, count: 1 });
200+
201+
if (!requests[0]) {
202+
throw new Error('No requests found');
203+
}
204+
205+
return requests[0];
200206
}
201207

202208
/**
@@ -239,7 +245,7 @@ export class TestEnv {
239245
.post('/api/1337/envelope/', body => {
240246
const envelope = parseEnvelope(body);
241247

242-
if (envelopeType.includes(envelope[1].type as EnvelopeItemType)) {
248+
if (envelopeType.includes(envelope[1]?.type as EnvelopeItemType)) {
243249
envelopes.push(envelope);
244250
} else {
245251
return false;
@@ -296,7 +302,7 @@ export class TestEnv {
296302
.post('/api/1337/envelope/', body => {
297303
const envelope = parseEnvelope(body);
298304

299-
if (options.envelopeType.includes(envelope[1].type as EnvelopeItemType)) {
305+
if (options.envelopeType.includes(envelope[1]?.type as EnvelopeItemType)) {
300306
reqCount++;
301307
return true;
302308
}

dev-packages/overhead-metrics/src/util/github.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const octokit = new Octokit({
1313
// log: console,
1414
});
1515

16-
const [, owner, repo] = (await Git.repository).split('/');
16+
const [, owner, repo] = (await Git.repository).split('/') as [string, string, string];
1717
const defaultArgs = { owner, repo };
1818

1919
async function downloadArtifact(url: string, path: string): Promise<void> {
@@ -51,15 +51,10 @@ async function tryAddOrUpdateComment(commentBuilder: PrCommentBuilder): Promise<
5151
For example, refs/heads/feature-branch-1.
5252
*/
5353
let prNumber: number | undefined;
54-
if (
55-
typeof process.env.GITHUB_REF == 'string' &&
56-
process.env.GITHUB_REF.length > 0 &&
57-
process.env.GITHUB_REF.startsWith('refs/pull/')
58-
) {
59-
prNumber = parseInt(process.env.GITHUB_REF.split('/')[2]);
60-
console.log(
61-
`Determined PR number ${prNumber} based on GITHUB_REF environment variable: '${process.env.GITHUB_REF}'`,
62-
);
54+
const githubRef = process.env.GITHUB_REF;
55+
if (typeof githubRef == 'string' && githubRef.length > 0 && githubRef.startsWith('refs/pull/')) {
56+
prNumber = parseInt(githubRef.split('/')[2] as string);
57+
console.log(`Determined PR number ${prNumber} based on GITHUB_REF environment variable: '${githubRef}'`);
6358
} else if (!(await Git.branchIsBase)) {
6459
prNumber = (
6560
await octokit.rest.pulls.list({
@@ -155,15 +150,17 @@ export const GitHub = {
155150
status: 'success',
156151
});
157152

158-
if (workflowRuns.data.total_count == 0) {
153+
const firstRun = workflowRuns.data.workflow_runs[0];
154+
155+
if (workflowRuns.data.total_count == 0 || !firstRun) {
159156
console.warn(`Couldn't find any successful run for workflow '${workflow.name}'`);
160157
return;
161158
}
162159

163160
const artifact = (
164161
await octokit.actions.listWorkflowRunArtifacts({
165162
...defaultArgs,
166-
run_id: workflowRuns.data.workflow_runs[0].id,
163+
run_id: firstRun.id,
167164
})
168165
).data.artifacts.find(it => it.name == artifactName);
169166

dev-packages/test-utils/src/event-proxy-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
5959
? zlib.gunzipSync(Buffer.concat(proxyRequestChunks)).toString()
6060
: Buffer.concat(proxyRequestChunks).toString();
6161

62-
const envelopeHeader: EnvelopeItem[0] = JSON.parse(proxyRequestBody.split('\n')[0]);
62+
const envelopeHeader: EnvelopeItem[0] = JSON.parse(proxyRequestBody.split('\n')[0] as string);
6363

6464
const shouldForwardEventToSentry = options.forwardToSentry != null ? options.forwardToSentry : true;
6565

packages/aws-serverless/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function tryPatchHandler(taskRoot: string, handlerPath: string): void {
141141
return;
142142
}
143143

144-
const [, handlerMod, handlerName] = match;
144+
const [, handlerMod = '', handlerName = ''] = match;
145145

146146
let obj: HandlerBag;
147147
try {

packages/aws-serverless/test/sdk.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ describe('AWSLambda', () => {
502502

503503
expect(evtProcessor).toBeInstanceOf(Function);
504504
// @ts-expect-error just mocking around...
505-
expect(evtProcessor(event).exception.values[0].mechanism).toEqual({
505+
expect(evtProcessor(event).exception.values[0]?.mechanism).toEqual({
506506
handled: false,
507507
type: 'generic',
508508
});

packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,22 @@ export function addPerformanceEntries(span: Span): void {
282282
_addTtfbRequestTimeToMeasurements(_measurements);
283283

284284
['fcp', 'fp', 'lcp'].forEach(name => {
285-
if (!_measurements[name] || !transactionStartTime || timeOrigin >= transactionStartTime) {
285+
const measurement = _measurements[name];
286+
if (!measurement || !transactionStartTime || timeOrigin >= transactionStartTime) {
286287
return;
287288
}
288289
// The web vitals, fcp, fp, lcp, and ttfb, all measure relative to timeOrigin.
289290
// Unfortunately, timeOrigin is not captured within the span span data, so these web vitals will need
290291
// to be adjusted to be relative to span.startTimestamp.
291-
const oldValue = _measurements[name].value;
292+
const oldValue = measurement.value;
292293
const measurementTimestamp = timeOrigin + msToSec(oldValue);
293294

294295
// normalizedValue should be in milliseconds
295296
const normalizedValue = Math.abs((measurementTimestamp - transactionStartTime) * 1000);
296297
const delta = normalizedValue - oldValue;
297298

298299
DEBUG_BUILD && logger.log(`[Measurements] Normalized ${name} from ${oldValue} to ${normalizedValue} (${delta})`);
299-
_measurements[name].value = normalizedValue;
300+
measurement.value = normalizedValue;
300301
});
301302

302303
const fidMark = _measurements['mark.fid'];
@@ -320,8 +321,8 @@ export function addPerformanceEntries(span: Span): void {
320321
delete _measurements.cls;
321322
}
322323

323-
Object.keys(_measurements).forEach(measurementName => {
324-
setMeasurement(measurementName, _measurements[measurementName].value, _measurements[measurementName].unit);
324+
Object.entries(_measurements).forEach(([measurementName, measurement]) => {
325+
setMeasurement(measurementName, measurement.value, measurement.unit);
325326
});
326327

327328
_tagMetricInfo(span);

packages/browser-utils/src/metrics/web-vitals/getCLS.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export const onCLS = (onReport: CLSReportCallback, opts: ReportOpts = {}): void
7070
// session.
7171
if (
7272
sessionValue &&
73+
firstSessionEntry &&
74+
lastSessionEntry &&
7375
entry.startTime - lastSessionEntry.startTime < 1000 &&
7476
entry.startTime - firstSessionEntry.startTime < 5000
7577
) {

packages/browser-utils/src/metrics/web-vitals/getINP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const processEntry = (entry: PerformanceEventTiming) => {
7474
if (
7575
existingInteraction ||
7676
longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER ||
77-
entry.duration > minLongestInteraction.latency
77+
(minLongestInteraction && entry.duration > minLongestInteraction.latency)
7878
) {
7979
// If the interaction already exists, update it. Otherwise create one.
8080
if (existingInteraction) {

packages/browser-utils/test/browser/browserMetrics.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe('_addResourceSpans', () => {
221221
},
222222
];
223223
for (let i = 0; i < table.length; i++) {
224-
const { initiatorType, op } = table[i];
224+
const { initiatorType, op } = table[i]!;
225225
const entry: ResourceEntry = {
226226
initiatorType,
227227
};
@@ -250,7 +250,7 @@ describe('_addResourceSpans', () => {
250250
_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);
251251

252252
expect(spans).toHaveLength(1);
253-
expect(spanToJSON(spans[0])).toEqual(
253+
expect(spanToJSON(spans[0]!)).toEqual(
254254
expect.objectContaining({
255255
data: {
256256
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'resource.css',
@@ -284,7 +284,7 @@ describe('_addResourceSpans', () => {
284284
_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);
285285

286286
expect(spans).toHaveLength(1);
287-
expect(spanToJSON(spans[0])).toEqual(
287+
expect(spanToJSON(spans[0]!)).toEqual(
288288
expect.objectContaining({
289289
data: {
290290
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'resource.css',
@@ -321,7 +321,7 @@ describe('_addResourceSpans', () => {
321321
_addResourceSpans(span, entry, resourceEntryName, 100, 23, 345);
322322

323323
expect(spans).toHaveLength(1);
324-
expect(spanToJSON(spans[0])).toEqual(
324+
expect(spanToJSON(spans[0]!)).toEqual(
325325
expect.objectContaining({
326326
data: {
327327
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'resource.css',

packages/browser/src/eventbuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function eventFromPlainObject(
8989
const frames = parseStackFrames(stackParser, syntheticException);
9090
if (frames.length) {
9191
// event.exception.values[0] has been set above
92-
event.exception.values[0].stacktrace = { frames };
92+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
93+
event.exception.values[0]!.stacktrace = { frames };
9394
}
9495
}
9596

packages/browser/src/integrations/httpclient.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,8 @@ function _fetchResponseHandler(
7777
let requestHeaders, responseHeaders, requestCookies, responseCookies;
7878

7979
if (_shouldSendDefaultPii()) {
80-
[{ headers: requestHeaders, cookies: requestCookies }, { headers: responseHeaders, cookies: responseCookies }] = [
81-
{ cookieHeader: 'Cookie', obj: request },
82-
{ cookieHeader: 'Set-Cookie', obj: response },
83-
].map(({ cookieHeader, obj }) => {
84-
const headers = _extractFetchHeaders(obj.headers);
85-
let cookies;
86-
87-
try {
88-
const cookieString = headers[cookieHeader] || headers[cookieHeader.toLowerCase()] || undefined;
89-
90-
if (cookieString) {
91-
cookies = _parseCookieString(cookieString);
92-
}
93-
} catch (e) {
94-
DEBUG_BUILD && logger.log(`Could not extract cookies from header ${cookieHeader}`);
95-
}
96-
97-
return {
98-
headers,
99-
cookies,
100-
};
101-
});
80+
[requestHeaders, requestCookies] = _parseCookieHeaders('Cookie', request);
81+
[responseHeaders, responseCookies] = _parseCookieHeaders('Set-Cookie', response);
10282
}
10383

10484
const event = _createEvent({
@@ -115,6 +95,26 @@ function _fetchResponseHandler(
11595
}
11696
}
11797

98+
function _parseCookieHeaders(
99+
cookieHeader: string,
100+
obj: Request | Response,
101+
): [Record<string, string>, Record<string, string> | undefined] {
102+
const headers = _extractFetchHeaders(obj.headers);
103+
let cookies;
104+
105+
try {
106+
const cookieString = headers[cookieHeader] || headers[cookieHeader.toLowerCase()] || undefined;
107+
108+
if (cookieString) {
109+
cookies = _parseCookieString(cookieString);
110+
}
111+
} catch (e) {
112+
DEBUG_BUILD && logger.log(`Could not extract cookies from header ${cookieHeader}`);
113+
}
114+
115+
return [headers, cookies];
116+
}
117+
118118
/**
119119
* Interceptor function for XHR requests
120120
*
@@ -192,7 +192,9 @@ function _getResponseSizeFromHeaders(headers?: Record<string, string>): number |
192192
function _parseCookieString(cookieString: string): Record<string, string> {
193193
return cookieString.split('; ').reduce((acc: Record<string, string>, cookie: string) => {
194194
const [key, value] = cookie.split('=');
195-
acc[key] = value;
195+
if (key && value) {
196+
acc[key] = value;
197+
}
196198
return acc;
197199
}, {});
198200
}
@@ -228,7 +230,9 @@ function _getXHRResponseHeaders(xhr: XMLHttpRequest): Record<string, string> {
228230

229231
return headers.split('\r\n').reduce((acc: Record<string, string>, line: string) => {
230232
const [key, value] = line.split(': ');
231-
acc[key] = value;
233+
if (key && value) {
234+
acc[key] = value;
235+
}
232236
return acc;
233237
}, {});
234238
}

0 commit comments

Comments
 (0)