Skip to content

Commit 09c9953

Browse files
committed
build: Switch core to using eslint
1 parent d44a1d9 commit 09c9953

18 files changed

+111
-89
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE
33

44
packages/apm/**/*
5-
packages/core/**/*
65
packages/ember/**/*
76
packages/gatsby/**/*
87
packages/hub/**/*

.eslintrc.js

Lines changed: 2 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
{

packages/core/.eslintrc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
};

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 & 25 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,7 +75,7 @@ export class API {
9975
/** Returns the url to the report dialog endpoint. */
10076
public getReportDialogEndpoint(
10177
dialogOptions: {
102-
[key: string]: any;
78+
[key: string]: unknown;
10379
user?: { name?: string; email?: string };
10480
} = {},
10581
): string {
@@ -129,4 +105,28 @@ export class API {
129105

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

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(

packages/core/test/lib/base.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
13
import { Hub, Scope } from '@sentry/hub';
24
import { Event, Severity, Span } from '@sentry/types';
35
import { SentryError } from '@sentry/utils';
@@ -8,6 +10,7 @@ import { TestIntegration } from '../mocks/integration';
810
import { FakeTransport } from '../mocks/transport';
911

1012
const PUBLIC_DSN = 'https://username@domain/123';
13+
// eslint-disable-next-line no-var
1114
declare var global: any;
1215

1316
jest.mock('@sentry/utils', () => {
@@ -18,7 +21,7 @@ jest.mock('@sentry/utils', () => {
1821
uuid4(): string {
1922
return '42';
2023
},
21-
getGlobalObject(): object {
24+
getGlobalObject(): any {
2225
return {
2326
console: {
2427
log(): void {

packages/core/test/lib/integration.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// tslint:disable:deprecation
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { Integration } from '@sentry/types';
33

44
import { getIntegrationsToSetup } from '../../src/integration';
55

66
/** JSDoc */
77
class MockIntegration implements Integration {
8+
public name: string;
9+
810
public constructor(name: string) {
911
this.name = name;
1012
}
11-
public name: string;
13+
1214
public setupOnce(): void {
1315
// noop
1416
}

packages/core/test/lib/integrations/inboundfilters.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { InboundFilters } from '../../../src/integrations/inboundfilters';
22

3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34
let inboundFilters: any;
45

56
describe('InboundFilters', () => {

packages/core/test/lib/sdk.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { Integration } from '@sentry/types';
1+
import { Integration, Client } from '@sentry/types';
22

33
import { installedIntegrations } from '../../src/integration';
44
import { initAndBind } from '../../src/sdk';
55
import { TestClient } from '../mocks/client';
66

7+
// eslint-disable-next-line no-var, @typescript-eslint/no-explicit-any
78
declare var global: any;
89

910
const PUBLIC_DSN = 'https://username@domain/123';
1011

1112
jest.mock('@sentry/hub', () => ({
1213
getCurrentHub(): {
13-
bindClient(client: any): boolean;
14+
bindClient(client: Client): boolean;
1415
getClient(): boolean;
1516
} {
1617
return {
1718
getClient(): boolean {
1819
return false;
1920
},
20-
bindClient(client: any): boolean {
21+
bindClient(client: Client): boolean {
2122
client.setupIntegrations();
2223
return true;
2324
},
@@ -26,11 +27,11 @@ jest.mock('@sentry/hub', () => ({
2627
}));
2728

2829
class MockIntegration implements Integration {
30+
public name: string;
31+
public setupOnce: () => void = jest.fn();
2932
public constructor(name: string) {
3033
this.name = name;
3134
}
32-
public name: string;
33-
public setupOnce: () => void = jest.fn();
3435
}
3536

3637
describe('SDK', () => {

0 commit comments

Comments
 (0)