Skip to content

Commit 1829886

Browse files
AbhiPrasadkamilogorek
authored andcommitted
build: Convert core, hub, minimal and types to use eslint (#2794)
* build: Switch `@sentry/core` to using eslint * build: Switch `@sentry/hub` to using eslint * build: Switch `@sentry/minimal` to using eslint * build: Switch `@sentry/types` to using eslint
1 parent e789971 commit 1829886

Some content is hidden

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

50 files changed

+377
-285
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE
33

44
packages/apm/**/*
5-
packages/core/**/*
65
packages/ember/**/*
76
packages/gatsby/**/*
8-
packages/hub/**/*
97
packages/integrations/**/*
10-
packages/minimal/**/*
118
packages/node/**/*
129
packages/react/**/*
1310
packages/tracing/**/*
14-
packages/types/**/*
1511
packages/typescript/**/*
1612
packages/utils/**/*

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ module.exports = {
9393
files: ['*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'],
9494
rules: {
9595
'max-lines': 'off',
96+
97+
'@typescript-eslint/explicit-function-return-type': 'off',
9698
},
9799
},
98100
{
@@ -123,5 +125,8 @@ module.exports = {
123125

124126
// Limit maximum file size to reduce complexity. Turned off in tests.
125127
'max-lines': 'error',
128+
129+
// We should require a whitespace beginning a comment
130+
'spaced-comment': 'error',
126131
},
127132
};

dangerfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import tslint from 'danger-plugin-tslint';
66
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
77
import { CLIEngine } from 'eslint';
88

9-
const PACKAGES = ['apm', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
9+
const PACKAGES = ['apm', 'integrations', 'node', 'utils'];
1010
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
1111

1212
/**

packages/browser/src/helpers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ export function wrap(
153153
},
154154
});
155155
}
156-
} catch (_oO) {
157-
/*no-empty*/
158-
}
156+
// eslint-disable-next-line no-empty
157+
} catch (_oO) {}
159158

160159
return sentryWrapped;
161160
}

packages/browser/test/integration/common/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function supportsOnunhandledRejection() {
5050
}
5151

5252
function isBelowIE11() {
53+
// eslint-disable-next-line spaced-comment
5354
return /*@cc_on!@*/ false == !false;
5455
}
5556

