diff --git a/packages/core/src/js/client.ts b/packages/core/src/js/client.ts index a9aedfcd48..3762099ced 100644 --- a/packages/core/src/js/client.ts +++ b/packages/core/src/js/client.ts @@ -116,7 +116,7 @@ export class ReactNativeClient extends Client { public close(): PromiseLike { // As super.close() flushes queued events, we wait for that to finish before closing the native SDK. return super.close().then((result: boolean) => { - return NATIVE.closeNativeSdk().then(() => result) as PromiseLike; + return NATIVE.closeNativeSdk().then(() => result); }); } diff --git a/packages/core/src/js/touchevents.tsx b/packages/core/src/js/touchevents.tsx index aaf541dad1..c6eb78770c 100644 --- a/packages/core/src/js/touchevents.tsx +++ b/packages/core/src/js/touchevents.tsx @@ -283,7 +283,7 @@ function getFileName(props: Record): string | undefined { function getLabelValue(props: Record, labelKey: string | undefined): string | undefined { return typeof props[SENTRY_LABEL_PROP_KEY] === 'string' && props[SENTRY_LABEL_PROP_KEY].length > 0 - ? props[SENTRY_LABEL_PROP_KEY] as string + ? props[SENTRY_LABEL_PROP_KEY] // For some reason type narrowing doesn't work as expected with indexing when checking it all in one go in // the "check-label" if sentence, so we have to assign it to a variable here first : typeof labelKey === 'string' && typeof props[labelKey] == 'string' && (props[labelKey] as string).length > 0 diff --git a/packages/core/src/js/tracing/reactnativetracing.ts b/packages/core/src/js/tracing/reactnativetracing.ts index 74e56c51b2..aee9e79753 100644 --- a/packages/core/src/js/tracing/reactnativetracing.ts +++ b/packages/core/src/js/tracing/reactnativetracing.ts @@ -172,5 +172,5 @@ export function getCurrentReactNativeTracingIntegration(): ReactNativeTracingInt * Returns React Native Tracing integration of given client. */ export function getReactNativeTracingIntegration(client: Client): ReactNativeTracingIntegration | undefined { - return client.getIntegrationByName(INTEGRATION_NAME) as ReactNativeTracingIntegration | undefined; + return client.getIntegrationByName(INTEGRATION_NAME); } diff --git a/packages/core/src/js/tracing/reactnavigation.ts b/packages/core/src/js/tracing/reactnavigation.ts index 28666b0f89..ff5b98f80b 100644 --- a/packages/core/src/js/tracing/reactnavigation.ts +++ b/packages/core/src/js/tracing/reactnavigation.ts @@ -177,7 +177,7 @@ export const reactNavigationIntegration = ({ debug.log(`${INTEGRATION_NAME} Navigation container ref is the same as the one already registered.`); return; } - navigationContainer = newNavigationContainer as NavigationContainer; + navigationContainer = newNavigationContainer; if (!navigationContainer) { debug.warn(`${INTEGRATION_NAME} Received invalid navigation container ref!`); diff --git a/packages/core/src/js/wrapper.ts b/packages/core/src/js/wrapper.ts index 6829182298..77cec4865b 100644 --- a/packages/core/src/js/wrapper.ts +++ b/packages/core/src/js/wrapper.ts @@ -259,6 +259,7 @@ export const NATIVE: SentryNativeWrapper = { throw this._NativeClientError; } const ignoreErrorsStr = options.ignoreErrors?.filter(item => typeof item === 'string') as string[] | undefined; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const ignoreErrorsRegex = options.ignoreErrors ?.filter(item => item instanceof RegExp) .map(item => (item as RegExp).source) as string[] | undefined; diff --git a/packages/core/test/integrations/logEnricherIntegration.test.ts b/packages/core/test/integrations/logEnricherIntegration.test.ts index 7834d19a78..3b83726fca 100644 --- a/packages/core/test/integrations/logEnricherIntegration.test.ts +++ b/packages/core/test/integrations/logEnricherIntegration.test.ts @@ -161,7 +161,7 @@ describe('LogEnricher Integration', () => { // Extract the log handler const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - logHandler = beforeCaptureLogCall![1] as (log: Log) => void; + logHandler = beforeCaptureLogCall[1]; mockLog = { message: 'Test log message', @@ -245,7 +245,7 @@ describe('LogEnricher Integration', () => { const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - const newLogHandler = beforeCaptureLogCall![1] as (log: Log) => void; + const newLogHandler = beforeCaptureLogCall[1]; newLogHandler(mockLog); @@ -291,7 +291,7 @@ describe('LogEnricher Integration', () => { const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - const emptyLogHandler = beforeCaptureLogCall![1] as (log: Log) => void; + const emptyLogHandler = beforeCaptureLogCall[1]; emptyLogHandler(mockLog); @@ -323,7 +323,7 @@ describe('LogEnricher Integration', () => { const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - const partialLogHandler = beforeCaptureLogCall![1] as (log: Log) => void; + const partialLogHandler = beforeCaptureLogCall[1]; partialLogHandler(mockLog); @@ -357,7 +357,7 @@ describe('LogEnricher Integration', () => { const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - const partialLogHandler = beforeCaptureLogCall![1] as (log: Log) => void; + const partialLogHandler = beforeCaptureLogCall[1]; partialLogHandler(mockLog); @@ -447,7 +447,7 @@ describe('LogEnricher Integration', () => { const beforeCaptureLogCall = mockOn.mock.calls.find(call => call[0] === 'beforeCaptureLog'); expect(beforeCaptureLogCall).toBeDefined(); - logHandler = beforeCaptureLogCall![1] as (log: Log) => void; + logHandler = beforeCaptureLogCall[1]; mockLog = { message: 'Test log message', diff --git a/packages/core/test/tracing/addTracingExtensions.test.ts b/packages/core/test/tracing/addTracingExtensions.test.ts index b413ffd429..c79c0624fc 100644 --- a/packages/core/test/tracing/addTracingExtensions.test.ts +++ b/packages/core/test/tracing/addTracingExtensions.test.ts @@ -15,7 +15,7 @@ describe('Tracing extensions', () => { test('transaction has default op', async () => { const transaction = startSpanManual({ name: 'parent' }, span => span); - expect(spanToJSON(transaction!)).toEqual( + expect(spanToJSON(transaction)).toEqual( expect.objectContaining({ op: 'default', }), @@ -25,7 +25,7 @@ describe('Tracing extensions', () => { test('transaction does not overwrite custom op', async () => { const transaction = startSpanManual({ name: 'parent', op: 'custom' }, span => span); - expect(spanToJSON(transaction!)).toEqual( + expect(spanToJSON(transaction)).toEqual( expect.objectContaining({ op: 'custom', }), @@ -36,7 +36,7 @@ describe('Tracing extensions', () => { startSpanManual({ name: 'parent', scope: getCurrentScope() }, () => {}); const span = startSpanManual({ name: 'child', scope: getCurrentScope() }, span => span); - expect(spanToJSON(span!)).toEqual( + expect(spanToJSON(span)).toEqual( expect.objectContaining({ op: 'default', }), @@ -47,7 +47,7 @@ describe('Tracing extensions', () => { startSpanManual({ name: 'parent', op: 'custom', scope: getCurrentScope() }, () => {}); const span = startSpanManual({ name: 'child', op: 'custom', scope: getCurrentScope() }, span => span); - expect(spanToJSON(span!)).toEqual( + expect(spanToJSON(span)).toEqual( expect.objectContaining({ op: 'custom', }), @@ -60,22 +60,22 @@ describe('Tracing extensions', () => { childSpan = startSpanManual({ name: 'child', scope: getCurrentScope() }, __span => __span); return _span; }); - childSpan!.end(); - transaction!.end(); + childSpan.end(); + transaction.end(); await client.flush(); expect(client.event).toEqual( expect.objectContaining({ contexts: expect.objectContaining({ trace: expect.objectContaining({ - trace_id: transaction!.spanContext().traceId, + trace_id: transaction.spanContext().traceId, }), }), }), ); - expect(spanToJSON(childSpan!)).toEqual( + expect(spanToJSON(childSpan)).toEqual( expect.objectContaining({ - parent_span_id: spanToJSON(transaction!).span_id, + parent_span_id: spanToJSON(transaction).span_id, }), ); }); diff --git a/packages/core/test/tracing/integrations/appStart.test.ts b/packages/core/test/tracing/integrations/appStart.test.ts index 9d62708d06..f017d2b113 100644 --- a/packages/core/test/tracing/integrations/appStart.test.ts +++ b/packages/core/test/tracing/integrations/appStart.test.ts @@ -1197,7 +1197,7 @@ function expectEventWithStandaloneColdAppStart( timestamp: expect.any(Number), trace_id: expect.any(String), span_id: expect.any(String), - parent_span_id: actualEvent!.contexts!.trace!.span_id, + parent_span_id: actualEvent.contexts.trace.span_id, origin: SPAN_ORIGIN_AUTO_APP_START, status: 'ok', data: { @@ -1248,7 +1248,7 @@ function expectEventWithStandaloneWarmAppStart( timestamp: expect.any(Number), trace_id: expect.any(String), span_id: expect.any(String), - parent_span_id: actualEvent!.contexts!.trace!.span_id, + parent_span_id: actualEvent.contexts.trace.span_id, origin: SPAN_ORIGIN_AUTO_APP_START, status: 'ok', data: { diff --git a/packages/core/test/tracing/integrations/stallTracking/stalltracking.test.ts b/packages/core/test/tracing/integrations/stallTracking/stalltracking.test.ts index e357984fe7..ea4cba19d2 100644 --- a/packages/core/test/tracing/integrations/stallTracking/stalltracking.test.ts +++ b/packages/core/test/tracing/integrations/stallTracking/stalltracking.test.ts @@ -153,7 +153,7 @@ describe('StallTracking', () => { jest.runOnlyPendingTimers(); }); jest.runOnlyPendingTimers(); - rootSpan!.end(childSpanEnd); + rootSpan.end(childSpanEnd); await client.flush(); @@ -169,7 +169,7 @@ describe('StallTracking', () => { jest.runOnlyPendingTimers(); }); jest.runOnlyPendingTimers(); - rootSpan!.end(childSpanEnd! + 20); + rootSpan.end(childSpanEnd! + 20); await client.flush(); diff --git a/packages/core/test/tracing/integrations/userInteraction.test.ts b/packages/core/test/tracing/integrations/userInteraction.test.ts index 19a65c4071..04af7738fe 100644 --- a/packages/core/test/tracing/integrations/userInteraction.test.ts +++ b/packages/core/test/tracing/integrations/userInteraction.test.ts @@ -212,7 +212,7 @@ describe('User Interaction Tracing', () => { op: 'different.op', }), ); - expect(firstTransactionEvent!.timestamp).toBeGreaterThanOrEqual(spanToJSON(secondTransaction!).start_timestamp!); + expect(firstTransactionEvent.timestamp).toBeGreaterThanOrEqual(spanToJSON(secondTransaction).start_timestamp); }); test('different UI event and same element finish first transaction with last span', () => { @@ -252,9 +252,9 @@ describe('User Interaction Tracing', () => { const firstTransactionContext = spanToJSON(firstTransaction!); const secondTransactionContext = spanToJSON(secondTransaction!); - expect(firstTransactionContext!.timestamp).toEqual(expect.any(Number)); - expect(secondTransactionContext!.timestamp).toEqual(expect.any(Number)); - expect(firstTransactionContext!.span_id).not.toEqual(secondTransactionContext!.span_id); + expect(firstTransactionContext.timestamp).toEqual(expect.any(Number)); + expect(secondTransactionContext.timestamp).toEqual(expect.any(Number)); + expect(firstTransactionContext.span_id).not.toEqual(secondTransactionContext.span_id); }); test('do not start UI event transaction if active transaction on scope', () => { @@ -297,7 +297,7 @@ describe('User Interaction Tracing', () => { timestamp: expect.any(Number), }), ); - expect(interactionTransactionContext!.timestamp).toBeLessThanOrEqual(routingTransactionContext!.start_timestamp!); + expect(interactionTransactionContext.timestamp).toBeLessThanOrEqual(routingTransactionContext.start_timestamp); }); test('does not start UI span when app is in background', () => { diff --git a/packages/core/test/tracing/reactnavigation.ttid.test.tsx b/packages/core/test/tracing/reactnavigation.ttid.test.tsx index 89bcc1015d..1a8a95dd67 100644 --- a/packages/core/test/tracing/reactnavigation.ttid.test.tsx +++ b/packages/core/test/tracing/reactnavigation.ttid.test.tsx @@ -285,10 +285,10 @@ describe('React Navigation - TTID', () => { TestRenderer.render(); mockRecordedTimeToDisplay({ ttidNavigation: { - [spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: nowInSeconds(), }, ttfd: { - [spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: nowInSeconds(), }, }); @@ -362,10 +362,10 @@ describe('React Navigation - TTID', () => { TestRenderer.render(); mockRecordedTimeToDisplay({ ttidNavigation: { - [spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: timestampInSeconds(), }, ttfd: { - [spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds() - 1, + [spanToJSON(getActiveSpan()).span_id]: timestampInSeconds() - 1, }, }); @@ -389,10 +389,10 @@ describe('React Navigation - TTID', () => { TestRenderer.render(); mockRecordedTimeToDisplay({ ttidNavigation: { - [spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: timestampInSeconds(), }, ttfd: { - [spanToJSON(getActiveSpan()!).span_id!]: timestampInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: timestampInSeconds(), }, }); @@ -489,7 +489,7 @@ describe('React Navigation - TTID', () => { timeToDisplayComponent.update(); mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(getActiveSpan()!).span_id!]: manualInitialDisplayEndTimestampMs / 1_000, + [spanToJSON(getActiveSpan()).span_id]: manualInitialDisplayEndTimestampMs / 1_000, }, }); @@ -670,7 +670,7 @@ describe('React Navigation - TTID', () => { function mockAutomaticTimeToDisplay(): void { mockRecordedTimeToDisplay({ ttidNavigation: { - [spanToJSON(getActiveSpan()!).span_id!]: nowInSeconds(), + [spanToJSON(getActiveSpan()).span_id]: nowInSeconds(), }, }); } diff --git a/packages/core/test/tracing/timetodisplay.test.tsx b/packages/core/test/tracing/timetodisplay.test.tsx index 4c6f6913ac..b66a4f8828 100644 --- a/packages/core/test/tracing/timetodisplay.test.tsx +++ b/packages/core/test/tracing/timetodisplay.test.tsx @@ -1,4 +1,4 @@ -import type { Event, Measurements, Span, SpanJSON} from '@sentry/core'; +import type { Event, Measurements, Span, SpanJSON } from '@sentry/core'; import { debug , getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, spanToJSON, startSpanManual } from '@sentry/core'; jest.spyOn(debug, 'warn'); @@ -71,7 +71,7 @@ describe('TimeToDisplay', () => { render(); mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, }); @@ -102,10 +102,10 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, ttfd: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, }); @@ -134,7 +134,7 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttfd: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, }); @@ -164,7 +164,7 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, }); @@ -195,10 +195,10 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, ttfd: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, }); @@ -230,10 +230,10 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttid: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds(), + [spanToJSON(activeSpan).span_id]: nowInSeconds(), }, ttfd: { - [spanToJSON(activeSpan!).span_id!]: nowInSeconds() + 40, + [spanToJSON(activeSpan).span_id]: nowInSeconds() + 40, }, }); @@ -270,10 +270,10 @@ describe('TimeToDisplay', () => { mockRecordedTimeToDisplay({ ttfd: { - [spanToJSON(activeSpan!).span_id!]: fullDisplayEndTimestampMs / 1_000, + [spanToJSON(activeSpan).span_id]: fullDisplayEndTimestampMs / 1_000, }, ttid: { - [spanToJSON(activeSpan!).span_id!]: initialDisplayEndTimestampMs / 1_000, + [spanToJSON(activeSpan).span_id]: initialDisplayEndTimestampMs / 1_000, }, });