Skip to content

Commit 7783de0

Browse files
committed
ref: Avoid optional chaining
1 parent 48a7ca5 commit 7783de0

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

packages/react/src/reactrouterv6.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {
226226

227227
// A value with stable identity to either pick `locationArg` if available or `location` if not
228228
const stableLocationParam =
229-
typeof locationArg === 'string' || locationArg?.pathname !== undefined
229+
typeof locationArg === 'string' || locationArg && locationArg.pathname !== undefined
230230
? (locationArg as { pathname: string })
231231
: location;
232232

packages/tracing/.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports = {
22
extends: ['../../.eslintrc.js'],
3+
overrides: [
4+
{
5+
files: ['src/integrations/node/**'],
6+
rules: {
7+
'@sentry-internal/sdk/no-optional-chaining': 'off',
8+
},
9+
},
10+
],
311
};

packages/tracing/src/browser/browsertracing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
9090
*
9191
* Default: undefined
9292
*/
93-
_experiments?: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>;
93+
_experiments: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>;
9494

9595
/**
9696
* beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction
@@ -170,7 +170,7 @@ export class BrowserTracing implements Integration {
170170
}
171171

172172
startTrackingWebVitals();
173-
if (this.options._experiments?.enableLongTask) {
173+
if (this.options._experiments.enableLongTask) {
174174
startTrackingLongTasks();
175175
}
176176
}
@@ -203,7 +203,7 @@ export class BrowserTracing implements Integration {
203203
registerBackgroundTabDetection();
204204
}
205205

206-
if (_experiments?.enableInteractions) {
206+
if (_experiments.enableInteractions) {
207207
this._registerInteractionListener();
208208
}
209209

@@ -258,7 +258,7 @@ export class BrowserTracing implements Integration {
258258
: finalContext.metadata;
259259

260260
this._latestRouteName = finalContext.name;
261-
this._latestRouteSource = finalContext.metadata?.source;
261+
this._latestRouteSource = finalContext.metadata && finalContext.metadata.source;
262262

263263
if (finalContext.sampled === false) {
264264
__DEBUG_BUILD__ &&

packages/utils/src/requestdata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ export function addRequestDataToEvent(
295295
): Event {
296296
const include = {
297297
...DEFAULT_INCLUDES,
298-
...options?.include,
298+
...(options ? options.include : undefined),
299299
};
300300

301301
if (include.request) {
302302
const extractedRequestData = Array.isArray(include.request)
303-
? extractRequestData(req, { include: include.request, deps: options?.deps })
304-
: extractRequestData(req, { deps: options?.deps });
303+
? extractRequestData(req, { include: include.request, deps: options ? options.deps : undefined })
304+
: extractRequestData(req, { deps: options ? options.deps : undefined });
305305

306306
event.request = {
307307
...event.request,

packages/utils/src/stacktrace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function node(getModule?: GetModuleFn): StackLineParserFn {
168168
functionName = typeName ? `${typeName}.${methodName}` : methodName;
169169
}
170170

171-
const filename = lineMatch[2]?.startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
171+
const filename = lineMatch[2] && lineMatch[2].startsWith('file://') ? lineMatch[2].slice(7) : lineMatch[2];
172172
const isNative = lineMatch[5] === 'native';
173173
const isInternal =
174174
isNative || (filename && !filename.startsWith('/') && !filename.startsWith('.') && filename.indexOf(':\\') !== 1);
@@ -180,7 +180,7 @@ function node(getModule?: GetModuleFn): StackLineParserFn {
180180

181181
return {
182182
filename,
183-
module: getModule?.(filename),
183+
module: getModule ? getModule(filename) : undefined,
184184
function: functionName,
185185
lineno: parseInt(lineMatch[3], 10) || undefined,
186186
colno: parseInt(lineMatch[4], 10) || undefined,

packages/vue/src/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const formatComponentName = (vm?: ViewModel, includeFile?: boolean): stri
4343
};
4444

4545
export const generateComponentTrace = (vm?: ViewModel): string => {
46-
if ((vm?._isVue || vm?.__isVue) && vm?.$parent) {
46+
if (vm && (vm._isVue || vm.__isVue) && vm.$parent) {
4747
const tree = [];
4848
let currentRecursiveSequence = 0;
4949
while (vm) {

packages/vue/src/tracing.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const HOOKS: { [key in Operation]: Hook[] } = {
3030

3131
/** Grabs active transaction off scope, if any */
3232
export function getActiveTransaction(): Transaction | undefined {
33-
return getCurrentHub().getScope()?.getTransaction();
33+
const scope = getCurrentHub().getScope();
34+
return scope && scope.getTransaction();
3435
}
3536

3637
/** Finish top-level span and activity with a debounce configured using `timeout` option */
@@ -40,7 +41,7 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void
4041
}
4142

4243
vm.$_sentryRootSpanTimer = setTimeout(() => {
43-
if (vm.$root?.$_sentryRootSpan) {
44+
if (vm.$root.$_sentryRootSpan) {
4445
vm.$root.$_sentryRootSpan.finish(timestamp);
4546
vm.$root.$_sentryRootSpan = undefined;
4647
}
@@ -96,7 +97,7 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
9697
// Start a new span if current hook is a 'before' hook.
9798
// Otherwise, retrieve the current span and finish it.
9899
if (internalHook == internalHooks[0]) {
99-
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction();
100+
const activeTransaction = this.$root.$_sentryRootSpan || getActiveTransaction();
100101
if (activeTransaction) {
101102
// Cancel old span for this hook operation in case it didn't get cleaned up. We're not actually sure if it
102103
// will ever be the case that cleanup hooks re not called, but we had users report that spans didn't get

0 commit comments

Comments
 (0)