Skip to content

Commit d089690

Browse files
committed
Add unsafe any rule
1 parent 894e402 commit d089690

File tree

29 files changed

+68
-6
lines changed

29 files changed

+68
-6
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ module.exports = {
9393

9494
// We should prevent against overloads unless necessary.
9595
'@typescript-eslint/unified-signatures': 'error',
96+
97+
// Disallow unsafe any usage. We should enforce that types be used as possible, or unknown be used
98+
// instead of any. This is especially important for methods that expose a public API, as users
99+
// should know exactly what they have to provide to use those methods. Turned off in tests.
100+
'@typescript-eslint/no-unsafe-member-access': 'error',
96101
},
97102
},
98103
{
@@ -125,6 +130,7 @@ module.exports = {
125130
'@typescript-eslint/explicit-function-return-type': 'off',
126131
'no-unused-expressions': 'off',
127132
'@typescript-eslint/no-unused-expressions': 'off',
133+
'@typescript-eslint/no-unsafe-member-access': 'off',
128134
},
129135
},
130136
{

packages/angular/src/tracing.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class TraceDirective implements OnInit, AfterViewInit {
146146
export function TraceClassDecorator(): ClassDecorator {
147147
let tracingSpan: Span;
148148

149+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
149150
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
150151
return target => {
151152
const originalOnInit = target.prototype.ngOnInit;
@@ -174,6 +175,7 @@ export function TraceClassDecorator(): ClassDecorator {
174175
}
175176
};
176177
};
178+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
177179
}
178180

179181
/**
@@ -196,6 +198,7 @@ export function TraceMethodDecorator(): MethodDecorator {
196198
});
197199
}
198200
if (originalMethod) {
201+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
199202
return originalMethod.apply(this, args);
200203
}
201204
};

packages/apm/src/integrations/tracing.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ export class Tracing implements Integration {
630630
let entryScriptStartEndTime: number | undefined;
631631
let tracingInitMarkStartTime: number | undefined;
632632

633+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
633634
performance
634635
.getEntries()
635636
.slice(Tracing._performanceCursor)
@@ -687,6 +688,7 @@ export class Tracing implements Integration {
687688
// Ignore other entry types.
688689
}
689690
});
691+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
690692

691693
if (entryScriptStartEndTime !== undefined && tracingInitMarkStartTime !== undefined) {
692694
_startChild(transactionSpan, {
@@ -771,6 +773,7 @@ export class Tracing implements Integration {
771773
return time / 1000;
772774
}
773775

776+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
774777
/**
775778
* Adds debug data to the span
776779
*/
@@ -792,6 +795,7 @@ export class Tracing implements Integration {
792795
debugData['Date.now()'] = Date.now();
793796
span.setData('sentry_debug', debugData);
794797
}
798+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
795799

796800
/**
797801
* @inheritDoc
@@ -934,6 +938,7 @@ export class Tracing implements Integration {
934938
}
935939
}
936940

941+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
937942
/**
938943
* Creates breadcrumbs from XHR API calls
939944
*/
@@ -1038,6 +1043,7 @@ function fetchCallback(handlerData: { [key: string]: any }): void {
10381043
}
10391044
}
10401045
}
1046+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
10411047

10421048
/**
10431049
* Creates transaction from navigation changes

packages/browser/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
'max-lines': 'off',
2525
'prefer-template': 'off',
2626
'no-unused-expressions': 'off',
27+
'guard-for-in': 'off',
2728
},
2829
},
2930
{

packages/browser/src/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ export function wrap(
6969
before.apply(this, arguments);
7070
}
7171

72-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
7373
const wrappedArguments = args.map((arg: any) => wrap(arg, options));
7474

7575
if (fn.handleEvent) {
7676
// Attempt to invoke user-land function
7777
// NOTE: If you are a Sentry user, and you are seeing this stack frame, it
7878
// means the sentry.javascript SDK caught an error invoking your application code. This
7979
// is expected behavior and NOT indicative of a bug with sentry.javascript.
80+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8081
return fn.handleEvent.apply(this, wrappedArguments);
8182
}
8283
// Attempt to invoke user-land function

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
/* eslint-disable max-lines */
23
import { getCurrentHub } from '@sentry/core';
34
import { Event, Integration, Severity } from '@sentry/types';

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
import { getCurrentHub } from '@sentry/core';
23
import { Event, Integration, Severity } from '@sentry/types';
34
import {

packages/browser/src/integrations/trycatch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class TryCatch implements Integration {
125125
private _wrapRAF(original: any): (callback: () => void) => any {
126126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
127127
return function(this: any, callback: () => void): () => void {
128+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
128129
return original.call(
129130
this,
130131
wrap(callback, {
@@ -145,8 +146,10 @@ export class TryCatch implements Integration {
145146
private _wrapEventTarget(target: string): void {
146147
// eslint-disable-next-line @typescript-eslint/no-explicit-any
147148
const global = getGlobalObject() as { [key: string]: any };
149+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
148150
const proto = global[target] && global[target].prototype;
149151

152+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
150153
if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
151154
return;
152155
}

packages/browser/src/tracekit.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* largely modified and is now maintained as part of Sentry JS SDK.
44
*/
55

6+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
7+
68
/**
79
* An object representing a single stack frame.
810
* {Object} StackFrame

packages/core/src/baseclient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
330330
// so this block overwrites the normalized event to add back the original
331331
// Transaction information prior to normalization.
332332
if (event.contexts && event.contexts.trace) {
333+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
333334
normalized.contexts.trace = event.contexts.trace;
334335
}
335336
return normalized;

0 commit comments

Comments
 (0)