packages/browser/test/integration/polyfills/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*!
1+
/* !
22
* @overview whatwg-fetch - an implementation of Fetch API.
33
* @copyright Copyright (c) 2014-2016 GitHub, Inc.
44
* @license Licensed under MIT license

packages/browser/test/integration/polyfills/promise.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*!
1+
/* !
22
* @overview es6-promise - an implementation of Promise API.
33
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
44
* @license Licensed under MIT license
@@ -222,7 +222,7 @@
222222
`value`
223223
*/
224224
function resolve$1(object) {
225-
/*jshint validthis:true */
225+
/* jshint validthis:true */
226226
var Constructor = this;
227227

228228
if (
@@ -722,7 +722,7 @@
722722
promise to settle.
723723
*/
724724
function race(entries) {
725-
/*jshint validthis:true */
725+
/* jshint validthis:true */
726726
var Constructor = this;
727727

728728
if (!isArray(entries)) {
@@ -774,7 +774,7 @@
774774
@return {Promise} a promise rejected with the given `reason`.
775775
*/
776776
function reject$1(reason) {
777-
/*jshint validthis:true */
777+
/* jshint validthis:true */
778778
var Constructor = this;
779779
var promise = new Constructor(noop);
780780
reject(promise, reason);

packages/browser/test/integration/suites/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if (IS_LOADER) {
4545
setTimeout(function() {
4646
Sentry.captureMessage("test");
4747
});
48-
undefinedMethod(); //trigger error
48+
undefinedMethod(); // trigger error
4949
}).then(function(summary) {
5050
assert.ok(summary.events[0].breadcrumbs);
5151
assert.lengthOf(summary.events[0].breadcrumbs, 1);

packages/core/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
},
6+
parserOptions: {
7+
ecmaVersion: 2018,
8+
},
9+
extends: ['../../.eslintrc.js'],
10+
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*'],
11+
overrides: [
12+
{
13+
files: ['*.ts', '*.tsx', '*.d.ts'],
14+
parserOptions: {
15+
project: './tsconfig.json',
16+
},
17+
},
18+
{
19+
files: ['test/**/*'],
20+
rules: {
21+
'@typescript-eslint/no-explicit-any': 'off',
22+
'@typescript-eslint/no-non-null-assertion': 'off',
23+
},
24+
},
25+
],
26+
};

packages/core/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"prettier": "^1.17.0",
2929
"prettier-check": "^2.0.0",
3030
"rimraf": "^2.6.3",
31-
"tslint": "5.16.0",
3231
"typescript": "3.4.5"
3332
},
3433
"scripts": {
@@ -40,13 +39,13 @@
4039
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
4140
"clean": "rimraf dist coverage",
4241
"link:yarn": "yarn link",
43-
"lint": "run-s lint:prettier lint:tslint",
42+
"lint": "run-s lint:prettier lint:eslint",
4443
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
45-
"lint:tslint": "tslint -t stylish -p .",
46-
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
47-
"fix": "run-s fix:tslint fix:prettier",
44+
"lint:eslint": "eslint . --format stylish",
45+
"lint:eslint:json": "eslint . --format json | tee lint-results.json",
46+
"fix": "run-s fix:eslint fix:prettier",
4847
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
49-
"fix:tslint": "tslint --fix -t stylish -p .",
48+
"fix:eslint": "lint:eslint --fix",
5049
"test": "jest",
5150
"test:watch": "jest --watch"
5251
},

packages/core/src/api.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ export class API {
3030
return this._getIngestEndpoint('store');
3131
}
3232

33-
/** Returns the envelope endpoint URL. */
34-
private _getEnvelopeEndpoint(): string {
35-
return this._getIngestEndpoint('envelope');
36-
}
37-
38-
/** Returns the ingest API endpoint for target. */
39-
private _getIngestEndpoint(target: 'store' | 'envelope'): string {
40-
const base = this.getBaseApiEndpoint();
41-
const dsn = this._dsnObject;
42-
return `${base}${dsn.projectId}/${target}/`;
43-
}
44-
4533
/**
4634
* Returns the store endpoint URL with auth in the query string.
4735
*
@@ -60,18 +48,6 @@ export class API {
6048
return `${this._getEnvelopeEndpoint()}?${this._encodedAuth()}`;
6149
}
6250

63-
/** Returns a URL-encoded string with auth config suitable for a query string. */
64-
private _encodedAuth(): string {
65-
const dsn = this._dsnObject;
66-
const auth = {
67-
// We send only the minimum set of required information. See
68-
// https://github.com/getsentry/sentry-javascript/issues/2572.
69-
sentry_key: dsn.user,
70-
sentry_version: SENTRY_API_VERSION,
71-
};
72-
return urlEncode(auth);
73-
}
74-
7551
/** Returns only the path component for the store endpoint. */
7652
public getStoreEndpointPath(): string {
7753
const dsn = this._dsnObject;
@@ -99,6 +75,7 @@ export class API {
9975
/** Returns the url to the report dialog endpoint. */
10076
public getReportDialogEndpoint(
10177
dialogOptions: {
78+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10279
[key: string]: any;
10380
user?: { name?: string; email?: string };
10481
} = {},
@@ -129,4 +106,28 @@ export class API {
129106

130107
return endpoint;
131108
}
109+
110+
/** Returns the envelope endpoint URL. */
111+
private _getEnvelopeEndpoint(): string {
112+
return this._getIngestEndpoint('envelope');
113+
}
114+
115+
/** Returns the ingest API endpoint for target. */
116+
private _getIngestEndpoint(target: 'store' | 'envelope'): string {
117+
const base = this.getBaseApiEndpoint();
118+
const dsn = this._dsnObject;
119+
return `${base}${dsn.projectId}/${target}/`;
120+
}
121+
122+
/** Returns a URL-encoded string with auth config suitable for a query string. */
123+
private _encodedAuth(): string {
124+
const dsn = this._dsnObject;
125+
const auth = {
126+
// We send only the minimum set of required information. See
127+
// https://github.com/getsentry/sentry-javascript/issues/2572.
128+
sentry_key: dsn.user,
129+
sentry_version: SENTRY_API_VERSION,
130+
};
131+
return urlEncode(auth);
132+
}
132133
}

packages/core/src/basebackend.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { NoopTransport } from './transports/noop';
2525
*/
2626
export interface Backend {
2727
/** Creates a {@link Event} from an exception. */
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2829
eventFromException(exception: any, hint?: EventHint): PromiseLike<Event>;
2930

3031
/** Creates a {@link Event} from a plain message. */
@@ -68,16 +69,10 @@ export abstract class BaseBackend<O extends Options> implements Backend {
6869
this._transport = this._setupTransport();
6970
}
7071

71-
/**
72-
* Sets up the transport so it can be used later to send requests.
73-
*/
74-
protected _setupTransport(): Transport {
75-
return new NoopTransport();
76-
}
77-
7872
/**
7973
* @inheritDoc
8074
*/
75+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
8176
public eventFromException(_exception: any, _hint?: EventHint): PromiseLike<Event> {
8277
throw new SentryError('Backend has to implement `eventFromException` method');
8378
}
@@ -104,4 +99,11 @@ export abstract class BaseBackend<O extends Options> implements Backend {
10499
public getTransport(): Transport {
105100
return this._transport;
106101
}
102+
103+
/**
104+
* Sets up the transport so it can be used later to send requests.
105+
*/
106+
protected _setupTransport(): Transport {
107+
return new NoopTransport();
108+
}
107109
}

packages/core/src/baseclient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-lines */
12
import { Scope } from '@sentry/hub';
23
import { Client, Event, EventHint, Integration, IntegrationClass, Options, Severity } from '@sentry/types';
34
import {
@@ -85,6 +86,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
8586
/**
8687
* @inheritDoc
8788
*/
89+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
8890
public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {
8991
let eventId: string | undefined = hint && hint.event_id;
9092
this._processing = true;
@@ -276,7 +278,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
276278
}
277279

278280
return result.then(evt => {
279-
// tslint:disable-next-line:strict-type-predicates
280281
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
281282
return this._normalizeEvent(evt, normalizeDepth);
282283
}
@@ -299,7 +300,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
299300
return null;
300301
}
301302

302-
// tslint:disable:no-unsafe-any
303303
const normalized = {
304304
...event,
305305
...(event.breadcrumbs && {
@@ -403,6 +403,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
403403
* @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
404404
*/
405405
protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<Event> {
406+
// eslint-disable-next-line @typescript-eslint/unbound-method
406407
const { beforeSend, sampleRate } = this.getOptions();
407408

408409
if (!this._isEnabled()) {
@@ -427,7 +428,8 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
427428

428429
let finalEvent: Event | null = prepared;
429430

430-
const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;
431+
const isInternalException =
432+
hint && hint.data && (hint.data as { [key: string]: unknown }).__sentry__ === true;
431433
// We skip beforeSend in case of transactions
432434
if (isInternalException || !beforeSend || isTransaction) {
433435
this._sendEvent(finalEvent);
@@ -436,7 +438,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
436438
}
437439

438440
const beforeSendResult = beforeSend(prepared, hint);
439-
// tslint:disable-next-line:strict-type-predicates
440441
if (typeof beforeSendResult === 'undefined') {
441442
logger.error('`beforeSend` method has to return `null` or a valid event.');
442443
} else if (isThenable(beforeSendResult)) {

packages/core/src/integrations/functiontostring.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ export class FunctionToString implements Integration {
77
/**
88
* @inheritDoc
99
*/
10-
public name: string = FunctionToString.id;
10+
public static id: string = 'FunctionToString';
1111

1212
/**
1313
* @inheritDoc
1414
*/
15-
public static id: string = 'FunctionToString';
15+
public name: string = FunctionToString.id;
1616

1717
/**
1818
* @inheritDoc
1919
*/
2020
public setupOnce(): void {
21+
// eslint-disable-next-line @typescript-eslint/unbound-method
2122
originalFunctionToString = Function.prototype.toString;
2223

24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2325
Function.prototype.toString = function(this: WrappedFunction, ...args: any[]): string {
2426
const context = this.__sentry_original__ || this;
25-
// tslint:disable-next-line:no-unsafe-any
2627
return originalFunctionToString.apply(context, args);
2728
};
2829
}

packages/core/src/integrations/inboundfilters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ export class InboundFilters implements Integration {
2424
/**
2525
* @inheritDoc
2626
*/
27-
public name: string = InboundFilters.id;
27+
public static id: string = 'InboundFilters';
28+
2829
/**
2930
* @inheritDoc
3031
*/
31-
public static id: string = 'InboundFilters';
32+
public name: string = InboundFilters.id;
3233

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

@@ -139,7 +140,6 @@ export class InboundFilters implements Integration {
139140

140141
/** JSDoc */
141142
private _mergeOptions(clientOptions: Partial<InboundFiltersOptions> = {}): Partial<InboundFiltersOptions> {
142-
// tslint:disable:deprecation
143143
return {
144144
allowUrls: [
145145
...(this._options.whitelistUrls || []),

packages/core/test/lib/api.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ describe('API', () => {
1616
});
1717

1818
test('getRequestHeaders', () => {
19-
// tslint:disable-next-line:deprecation
2019
expect(new API(dsnPublic).getRequestHeaders('a', '1.0')).toMatchObject({
2120
'Content-Type': 'application/json',
2221
'X-Sentry-Auth': expect.stringMatching(/^Sentry sentry_version=\d, sentry_client=a\/1\.0, sentry_key=abc$/),
2322
});
2423

25-
// tslint:disable-next-line:deprecation
2624
expect(new API(legacyDsn).getRequestHeaders('a', '1.0')).toMatchObject({
2725
'Content-Type': 'application/json',
2826
'X-Sentry-Auth': expect.stringMatching(

0 commit comments

Comments
 (0)