Skip to content

Commit 5c21faf

Browse files
committed
Update rules
1 parent edd0d1d commit 5c21faf

File tree

17 files changed

+77
-40
lines changed

17 files changed

+77
-40
lines changed

.eslintrc.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ module.exports = {
66
extends: ['prettier', 'eslint:recommended'],
77
plugins: ['sentry-sdk'],
88
overrides: [
9+
{
10+
files: ['*.js'],
11+
rules: {
12+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
13+
},
14+
},
915
{
1016
files: ['*.ts'],
1117
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
1218
plugins: ['@typescript-eslint'],
1319
parser: '@typescript-eslint/parser',
1420
rules: {
1521
'sentry-sdk/no-async-await': 'error',
22+
// Make sure variables marked with _ are ignored (ex. _varName)
23+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
1624
},
1725
},
1826
{
1927
env: {
2028
jest: true,
2129
},
2230
files: ['*.test.ts'],
23-
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
24-
plugins: ['@typescript-eslint'],
25-
parser: '@typescript-eslint/parser',
2631
},
2732
{
2833
files: ['*.config.js'],

packages/browser/.eslintrc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
browser: true,
66
},
77
extends: ['../../.eslintrc.js'],
8-
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*'],
8+
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*', 'src/loader.js'],
99
overrides: [
1010
{
1111
files: ['test/integration/**/*'],
@@ -23,5 +23,7 @@ module.exports = {
2323
},
2424
},
2525
],
26-
rules: {},
26+
rules: {
27+
'no-prototype-builtins': 'off',
28+
},
2729
};

packages/browser/src/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
6262
/**
6363
* @inheritDoc
6464
*/
65-
public eventFromException(exception: any, hint?: EventHint): PromiseLike<Event> {
65+
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
6666
return eventFromException(this._options, exception, hint);
6767
}
6868
/**

packages/browser/src/eventbuilder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { computeStackTrace } from './tracekit';
1818
* Builds and Event from a Exception
1919
* @hidden
2020
*/
21-
export function eventFromException(options: Options, exception: any, hint?: EventHint): PromiseLike<Event> {
21+
export function eventFromException(options: Options, exception: unknown, hint?: EventHint): PromiseLike<Event> {
2222
const syntheticException = (hint && hint.syntheticException) || undefined;
2323
const event = eventFromUnknownInput(exception, syntheticException, {
2424
attachStacktrace: options.attachStacktrace,
@@ -71,7 +71,7 @@ export function eventFromUnknownInput(
7171
if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {
7272
// If it is an ErrorEvent with `error` property, extract it to get actual Error
7373
const errorEvent = exception as ErrorEvent;
74-
exception = errorEvent.error; // tslint:disable-line:no-parameter-reassignment
74+
exception = errorEvent.error;
7575
event = eventFromStacktrace(computeStackTrace(exception as Error));
7676
return event;
7777
}
@@ -97,7 +97,7 @@ export function eventFromUnknownInput(
9797
// If it is plain Object or Event, serialize it manually and extract options
9898
// This will allow us to group events based on top-level keys
9999
// which is much better than creating new group when any key/value change
100-
const objectException = exception as {};
100+
const objectException = exception as Record<string, unknown>;
101101
event = eventFromPlainObject(objectException, syntheticException, options.rejection);
102102
addExceptionMechanism(event, {
103103
synthetic: true,

packages/browser/src/helpers.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { API, captureException, withScope } from '@sentry/core';
22
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
33
import { addExceptionMechanism, addExceptionTypeValue, logger } from '@sentry/utils';
44

5-
let ignoreOnError: number = 0;
5+
let ignoreOnError = 0;
66

77
/**
88
* @hidden
@@ -36,6 +36,7 @@ export function wrap(
3636
mechanism?: Mechanism;
3737
} = {},
3838
before?: WrappedFunction,
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3940
): any {
4041
// tslint:disable-next-line:strict-type-predicates
4142
if (typeof fn !== 'function') {
@@ -59,6 +60,8 @@ export function wrap(
5960
return fn;
6061
}
6162

63+
/* eslint-disable prefer-rest-params */
64+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6265
const sentryWrapped: WrappedFunction = function(this: any): void {
6366
const args = Array.prototype.slice.call(arguments);
6467

@@ -69,6 +72,7 @@ export function wrap(
6972
before.apply(this, arguments);
7073
}
7174

75+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7276
const wrappedArguments = args.map((arg: any) => wrap(arg, options));
7377

7478
if (fn.handleEvent) {
@@ -110,6 +114,7 @@ export function wrap(
110114
throw ex;
111115
}
112116
};
117+
/* eslint-enable prefer-rest-params */
113118

114119
// Accessing some objects may throw
115120
// ref: https://github.com/getsentry/sentry-javascript/issues/1168
@@ -119,7 +124,7 @@ export function wrap(
119124
sentryWrapped[property] = fn[property];
120125
}
121126
}
122-
} catch (_oO) {} // tslint:disable-line:no-empty
127+
} catch (_oO) {} // eslint-disable-line no-empty
123128

124129
fn.prototype = fn.prototype || {};
125130
sentryWrapped.prototype = fn.prototype;
@@ -163,6 +168,7 @@ export function wrap(
163168
* All properties the report dialog supports
164169
*/
165170
export interface ReportDialogOptions {
171+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
166172
[key: string]: any;
167173
eventId?: string;
168174
dsn?: DsnLike;

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
* @hidden
1414
*/
1515
export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1617
[key: string]: any;
1718
__sentry_xhr__?: {
1819
method?: string;
@@ -44,7 +45,7 @@ export class Breadcrumbs implements Integration {
4445
/**
4546
* @inheritDoc
4647
*/
47-
public static id: string = 'Breadcrumbs';
48+
public static id = 'Breadcrumbs';
4849

4950
/** JSDoc */
5051
private readonly _options: BreadcrumbsOptions;
@@ -87,6 +88,7 @@ export class Breadcrumbs implements Integration {
8788
/**
8889
* Creates breadcrumbs from console API calls
8990
*/
91+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9092
private _consoleBreadcrumb(handlerData: { [key: string]: any }): void {
9193
const breadcrumb = {
9294
category: 'console',
@@ -117,6 +119,7 @@ export class Breadcrumbs implements Integration {
117119
/**
118120
* Creates breadcrumbs from DOM API calls
119121
*/
122+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120123
private _domBreadcrumb(handlerData: { [key: string]: any }): void {
121124
let target;
122125

@@ -148,6 +151,7 @@ export class Breadcrumbs implements Integration {
148151
/**
149152
* Creates breadcrumbs from XHR API calls
150153
*/
154+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
151155
private _xhrBreadcrumb(handlerData: { [key: string]: any }): void {
152156
if (handlerData.endTimestamp) {
153157
// We only capture complete, non-sentry requests
@@ -173,6 +177,7 @@ export class Breadcrumbs implements Integration {
173177
/**
174178
* Creates breadcrumbs from fetch API calls
175179
*/
180+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
176181
private _fetchBreadcrumb(handlerData: { [key: string]: any }): void {
177182
// We only capture complete fetch requests
178183
if (!handlerData.endTimestamp) {
@@ -218,6 +223,7 @@ export class Breadcrumbs implements Integration {
218223
/**
219224
* Creates breadcrumbs from history API calls
220225
*/
226+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221227
private _historyBreadcrumb(handlerData: { [key: string]: any }): void {
222228
const global = getGlobalObject<Window>();
223229
let from = handlerData.from;

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ export class GlobalHandlers implements Integration {
2929
/**
3030
* @inheritDoc
3131
*/
32-
public static id: string = 'GlobalHandlers';
32+
public static id = 'GlobalHandlers';
3333

3434
/** JSDoc */
3535
private readonly _options: GlobalHandlersIntegrations;
3636

3737
/** JSDoc */
38-
private _onErrorHandlerInstalled: boolean = false;
38+
private _onErrorHandlerInstalled = false;
3939

4040
/** JSDoc */
41-
private _onUnhandledRejectionHandlerInstalled: boolean = false;
41+
private _onUnhandledRejectionHandlerInstalled = false;
4242

4343
/** JSDoc */
4444
public constructor(options?: GlobalHandlersIntegrations) {
@@ -72,6 +72,7 @@ export class GlobalHandlers implements Integration {
7272
}
7373

7474
addInstrumentationHandler({
75+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7576
callback: (data: { msg: any; url: any; line: any; column: any; error: any }) => {
7677
const error = data.error;
7778
const currentHub = getCurrentHub();
@@ -117,6 +118,7 @@ export class GlobalHandlers implements Integration {
117118
}
118119

119120
addInstrumentationHandler({
121+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120122
callback: (e: any) => {
121123
let error = e;
122124

@@ -177,6 +179,7 @@ export class GlobalHandlers implements Integration {
177179
/**
178180
* This function creates a stack from an old, error-less onerror handler.
179181
*/
182+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
180183
private _eventFromIncompleteOnError(msg: any, url: any, line: any, column: any): Event {
181184
const ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
182185

@@ -209,6 +212,7 @@ export class GlobalHandlers implements Integration {
209212
/**
210213
* This function creates an Event from an TraceKitStackTrace that has part of it missing.
211214
*/
215+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
212216
private _eventFromIncompleteRejection(error: any): Event {
213217
return {
214218
exception: {
@@ -223,6 +227,7 @@ export class GlobalHandlers implements Integration {
223227
}
224228

225229
/** JSDoc */
230+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
226231
private _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column: any): Event {
227232
event.exception = event.exception || {};
228233
event.exception.values = event.exception.values || [];

packages/browser/src/integrations/linkederrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class LinkedErrors implements Integration {
1818
/**
1919
* @inheritDoc
2020
*/
21-
public static id: string = 'LinkedErrors';
21+
public static id = 'LinkedErrors';
2222

2323
/**
2424
* @inheritDoc

packages/browser/src/integrations/trycatch.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class TryCatch implements Integration {
5656
/**
5757
* @inheritDoc
5858
*/
59-
public static id: string = 'TryCatch';
59+
public static id = 'TryCatch';
6060

6161
/** JSDoc */
6262
private readonly _options: TryCatchOptions;
@@ -77,6 +77,7 @@ export class TryCatch implements Integration {
7777

7878
/** JSDoc */
7979
private _wrapTimeFunction(original: () => void): () => number {
80+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8081
return function(this: any, ...args: any[]): number {
8182
const originalCallback = args[0];
8283
args[0] = wrap(originalCallback, {
@@ -91,7 +92,9 @@ export class TryCatch implements Integration {
9192
}
9293

9394
/** JSDoc */
95+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9496
private _wrapRAF(original: any): (callback: () => void) => any {
97+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9598
return function(this: any, callback: () => void): () => void {
9699
return original.call(
97100
this,
@@ -111,6 +114,7 @@ export class TryCatch implements Integration {
111114

112115
/** JSDoc */
113116
private _wrapEventTarget(target: string): void {
117+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
114118
const global = getGlobalObject() as { [key: string]: any };
115119
const proto = global[target] && global[target].prototype;
116120

@@ -122,6 +126,7 @@ export class TryCatch implements Integration {
122126
original: () => void,
123127
): (eventName: string, fn: EventListenerObject, options?: boolean | AddEventListenerOptions) => void {
124128
return function(
129+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125130
this: any,
126131
eventName: string,
127132
fn: EventListenerObject,
@@ -149,6 +154,7 @@ export class TryCatch implements Integration {
149154
return original.call(
150155
this,
151156
eventName,
157+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152158
wrap((fn as any) as WrappedFunction, {
153159
mechanism: {
154160
data: {
@@ -167,8 +173,10 @@ export class TryCatch implements Integration {
167173

168174
fill(proto, 'removeEventListener', function(
169175
original: () => void,
176+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
170177
): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {
171178
return function(
179+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
172180
this: any,
173181
eventName: string,
174182
fn: EventListenerObject,
@@ -203,13 +211,16 @@ export class TryCatch implements Integration {
203211

204212
/** JSDoc */
205213
private _wrapXHR(originalSend: () => void): () => void {
214+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
206215
return function(this: XMLHttpRequest, ...args: any[]): void {
207-
const xhr = this; // tslint:disable-line:no-this-assignment
216+
// eslint-disable-next-line @typescript-eslint/no-this-alias
217+
const xhr = this;
208218
const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
209219

210220
xmlHttpRequestProps.forEach(prop => {
211221
if (prop in xhr && typeof xhr[prop] === 'function') {
212-
fill(xhr, prop, function(original: WrappedFunction): Function {
222+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
223+
fill(xhr, prop, function(original: WrappedFunction): () => any {
213224
const wrapOptions = {
214225
mechanism: {
215226
data: {

packages/browser/src/integrations/useragent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class UserAgent implements Integration {
1414
/**
1515
* @inheritDoc
1616
*/
17-
public static id: string = 'UserAgent';
17+
public static id = 'UserAgent';
1818

1919
/**
2020
* @inheritDoc

0 commit comments

Comments
 (0)