Skip to content

Commit b349678

Browse files
committed
build: Switch hub to using eslint
1 parent 09c9953 commit b349678

File tree

12 files changed

+165
-132
lines changed

12 files changed

+165
-132
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
packages/apm/**/*
55
packages/ember/**/*
66
packages/gatsby/**/*
7-
packages/hub/**/*
87
packages/integrations/**/*
98
packages/minimal/**/*
109
packages/node/**/*

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,8 @@ module.exports = {
125125

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

packages/hub/.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/hub/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"prettier": "^1.17.0",
2727
"prettier-check": "^2.0.0",
2828
"rimraf": "^2.6.3",
29-
"tslint": "5.16.0",
3029
"typescript": "3.4.5"
3130
},
3231
"scripts": {
@@ -38,13 +37,13 @@
3837
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
3938
"clean": "rimraf dist coverage",
4039
"link:yarn": "yarn link",
41-
"lint": "run-s lint:prettier lint:tslint",
40+
"lint": "run-s lint:prettier lint:eslint",
4241
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
43-
"lint:tslint": "tslint -t stylish -p .",
44-
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
45-
"fix": "run-s fix:tslint fix:prettier",
42+
"lint:eslint": "eslint . --format stylish",
43+
"lint:eslint:json": "eslint . --format json | tee lint-results.json",
44+
"fix": "run-s fix:eslint fix:prettier",
4645
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
47-
"fix:tslint": "tslint --fix -t stylish -p .",
46+
"fix:eslint": "lint:eslint --fix",
4847
"test": "jest",
4948
"test:watch": "jest --watch"
5049
},

packages/hub/src/hub.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-lines */
12
import {
23
Breadcrumb,
34
BreadcrumbHint,
@@ -66,19 +67,6 @@ export class Hub implements HubInterface {
6667
this.bindClient(client);
6768
}
6869

69-
/**
70-
* Internal helper function to call a method on the top client if it exists.
71-
*
72-
* @param method The method to call on the client.
73-
* @param args Arguments to pass to the client function.
74-
*/
75-
private _invokeClient<M extends keyof Client>(method: M, ...args: any[]): void {
76-
const top = this.getStackTop();
77-
if (top && top.client && top.client[method]) {
78-
(top.client as any)[method](...args, top.scope);
79-
}
80-
}
81-
8270
/**
8371
* @inheritDoc
8472
*/
@@ -156,6 +144,7 @@ export class Hub implements HubInterface {
156144
/**
157145
* @inheritDoc
158146
*/
147+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
159148
public captureException(exception: any, hint?: EventHint): string {
160149
const eventId = (this._lastEventId = uuid4());
161150
let finalHint = hint;
@@ -244,6 +233,7 @@ export class Hub implements HubInterface {
244233
return;
245234
}
246235

236+
// eslint-disable-next-line @typescript-eslint/unbound-method
247237
const { beforeBreadcrumb = null, maxBreadcrumbs = DEFAULT_BREADCRUMBS } =
248238
(top.client.getOptions && top.client.getOptions()) || {};
249239

@@ -322,7 +312,7 @@ export class Hub implements HubInterface {
322312
/**
323313
* @inheritDoc
324314
*/
325-
public setContext(name: string, context: { [key: string]: any } | null): void {
315+
public setContext(name: string, context: { [key: string]: unknown } | null): void {
326316
const top = this.getStackTop();
327317
if (!top.scope) {
328318
return;
@@ -389,14 +379,29 @@ export class Hub implements HubInterface {
389379
return this._callExtensionMethod<{ [key: string]: string }>('traceHeaders');
390380
}
391381

382+
/**
383+
* Internal helper function to call a method on the top client if it exists.
384+
*
385+
* @param method The method to call on the client.
386+
* @param args Arguments to pass to the client function.
387+
*/
388+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
389+
private _invokeClient<M extends keyof Client>(method: M, ...args: any[]): void {
390+
const top = this.getStackTop();
391+
if (top && top.client && top.client[method]) {
392+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
393+
(top.client as any)[method](...args, top.scope);
394+
}
395+
}
396+
392397
/**
393398
* Calls global extension method and binding current instance to the function call
394399
*/
395-
// @ts-ignore
400+
// @ts-ignore Function lacks ending return statement and return type does not include 'undefined'. ts(2366)
401+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
396402
private _callExtensionMethod<T>(method: string, ...args: any[]): T {
397403
const carrier = getMainCarrier();
398404
const sentry = carrier.__SENTRY__;
399-
// tslint:disable-next-line: strict-type-predicates
400405
if (sentry && sentry.extensions && typeof sentry.extensions[method] === 'function') {
401406
return sentry.extensions[method].apply(this, args);
402407
}
@@ -459,10 +464,10 @@ function getHubFromActiveDomain(registry: Carrier): Hub {
459464
const property = 'domain';
460465
const carrier = getMainCarrier();
461466
const sentry = carrier.__SENTRY__;
462-
// tslint:disable-next-line: strict-type-predicates
463467
if (!sentry || !sentry.extensions || !sentry.extensions[property]) {
464468
return getHubFromCarrier(registry);
465469
}
470+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
466471
const domain = sentry.extensions[property] as any;
467472
const activeDomain = domain.active;
468473

packages/hub/src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface Carrier {
2222
/**
2323
* These are extension methods for the hub, the current instance of the hub will be bound to it
2424
*/
25+
// eslint-disable-next-line @typescript-eslint/ban-types
2526
extensions?: { [key: string]: Function };
2627
};
2728
}

0 commit comments

Comments
 (0)