Skip to content

ref: Add no-class-field-initializers eslint rule #8700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/angular/src/errorhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ class SentryErrorHandler implements AngularErrorHandler {
protected readonly _options: ErrorHandlerOptions;

/* indicates if we already registered our the afterSendEvent handler */
private _registeredAfterSendEventHandler = false;
private _registeredAfterSendEventHandler;

public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) {
this._registeredAfterSendEventHandler = false;

this._options = {
logErrors: true,
...options,
Expand Down
7 changes: 5 additions & 2 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ export class TraceService implements OnDestroy {
}),
);

private _routingSpan: Span | null = null;
private _routingSpan: Span | null;

private _subscription: Subscription = new Subscription();
private _subscription: Subscription;

public constructor(private readonly _router: Router) {
this._routingSpan = null;
this._subscription = new Subscription();

this._subscription.add(this.navStart$.subscribe());
this._subscription.add(this.resEnd$.subscribe());
this._subscription.add(this.navEnd$.subscribe());
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Breadcrumbs implements Integration {
/**
* @inheritDoc
*/
public name: string = Breadcrumbs.id;
public name: string;

/**
* Options of the breadcrumbs integration.
Expand All @@ -68,6 +68,7 @@ export class Breadcrumbs implements Integration {
* @inheritDoc
*/
public constructor(options?: Partial<BreadcrumbsOptions>) {
this.name = Breadcrumbs.id;
this.options = {
console: true,
dom: true,
Expand Down
6 changes: 5 additions & 1 deletion packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ export class Dedupe implements Integration {
/**
* @inheritDoc
*/
public name: string = Dedupe.id;
public name: string;

/**
* @inheritDoc
*/
private _previousEvent?: Event;

public constructor() {
this.name = Dedupe.id;
}

/**
* @inheritDoc
*/
Expand Down
13 changes: 8 additions & 5 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GlobalHandlers implements Integration {
/**
* @inheritDoc
*/
public name: string = GlobalHandlers.id;
public name: string;

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

/** JSDoc */
public constructor(options?: GlobalHandlersIntegrations) {
this.name = GlobalHandlers.id;
this._options = {
onerror: true,
onunhandledrejection: true,
...options,
};

this._installFunc = {
onerror: _installGlobalOnErrorHandler,
onunhandledrejection: _installGlobalOnUnhandledRejectionHandler,
};
}
/**
* @inheritDoc
Expand Down
6 changes: 5 additions & 1 deletion packages/browser/src/integrations/httpcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class HttpContext implements Integration {
/**
* @inheritDoc
*/
public name: string = HttpContext.id;
public name: string;

public constructor() {
this.name = HttpContext.id;
}

/**
* @inheritDoc
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class LinkedErrors implements Integration {
/**
* @inheritDoc
*/
public readonly name: string = LinkedErrors.id;
public readonly name: string;

/**
* @inheritDoc
Expand All @@ -37,6 +37,7 @@ export class LinkedErrors implements Integration {
* @inheritDoc
*/
public constructor(options: Partial<LinkedErrorsOptions> = {}) {
this.name = LinkedErrors.id;
this._key = options.key || DEFAULT_KEY;
this._limit = options.limit || DEFAULT_LIMIT;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/integrations/trycatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TryCatch implements Integration {
/**
* @inheritDoc
*/
public name: string = TryCatch.id;
public name: string;

/** JSDoc */
private readonly _options: TryCatchOptions;
Expand All @@ -65,6 +65,7 @@ export class TryCatch implements Integration {
* @inheritDoc
*/
public constructor(options?: Partial<TryCatchOptions>) {
this.name = TryCatch.id;
this._options = {
XMLHttpRequest: true,
eventTarget: true,
Expand Down
11 changes: 9 additions & 2 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ import {
* @experimental
*/
export class BrowserProfilingIntegration implements Integration {
public readonly name: string = 'BrowserProfilingIntegration';
public getCurrentHub?: () => Hub = undefined;
public static id: string = 'BrowserProfilingIntegration';

public readonly name: string;

public getCurrentHub?: () => Hub;

public constructor() {
this.name = BrowserProfilingIntegration.id;
}

/**
* @inheritDoc
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
protected readonly _transport?: Transport;

/** Array of set up integrations. */
protected _integrations: IntegrationIndex = {};
protected _integrations: IntegrationIndex;

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

/** Number of calls being processed */
protected _numProcessing: number = 0;
protected _numProcessing: number;

/** Holds flushable */
private _outcomes: { [key: string]: number } = {};
private _outcomes: { [key: string]: number };

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

/**
* Initializes this client instance.
Expand All @@ -114,6 +114,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
*/
protected constructor(options: O) {
this._options = options;
this._integrations = {};
this._integrationsInitialized = false;
this._numProcessing = 0;
this._outcomes = {};
this._hooks = {};

if (options.dsn) {
this._dsn = makeDsn(options.dsn);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/integrations/functiontostring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class FunctionToString implements Integration {
/**
* @inheritDoc
*/
public name: string = FunctionToString.id;
public name: string;

public constructor() {
this.name = FunctionToString.id;
}

/**
* @inheritDoc
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ export class InboundFilters implements Integration {
/**
* @inheritDoc
*/
public name: string = InboundFilters.id;
public name: string;

public constructor(private readonly _options: Partial<InboundFiltersOptions> = {}) {}
private readonly _options: Partial<InboundFiltersOptions>;

public constructor(options: Partial<InboundFiltersOptions> = {}) {
this.name = InboundFilters.id;
this._options = options;
}

/**
* @inheritDoc
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/integrations/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class ModuleMetadata implements Integration {
/**
* @inheritDoc
*/
public name: string = ModuleMetadata.id;
public name: string;

public constructor() {
this.name = ModuleMetadata.id;
}

/**
* @inheritDoc
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/sessionflusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ type ReleaseHealthAttributes = {
* @inheritdoc
*/
export class SessionFlusher implements SessionFlusherLike {
public readonly flushTimeout: number = 60;
private _pendingAggregates: Record<number, AggregationCounts> = {};
public readonly flushTimeout: number;
private _pendingAggregates: Record<number, AggregationCounts>;
private _sessionAttrs: ReleaseHealthAttributes;
private _intervalId: ReturnType<typeof setInterval>;
private _isEnabled: boolean = true;
private _isEnabled: boolean;
private _client: Client;

public constructor(client: Client, attrs: ReleaseHealthAttributes) {
this._client = client;
this.flushTimeout = 60;
this._pendingAggregates = {};
this._isEnabled = true;

// Call to setInterval, so that flush is called every 60 seconds
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);
this._sessionAttrs = attrs;
Expand Down
20 changes: 13 additions & 7 deletions packages/core/src/tracing/idletransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,27 @@ export type BeforeFinishCallback = (transactionSpan: IdleTransaction, endTimesta
*/
export class IdleTransaction extends Transaction {
// Activities store a list of active spans
public activities: Record<string, boolean> = {};

public activities: Record<string, boolean>;
// Track state of activities in previous heartbeat
private _prevHeartbeatString: string | undefined;

// Amount of times heartbeat has counted. Will cause transaction to finish after 3 beats.
private _heartbeatCounter: number = 0;
private _heartbeatCounter: number;

// We should not use heartbeat if we finished a transaction
private _finished: boolean = false;
private _finished: boolean;

// Idle timeout was canceled and we should finish the transaction with the last span end.
private _idleTimeoutCanceledPermanently: boolean = false;
private _idleTimeoutCanceledPermanently: boolean;

private readonly _beforeFinishCallbacks: BeforeFinishCallback[] = [];
private readonly _beforeFinishCallbacks: BeforeFinishCallback[];

/**
* Timer that tracks Transaction idleTimeout
*/
private _idleTimeoutID: ReturnType<typeof setTimeout> | undefined;

private _finishReason: (typeof IDLE_TRANSACTION_FINISH_REASONS)[number] = IDLE_TRANSACTION_FINISH_REASONS[4];
private _finishReason: (typeof IDLE_TRANSACTION_FINISH_REASONS)[number];

public constructor(
transactionContext: TransactionContext,
Expand All @@ -110,6 +109,13 @@ export class IdleTransaction extends Transaction {
) {
super(transactionContext, _idleHub);

this.activities = {};
this._heartbeatCounter = 0;
this._finished = false;
this._idleTimeoutCanceledPermanently = false;
this._beforeFinishCallbacks = [];
this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[4];

if (_onScope) {
// We set the transaction here on the scope so error events pick up the trace
// context and attach it to the error.
Expand Down
22 changes: 15 additions & 7 deletions packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { dropUndefinedKeys, generateSentryTraceHeader, logger, timestampInSecond
* @hidden
*/
export class SpanRecorder {
public spans: Span[] = [];
public spans: Span[];

private readonly _maxlen: number;

public constructor(maxlen: number = 1000) {
this._maxlen = maxlen;
this.spans = [];
}

/**
Expand All @@ -46,12 +47,12 @@ export class Span implements SpanInterface {
/**
* @inheritDoc
*/
public traceId: string = uuid4();
public traceId: string;

/**
* @inheritDoc
*/
public spanId: string = uuid4().substring(16);
public spanId: string;

/**
* @inheritDoc
Expand All @@ -71,7 +72,7 @@ export class Span implements SpanInterface {
/**
* Timestamp in seconds when the span was created.
*/
public startTimestamp: number = timestampInSeconds();
public startTimestamp: number;

/**
* Timestamp in seconds when the span ended.
Expand All @@ -91,13 +92,13 @@ export class Span implements SpanInterface {
/**
* @inheritDoc
*/
public tags: { [key: string]: Primitive } = {};
public tags: { [key: string]: Primitive };

/**
* @inheritDoc
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public data: { [key: string]: any } = {};
public data: { [key: string]: any };

/**
* List of spans that were finalized
Expand All @@ -112,7 +113,7 @@ export class Span implements SpanInterface {
/**
* The instrumenter that created this span.
*/
public instrumenter: Instrumenter = 'sentry';
public instrumenter: Instrumenter;

/**
* You should never call the constructor manually, always use `Sentry.startTransaction()`
Expand All @@ -122,6 +123,13 @@ export class Span implements SpanInterface {
* @hidden
*/
public constructor(spanContext?: SpanContext) {
this.traceId = uuid4();
this.spanId = uuid4().substring(16);
this.startTimestamp = timestampInSeconds();
this.tags = {};
this.data = {};
this.instrumenter = 'sentry';

if (!spanContext) {
return this;
}
Expand Down
Loading