Skip to content

Commit 050a636

Browse files
authored
ref: Add no-class-field-initializers eslint rule (#8700)
Adding a lint rule (see #5316) to enforce initializing of fields in constructor, to reduce bundle size of transpiled code (and streamline this a bit overall). Closes #5316
1 parent 6196bc5 commit 050a636

Some content is hidden

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

67 files changed

+400
-147
lines changed

packages/angular/src/errorhandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ class SentryErrorHandler implements AngularErrorHandler {
8383
protected readonly _options: ErrorHandlerOptions;
8484

8585
/* indicates if we already registered our the afterSendEvent handler */
86-
private _registeredAfterSendEventHandler = false;
86+
private _registeredAfterSendEventHandler;
8787

8888
public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) {
89+
this._registeredAfterSendEventHandler = false;
90+
8991
this._options = {
9092
logErrors: true,
9193
...options,

packages/angular/src/tracing.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,14 @@ export class TraceService implements OnDestroy {
145145
}),
146146
);
147147

148-
private _routingSpan: Span | null = null;
148+
private _routingSpan: Span | null;
149149

150-
private _subscription: Subscription = new Subscription();
150+
private _subscription: Subscription;
151151

152152
public constructor(private readonly _router: Router) {
153+
this._routingSpan = null;
154+
this._subscription = new Subscription();
155+
153156
this._subscription.add(this.navStart$.subscribe());
154157
this._subscription.add(this.resEnd$.subscribe());
155158
this._subscription.add(this.navEnd$.subscribe());

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class Breadcrumbs implements Integration {
5656
/**
5757
* @inheritDoc
5858
*/
59-
public name: string = Breadcrumbs.id;
59+
public name: string;
6060

6161
/**
6262
* Options of the breadcrumbs integration.
@@ -68,6 +68,7 @@ export class Breadcrumbs implements Integration {
6868
* @inheritDoc
6969
*/
7070
public constructor(options?: Partial<BreadcrumbsOptions>) {
71+
this.name = Breadcrumbs.id;
7172
this.options = {
7273
console: true,
7374
dom: true,

packages/browser/src/integrations/dedupe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ export class Dedupe implements Integration {
1111
/**
1212
* @inheritDoc
1313
*/
14-
public name: string = Dedupe.id;
14+
public name: string;
1515

1616
/**
1717
* @inheritDoc
1818
*/
1919
private _previousEvent?: Event;
2020

21+
public constructor() {
22+
this.name = Dedupe.id;
23+
}
24+
2125
/**
2226
* @inheritDoc
2327
*/

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class GlobalHandlers implements Integration {
3030
/**
3131
* @inheritDoc
3232
*/
33-
public name: string = GlobalHandlers.id;
33+
public name: string;
3434

3535
/** JSDoc */
3636
private readonly _options: GlobalHandlersIntegrations;
@@ -39,18 +39,21 @@ export class GlobalHandlers implements Integration {
3939
* Stores references functions to installing handlers. Will set to undefined
4040
* after they have been run so that they are not used twice.
4141
*/
42-
private _installFunc: Record<GlobalHandlersIntegrationsOptionKeys, (() => void) | undefined> = {
43-
onerror: _installGlobalOnErrorHandler,
44-
onunhandledrejection: _installGlobalOnUnhandledRejectionHandler,
45-
};
42+
private _installFunc: Record<GlobalHandlersIntegrationsOptionKeys, (() => void) | undefined>;
4643

4744
/** JSDoc */
4845
public constructor(options?: GlobalHandlersIntegrations) {
46+
this.name = GlobalHandlers.id;
4947
this._options = {
5048
onerror: true,
5149
onunhandledrejection: true,
5250
...options,
5351
};
52+
53+
this._installFunc = {
54+
onerror: _installGlobalOnErrorHandler,
55+
onunhandledrejection: _installGlobalOnUnhandledRejectionHandler,
56+
};
5457
}
5558
/**
5659
* @inheritDoc

packages/browser/src/integrations/httpcontext.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export class HttpContext implements Integration {
1313
/**
1414
* @inheritDoc
1515
*/
16-
public name: string = HttpContext.id;
16+
public name: string;
17+
18+
public constructor() {
19+
this.name = HttpContext.id;
20+
}
1721

1822
/**
1923
* @inheritDoc

packages/browser/src/integrations/linkederrors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LinkedErrors implements Integration {
2121
/**
2222
* @inheritDoc
2323
*/
24-
public readonly name: string = LinkedErrors.id;
24+
public readonly name: string;
2525

2626
/**
2727
* @inheritDoc
@@ -37,6 +37,7 @@ export class LinkedErrors implements Integration {
3737
* @inheritDoc
3838
*/
3939
public constructor(options: Partial<LinkedErrorsOptions> = {}) {
40+
this.name = LinkedErrors.id;
4041
this._key = options.key || DEFAULT_KEY;
4142
this._limit = options.limit || DEFAULT_LIMIT;
4243
}

packages/browser/src/integrations/trycatch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class TryCatch implements Integration {
5656
/**
5757
* @inheritDoc
5858
*/
59-
public name: string = TryCatch.id;
59+
public name: string;
6060

6161
/** JSDoc */
6262
private readonly _options: TryCatchOptions;
@@ -65,6 +65,7 @@ export class TryCatch implements Integration {
6565
* @inheritDoc
6666
*/
6767
public constructor(options?: Partial<TryCatchOptions>) {
68+
this.name = TryCatch.id;
6869
this._options = {
6970
XMLHttpRequest: true,
7071
eventTarget: true,

packages/browser/src/profiling/integration.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ import {
2222
* @experimental
2323
*/
2424
export class BrowserProfilingIntegration implements Integration {
25-
public readonly name: string = 'BrowserProfilingIntegration';
26-
public getCurrentHub?: () => Hub = undefined;
25+
public static id: string = 'BrowserProfilingIntegration';
26+
27+
public readonly name: string;
28+
29+
public getCurrentHub?: () => Hub;
30+
31+
public constructor() {
32+
this.name = BrowserProfilingIntegration.id;
33+
}
2734

2835
/**
2936
* @inheritDoc

packages/core/src/baseclient.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
9393
protected readonly _transport?: Transport;
9494

9595
/** Array of set up integrations. */
96-
protected _integrations: IntegrationIndex = {};
96+
protected _integrations: IntegrationIndex;
9797

9898
/** Indicates whether this client's integrations have been set up. */
99-
protected _integrationsInitialized: boolean = false;
99+
protected _integrationsInitialized: boolean;
100100

101101
/** Number of calls being processed */
102-
protected _numProcessing: number = 0;
102+
protected _numProcessing: number;
103103

104104
/** Holds flushable */
105-
private _outcomes: { [key: string]: number } = {};
105+
private _outcomes: { [key: string]: number };
106106

107107
// eslint-disable-next-line @typescript-eslint/ban-types
108-
private _hooks: Record<string, Function[]> = {};
108+
private _hooks: Record<string, Function[]>;
109109

110110
/**
111111
* Initializes this client instance.
@@ -114,6 +114,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
114114
*/
115115
protected constructor(options: O) {
116116
this._options = options;
117+
this._integrations = {};
118+
this._integrationsInitialized = false;
119+
this._numProcessing = 0;
120+
this._outcomes = {};
121+
this._hooks = {};
117122

118123
if (options.dsn) {
119124
this._dsn = makeDsn(options.dsn);

0 commit comments

Comments
 (0)