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;

packages/core/test/mocks/backend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export class TestBackend extends BaseBackend<TestOptions> {
2626
exception: {
2727
values: [
2828
{
29+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2930
type: exception.name,
3031
value: exception.message,
32+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
3133
},
3234
],
3335
},

packages/hub/src/hub.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class Hub implements HubInterface {
390390
private _invokeClient<M extends keyof Client>(method: M, ...args: any[]): void {
391391
const top = this.getStackTop();
392392
if (top && top.client && top.client[method]) {
393-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
393+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
394394
(top.client as any)[method](...args, top.scope);
395395
}
396396
}
@@ -470,6 +470,7 @@ function getHubFromActiveDomain(registry: Carrier): Hub {
470470
}
471471
// eslint-disable-next-line @typescript-eslint/no-explicit-any
472472
const domain = sentry.extensions[property] as any;
473+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
473474
const activeDomain = domain.active;
474475

475476
// If there no active domain, just return global hub

packages/integrations/src/angular.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Angular implements Integration {
4141
*/
4242
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4343
public constructor(options: { angular?: any } = {}) {
44-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
4545
this._angular = options.angular || getGlobalObject<any>().angular;
4646
}
4747

@@ -56,10 +56,12 @@ export class Angular implements Integration {
5656

5757
this._getCurrentHub = getCurrentHub;
5858

59+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5960
this._angular.module(Angular.moduleName, []).config([
6061
'$provide',
6162
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6263
($provide: any): void => {
64+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6365
$provide.decorator('$exceptionHandler', ['$delegate', this._$exceptionHandlerDecorator.bind(this)]);
6466
},
6567
]);

packages/integrations/src/ember.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Ember implements Integration {
2424
*/
2525
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2626
public constructor(options: { Ember?: any } = {}) {
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
2828
this._Ember = options.Ember || getGlobalObject<any>().Ember;
2929
}
3030

@@ -37,6 +37,7 @@ export class Ember implements Integration {
3737
return;
3838
}
3939

40+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
4041
const oldOnError = this._Ember.onerror;
4142

4243
this._Ember.onerror = (error: Error): void => {
@@ -66,4 +67,5 @@ export class Ember implements Integration {
6667
}
6768
});
6869
}
70+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
6971
}

packages/integrations/src/reportingobserver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ export class ReportingObserver implements Integration {
8989

9090
this._getCurrentHub = getCurrentHub;
9191

92+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
9293
const observer = new (getGlobalObject<any>().ReportingObserver)(this.handler.bind(this), {
9394
buffered: true,
9495
types: this._options.types,
9596
});
9697

98+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
9799
observer.observe();
98100
}
99101

packages/integrations/src/vue.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export class Vue implements Integration {
153153
*/
154154
public constructor(options: Partial<IntegrationOptions>) {
155155
this._options = {
156+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
156157
Vue: getGlobalObject<any>().Vue,
157158
attachProps: true,
158159
logErrors: false,
@@ -255,6 +256,7 @@ export class Vue implements Integration {
255256

256257
// We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency.
257258
// We also need to ask for the `.constructor`, as `pushActivity` and `popActivity` are static, not instance methods.
259+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
258260
// eslint-disable-next-line deprecation/deprecation
259261
const tracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);
260262
if (tracingIntegration) {
@@ -276,6 +278,7 @@ export class Vue implements Integration {
276278
});
277279
}
278280
}
281+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
279282
});
280283
}
281284
};
@@ -351,6 +354,7 @@ export class Vue implements Integration {
351354
// eslint-disable-next-line deprecation/deprecation
352355
const tracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);
353356
if (tracingIntegration) {
357+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
354358
(tracingIntegration as any).constructor.popActivity(this._tracingActivity);
355359
}
356360
}

packages/node/src/handlers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function tracingHandler(): (
6464

6565
// We also set __sentry_transaction on the response so people can grab the transaction there to add
6666
// spans to it later.
67+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
6768
(res as any).__sentry_transaction = transaction;
6869

6970
res.once('finish', () => {
@@ -411,11 +412,13 @@ export function errorHandler(options?: {
411412
if (shouldHandleError(error)) {
412413
withScope(_scope => {
413414
// For some reason we need to set the transaction on the scope again
415+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
414416
const transaction = (res as any).__sentry_transaction as Span;
415417
if (transaction && _scope.getSpan() === undefined) {
416418
_scope.setSpan(transaction);
417419
}
418420
const eventId = captureException(error);
421+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
419422
(res as any).sentry = eventId;
420423
next(error);
421424
});

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function createHandlerWrapper(
9393
}
9494
}
9595

96+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
9697
return originalHandler
9798
.apply(this, arguments)
9899
.once('response', function(this: http.IncomingMessage, res: http.ServerResponse): void {

packages/node/src/integrations/onunhandledrejection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class OnUnhandledRejection implements Integration {
5252
return;
5353
}
5454

55+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
5556
const context = (promise.domain && promise.domain.sentryContext) || {};
5657

5758
hub.withScope((scope: Scope) => {
@@ -70,6 +71,7 @@ export class OnUnhandledRejection implements Integration {
7071

7172
hub.captureException(reason, { originalException: promise });
7273
});
74+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
7375

7476
this._handleRejection(reason);
7577
}
@@ -90,6 +92,7 @@ export class OnUnhandledRejection implements Integration {
9092
if (this._options.mode === 'warn') {
9193
consoleSandbox(() => {
9294
console.warn(rejectionWarning);
95+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
9396
console.error(reason && reason.stack ? reason.stack : reason);
9497
});
9598
} else if (this._options.mode === 'strict') {

packages/node/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function init(options: NodeOptions = {}): void {
101101
options.environment = process.env.SENTRY_ENVIRONMENT;
102102
}
103103

104-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
104+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
105105
if ((domain as any).active) {
106106
setHubOnCarrier(getMainCarrier(), getCurrentHub());
107107
}

packages/react/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ module.exports = {
3232
],
3333
rules: {
3434
'react/prop-types': 'off',
35+
'@typescript-eslint/no-unsafe-member-access': 'off',
3536
},
3637
};

packages/react/src/profiler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type ProfilerProps = {
7878
// If component updates should be displayed as spans. True by default.
7979
includeUpdates?: boolean;
8080
// props given to component being profiled.
81-
updateProps: { [key: string]: any };
81+
updateProps: { [key: string]: unknown };
8282
};
8383

8484
/**

packages/tracing/src/browser/request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ export function _fetchCallback(
166166
headers = (request as Request).headers;
167167
}
168168
if (headers) {
169+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
169170
if (typeof headers.append === 'function') {
171+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
170172
headers.append('sentry-trace', span.toTraceparent());
171173
} else if (Array.isArray(headers)) {
172174
headers = [...headers, ['sentry-trace', span.toTraceparent()]];

0 commit comments

Comments
 (0)